AMQP

AMQP可以看做是RabbitMQ一个Client,安装的话

Linux比如Debian

sudo apt-get install amqp-tools

OS X下也可以安装

brew install amqp

 

安装好之后,如果有环境变量问题,可以自行修改PATH

首先,依旧启动RabbitMQ Server

~ on  master! ⌚ 18:53:56
$ sudo /usr/local/Cellar/rabbitmq/3.5.6/sbin/rabbitmq-server start
Password:

              RabbitMQ 3.5.6. Copyright (C) 2007-2015 Pivotal Software, Inc.
  ##  ##      Licensed under the MPL.  See http://www.rabbitmq.com/
  ##  ##
  ##########  Logs: /usr/local/var/log/rabbitmq/rabbit@localhost.log
  ######  ##        /usr/local/var/log/rabbitmq/rabbit@localhost-sasl.log
  ##########
              Starting broker... completed with 10 plugins.

 

然后,这里发送端依旧用之前python脚本

#!/usr/bin/env python
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters('127.0.0.1'))
channel = connection.channel()
channel.queue_declare(queue='myqueue')
channel.basic_publish(exchange='',routing_key='myqueue',body='Congratulations!')
print 'Send Congratulations!'
connection.close()

执行三次

~ on  master! ⌚ 19:02:30
$ python send.py
Send Congratulations!

~ on  master! ⌚ 19:02:36
$ python send.py
Send Congratulations!

~ on  master! ⌚ 19:02:37
$ python send.py
Send Congratulations!

这里先执行TX

 

最后,通过AMQP的tools工具来接收,注意终端显示的时间,RX的确是后执行的,正好收到了三次

~ on  master! ⌚ 19:04:01
$ amqp-consume --queue=myqueue cat
Congratulations!Congratulations!Congratulations!

发表评论