Reputation: 4928
I have a system that posts messages to an Azure Service Bus topic. The topic has multiple subscribers and I am writing a webJob to process the messages.
When I care a new WebJob project in Visual Studio, I get a class called 'Functions.cs', which has code to check a queue. I have updated the code to check a subscription within a topic:
public static void ProcessTopicMessage([ServiceBusTrigger("topic-name", "subscription-name")] string message, TextWriter log)
{
// Processing goes here
}
The topic has multiple subscriptions, which I need to monitor and then perform different actions for each message that is received. This will involve connecting to third-party services through API's, a different API for each subscription.
Example:
topic-name
subscription-1 // Perform action #1
subscription-2 // Perform action #2
subscription-3 // Perform action #3
...
My question is: Should I write a separate WebJob for each subscription or should I add additional methods into the 'Functions.cs' class?
I wonder if the performance will reduce if I have multiple methods in the same WebJob and if I need to make the methods asyncronous.
Upvotes: 2
Views: 1412
Reputation: 4456
Creating a web job per each subscription or one web job for all depends on your requirement.
ex:
How much time does it take to process a request?
Answering this question will determine if more than one subscription will highly impact the performance or not
Is there an SLA for this time?
If you have an SLA for each request, then you may need to scale the web job into different one for each subscription, otherwise, one will be enough
Are there any special configuration for each subscription?
If all subscriptions share the same connection, configuration, then you may not need separate web job for each subscription.
You can also you the strategy pattern, and move each subscription to its own class for implementing the logic specific to each one
Upvotes: 1
Reputation: 18465
My question is: Should I write a separate WebJob for each subscription or should I add additional methods into the 'Functions.cs' class?
According to your requirement, you have multiple subscriptions which subscrible the same Topic and each subscription has the different logic to deal with the same message.
Per my understanding, since the multiple subscriptions share the same configuration(App Settings of Azure ServiceBus) and each subscription handles the similar logic. Multiple functions could reuse the same host which could be scaled to multiple instances. I assumed that multiple functions in the same WebJob is a better approach for you.
I wonder if the performance will reduce if I have multiple methods in the same WebJob and if I need to make the methods asynchronous.
As I known, the JobHost
would start a thread from the managed thread pool, when your functions are triggered. You could configure the maximum number of concurrent calls to handle the messages from ServiceBus as follows:
ServiceBusConfiguration.MessageOptions.MaxConcurrentCalls=20 //16 by default
Since you would invoke a third-party API, you could mark your function as asynchronous to increase scalability of your WebJob. Also, there is an issue about async for performance, you could refer to it.
Upvotes: 1