0
votes

I have a program that uses NServiceBus for queued messages mechanism. I see in the logs that sometimes a message is being handled twice, by different thread, though these messages are only sent once.

More so, if i enforce my service to use only 1 thread, i do not have this problem.

How can i ensure a message is only handled once?

Thank you.

Shortened log example (where you can see i get the message with chunkId 48, i finish processing everything including removing the callback, then i get the same message with chunkId 48 again, and at this point im unable to find the callback. and afterwards, an NserviceBus exception):

Risco.Rsp.RACServiceImpl.RACOutputMessageHandler [(null)] <(null)> - RACOutputMessageHandler.Handle start for ProcessType:GetClientCacheEntity with ProcessId:44eb600b-87e6-4eab-a54e-0a12480c9784 and ChunkId: 48 and TotalChunks: 57 and Topic: 23b041a3-4a62-48d1-a199-20a20e5de72a .... .... ... Risco.Rsp.RACServiceImpl.RACOutputMessageHandler [(null)] <(null)> - Sucessfuly sent result(s) for process id:44eb600b-87e6-4eab-a54e-0a12480c9784 with Process Type:GetClientCacheEntity, Client 44eb600b-87e6-4eab-a54e-0a12480c9784 (chunks 0 of 0) 2017-01-02 11:13:13,882 [64] INFO Risco.Rsp.RACServiceImpl.RACOutputMessageHandler [(null)] <(null)> - RACOutputMessageHandler.Handle start for ProcessType:GetClientCacheEntity with ProcessId:44eb600b-87e6-4eab-a54e-0a12480c9784 and ChunkId: 48 and TotalChunks: 57 and Topic: 23b041a3-4a62-48d1-a199-20a20e5de72a 2017-01-02 11:13:13,888 [64] INFO Risco.Rsp.RACServiceImpl.RACOutputMessageHandler [(null)] <(null)> - Handle(RACOutputMessage) - Unable to find callback for key 44eb600b-87e6-4eab-a54e-0a12480c9784, process id:44eb600b-87e6-4eab-a54e-0a12480c9784 with process Type:GetClientCacheEntity 2017-01-02 11:13:13,923 [158] ERROR NServiceBus.Timeout.TimeoutManagerDeferrer [(null)] <(null)> - There was a problem deferring the message. Make sure that DisableTimeoutManager was not called for your endpoint. NServiceBus.Unicast.Queuing.QueueNotFoundException: Exchange for the recipient does not exist ---> RabbitMQ.Client.Exceptions.AlreadyClosedException: Already closed: The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=404, text="NOT_FOUND - no exchange 'Risco.Rsp.Ac.AMAC.Service.Timeouts' in vhost 'AxesPlus'", classId=60, methodId=40, cause= at RabbitMQ.Client.Impl.ModelBase.WaitForConfirms(TimeSpan timeout, Boolean& timedOut) at RabbitMQ.Client.Impl.ModelBase.WaitForConfirmsOrDie(TimeSpan timeout) at NServiceBus.Transports.RabbitMQ.ConfirmsAwareChannel.Dispose() in c:\BuildAgent\work\ef98ad7376e3379a\src\NServiceBus.RabbitMQ\ConfirmsAwareChannel.cs:line 31 --- End of inner exception stack trace --- at NServiceBus.Transports.RabbitMQ.ConfirmsAwareChannel.Dispose() in c:\BuildAgent\work\ef98ad7376e3379a\src\NServiceBus.RabbitMQ\ConfirmsAwareChannel.cs:line 47 at NServiceBus.Transports.RabbitMQ.RabbitMqMessageSender.Send(TransportMessage message, SendOptions sendOptions) in c:\BuildAgent\work\ef98ad7376e3379a\src\NServiceBus.RabbitMQ\RabbitMqMessageSender.cs:line 27 at NServiceBus.Timeout.TimeoutManagerDeferrer.Defer(TransportMessage message, SendOptions sendOptions) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Timeout\Core\TimeoutManagerDeferrer.cs:line 42 2017-01-02 11:13:13,936 [174] ERROR NServiceBus.Timeout.TimeoutManagerDeferrer [(null)] <(null)> - There was a problem deferring the message. Make sure that DisableTimeoutManager was not called for your endpoint. NServiceBus.Unicast.Queuing.QueueNotFoundException: Exchange for the recipient does not exist ---> RabbitMQ.Client.Exceptions.AlreadyClosedException: Already closed: The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=404, text="NOT_FOUND - no exchange 'Risco.Rsp.Ac.AMAC.Service.Timeouts' in vhost 'AxesPlus'", classId=60, methodId=40, cause= at RabbitMQ.Client.Impl.ModelBase.WaitForConfirms(TimeSpan timeout, Boolean& timedOut) at RabbitMQ.Client.Impl.ModelBase.WaitForConfirmsOrDie(TimeSpan timeout) at NServiceBus.Transports.RabbitMQ.ConfirmsAwareChannel.Dispose() in c:\BuildAgent\work\ef98ad7376e3379a\src\NServiceBus.RabbitMQ\ConfirmsAwareChannel.cs:line 31 --- End of inner exception stack trace --- at NServiceBus.Transports.RabbitMQ.ConfirmsAwareChannel.Dispose() in c:\BuildAgent\work\ef98ad7376e3379a\src\NServiceBus.RabbitMQ\ConfirmsAwareChannel.cs:line 47 at NServiceBus.Transports.RabbitMQ.RabbitMqMessageSender.Send(TransportMessage message, SendOptions sendOptions) in c:\BuildAgent\work\ef98ad7376e3379a\src\NServiceBus.RabbitMQ\RabbitMqMessageSender.cs:line 27 at NServiceBus.Timeout.TimeoutManagerDeferrer.Defer(TransportMessage message, SendOptions sendOptions) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Timeout\Core\TimeoutManagerDeferrer.cs:line 42

1

1 Answers

0
votes

The problem was the timeout configuration. The MessageHandler wasnt quick enough to process the message and leave the handler, so i fixed it by creating a new Task that would 'replace' the handler (meaning, at the start of the handler invoke a function that replaces the original handler)