2

I am trying to implement publish/subscribe architecture using Web API and Rabbit MQ message broker. I have two projects in my solution: Publisher and Subscriber.

Publishing is implementing successfully but I cannot find place in my subscriber project to read published message from the queue.

Both of my projects are .Net Core ASP WEB API

Thanks in advance

kakha
  • 115
  • 2
  • 8
  • You should show some code of what you have tried so far – matt_lethargic Nov 01 '18 at 13:27
  • Thanks for your response. I think I found out best practice of doing that. I registered rabbit as HostedService using AddSingleton method in ConfigureServices Method. IHostedService internally calls ApplicationGetStarted event. So rabbit starts listening there – kakha Nov 02 '18 at 18:50
  • You should probably post this as an answer to your own question because it helped me solve my issue (https://stackoverflow.com/questions/56360983/signalr-hub-resolves-to-null-inside-rabbitmq-subscription-handler-in-asp-net-cor). – Sandor Drieënhuizen May 29 '19 at 16:14

1 Answers1

1

Register rabbitMq as HostedService using the AddSingleton method in ConfigureServices Method. IHostedService internally calls ApplicationGetStarted event. So the rabbit starts listening there

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMassTransit(x =>
        {
            x.UsingRabbitMq();
        });

        // OPTIONAL, but can be used to configure the bus options
        services.AddOptions<MassTransitHostOptions>()
            .Configure(options =>
            {
                // if specified, waits until the bus is started before
                // returning from IHostedService.StartAsync
                // default is false
                options.WaitUntilStarted = true;

                // if specified, limits the wait time when starting the bus
                options.StartTimeout = TimeSpan.FromSeconds(10);

                // if specified, limits the wait time when stopping the bus
                options.StopTimeout = TimeSpan.FromSeconds(30);
            });
    }
}
Birhan Nega
  • 663
  • 12
  • 24
Mohm Zanaty
  • 544
  • 7
  • 27