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

3
  • You should show some code of what you have tried so far Commented Nov 1, 2018 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 Commented Nov 2, 2018 at 18:50
  • You should probably post this as an answer to your own question because it helped me solve my issue (stackoverflow.com/questions/56360983/…). Commented May 29, 2019 at 16:14

1 Answer 1

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);
            });
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.