0
votes

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.

2
I have seen it, but that was in 2014, I thought the SDK changed a bit since then.Robert Iagar

2 Answers

0
votes

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.

0
votes

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