发布/ .NET与RabbitMQ的订阅样本 [英] Publish/Subscribe samples with RabbitMQ in .NET

查看:334
本文介绍了发布/ .NET与RabbitMQ的订阅样本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了这个示例:入门:在.NET RabbitMQ的,但做2个节目:

I've built this sample: Getting Started With RabbitMQ in .net, but made 2 programs:


  • 一个出版商

  • 一户

我用 BasicPublish 公布和 BasicAck 来聆听示例所示。如果我的用户运行一个发布和若干从每只有个出版者一个用户得到它发送消息。所以,有一些顺序(如用户已启动),其中发行人发送消息给用户,我想发一条消息给所有用户。什么是错的样品?可能是你能提供通过RabbitMQ的工作出版商/订户信息交换的样本?

I'm using BasicPublish to publish and BasicAck to listen as in example. If I run one publisher and several subscribers-on every "send message" from publisher- only one subscriber gets it. So that there is some order (as subscribers were started) in which publisher sends message to subscribers, and I want to send one message to all subscribers. What is wrong with that sample? May be you can provide working sample of publisher/subscribers message exchange via RabbitMq?

推荐答案

您链接到该示例使用简单的队列,而不交换,从而确保只有一个消费者将处理消息。为了支持RabbitMQ的发布/订阅,您需要首先创建Exchange,然后让每个用户绑定一个队列上上市。然后,生产商将消息发送到交易所,这将发布消息,已绑定到它的每个队列(至少用简单的扇出交换类型。路由可以直接和主题​​的交流来实现。)

The example you link to uses simple queueing without an exchange, which ensures that only a single consumer will handle the message. To support pub/sub in RabbitMQ, you need to first create an Exchange, and then have each subscriber bind a Queue on that Exchange. The producer then sends messages to the Exchange, which will publish the message to each Queue that has been bound to it (at least with the simple Fanout exchange type. Routing can be achieved with Direct and Topic exchanges.)

对于Java样品(这可以很容易地转换为C#)请参阅的这里

For a Java sample (which could be converted to C# pretty easily) please see here.

编辑:
更新.NET版本可以发现的这里

这篇关于发布/ .NET与RabbitMQ的订阅样本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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