从 Node 连接到 Local ServiceBus 的连接字符串

Connection String to connect to Local ServiceBus from Node

我正在尝试使用 Node.js 连接到 Windows 服务总线的本地实例。

我已经从 powershell 获得了我的连接字符串:

PS C:\Users\Juan> Get-SBClientConfiguration
Endpoint=sb://juan-vaio/MyNamespace;StsEndpoint=https://juan-vaio:9355/MyNamespace;RuntimePort=9354;ManagementPort=9355

但是,当使用 azure-node 包从 Node 使用此连接字符串时,出现以下错误:

代码

var connectionString = "Endpoint=sb://localhost/MyNamespace;StsEndpoint=https://localhost:9355/MyNamespace;RuntimePort=9354;ManagementPort=9355";
var serviceBusService = Azure.createServiceBusService(connectionString);

错误

      throw new Error('Invalid connection string setting key "' + key + '"');
            ^
Error: Invalid connection string setting key "runtimeport"

我曾尝试删除连接字符串的运行时端口设置,但由于 ManagementPort 而失败。如果我删除那个一二,它最终会因为设置不完整而无法连接:

  throw new NoMatchError('The provided connection string "' + connectionString
        ^
NoMatchError: The provided connection string "Endpoint=sb://localhost/MyNamespace;StsEndpoint=https://localhost:9355/MyNamespace;" 
does not have complete configuration settings.

谷歌搜索了一下,我发现这似乎是一个已知问题:

https://github.com/Azure/azure-sdk-for-node/issues/1254

但我想知道是否有解决此问题的方法,或者我是否做错了什么。

Azure SDK for Node 专为 Microsoft Azure 服务总线而设计,不适用于 Windows 服务器上的服务总线。所以不能直接用它来连接本地Service Bus。

他们的连接字符串不同,见下:

对于 Azure 服务总线,公式如下: Endpoint=sb://<azure-sb-name>.servicebus.windows.net/;SharedAccessKeyName=<key-name>;SharedAccessKey=<key> 对于 Windows 服务器上的服务总线,公式如下:Endpoint=sb://yourHost/ServiceBusDefaultNamespace;StsEndpoint=https://yourHost:9355/ServiceBusDefaultNamespace;RuntimePort=9354;ManagementPort=9355

根据官方文档 https://msdn.microsoft.com/en-us/library/dn441376.aspx,Windows 服务器的服务总线提供 REST API 类似于 Microsoft Azure 服务总线提供的 API。

所以你可以参考 Azure Service Bus REST APIs https://msdn.microsoft.com/en-us/library/hh780717.aspx 并将 Azure 的参数替换为本地的。

但是,我建议您在 dotNet 中使用 Windows 服务器 SDK 的服务总线(https://msdn.microsoft.com/en-us/library/dn441398.aspx and https://msdn.microsoft.com/en-us/library/dn441414.aspx), or refer to the doc https://msdn.microsoft.com/en-us/library/dn574799.aspx 尝试从 Java 连接 AMQP。