Is Azure Service Bus BrokeredMessage already in use?

I have a problem with the Azure Service bus. Gradually placing a message on the bus raises the following exception:

TYPE: InvalidOperationException

MESSAGE: The operation could not be completed because the brokerage message "723eab13dab34351a78bb687d0923b89" has already been used. Use a new instance of BrokeredMessage to work.

Stacktrace

at Microsoft.ServiceBus.Messaging.MessagingUtilities.ValidateAndSetConsumedMessages(IEnumerable`1 messages) at Microsoft.ServiceBus.Messaging.MessageSender.Send(TrackingContext trackingContext, IEnumerable`1 messages, TimeSpan timeout) at Microsoft.Practices.TransientFaultHandling.RetryPolicy.<>c__DisplayClass1.<ExecuteAction>b__0() at Microsoft.Practices.TransientFaultHandling.RetryPolicy.ExecuteAction[TResult](Func`1 func) at IQ.IR.Core.ServiceBus.AzureBus`1.Enqueue(T message) in c:\BuildAgent\work\cc0c51104c02a4e9\IQ.IR.Core\ServiceBus\AzureBus.cs:line 69 ...Rest of stacktrace snipped as it within my app 

AzureBus Protection Code:

 public void Enqueue(T message) { using (var brokeredMessage = new BrokeredMessage(message) { Label = message.GetType().FullName, TimeToLive = _timeToLive }) { _retryPolicy.ExecuteAction(() => _sender.Send(brokeredMessage)); } } 

Where message T is transmitted,

 [Serializable] public class ValidationMessage { public string ValidationToken { get; set;} } 

And _retryPolicy is

 RetryPolicy<ServiceBusTransientErrorDetectionStrategy> 

_timeToLive is a 12-hour time span

Any ideas?

+6
source share
3 answers

An error indicates that a message has already been sent, but an error has occurred in the process. Unfortunately, there is no easy way to find out by checking the message, and the message cannot be reused again, as it is considered consumed. We are working on some improvements, for example, allowing you to query the status of such a message and throw a MessagingException instead of InvalidOperation. Finally, the ability to clone a message will help facilitate recovery from such failures.

+5
source

.... and push Abhishek the answer: right now you need to build a new BrokeredMessage for each retry, so your retry policy area should be one level further. Keep in mind that if you place a stream, we will use this stream as it is inside the broker message and pull it directly onto the wire, so you will need to make copies of the stream during the repetition cycle.

+5
source

Is it possible that a message could be sent even though an error occurred? Should the message be idempotent before trying to repeat in this case?

+1
source

Source: https://habr.com/ru/post/924796/


All Articles