I have a WebJob which reads messages from an event topic, processes them and then creates a message on a different topic.
I can achieve this easily using a service bus trigger.
public void EventSubscriptionToNotificationTopic(
[ServiceBusTrigger(Subscribe.TopicName, Subscribe.SubscriptionName)] BrokeredMessage input,
[ServiceBus(Publish.TopicName)] out BrokeredMessage output)
To do this we have to use a service bus connection string which contains a shared access key which permits send and listen permissions at a level which has access to both topics (root).
We would like to be able to use different connection strings/SAS tokens locked down to permissions we need on these topics (Listen on event topic subscription and Send for the topic to publish to).
Is at all possible to specify which connection a service bus trigger or attribute would use?
If not would I have to roll my own, maybe just using the service bus trigger and WebJob connection string to read the message and then use a TopicClient to create a new message on the publish topic?
There is a ServiceBusAccountAttribute
that let you specify the connection string you want to use. you'll also need to specify the AccessRights
:
so your code can look this:
public void EventSubscriptionToNotificationTopic(
[ServiceBusTrigger(Subscribe.TopicName, Subscribe.SubscriptionName, AccessRights.Listen),
ServiceBusAccount("Topic1Listen")] BrokeredMessage input,
[ServiceBus(Publish.TopicName, AccessRights.Send),
ServiceBusAccount("Topic2Send")] out BrokeredMessage output)
{
...
}
Topic1Listen
and Topic2Send
are the names of the connection in your app.config but in the config file you need to prefix the name of the connectionstring with AzureWebJobs
So in your config file you'll need two connectionstrings that looks like that:
<connectionStrings>
...
<add name="AzureWebJobsTopic1Listen" connectionString="..." />
<add name="AzureWebJobsTopic2Send" connectionString="..." />
</connectionStrings>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With