What I Would like to do: Log the producer name in the consumer who published the message
My setup: A simple web application to Publish the message
Publisher Code:
private static IBusControl _busControl;
private static async Task<IBusControl> GetBusControl()
{
if (_busControl == null)
{
var servicebusConnectionstring = <myservicebusconnection>;
_busControl = Bus.Factory.CreateUsingAzureServiceBus(conf =>
{
conf.Host(servicebusConnectionstring);
});
await _busControl.StartAsync();
}
return _busControl;
}
private static async Task PublishEvents<T>(IEnumerable<T> events) where T : class
{
var busControl = await GetBusControl();
var busSendMessages = events
.Select(c => busControl.Publish<T>(c))
.ToList();
await Task.WhenAll(busSendMessages);
}
I can see that the consumer receive the message successfully. So it's working perfectly. But I have found that the Host name (which I assume the message producer name) shows 'MassTransit'. I can assume that this is the only way we can get the Producer name in the consumer. On the other hand, instead of web application , if I make a simple console application as a Producer then I get the correct Host name. Is there any other way we can get the producer name into consumer class?