Message metadata depending on the current HTTP request

43 views
Skip to first unread message

Pedro Felix

unread,
Nov 18, 2016, 5:41:37 AM11/18/16
to masstransit-discuss
Hi, 

I have a scenario where bus messages are published from Web API controllers. In this scenario I want to automatically add metadata to the bus message that depends on the current HTTP request (e.g propagate a correlation ID), without having to do so explicitly on the send (e.g. using some "middleware" on the send pipeline that adds that metadata).

1) What would be the proper send "middleware" extensibility point to use?
2) Since the bus is singleton-scoped, how can I access the current request message in this "middleware"? I.e., how can I access request-scoped dependencies on the pipeline of a singleton-scoped bus.

Thanks
Pedro

Dru Sellers

unread,
Dec 12, 2016, 1:43:22 PM12/12/16
to masstrans...@googlegroups.com
Ok, here is what I would try to do.

I would start by adding a service class that does the message sending for you rather than letting the controllers have direct access to the bus or the GetSendEndpoint methods.

Then in your service you can do something like:

            _bus.GetSendEndpoint(new Uri("rabbitmq://localhost/some_endpoint")).Result.Send<PingMessage>(new {}, p =>

            {

                // lots of fun message pipe middle ware here to explore

                p.Headers.Set("Key","value");

            });


I don't know if we have a place to add generic outbound pipe configuration, but the possibility is there. We would need to look at a semantic like `Use` (which is what we use on the receiving side). and then we just let you configure the correct pipe that we send on.


-d


--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstransit-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/f1128732-4087-48b4-9226-36325426a038%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages