MSMQ - Messages Processed Again and Again

We use MSMQ and an integration mechanism that processes messages. This mechanism parses and checks each message in a transactional context, and if the check fails, a rollback occurs and the message is returned to the queue. In addition, the integration engine expects 20 seconds to process error messages.

The problem is that this approach causes error messages to be processed many times, even if we clear the queue. We also tried to clear the cache, but this also did not show results.

Does anyone have a clue?

Updated with call code

using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew)) { //message validation function servicoIntegracao.Validar(identificadorMensagem, mensagem.Substring(_tamanhoCampoTipoEvento)); servicoIntegracao.ExecutarServico(); AtualizarStatusEventoNegocio(identificadorMensagem, Status.Finalizado); retorno = 0; ts.Complete(); } 
+4
source share
1 answer

Instead of rolling back the read operation, you should update the message and reinstall it.

The first thing you need to do is create an unsuccessful check queue for messages that you do not want to process again. (It’s useful to keep messages looking for problems, and the queue is a natural place.)

Further, if you want to retry only once, you can write it to the retry queue and change the verification process so that it sends failures coming from the retry queue to the failed verification queue.

If you want to retest more than once, you must change the message format to include the number of attempts and increase this number each time the process reorders the message.

Once the message reaches the maximum allowed attempts, your process may send it to the failed verification queue.

In MSMQ, you don’t have to change the format of the message: you can use Message.Extension to store the number of attempts, although it usually frowned - as this property documentation says: "If possible, you should include the message data in the Message body property, and not an Extension property. "

+3
source

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


All Articles