Mr. T
Mr. T

Reputation: 4170

Azure ServiceBus ReceiveDeferredMessageAsync() Fails

I'm trying to implement the "message deferral" pattern in Azure ServiceBus and having trouble just getting a basic sample to work correctly. I'm using Microsoft.Azure.ServiceBus v5.0.0 and following advice from this SO question and this Microsoft Documentation.

// Send a message
var sender = new MessageSender("my_sb_connection_string", "my_queue_name", RetryPolicy.Default);
await sender.SendAsync(new Message());

// Receive the message, defer it and then receive the deferred message
var receiver = new MessageReceiver("my_sb_connection_string", "my_queue_name", 
                                   ReceiveMode.PeekLock, RetryPolicy.Default);

var msg = await receiver.ReceiveAsync();

await receiver.DeferAsync(msg.SystemProperties.LockToken);

var deferredMsg = await receiver.ReceiveDeferredMessageAsync(msg.SystemProperties.SequenceNumber);

Every time I call ReceiveDeferredMessageAsync(), I get an exception:

Microsoft.Azure.ServiceBus.MessageNotFoundException: Messages not found. One or more sequence numbers missing. 

I'm sure there's something simple that I'm doing wrong, but I can't see what it might be.

Upvotes: 0

Views: 1139

Answers (1)

Mr. T
Mr. T

Reputation: 4170

The problem turned out to be that I had the queue's "Max Delivery Count" setting at 1 - the message was going into the DLQ (apparently) because it hit max delivery count.

Changing Max Delivery Count to a value greater than 1 allows the `DeferAsync() call to properly mark the message as deferred.

That seems like a bug to me. https://github.com/Azure/azure-service-bus/issues/375

Upvotes: 1

Related Questions