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=";

    评论

报告相同问题?

悬赏问题

  • ¥15 优质github账号直接兑换rmb,感兴趣伙伴可以私信
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)