0

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?

enter image description here

Rob
  • 14,746
  • 28
  • 47
  • 65
Molay
  • 39
  • 7
  • No idea, must be something when using `iisexpress` as the host. – Chris Patterson Oct 18 '21 at 14:03
  • [Related information](https://stackoverflow.com/questions/34982970/getentryassembly-doesnt-appear-to-work-when-the-entry-assembly-is-asp-net) is likely explained in this question. – Chris Patterson Oct 18 '21 at 14:08
  • Thank you @ChrisPatterson.I'll look into more details on it. May I ask you, what is the Best way we can get the producer name into consumer class? Should I send the Producer name as header as mention here https://masstransit-project.com/usage/producers.html#message-initializers? – Molay Oct 18 '21 at 20:36
  • If it matters, you could sure. – Chris Patterson Oct 18 '21 at 20:41

0 Answers0