0
votes

I am trying to connect to a service bus queue in Microsoft Azure using PHP, using the following code found on the Azure guide:

<?php
    require_once 'vendor/autoload.php';
    use MicrosoftAzure\Storage\Queue\QueueRestProxy;
    use MicrosoftAzure\Storage\Common\Exceptions\ServiceException;
    use MicrosoftAzure\Storage\Queue\Models\CreateMessageOptions;
    $connectionString = "DefaultEndpointsProtocol=https;AccountName="name";AccountKey=key";
    // Create queue REST proxy.
    $queueClient = QueueRestProxy::createQueueService($connectionString);
    try{
        // Create message.
        $builder = new ServicesBuilder();
        $queueClient->createMessage("cmps297r1", "Hello World!");
    }
    catch(ServiceException $e){
        // Handle exception based on error codes and messages.
        // Error codes and messages are here:
        // http://msdn.microsoft.com/library/azure/dd179446.aspx
        $code = $e->getCode();
        $error_message = $e->getMessage();
        echo $code.": ".$error_message."<br />";
    }
?>

However, when I run it, I get this error:

Catchable fatal error: Argument 4 passed to MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy::__construct() must be an instance of MicrosoftAzure\Storage\Common\Internal\Serialization\ISerializer, array given, called in /Applications/XAMPP/xamppfiles/htdocs/297R/vendor/microsoft/azure-storage/src/Queue/QueueRestProxy.php on line 110 and defined in /Applications/XAMPP/xamppfiles/htdocs/297R/vendor/microsoft/azure-storage/src/Common/Internal/ServiceRestProxy.php on line 77

2
Could you post the full source code? From your code I don't see whether you have created queue or not yet. Note that the code below belongs to Azure Storage Queue, not Service Bus Queue.EagleDev

2 Answers

0
votes

The code you pasted looks fine to me (except that you didn't include use statement for ServicesBuilder class which would cause an "Class not found" error).

And as @Thuan Ng mentioned the code above belongs to Azure Storage Queue, not Service Bus Queue. You need to refer to this documentation How to use Service Bus queues with PHP if you are using Azure Service Bus.

0
votes

I Know this is an old Post but you are trying to create a storage queue and not a service bus queue