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

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.

主站蜘蛛池模板: 吉木萨尔县| 汤原县| 蓬溪县| 余干县| 赤城县| 泰来县| 云安县| 曲周县| 普陀区| 长泰县| 丹江口市| 镇远县| 东丽区| 达拉特旗| 汝阳县| 百色市| 华蓥市| 石屏县| 会泽县| 迭部县| 聂荣县| 永定县| 衡山县| 扬州市| 临城县| 修文县| 象山县| 灵寿县| 丘北县| 鄂尔多斯市| 龙岩市| 大兴区| 江安县| 青浦区| 彭阳县| 资兴市| 泾阳县| 太谷县| 桐梓县| 芦溪县| 牟定县|