Reputation: 23087
I'm using my CustomFaultManager to process failed messages, so I can handle them just before putting them in error queue.
in
void IManageMessageFailures.ProcessingAlwaysFailsForMessage(TransportMessage message, Exception e)
{
I get TransportMessage and I have to get type from:
var header = message.Headers["NServiceBus.EnclosedMessageTypes"];
var messageType = MessageTypes.Where(x => x.AssemblyQualifiedName != null
&& header.Contains(x.AssemblyQualifiedName)).ToList();
and then apply my custom logic to unzip message (because I'm zipping large msmq messages). Is it possible to get in this method a message which is just like original message which I have in Handle
method?
Why this bothers me? For now I need to remember to apply changes in my custom error handler whenever I change serialization method or zipping method.
I would be happy if I could just cast TransportMessage to my custom message implementation just like:
var myMessage = message as MyCustomMessage;
Do you know guys if there is a way to do custom error handling in NServiceBus without doing manual deserialization?
I tried casting to my type of a message (as above), but it keeps giving me null as a result, because message is serialized in Message
field in TransportMessage
Upvotes: 1
Views: 401
Reputation: 170
We're also on an older version of NServiceBus (3.x). So far, our solution is to have our message handler catch any exceptions, and then wrap them in a custom exception that contains the values that we need from the message. We then throw this exception for NServiceBus to handle.
In our IManageMessageFailures.ProcessingAlwaysFailsForMessage
implementation, we invoke the appropriate error handler based on the the Exception type as well as the NServiceBus.EnclosedMessageTypes values.
Hope this helps.
Upvotes: 1