![](/img/trans.png)
[英]How to configure MassTransit Saga in Asp.Net Core application
[英]Send message to MassTransit Saga in ASP.Net Core application
我在Asp.Net Core應用程序中有一個簡單的傳奇配置:
services.AddSingleton<ISagaRepository<Request>, InMemorySagaRepository<Request>>();
services.AddMassTransit(x =>
{
x.AddSagaStateMachine<RequestStateMachine, Request>();
x.AddRequestClient<IRequestCreated>();
x.AddBus(provider => Bus.Factory.CreateUsingInMemory(cfg =>
{
cfg.UseInMemoryOutbox();
cfg.ConfigureEndpoints(provider);
}));
});
如果以后我通過IRequestClient<IRequestCreated>
向Saga發送消息:
var client = context.RequestServices.GetService<IRequestClient<IRequestCreated>>();
var response = await client.GetResponse<RequestCreatedResponse>(new
{
CorrelationId = Guid.NewGuid(),
ClientId = 1,
});
一切正常。 但是,如果我通過IBus
嘗試相同的IBus
:
var mtbus = context.RequestServices.GetService<IBus>();
await mtbus.Send<IRequestCreated>(new
{
CorrelationId = Guid.NewGuid(),
ClientId = 1,
});
我收到錯誤A convention for the message type Sample.AspNetCore.Host.Saga.IRequestCreated was not found
我想念什么?
在上面的示例中,由於未為請求客戶端指定服務地址,因此它正在發布請求。 哪個路由到消費者。
在失敗的情況下,您使用的是發送,沒有地址的發送者需要知道將消息發送到哪里。 唯一的后退是沒有配置的約定。 老實說,如果您想要相同的行為,因為您要發布RequestCreated
事件,則也應該調用Publish。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.