大众运输:没有消费者 [英] Mass Transit : No consumer

查看:78
本文介绍了大众运输:没有消费者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个关于大众运输ESB的新手问题

Have a newbie question about Mass Transit ESB

我是第一次尝试MassTransit,并试图弄清如何创建队列以及如何使用消息.

I am trying MassTransit for the first time and trying to get my head around how the queues are created and how messages are consumed.

我有一个Web应用程序和一个Console应用程序试图分别发布/使用

I have a web application and a Console application trying to do publish / consume respectively

这是我的初始化代码.

var bus = Bus.Factory.CreateUsingRabbitMq(sbc =>
            {
                var host = sbc.Host(new Uri(hostName), h =>
                {
                    h.Username(userName);
                    h.Password(password);
                });

           });

然后从Web应用程序中调用以下代码.

Then from the web app i call the following code.

 using (Bus.Start())
            {
                var pubr = Bus.Publish<T>(message);

                pubr.Wait();

            }

这导致消息在Rabbit MQ中丢失.

This leads to the message being lost in Rabbit MQ .

如果在控制台应用程序中添加使用者,则可以使示例工作.

I can get the sample to work if I add a consumer in the console application.

 sbc.ReceiveEndpoint(host, 
                    e =>
                       e.Consumer<LoginEventConsumer>(d => { })
              { }

我的问题是,如果没有消费者,为什么我的信息会丢失?

My question is why does my message get lost if there are no consumers ?

Rabbit MQ似乎认为没有队列连接到交换机,因此消息丢失了.那是对的吗 ?有没有一种方法可以在初始化期间创建队列并一起交换,而不会因大量随机命名的队列/交换而使Rabbit MQ混乱?

It looks like Rabbit MQ believes that there is no queue connected to the exchange and hence the message is lost . Is that correct ? Is there a way to create queues and exchange together during initialization without cluttering Rabbit MQ with lots of randomly named queues / exchanges ?

在我对MassTransit/Rabbit MQ的工作方式的理解中,我似乎缺少了一些非常基本的知识.我本以为这是一个非常普遍的情况,即消费者注册发生在发布事件之后,并且一旦消费者连接,消费者将收到所有已发布的项目.

Looks like i am missing something very basic in my understanding of how MassTransit / Rabbit MQ works. I would have thought its a very common scenario that a consumer registration happens at a later point than the publish event and that the consumer will be sent all the items that have been published once it connects .

推荐答案

RabbitMQ由交换和队列组成.

RabbitMQ consists of exchanges and queues.

在发布消息时,MassTransit根据消息类型创建交换.发布不会创建任何队列.队列是存储消息以传递给消费者的地方.

Exchanges are created by MassTransit when publishing messages, based on the message types. Publishing does not create any queues. Queues are where messages are stored for delivery to consumers.

在将接收端点添加到总线时创建队列.对于添加到接收端点的使用者,处理程序和Sagas,将创建并绑定交换,以便接收端点(通过队列)接收发布到交换的消息.

Queues are created when receive endpoints are added to a bus. For the consumers, handlers, and sagas added to a receive endpoint, the exchanges are created and bound so that messages published to the exchanges are received by the receive endpoint (via the queue).

直到接收端点启动并且在RabbitMQ(交换交换队列绑定)中配置了它们的拓扑之前,发布的任何消息都不会传递,因为没有任何队列的绑定.启动接收端点后,这些绑定就存在了,消息将传递到队列中.

Until the receive endpoints are started, and their topology configured in RabbitMQ (the exchange-exchange-queue bindings), any messages published are not delivered because there are no bindings to any queues. Once the receive endpoints are started, those bindings exist and messages will be delivered to the queues.

这篇关于大众运输:没有消费者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆