RabbitMQ is a post box, a post office and a postman.
RabbitMQ, and messaging in general, uses some jargon.
RabbitMQ 中的专有名词
名称 | 描述 |
---|---|
producer | Producing means nothing more than sending. A program that sends messages is a producer |
queue | A queue is the name for a post box which lives inside RabbitMQ. Although messages flow through RabbitMQ and your applications, they can only be stored inside a queue. A queue is only bound by the host's memory & disk limits, it's essentially a large message buffer. Many producers can send messages that go to one queue, and many consumers can try to receive data from one queue. |
consumer | Consuming has a similar meaning to receiving. A consumer is a program that mostly waits to receive messages: |
connection | The connection abstracts the socket connection, and takes care of protocol version negotiation and authentication and so on for us. Here we connect to a broker on the local machine - hence the localhost. If we wanted to connect to a broker on a different machine we'd simply specify its name or IP address here. |
channel | where most of the API for getting things done resides |
发送方式
named queue

Work Queues

Publish/Subscribe

There are a few exchange types available: direct, topic, headers and fanout
exchange type | desc |
---|---|
fanout | The fanout exchange is very simple. As you can probably guess from the name, it just broadcasts all the messages it receives to all the queues it knows. |
direct | The routing algorithm behind a direct exchange is simple - a message goes to the queues whose binding key exactly matches the routing key of the message. |
topic | Messages sent to a topic exchange can't have an arbitrary routing_key - it must be a list of words, delimited by dots. The words can be anything, but usually they specify some features connected to the message. A few valid routing key examples: "stock.usd.nyse", "nyse.vmw", "quick.orange.rabbit". There can be as many words in the routing key as you like, up to the limit of 255 bytes. |
direct exchage

这个图以日志为例,C1 只想打印error 日志到文件,而C2 需要打印所有日志到控制台。Q1 需要 绑定 exchange 通过 routeKey error 。
而 Q2 需要绑定 exchange 通过 routeKey info 、 error 、warning 。
topic exchage

topic exchange 和 direct exchange 的主要区别是binding key 的 形式。
不是通过具体的key ,而是通过规则去匹配。
* (star) can substitute for exactly one word.
# (hash) can substitute for zero or more words.
参考地址
https://www.rabbitmq.com/tutorials/tutorial-one-java.html
网友评论