Officially: No it is not supported. you could raise a feature request here
https://github.com/Particular/NServiceBus.RabbitMQ/issues or your can run a forked version of the nsb.rabbit transport with your own customisations
Unofficially you can leverage the CustomMessageIdStrategy feature to monkey patch the current exchange back into the headers.
Add this class
public static class ExchangeCapture
{
public static string InjectExchange(BasicDeliverEventArgs deliverEventArgs)
{
var properties = deliverEventArgs.BasicProperties;
properties.Headers["CurrentExchange"] = deliverEventArgs.Exchange;
if (!properties.IsMessageIdPresent() || string.IsNullOrWhiteSpace(properties.MessageId))
{
throw new InvalidOperationException("A non empty message_id property is required when running NServiceBus on top of RabbitMq. If this is a interop message please make sure to set the message_id property before publishing the message");
}
return properties.MessageId;
}
}
Then in your bus config add
busConfiguration.UseTransport<RabbitMQTransport>()
.CustomMessageIdStrategy(ExchangeCapture.InjectExchange)
Then in your handler you can do
public class MyHandler : IHandleMessages<MyMessage>
{
IBus bus;
static ILog logger = LogManager.GetLogger(typeof(MyHandler));
public MyHandler(IBus bus)
{
this.bus = bus;
}
public void Handle(MyMessage message)
{
logger.Info("Hello from MyHandler");
logger.Info("Current exchange:" + bus.CurrentMessageContext.Headers["CurrentExchange"]);
}
}