MassTransit消费者引发注册消费者的“未找到消息类型{type}的约定”异常

时间:2020-07-06 15:10:57

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

我有一个简单的服务,可以在HTTP端点上接受请求。终结点的操作使用MassTransit发布事件,以提醒消费者实体已更新。然后,我的已发布事件的使用者将同步请求发送给我的同步使用者以完成工作单元。

但是,当事件使用者尝试分派请求时,MassTransit会抛出一个异常A convention for the message type {type} was not found。这似乎暗示我的消费者尚未注册,但我相信已经注册。

这是我的Startup注册代码:

public void ConfigureServices(IServiceCollection services)
{
    // -- removed non MassTransit code
    services.AddMassTransit(x =>
    {
        x.SetKebabCaseEndpointNameFormatter();
        x.AddConsumers(typeof(Startup).Assembly);
        x.UsingRabbitMq((context, cfg) =>
        {
            var rabbitMq = Configuration.GetSection("RabbitMq");
            var url = rabbitMq.GetValue<string>("Url");
            var username = rabbitMq.GetValue<string>("Username");
            var password = rabbitMq.GetValue<string>("Password");
            
            cfg.Host(url, h =>
            {
                h.Username(username);
                h.Password(password);
            });
            cfg.ConfigureEndpoints(context);
        });
    });
    services.AddMassTransitHostedService();
}

我的API控制器如下所示:

[Route("~/api/[controller]")]
public class JobSchedulingController : ApiControllerBase
{
    private readonly IPublishEndpoint _publishEndpoint;

    public JobSchedulingController(IPublishEndpoint publishEndpoint)
    {
        _publishEndpoint = publishEndpoint;
    }

    [HttpPost]
    public async Task<IActionResult> UpdateJob(JobSchedulingInputModel model)
    {
        await _publishEndpoint.Publish<JobSchedulerJobUpdated>(model);
        return Ok();
    }
}

这里是事件使用者:

public class JobSchedulerJobUpdatedConsumer 
    : IConsumer<JobSchedulerJobUpdated>
{
    public async Task Consume(
        ConsumeContext<JobSchedulerJobUpdated> context)
    {
        await context.Send<SyncJobSchedulingToLacrm>(context.Message);
    }
}

最后,同步请求使用者:

public class SyncJobSchedulingToLacrmConsumer 
    : IConsumer<SyncJobSchedulingToLacrm>
{
    private readonly LacrmClient _client;
    private readonly JobSchedulingContext _context;

    public SyncJobSchedulingToLacrmConsumer(
        LacrmClient client, 
        JobSchedulingContext context)
    {
        _client = client;
        _context = context;
    }

    public async Task Consume(ConsumeContext<SyncJobSchedulingToLacrm> context)
    {
        await context.Publish<JobSchedulerSyncedToLacrm>(new
        {
            LacrmPipelineItemId = ""
        });
    }
}

我从事件使用者中收到错误,并且从未到达同步使用者。是什么原因导致这种行为?

1 个答案:

答案 0 :(得分:2)

您正在呼叫发送,这是一种方便的方法。

ffmpeg -i input.mp3 -ar 8000 -ac 1 -ab 64 output.al -ar 8000 -ac 1 -ab 64 -f mulaw 

如果您尚未为该消息类型配置EndpointConvention,则找不到该消息类型。

我建议您阅读以下答案:https://stackoverflow.com/a/62714778/1882

相关问题