【发布时间】:2020-02-17 16:56:03
【问题描述】:
我无法弄清楚在发送/发布消息时如何在我的GetSendEndpoint()) 任务中指定Exchange 和Queue?
根据 MassTransit 文档https://masstransit-project.com/usage/producers.html#send,您可以像这样指定交换和队列
GetSendEndpoint(new Uri("queue:input-queue"))
但是,我只能做其中一个吗?
是否有指定交换和队列的替代发送方式?
我在 Asp.Net Core 中执行此操作,所以这是我的配置:
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMassTransit();
services.AddSingleton(p => Bus.Factory.CreateUsingRabbitMq(cfg =>
{
cfg.Host("rabbitmq://localhost", h =>
{
h.Username("admin");
h.Password("admin");
});
}));
services.AddSingleton<IBus>(p => p.GetRequiredService<IBusControl>());
services.AddSingleton<IHostedService, BusService>();
}
这就是发送消息的方式
var endpoint = await _bus.GetSendEndpoint(new Uri(queue:Test.Queue));
await endpoint.Send(new Message()
{
Text = "This is a test message"
});
如您所见,我只能指定队列名称。
【问题讨论】:
标签: c# rabbitmq masstransit