简体   繁体   中英

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? We want to use the SAS Key to read the messages from the subscription.

There is something a about SAS in the documentation but nothing concrete.

I can't figure it out.

Shared Access Signatures (SAS) are the primary security mechanism for Service Bus messaging. Normally, SAS tokens for Service Bus publishers are created with only sending and receiving privileges on a specific queue or topic. So you'd need to use the connection string to connect to an Azure Service Bus namespace instead.

This package allows you to easily generate a 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 .

For more information about working with SAS, see Shared Access Signature Authentication with 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 ?

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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