Is it possible to modify a message before retry

I wonder if it is possible to modify NServiceBus message in order to get the stored value on the next message handling attempt? To be more specific on use case: inside Nsb handler we’re calling service feeding number in certain range by round-robin like 1,2,3,4,5, 1,2,3,4,5, 1,… It’s important to utilize all released numbers eventually (after retries or after error queue re-processing). The easiest approach would be to store the next released number (one per handler call) inside the message, and if some exception occur down the road, on the next retry we’ll be able to check the number stored in the message, and if it’s not null, then just take another attempt to use it, no need to make another call to service-feeder.

As a workaround I think it could be 2 different handlers that runs the number feeder service and process the number, but makes things a bit more complicated, with more messages moving around. Before tackle to it, I would like to make sure there is no better solution. Thanks

Hi Yuri,

The new version of ServicePulse released a few weeks ago allows you manually edit the message body and header, before retrying. If these kind of issues need to be edited manually, this is a good fit. Please have a look at the documentation on our website.

Hope this helps,
Hadi

Hi @HEskandari, thank you for your response. I think you meant to modify message manually in ServicePulse by user. I would be rather interested in scenario when handler itself modifies the message so that in case of failure and further retry handler can see its own modifications made in the previous failed attempt to handle the message. Thanks

Yuri,

In that case, a behavior in the message processing pipeline would be a better fit. We have a sample that does that in-place message update. You can find it here.

Would that work for you?