PHP code example of flaschenpost / azurelib
1. Go to this page and download the library: Download flaschenpost/azurelib library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
flaschenpost / azurelib example snippets
use WindowsAzure\Common\ServicesBuilder;
use WindowsAzure\Common\ServiceException;
$serviceBusRestProxy = ServicesBuilder::getInstance()->createServiceBusService($connectionString);
try {
$queueInfo = new QueueInfo("myqueue");
// Create queue.
$serviceBusRestProxy->createQueue($queueInfo);
} catch(ServiceException $e){
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}
try {
// Create message.
$message = new BrokeredMessage();
$message->setBody("my message");
// Send message.
$serviceBusRestProxy->sendQueueMessage("myqueue", $message);
} catch(ServiceException $e){
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}
try {
// Set the receive mode to PeekLock (default is ReceiveAndDelete).
$options = new ReceiveMessageOptions();
$options->setPeekLock(true);
// Receive message.
$message = $serviceBusRestProxy->receiveQueueMessage("myqueue", $options);
echo "Body: ".$message->getBody()."<br />";
echo "MessageID: ".$message->getMessageId()."<br />";
// *** Process message here ***
// Delete message.
$serviceBusRestProxy->deleteMessage($message);
} catch(ServiceException $e){
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}
try {
// Create topic.
$topicInfo = new TopicInfo("mytopic");
$serviceBusRestProxy->createTopic($topicInfo);
} catch(ServiceException $e){
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}
try {
// Create subscription.
$subscriptionInfo = new SubscriptionInfo("mysubscription");
$serviceBusRestProxy->createSubscription("mytopic", $subscriptionInfo);
} catch(ServiceException $e){
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}
try {
// Create message.
$message = new BrokeredMessage();
$message->setBody("my message");
// Send message.
$serviceBusRestProxy->sendTopicMessage("mytopic", $message);
} catch(ServiceException $e){
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}
try {
// Set receive mode to PeekLock (default is ReceiveAndDelete)
$options = new ReceiveMessageOptions();
$options->setReceiveAndDelete();
// Get message.
$message = $serviceBusRestProxy->receiveSubscriptionMessage("mytopic",
"mysubscription",
$options);
echo "Body: ".$message->getBody()."<br />";
echo "MessageID: ".$message->getMessageId()."<br />";
} catch(ServiceException $e){
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}
php composer.phar install