As in title I wanted to ask is it possible to commit transaction in BeforeTransportMessage event so for example if specific headers occur in TransportMessage I could wrap it in another message and send somewhere else and stop Rebus from futher processing.
I didn't find any real life example of using that event, is there maybe something you could share?
Thanks in advance :)
If you can safely deserialize all incoming message, this is what you can do:
If you're trying to implement a filter that inspects all incoming messages, I suggest you create a "catch-all" message handler, i.e. an implementation of
IHandleMessages<object>
. Let's call itCatchAllHandler
, although I'm sure you can come up with a better name ;)Then you can
in order to have all incoming messages dispatched to your
CatchAllHandler
before any other handlers. Since it implementsIHandleMessage<object>
, it is capable of handling all incoming messages. YourCatchAllHandler
can then do something like this:If, however, you don't know whether the incoming
byte[]
is good for you, you need to do something else. It's fairly straightforward though to use Rebus' transport implementations without the rest of Rebus, but you'll have to implement the threading model yourself.The following code is an example (written completely from memory, so you might need to correct some small bits) on what such a worker thread might look like if you're using MSMQ:
You'd need a separate queue for this special kind of content-based router to work though. Do you think that would work for you?