Reputation: 135
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
Upvotes: 2
Views: 1746
Reputation: 649
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);
});
}
}
Upvotes: 1