Just copy and paste this code if you ever need to authenticate against azure event hubs or service bus.
If you intend to use the API to interact with the service bus, you will need a SAS token which must be passed as an Authorization header porperty.
Let’s see how to generate this token.
Remember, this SAS key works for everything. You can create SAS for a queue, topic, subscription, event hub, or relay.
Prerequisite:
-Azure subscription. To use Azure services, including Azure Service Bus, you need a subscription. If you don't have an existing Azure account, you can sign up for a free trial.
-Visual Studio.
Steps:
-Create a queue in your service bus from Azure portal.
-Create a new Shared Access policy/key from the left hand side naviagation on Azure portal.
-Copy the connection string - it contains the key name, key, and the URI.
Insert the values into the sample code below.
Now that you know how to create Shared Access Signatures for any entities in Service Bus, you are ready to perform an HTTP POST to the azure service bus, just like I did in my previous post.
An important thing to remember is that if you change the primary key in the policy on Azure portal, any Shared Access Signatures created from it is invalidated.
Discussion about this post
No posts