0

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.

Robert Iagar
  • 155
  • 2
  • 13

2 Answers2

0

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://learn.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.

Aaron Chen
  • 9,835
  • 1
  • 16
  • 28
  • We'll be generating sas keys in our backend. We thought of using the Node.js SDK on the client side for reading messages. That's why I asked if there is a way of using the Node SDK for reading messages with SAS keys. We're switching to using the REST API to read the messages in node using 'https' model. – Robert Iagar Feb 16 '17 at 09:58
0

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

Community
  • 1
  • 1
Le Roi Beukes
  • 70
  • 1
  • 7