我正在尝试使用 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/