Azure Service Bus: 1 client -> 1 queue approach - how to manage dead-letter queues? - azure

In my messaging app I decided to allocate an individual queue for a client. This way routing and security are quite easy. But I can't figure out how to deal with dead-letter queues then (when message expires, let's say). I want to use serverless approach with Azure functions to handle messages from DLQ. It's easy to setup to trigger a function when a message gets placed in a queue. But if I have 1000 clients, that would require 1000 functions?.. From what I can see you can attach a function to a single "trigger" - meaning single queue. Am I missing something here? what's the right approach to uniformly deal with DLQ messages?
Any help is appreciated. Thank you.

If your concern is how to deal with thousands of DLQs, one possible solution would be to configure your queues and set ForwardDeadLetteredMessagesTo property in each of the queue to point to another queue.
That way the dead-lettered messages from all the queues will go in a single queue and you can attach a Function to that queue for processing of such messages.

Related

Is it possible to set up a TTL on a ServiceBus Dead Letter Queue messages?

It is possible to set up TTL for messages in Azure Service Bus. I am wondering if there is a possibility to do the same for Dead Letter Queue?
What I want to achieve is "auto-cleaning" of the DLQ of the old messages that are probably not relevant anymore anyway, so that we don't need to do this manually (which is not supported out of the box either).
What I want to achieve is "auto-cleaning" of the DLQ of the old messages that are probably not relevant anymore anyway so that we don't need to do this manually (which is not supported out of the box either).
You can receive and delete messages from the dead-letter queue, but you cannot set up a TTL on the dead-lettered messages as those are created and moved into the sub-queue by the service. While the dead-letter queue mimics the regular queue in many concepts, it is not.
One of the semi-automated would be to create a process that peeks messages and completes based on the criteria you define, such as message age. Unfortunately, there's no good way to peek at messages in general. Not much can be done for the dead-lettered messages, other than peeking all and then filtering out those that need to be actioned.
Another alternative is to transition those dead-lettered messages into a database and then have a process to retire based on the defined criteria w/o the need to peek at all of the messages constantly.

Visibility timeout for part of consumers

I'm trying to create a resilient system based on Azure Storage Queue.
I have workers in two different Azure Regions that are processing messages from the same queue. I would like to prioritize the worker from the same region as a Queue before the worker from the second region will start handling the message.
My idea was to use a visibility timeout feature that will vary by worker type. Is it possible?
My idea was to use a visibility timeout feature that will vary by
worker type. Is it possible?
To the best of my knowledge, it is not possible. A message can only have a single visibility timeout that is set either when a message is sent to the queue or when a worker updates the message by dequeuing it.

Move all messages from deadletter queue back into main queue of subscription

My service consumes messages from an Azure Service Bus subscription. A dependency of my service was down for a while, which caused a lot of messages to end up in the deadletter queue (DLQ). Now that the service is back up, I want to reprocess all messages from the DLQ. How can I move/resubmit all messages from the DLQ back in to the main queue.
Restrictions:
It's thousands of messages, so manually handling them isn't feasible.
The topic has about ten subscriptions. I don't want to resubmit the messages to the topic, because then all subscriptions would receive the messages, leading to double-processing.
I don't want to run the service against the DLQ directly, because some messages are broken and cause permanent errors, i.e. they would end up in the DLQ again, which would lead to an infinite loop. Moreover, the broken messages are put back at the front of the queue, effectively starving healthy messages that come after the broken ones.
I realize this is a while after the original post but if anyone else stumbles on this problem, there is a fairly handy solution baked into the Service Bus Explorer (which I have found to be incredibly handy with ASB development).
After connecting to your Service Bus and finding the needed namespace, find the desired topic and subscription with the deadletters in it. From there Right Click and Receive Deadletter Queue Messages and hit OK.
From there, highlight which you would like to send back to the main queue and hit Resubmit Selected Messages in Batch Mode.
Thomas, you probably already found your answer since this is quite awhile ago. think of DLQ (or any existing queue that you have) as just another collection variable like in a PC app, but residing on the cloud. just like a PC-app or in-memory collection variable from your tool-kit, you have many ways of utilising it. off course there are limitations and differences between these 2 types of collection variables, but that's how you design your solution as though the DLQ is just another collection variable by knowing those limitations and differences.
For some queuing implementations, one of the solutions would be to have another instance of the same app pointing to the DLQ, but with a fairly long visibility timeout (e.g. 6 or 12 or even 24 hours depending on your SLA), since you don't want to repeat them too often. However, this is not applicable to Azure service bus, as it limits the visibility timeout to at most 5 minutes.
if the DLQ contains broken un-recoverable jobs, you should fix the app to delete them based on the error messages when the unknown exception occurred. once the fix is deployed, such broken un-recoverable jobs would have been removed by your app and never get sent to the DLQ in the first place. and those already in the DLQ will be removed by the fixed app.
The only option to replay DLQ messages is to receive them from DLQ, create new message with same content and send it again to the topic. They will end up at the end of subscription queue.
You can't send messages directly to the subscription. There is a trick to add a metadata property to the message, and then adjust all except one subscription to filter out such messages. It's up to you to decide if it's going to help in your scenario.
As for tooling, we always did that with custom code, because we always needed some extra work to be done, like logging each replayed message for further analysis.
The quick answer is that you cannot directly move messages back to the main queue of a subscription. This is by design with how Microsoft implemented their topics and subscriptions.
Option #1
There is the option to use Azure Service Bus topic filters https://learn.microsoft.com/en-us/azure/service-bus-messaging/topic-filters and define/tag your messages in a manner that would only allow them to be received on the targeted subscription.
Option #2
The other option would be to change your current implementation. You would set up "delivery queues" (regular service bus queues) and configure each corresponding subscription to auto forward its messages to these delivery queues. Your message processing logic would then listen on these "delivery queues" vs the subscription. Any failures would then result in DLQ messages on these associated "delivery queues" which could then be handled outside of the topic/subscriptions.

Competing-Consumers Messaging Pattern in Azure Service Bus

I'm just getting started with Windows Azure Service Bus (Topics & Queues) and I'm trying to implement a Competing-Consumers messaging pattern.
Essentially, I want to have a set of message Producers and a set of message Consumers. Once a message is produced, I want the first available Consumer to process the message. No other Consumers should get the message.
Is there a way to do this in Azure?
Simple. Just make two (or more) receivers that concurrently receive from a single queue and you're done. Any retrieved message goes to exactly one of those receivers since the cursor over the mesasage log is advanced as a message is taken. Competing consumers are an inherent capability of a networked queue so there's really nothing special needed.
If you need the opposite - each message goes to each consumer - you make a subscrioption per consumer which gives you an isolated cusor over the message log that can move independent of other receivers. For kicks, you can obviously also have competing consumers on a subscription.
Clemens
Topics are a feature of brokered messaging, but are a one-to-many "publish/subscribe" pattern. Queues are one-to-one message communication. So yes, it sounds like you should simply use queues. Also see http://msdn.microsoft.com/en-us/library/hh689723(VS.103).aspx.
You probably don't want Topics then, but rather Brokered Messaging.
You can emulate Topic-like functionality in Brokered Messaging by using the message's Label and/or Content Type properties along with the PeekLock receive mode.

Azure Queue Async Messages

We are thinking of speparate Queues for:
Request (RequestQueue)
Response (ResponseQueue)
Scenario:
Worker role will putMessage to RequestQueue e.g. GetOrders
Third party will monitor RequestQueue. If they see GetOrders
request they will getMessage, process them and put the response in
ResponseQueue.
Question:
If I putMessage to RequestQueue, I will like to get results back from ResponseQueue. Is there easy way to achieve this and how?
Thank you.
No, this is not possible. If you put a message in a queue, you must pop the message from the same queue (it will not magically appear in any other queue). Perhaps if you explained more why you think you need two separate queues here for push/pop, there might be a more expansive answer and suggestion.
EDIT: Perhaps I misunderstood your intent. I guess I don't get the question now - can you help clarify. You seem to be asking how to put a message on one queue, acknowledge it by putting another message on another queue, and have someone read the acknowledgment from the second queue? What is the question here? I should point out that you won't want some 3rd party to read directly from a Windows Azure queue as that would require sharing the master storage key with them (a non-starter). Perhaps you are looking for how to have 3rd parties read from a queue?
EDIT 2: Sounds like you want to consume messages with a 3rd Party. Windows Azure queues probably are not a good fit as I mentioned due to security reasons (you need to share the master key). Instead, you could either layer a WCF service over the queue (using queues via proxy) or use the queueing from the Service Bus - that will allow you to have separate credentials. Using the Service Bus capability might be the right choice here in terms of simplicity. Take a look here for demos.
Have a worker of some sort monitor the question queue, then post an answer to the answer queue. Interface out the queue managers and you shouldn't have any problems using any sort of queue tech. Also, the worker doesn't really need to use a queue for answers..
Caveats:
Worker service has access to both queues
Each queue item contains a serialized foreign key to identify themselves.

Resources