【问题标题】:Send message to MassTransit Saga in ASP.Net Core application在 ASP.Net Core 应用程序中向 MassTransit Saga 发送消息
【发布时间】:2019-11-27 12:58:03
【问题描述】:

我在 Asp.Net Core 应用程序中有一个简单的 saga 配置:

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&lt;IRequestCreated&gt; 向 Saga 发送消息:

var client = context.RequestServices.GetService<IRequestClient<IRequestCreated>>();
var response = await client.GetResponse<RequestCreatedResponse>(new
{
    CorrelationId = Guid.NewGuid(),
    ClientId = 1,
});

一切正常。但是如果我在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

我错过了什么?

【问题讨论】:

    标签: c# asp.net-core masstransit saga


    【解决方案1】:

    在上面的示例中,由于没有为请求客户端指定服务地址,因此它正在发布请求。哪个被路由给消费者。

    在您失败的情况下,您使用的是发送,它没有地址需要知道将消息发送到哪里。唯一的后备是未配置的约定。如果您想要相同的行为,老实说,由于您要发布 RequestCreated 事件,您也应该调用 Publish。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-22
      • 2015-11-25
      相关资源
      最近更新 更多