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

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.

主站蜘蛛池模板: 溧水县| 甘泉县| 井陉县| 新泰市| 曲阜市| 偏关县| 金门县| 靖远县| 南宁市| 葫芦岛市| 霸州市| 北海市| 林西县| 石门县| 彩票| 佛山市| 怀安县| 德昌县| 宁晋县| 永康市| 澄江县| 钦州市| 安化县| 红河县| 区。| 南充市| 工布江达县| 金门县| 普兰店市| 辽宁省| 宁河县| 盐池县| 日土县| 赤壁市| 岑溪市| 尤溪县| 高台县| 昭通市| 睢宁县| 六枝特区| 寻乌县|