Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1792113
  • 博文数量: 335
  • 博客积分: 4690
  • 博客等级: 上校
  • 技术积分: 4341
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-08 21:38
个人简介

无聊之人--除了技术,还是技术,你懂得

文章分类

全部博文(335)

文章存档

2016年(29)

2015年(18)

2014年(7)

2013年(86)

2012年(90)

2011年(105)

分类: Python/Ruby

2012-12-01 14:13:00

之所以对mq感兴趣,是因为IBM的MQ,想看看到底它是做什么东西,由于mainframe的东西测试比较麻烦因此
先学习一下rabbitmq,整体上有一个理解,
后续可能会继续深入一点,运维的东西不好做啊,涉及的东西比较多。
准备步骤:
下载python
下载 
下载 rabbitmq-server-3.0.0
下载 mQ的组件  otp_win32_R15B02_with_MSVCR100_installer_fix
安装pika,需要说明的是在安装完python,安装pika的时候需要手动安装

点击(此处)折叠或打开

  1. C:\Python27\Scripts>easy_install.exe pip
  2. Searching for pip
  3. Reading http://pypi.python.org/simple/pip/
  4. Reading http://www.pip-installer.org
  5. Reading http://pip.openplans.org
  6. Best match: pip 1.2.1
  7. Downloading http://pypi.python.org/packages/source/p/pip/pip-1.2.1.tar.gz#md5=db
  8. 8a6d8a4564d3dc7f337ebed67b1a85
  9. Processing pip-1.2.1.tar.gz
  10. Running pip-1.2.1\setup.py -q bdist_egg --dist-dir c:\users\kinfin~1\appdata\loc
  11. al\temp\easy_install-l9uerz\pip-1.2.1\egg-dist-tmp-y6ihcs
  12. warning: no files found matching '*.html' under directory 'docs'
  13. warning: no previously-included files matching '*.txt' found under directory 'do
  14. cs\_build'
  15. no previously-included directories found matching 'docs\_build\_sources'
  16. Adding pip 1.2.1 to easy-install.pth file
  17. Installing pip-script.py script to C:\Python27\Scripts
  18. Installing pip.exe script to C:\Python27\Scripts
  19. Installing pip.exe.manifest script to C:\Python27\Scripts
  20. Installing pip-2.7-script.py script to C:\Python27\Scripts
  21. Installing pip-2.7.exe script to C:\Python27\Scripts
  22. Installing pip-2.7.exe.manifest script to C:\Python27\Scripts

  23. Installed c:\python27\lib\site-packages\pip-1.2.1-py2.7.egg
  24. Processing dependencies for pip
  25. Finished processing dependencies for pip

  26. C:\Python27\Scripts>pip install pika==0.9.5
  27. Downloading/unpacking pika==0.9.5
  28.   Downloading pika-0.9.5.tar.gz
  29.   Running setup.py egg_info for package pika

  30. Installing collected packages: pika
  31.   Running setup.py install for pika

  32. Successfully installed pika
  33. Cleaning up...
整个准备过程就完成了,
整个MQ的原理: 

我所使用版本的情况: 
H:\mq>python --version
Python 2.7.3
C:\Program Files\erl5.9.2\bin>erl.exe --version
Eshell V5.9.2  
pika==0.9.5
rabbitmq-server-3.0.0
然后你就可以进程间进行通信(IPC)

点击(此处)折叠或打开

  1. #!/usr/bin/env python
  2. import pika

  3. connection = pika.BlockingConnection(pika.ConnectionParameters(
  4.         host='localhost'))
  5. channel = connection.channel()

  6. channel.queue_declare(queue='hello')

  7. channel.basic_publish(exchange='',
  8.                       routing_key='hello',
  9.                       body='Hello World!')
  10. print " [x] Sent 'Hello World!'"
  11. connection.close()

点击(此处)折叠或打开

  1. #!/usr/bin/env python
  2. import pika

  3. connection = pika.BlockingConnection(pika.ConnectionParameters(
  4.         host='localhost'))
  5. channel = connection.channel()

  6. channel.queue_declare(queue='hello')

  7. print ' [*] Waiting for messages. To exit press CTRL+C'

  8. def callback(ch, method, properties, body):
  9.     print " [x] Received %r" % (body,)

  10. channel.basic_consume(callback,
  11.                       queue='hello',
  12.                       no_ack=True)

  13. channel.start_consuming()


效果如下:




阅读(1420) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~