durable subscriber pattern with azure service bus - azure

I'm looking to use Azure Service Bus with topics but need to handle the scenario where a subscriber might not be listening for a message it's interested in (e.g. server being rebooted etc.). This is the typical durable subscriber pattern as described here http://www.eaipatterns.com/DurableSubscription.html.
What I can't work out is how to apply this with Azure Service Bus and I can't seem to find any examples or discussion of this in the documentation. Is this something that Azure service bus provides or should I start looking at alternatives to Azure Service Bus?

This is built straight into Service Bus. As long as a subscription is created it is durable. You create a topic and then create one or more subscriptions. One or more consumers then listen to a subscription when they are active. If they go inactive, such as the server being rebooted, then the subscription stores the messages until a consumer comes back up and asks for one.
Service Bus would only be nondurable if you were creating and destroying subscriptions on the fly as each consumer becomes active or becomes inactive. If there are no subscriptions then messages sent to a topic are lost. Once you create a subscription, any messages sent to the topic (if they pass any filters applied) will be available on the subscription regardless if there are any active consumers using that subscription. Subscriptions exist until you remove them or, if you have the idle removal feature turned on, they surpass the idle deletion time.
You can verify this with a simple console application, or using LinqPad to set up code that does the following:
Create a topic.
Create a subscription on that topic (no filters)
Send a few messages to the topic.
In a different script or console app, create a MessageReceiver for that subscription and pull down the messages.
The messages within a subscription are durable for the life of that subscription, until they are processed (completed, etc.), they are forwarded somewhere else or they expire.

I am not sure where you looked for documentation, following are good to read:
1) http://azure.microsoft.com/en-us/documentation/articles/service-bus-dotnet-how-to-use-topics-subscriptions/
2) http://code.msdn.microsoft.com/windowsazure/Simple-Publish-Subscribe-d406eb03

Related

how to send a message to azure service bus Topic (subscription using) Logic app send message connector?

I have a Azure service bus Topic with two subscriptions.
I want to send a message to topic from logic app using send message connector. How to send the message to a specific subscription.
Now it takes only topic name and does not have property to accept subscription name, how can i implement the same.
thanks in advance.
Unfortunately, that is not possible (just not with logic apps, but in general)
This is how a topic and subscription works.
A Service Bus topic provides an endpoint for sender applications to
send messages.
Each subscription of a topic gets a copy of the message sent to the topic.
Topics and subscriptions provide a one-to-many form of communication.
Having, said that you can configure filters at the Subscription end. This will facilitate receiving only those messages meeting the criteria from the central pool. When you want a specific subscription to receive it. You could send the message such a way that it matches the filter condition.
So, something like this :
Image Source
100 messages are sent to the topic, but are split to each subscription as 30,45,25 based on the filter rule. the messages that did not meet filter are not made available to the subscription.
In your case, you need set filters for both the subscription. Trigger the message such a way that it matches only for one of the subscription.
Alternatively, if it is going 1:1 - you could make use of the Queue.
References to set up filters at subscription level :
Filters Service Bus
Filtering the Service Bus
Stackthread on the implementation
A subscription in Service Bus is an isolated view into the messages of a Topic, essentially a copy of the messages private to the subscription. This allows multiple consumers to process topic messages without competing with one another.
You can't publish messages messages directly to a subscription, only to the topic that the subscription is associated with. All subscriptions associated with the topic will have access to the message.
If you are looking to send messages for a single consumer (or a set of competing consumers), a Service Bus queue may be a better fit for your scenario.

Using Azure App Configuration for dynamic configuration in a microservice environment

I have tried to find out how I can notify multiple microservice (MS) instances via eventdriven approach if their Azure App Configuration values are changed. I have found that I via Eventgrid can listen on changes in Azure App Configuration but I don't find any built in method to distribute event to multiple instances (many MS instances)... I can choose webhook but then it will be to one instance, I can choose other eventdriven approaches as Event Hub but then I have to setup that and I wonder what is best practice for this? I don't want each MS to poll for changes rather to be notified and receive what has been changed or is there a better built in approach/strategy?
For push-based configuration updates from Azure App Configuration, the suggested approach is to forward events to a Service Bus Topic. Azure Service Bus SDK provides RegisterMessageHandler method that allows clients to register a message handler that would be triggered for every message recieved in the topic. Each instance of the microservice could set up a subscription to this Service Bus Topic and register a message handler during service initialization to receive configuration updates.
The instructions to set up a service bus topic can be found here. Details on the protocols available to subscribe to service bus topics and the required firewall configuration can be found here. Since a single topic can support up to 2000 subscriptions, this approach would allow up to 2000 service instances.

Azure Service Bus: How to achieve eventual consistency when a subscriber goes down

Currently I am using Azure Service Bus as a means to communicate and keep data consistent among the different services in my platform. However, let's say that one of my services (subscribers) goes down for an extended period of time and is unable to receive any events. Suddenly this service is in an inconsistent state.
Does Azure Service Bus have any type of "event sourcing" solution in place in order to replay my events? I understand that Azure Event Hubs has this feature where I can store events in an append only fashion to azure blob storage. However, the only thing I am finding for Azure Service Bus is the dead letter queue and my understanding that this is only used when no subscribers are capable of processing an event.
Is this something that I will have to build myself?
All events stored in a subscription will be delivered once the consumer is up and running unless the subscription has DefaultMessageTimeToLive (TTL) set to purge messages.

Azure Service Bus synchronize all masterdata

Let's say I've got an azure service bus in a microservice scenario.
One microservice pushes master data changes to the other services with a subscription.
Now let's say a new service is introduced and subscribes to the master data service. How can I make sure that the new service receives all neccessary data?
Do I have to resend all master data on the master data service or does the azure service bus (or alternatives) provide some features for that?
As far as I know there is no way to achieve what you want within the capabilities of Azure Service Bus. Also, I don't think this what Service Bus is there for.
Of course there is a configurable "time to live" value for messages within queues and topics, which could probably be set to some really high value, but this would still not make your master data be infinitely available for future services. And - but this is just my opinion and I'm far from being an expert - I wouldn't want to load up my service bus with potentially thousands or even millions of messages (depending on what you're doing) without them being processed quickly.
For your specific concern I'd rather implement something like a "master data import service" without any service bus integration. Details of this, however, depend on your environment and specific requirements.
Couple of points:
1) This is not possible with Azure Service bus. Even If you set TTL at Topic level, the messages will only be delivered to available subscriptions at that point of time. you cant read messages directly from Topic.
2) you can consider Eventhub option where you can create new consumer group with offset from when you want to start reading messages but Eventhub has maximum retention period as 7 days. If you need message retention beyond 7 days, enabling Event Hubs Capture on your event hub pulls the data from your event hub to the Storage account. But in this case you would require additional logic to read from this storage account to replay the messages.

Pattern to determine if a specific message is still queued in an Azure Service Bus

I have a pusher which brokers message x into an Azure Service bus. This is a customer request for some order.
A consumer comes along and wants to know "what is the state of message x"? I'd like to know as much as I can about message x, but at a minimum I need to answer "yes/no" is it still in the queue? Is there a recommended pattern for this within Azure Service Bus?
In View content of an Azure Service Bus queue Clemens Vasters explains that there is no browse feature available in Service Bus Queues/Topics at the moment. The only way to know the state is by storing it externally (take Table Storage for example).

Resources