dpv21589 2016-07-01 08:44
浏览 143

Azure Service Bus中的绝对HTTP(S)请求URL

I'm trying to setup a basic connection towards Azure's Service Bus using PHP and can't get it to work. I get the error:

1: HTTP_Request2 needs an absolute HTTP(S) request URL, 'sb://mynamespace.servicebus.windows.net/myqueue/messages' given

This is the code I'm now trying to run:

<?php
    require_once '../vendor/autoload.php';

    use WindowsAzure\Common\ServicesBuilder;
    use WindowsAzure\Common\ServiceException;
    use WindowsAzure\ServiceBus\Models\BrokeredMessage;

    // Create Service Bus REST proxy.
    $connectionString = "Endpoint=sb://mynamespace.servicebus.windows.net/;SharedSecretIssuer=owner;SharedSecretValue=[MyVal]";
    $serviceBusRestProxy = ServicesBuilder::getInstance()->createServiceBusService($connectionString);

    try {
        // Create message.
        $message = new BrokeredMessage();
        $message->setBody("my message");

        // Send message.
        $serviceBusRestProxy->sendQueueMessage("myqueue", $message); // this is the line that causes the error
    }
    catch(Exception $e){
        // Handle exception based on error codes and messages.
        // Error codes and messages are here: 
        // http://msdn.microsoft.com/library/windowsazure/hh780775
        $code = $e->getCode();
        $error_message = $e->getMessage();
        echo $code.": ".$error_message."<br />";
    }
?>

I don't understand where this is going wrong. Anyone have any idea what I can do to prevent this error?

  • 写回答

2条回答 默认 最新

  • duandeng1824 2016-07-01 09:08
    关注

    Based on the comments here, it seems you're getting this error because you're using an older way of connecting to Azure Service Bus. Please use Shared Access Signature based connection string that you can get from Azure Portal. It should be in the following format:

    $connectionString = "Endpoint=<namespacename>.servicebus.windows.net;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=<your_key_from_the_portal>";
    

    From the comments:

    Hi Martin, thank you for the feedback. You are correct, the connection string in this example uses the old ACS format, while the portal produces strings that use the newer Shared Access Signature token (see https://msdn.microsoft.com/lib... for more info). I will get this topic updated ASAP.

    You should be able to just substitute the new connection string from the portal. Make sure it is in the correct format. It should be something like

    $connectionString = "Endpoint=.servicebus.windows.net;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=";

    评论

报告相同问题?