日期:2014-05-16  浏览次数:20516 次

rabbitmq php tutorial -1

Introduction


RabbitMQ is a message broker. In essence, it accepts messages from producers, and delivers them to consumers. In-between, it can route, buffer, and persist the messages according to rules you give it.

RabbitMQ 是一个消息代理。说白了,它从“生产者”接收消息,并将这些消息发送给“消费者”。在这个过程中,它可以根据你给定的规则对消息进行路由、缓冲和持久化。

RabbitMQ, and messaging in general, uses some jargon.(常用术语)

  • Producing means nothing more than sending. A program that sends messages is a producer. We'll draw it like that, with "P":

  • 生产无非就是发送。一个发送消息的程序就是一个“生产者”,我们用“P”来表示它。
  •  

  • A queue is the name for a mailbox. It lives inside RabbitMQ. Although messages flow through RabbitMQ and your applications, they can be stored only inside a queue. A queue is not bound by any limits, it can store as many messages as you like - it's essentially an infinite buffer. Many producers can send messages that go to one queue - many consumers can try to receive data from one queue. A queue will be drawn like this, with its name above it:

  • 队列就像是邮箱的名字。它存于RabbitMQ内部。尽管消息流贯穿于RabbitMQ和你的应用,但它只能存储于队列当中。队列不受任何限制,随便你存多少消息,看你心情-队列本质上是一个无穷大的缓冲区。 多个“消费者”可以发送消息给一个队列-多个“消费者”也可以从一个队列接收消息。我们这样来表示一个队列(如下),上面是它的名字。
  •  

  • Consuming has a similar meaning to receiving. A consumer is a program that mostly waits to receive messages. On our drawings it's shown with "C":

  • 消费意思就是接收。”消费者“通常是一个等待接受消息的程序。我们用“C”来表示。
  •  

Note that the producer, consumer, and broker do not have to reside on the same machine; indeed in most applications they don't.

注意:生产者、消费者和消息代理(中间人)不是必须在一个机器上,确实如此,大多数应用程序都这样。

"Hello World"

(using the php-amqplib Client)

In this part of the tutorial we'll write two programs in PHP; a producer that sends a single message, and a consumer that receives messages and prints them out. We'll gloss over some of the detail in the php-amqplib API, concentrating on this very simple thing just to get started. It's a "Hello World" of messaging.