0

I am trying to receive all messages for a given subscription to a Service Bus Topic, but for the context of this app I do not want them dead lettered at this time, I just want to view them and leave them on the subscription. Despite instantiating the Client as

SubscriptionClient sc = SubscriptionClient.CreateFromConnectionString(connectionString, sub.topicName, sub.subscriptionName, ReceiveMode.PeekLock);

and making sure that I am using message.Abandon() rather than message.Complete() the message always gets Dead-lettered after accessing the message. I also have options.AutoComplete set to false

full method code below:

public List<ServiceBusMessage> RetrieveSubscriptionMessages(Subscription sub) {
        ServiceBusMessage sbm;
        List<ServiceBusMessage> list = new List<ServiceBusMessage>();
        String connectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"].ToString();
        SubscriptionClient sc = SubscriptionClient.CreateFromConnectionString(connectionString, sub.topicName, sub.subscriptionName, ReceiveMode.PeekLock);
        OnMessageOptions options = new OnMessageOptions();
        options.AutoComplete = false;

        sc.OnMessage((message) => {
            try {

                sbm = new ServiceBusMessage() {
                    topicName = sub.topicName, 
                    messageText = message.GetBody<String>()
                };

                list.Add(sbm);
                message.Abandon();
            }

            catch (Exception) {
                message.Abandon();
                throw;
            }

        }, options);

         return list;
    }

Am I missing something ? Or is there an issue with auto dead-lettering with the onMessage() method?

Thanks !

Adamski343
  • 39
  • 9
  • Ok, so I have dug a little deeper and it looks like the messages are being Dead Lettered due to a MaxDeliveryCountExceeded error, apparently there are 11 attempts to send each message which exceeds the default max of 10. Why is each message being delivered 11 times using the OnMessage method, or is this a red herring? Is the deliveryAttempts being set to 11 somewhere else to ensure that the message gets dead lettered? – Adamski343 Sep 01 '15 at 14:52

1 Answers1

1

When a message is abandoned the service bus will immediately make it available for re-delivery to any subscriber of the topic.

If you are trying to configure a multicast mechanism in which multiple listeners all receive the same message, then understand that all listeners on a given subscription will be competing for the same message. In order for every listener to receive its own copy of the message, then simply create a unique subscription to the topic for each listener.

If your intent is to delay re-delivery of the abandoned message, you might look at the SO question: What's the proper way to abandon an Azure SB Message so that it becomes visible again in the future in a way I can control?

Community
  • 1
  • 1
John Hoerr
  • 7,955
  • 2
  • 30
  • 40