简体   繁体   English

如何使用SAS密钥通过Node.js SDK连接到Azure Service Bus订阅?

[英]How to connect to an Azure Service Bus subscription with the Node.js SDK using SAS Keys?

Is there a way to connect to an Azure Service Bus Subscription using a Shared Access Signature Key in the Node.js SDK? 有没有一种方法可以使用Node.js SDK中的共享访问签名密钥连接到Azure服务总线订阅? We want to use the SAS Key to read the messages from the subscription. 我们要使用SAS密钥从订阅中读取消息。

There is something a about SAS in the documentation but nothing concrete. 文档中有关于SAS内容,但没有具体内容。

I can't figure it out. 我不知道。

Shared Access Signatures (SAS) are the primary security mechanism for Service Bus messaging. 共享访问签名(SAS)是服务总线消息传递的主要安全机制。 Normally, SAS tokens for Service Bus publishers are created with only sending and receiving privileges on a specific queue or topic. 通常,仅在特定队列或主题上具有发送和接收特权的情况下创建服务总线发布者的SAS令牌。 So you'd need to use the connection string to connect to an Azure Service Bus namespace instead. 因此,您需要使用连接字符串来连接到Azure Service Bus命名空间。

This package allows you to easily generate a Shared Access Signature: https://github.com/mitchdenny/shared-access-signature . 该软件包使您可以轻松生成共享访问签名: https : //github.com/mitchdenny/shared-access-signature

About how to send a message to a Service Bus queue or topic using a SAS token via REST API, you can refer to https://docs.microsoft.com/en-us/rest/api/servicebus/send-message-to-queue . 关于如何通过REST API使用SAS令牌将消息发送到服务总线队列或主题的方法,可以参考https://docs.microsoft.com/zh-cn/rest/api/servicebus/send-message-to -队列

For more information about working with SAS, see Shared Access Signature Authentication with Service Bus . 有关使用SAS的更多信息,请参阅使用Service Bus进行共享访问签名身份验证

In response to your comment: 针对您的评论:

Understood but without creating an instance , you wont be able to do anything with regard to service bus operations - these include being able to read messages from the subscription no ? 理解但没有创建实例,您将无法对服务总线操作进行任何操作-这些功能包括能够从订阅中读取消息?

So in theory your code should look something like this : 因此,理论上,您的代码应如下所示:

var serviceBusConnectionString = "Endpoint=sb://somens.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=mykey";

var retryOperations = new azure.ExponentialRetryPolicyFilter();
var serviceBusService = azure.createServiceBusService(serviceBusConnectionString).withFilter(retryOperations);

serviceBusService.receiveSubscriptionMessage('MyTopic', 'LowMessages', function(error, receivedMessage){
    if(!error){
        // Message received and deleted
        console.log(receivedMessage);
    }
});

More info here 更多信息在这里

Original : 原件

Check this one out as well followup stackoverflow answer , Combined these two links should sort you out ? 检查一下这个以及后续stackoverflow的答案 ,结合这两个链接应该可以把您整理出来?

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM