是否可以从启动时直接连接到多个公共交通队列?

Is it possible to connect to multiple masstransit queues directly from startup?

services.AddMassTransit(config =>
        {
            config.AddConsumer<Consumer1>();
            config.UsingRabbitMq((ctx, cfg) => {
                cfg.Host("amqp://guest:guest@localhost:5672");

            
                cfg.ReceiveEndpoint("firstqueue", c => {
                    c.ConfigureConsumer<Consumer1>(ctx);
                });


            
            });

我需要从一个队列中获取一些请求,然后将它们发布到另一个队列中。这就是我连接到其中一个的方式,我试图直接添加它,但我没有成功,因为我不能有 3 个参数

发布消息时不需要连接任何队列。您只需使用 IPublishEndpoint 发布到地址 described in the docs。您 发布到队列,这就是它被称为发布 的原因。如果需要 Send,则使用 ISendEndpoint 实例。 Send 方法需要一个地址。

仅当您需要使用 消息时才连接 到队列(和交换)。

使用 MassTransit,如果您在消费者内部发送或发布,建议使用 ConsumeContext。您可以使用 context.Publishcontext.GetSendEndpoint.