php - Azure 服务总线中的绝对 HTTP(S) 请求 URL

标签 php azure servicebus

我正在尝试使用 PHP 设置与 Azure 服务总线的基本连接,但无法使其正常工作。我收到错误:

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

这是我现在尝试运行的代码:

<?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 />";
    }
?>

我不明白哪里出了问题。有人知道我可以采取什么措施来防止此错误吗?

最佳答案

基于评论here ,您似乎收到此错误,因为您使用的是较旧的方式连接到 Azure 服务总线。请使用可从 Azure 门户获取的基于共享访问签名的连接字符串。它应该采用以下格式:

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

来自评论:

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

关于php - Azure 服务总线中的绝对 HTTP(S) 请求 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38140898/

相关文章:

php - 在 PHP 中解码和访问 json 字典数组

excel - 如何在 Azure 逻辑应用中解析 Excel 电子表格

sql-server - 使用 EF Core、Docker 和系统分配标识从 Web 应用程序访问 Azure SQL

c# - Azure:如何从服务总线队列中删除 "DeadLettered"消息

java - RabbitMQ Java 客户端到 Windows 服务总线

php - __construct 函数未按预期工作

php - 从 HTML 表单发送变量

php - 表格内的下拉菜单 - 然后更新

Azure Cosmos DB 每个分区大小限制

ssh - 代理/ServiceBus/反向SSH