rabbitmq的消息模式

rabbitmq的消息模式(message pattern)

rabbitmq的消息模型是基于交换器(exchange),队列(queue)和它们之间的绑定(bingdings),有以下几种:

  • For point-to-point communication between the publisher and the broker, you can use a default or a direct exchange in order to deliver a message to a single queue.However, note that there might be multiple subscribers to this single queue, thus implementing publish-subscribe between the broker and the message receivers bound to that queue.
  • For publish-subscribe, we can use a fanout exchange, which will deliver a message from an exchange to all queues that are bound to this exchange; in this manner, we may have a queue-per-subscriber strategy for implementing publish-subscribe.
  • For request-response communication, we can use two separate exchanges and two queues; the publisher sets a message identifier in the message header and sends the request message to the request exchange, which in turn delivers the message to the request queue. The subscriber retrieves the message from the request queue, processes it, and sends a response message to the response exchange by also setting the same message identifier found in the request message to the response message header. The response exchange then delivers the message to a response queue. The publisher is subscribed to a response queue in order to retrieve response messages and uses the message identifier from the response message header to map the response message to the corresponding request message.
  • For message routing we can use a topic exchange in order to deliver messages based on a binding key pattern or a headers exchange based on one or more headers

大概意思:

  • 点对点方式,发生在pushlisher和broker之间,可以使用默认或者是direct类型的交换器将消息分发到一个单一队列。但是,要注意的是一个队列可能会被多个消费者订阅,因此对于绑定在同一队列的broker和消息接收者之间需要实现发布-订阅的模式
  • 发布订阅方式,使用的是fanout类型的交换器,这种交换器会把消息颁发到所有与这个交换器绑定的队列上,在这种方式下,实现发布-订阅是基于一个队列一个订阅者的策略
  • 请求响应方式(也就是RPC方式),使用两个不同的交换器和两个不同的队列;发布者在消息的头部设置唯一编号,并将消息发送到request的交换器上,然后由这个request交换器将消息转发到请求队列上。订阅者从请求队列中接收并处理消息,然后也在响应的消息头部加入从请求消息中获取的唯一编号,并把响应消息发送到response的交换器上,然后response交换器将消息转发到响应的队列串。消息发布者订阅了这个响应队列去获取响应的消息,使用响应消息头部中的唯一编号去匹配相关联的请求消息
  • 路由方式,使用的是topic类型的交换器,转发消息是通过匹配binding key或者是headers类型的交换器基于一个或多个headers

point-to-point

publish-subscribe

request-response

message routing

你可能感兴趣的:(rabbitmq)