SzymonPobiega / NServiceBus.Router

Cross-transport, cross-site and possibly cross-cloud router component for NServiceBus
MIT License
5 stars 10 forks source link

Transform messages #32

Closed Adam-MagmaSw closed 4 years ago

Adam-MagmaSw commented 4 years ago

Hi,

Is there a way to configure the router to transform messages on the way through? I can see there are Rules which look like they might be useful but I can't tell whether the messages are immutable from within a rule.

Thanks

Adam

SzymonPobiega commented 4 years ago

Hi @Adam-MagmaSw

The Router has not been designed with this use case in mind but I am pretty sure it is doable using a rule in the PreroutingContext. This is the only stage of the routing engine that allows replacing the body (as byte[]). Further down the line the body is readonly. I haven't tested this myself, though.

An alternative would be to use a simple NServiceBus.Raw endpoint or full NServiceBus endpoint. The downside of the former is the fact that is very low level.

Adam-MagmaSw commented 4 years ago

Thanks for getting back to me Szymon

gursharan001 commented 3 years ago

Hello, just a comment on this. We were wanting to do something similar - JSON <-> XML. In pre-routing, body can be changed but not the headers. In post-routing, headers can be changed but not the body. So how do I change content type header and body at the same time?