Putting service bus messages in deadletter queue

I’m using azure service bus in my project and I’m trying to put messages in the deadletter queue “manually”.

Basically:

 private static async ValueTask OnQueueItemAdded([NotNull] ServiceBusMessage<SomeMessage> arg)
        {
            try
            {
                DoSomething(arg.Message);
            }
            catch (Exception e)
            {
                Log.Error("Error", e);
                arg.PutInDeadLetter();
            }
        }

Is this possible? :slight_smile:

Litium version: [7.6.3]

I remember Dead Letter Queue gets populated when some queue or topic fails internally when a job/task is running not that you can put your own stuff there.

Hmm, that’s not really true I believe.

Looking at the litium source code in this file:

Litium.Infrastructure.MicrosoftServiceBus -> internal class ServiceBusInternal<T>

there is a lot of code putting messages in deadletter (I think), for example:

I’m trying to figure out the correct way (if there is a way) of doing it using the litium api which is what’s being exposed :slight_smile:

Ok I see… not sure of best way of approach on this but some good info here

Yeah but I know how to do it using the microsoft service bus api but I want to do it using the api exposed by litium :slight_smile:

No, it’s not possible to do that with usage of Litium’s API.

You have any plans of adding that? :slight_smile:

No, we have not any plan to adding that. The connection for MS Azure Service Bus for Litium is not upgraded to Litium 8 and the recommendation is to use our Redis implementation instead.

@patric.forsgard @steve.redstorm

How does the Redis implementation deal with this.

  • Do we have the possibility to add messages to a dead-letter queue?
  • Does a message get automatically transferred to a dead-letter queue in case an exception gets thrown when a subscriber is processing the message.

When using the Microsoft Azure Service Bus the dead letter queue is used for messages that not is understandable, example malformed json or references to a type that not exists. If an exception is thrown during execution the Abandon method is invoked that stops the current execution of the message. When the retry count for a message is reached the Service Bus will automatic put it in dead letter. If the project not handle the dead letters manually they will be removed automatic from the dead letter queue regarding to the settings on the queue.

When using Redis the concept of dead letters does not exists and messages that is malformed will be sent to the error log. If an exception happens during execution the message is logged and if not the retry count for a message is reached the message is put back into the queue again, otherwise discarded.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.