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

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.

主站蜘蛛池模板: 东辽县| 华容县| 内江市| 宜君县| 手游| 阳朔县| 长沙县| 东阳市| 山阴县| 宁南县| 资兴市| 周口市| 湖口县| 堆龙德庆县| 思茅市| 邵阳市| 涟水县| 灌阳县| 武宣县| 五家渠市| 海城市| 崇明县| 廉江市| 万源市| 延长县| 江川县| 海原县| 犍为县| 周口市| 出国| 林周县| 小金县| 崇仁县| 汾西县| 桂东县| 大姚县| 六盘水市| 太和县| 榆林市| 逊克县| 宿迁市|