官术网_书友最值得收藏!

Message subscriptions

Now that we have shown you what a deployment message looks like, let's discuss what happens when you subscribe to a message.

An EasyNetQ subscriber subscribes to a message type (the .NET type of the message class). Once the subscription to a type has been set up by calling the Subscribe method, a persistent queue will be created on the RabbitMQ broker and any messages of that type will be placed on the queue. RabbitMQ will send any messages from the queue to the subscriber whenever it is connected.

To subscribe to a message, we need to give EasyNetQ an action to perform whenever a message arrives. We do this by passing the Subscribe method a delegate such as this:

bus.Subscribe<MyMessage>("my_subscription_id", msg => Console.WriteLine(msg.Text));

Now, every time an instance of MyMessage is published, EasyNetQ will call our delegate and print the message's Text property to the console.

主站蜘蛛池模板: 本溪市| 朝阳区| 扎兰屯市| 广水市| 松滋市| 怀宁县| 大安市| 盐津县| 永丰县| 拜城县| 新泰市| 富宁县| 瑞安市| 汉寿县| 航空| 鄱阳县| 汕尾市| 女性| 集贤县| 博兴县| 洛扎县| 西乌珠穆沁旗| 方山县| 奉新县| 当阳市| 临武县| 湘阴县| 县级市| 宜春市| 祥云县| 吉木乃县| 沽源县| 盱眙县| 将乐县| 嫩江县| 邢台市| 精河县| 静宁县| 丽江市| 章丘市| 东乌|