Asp.Net核心Web API订阅RabbitMQ的位置



我正在尝试使用Web API和Rabbit MQ消息代理实现发布/订阅架构。我的解决方案中有两个项目:Publisher和Subscriber。

发布正在成功实施,但我在subscriber项目,以便从队列中读取已发布的消息。

我的两个项目都是.Net核心ASP WEB API

提前感谢

使用ConfigureServices方法中的AddSingleton方法将rabbitMq注册为HostedService。IHostedService内部调用ApplicationGetStarted事件。所以兔子开始在那里听

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);
});
}
}

最新更新