作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道我是否做错了什么,我预计 MassTransit会自动注册 ReceiveEndpoints
在 EndpointConvention
.
示例代码:
services.AddMassTransit(x =>
{
x.AddServiceBusMessageScheduler();
x.AddConsumersFromNamespaceContaining<MyNamespace.MyRequestConsumer>();
x.UsingAzureServiceBus((context, cfg) =>
{
// Load the connection string from the configuration.
cfg.Host(context.GetRequiredService<IConfiguration>().GetValue<string>("ServiceBus:ConnectionString"));
cfg.UseServiceBusMessageScheduler();
// Without this line I'm getting an error complaining about no endpoint convention for x could be found.
EndpointConvention.Map<MyRequest>(new Uri("queue:queue-name"));
cfg.ReceiveEndpoint("queue-name", e =>
{
e.MaxConcurrentCalls = 1;
e.ConfigureConsumer<MyRequestConsumer>(context);
});
cfg.ConfigureEndpoints(context);
});
});
我以为这条线
EndpointConvention.Map<MyRequest>(new Uri("queue:queue-name"));
没有必要在不指定队列名称的情况下允许发送到总线,或者我错过了什么?
await bus.Send<MyRequest>(new { ...});
最佳答案
EndpointConvention
是一种方便的方法,它允许在不指定端点地址的情况下使用 Send。 MassTransit 中没有任何东西会自动配置它,因为坦率地说,我不使用它。而且我认为其他人也不应该这样做。也就是说,人们确实出于任何原因使用它。
首先,考虑一下后果——如果每个消息类型都注册为端点约定,那么在多个端点上发布和使用的消息呢?那行不通。
因此,如果您想按消息类型路由消息,MassTransit 有一个功能。它叫Publish
而且效果很好。
But wait, it's a command, and commands should be Sent.
KickTheTiresAndLightTheFires
,这是正确的。消息合约,发布和发送一样好,你不需要知道地址!
IEndpointNameFormatter
根据通过
AddConsumer
注册的类型生成接收端点队列名称,
AddSagaStateMachine
等,如果您想在不指定目标地址的情况下使用 Send,则可以使用相同的接口(interface)来注册您自己的端点约定。
string queueName = formatter.Consumer<T>()
将该字符串用于该消费者中的消息类型作为
$"queue:{queueName}"
地址并将其注册到 EndpointConvention 上。
Publish
.
关于Masstransit EndpointConvention Azure 服务总线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62713786/
我想知道我是否做错了什么,我预计 MassTransit会自动注册 ReceiveEndpoints在 EndpointConvention . 示例代码: services.AddMassTrans
我是一名优秀的程序员,十分优秀!