I’ve been trying to implement IHandleSagaNotFound interface to catch and log all commands and messages that can’t be handled by Saga or handlers. The problem is that I can’t seem to get the Handle on IHandleSagaNotFound to be executed when an unknown ICommand is sent to the endpoint.
15:41:35.051 INFO Immediate Retry is going to retry message '153c6f30-669c-4500-b092-af0100d11e2d' because of an exception:
System.InvalidOperationException: No handlers could be found for message type: Messages.UnknownCommand
I had an assumption that IHandleSagaNotFound’s Handle method should be called instead.
I had an assumption that IHandleSagaNotFound’s Handle method should be called instead.
This is not the case. The not found handler is only called for messages that both
are recognized (implement IMessage) or match the convention
are mapped to a saga type that handles it
The exception you get is what gets raised when the latter condition is not met. Is the NServiceBus way of logging that case not enough for your requirements?
Ah, so IHandleSagaNotFound is called only when an IMessage handling instance of Saga for some reason is missing in runtime?
Yeah. The most common scenario is that a reply to a message send by a saga arrives after a given saga has already been completed. Note, that the behavior is different for timeout messages. If these arrive and the saga instance is no longer there, the message is silently dropped.
Thanks.
In the end I created a new Behavior with IIncomingLogicalMessageContext. I added try/catch in the Invoke method to handle InvalidOperationException.