之所以对mq感兴趣,是因为IBM的MQ,想看看到底它是做什么东西,由于mainframe的东西测试比较麻烦因此
先学习一下rabbitmq,整体上有一个理解,
后续可能会继续深入一点,运维的东西不好做啊,涉及的东西比较多。
准备步骤:
下载python
下载
下载 rabbitmq-server-3.0.0
下载 mQ的组件 otp_win32_R15B02_with_MSVCR100_installer_fix
安装pika,需要说明的是在安装完python,安装pika的时候需要手动安装
- C:\Python27\Scripts>easy_install.exe pip
- Searching for pip
- Reading http://pypi.python.org/simple/pip/
- Reading http://www.pip-installer.org
- Reading http://pip.openplans.org
- Best match: pip 1.2.1
- Downloading http://pypi.python.org/packages/source/p/pip/pip-1.2.1.tar.gz#md5=db
- 8a6d8a4564d3dc7f337ebed67b1a85
- Processing pip-1.2.1.tar.gz
- Running pip-1.2.1\setup.py -q bdist_egg --dist-dir c:\users\kinfin~1\appdata\loc
- al\temp\easy_install-l9uerz\pip-1.2.1\egg-dist-tmp-y6ihcs
- warning: no files found matching '*.html' under directory 'docs'
- warning: no previously-included files matching '*.txt' found under directory 'do
- cs\_build'
- no previously-included directories found matching 'docs\_build\_sources'
- Adding pip 1.2.1 to easy-install.pth file
- Installing pip-script.py script to C:\Python27\Scripts
- Installing pip.exe script to C:\Python27\Scripts
- Installing pip.exe.manifest script to C:\Python27\Scripts
- Installing pip-2.7-script.py script to C:\Python27\Scripts
- Installing pip-2.7.exe script to C:\Python27\Scripts
- Installing pip-2.7.exe.manifest script to C:\Python27\Scripts
- Installed c:\python27\lib\site-packages\pip-1.2.1-py2.7.egg
- Processing dependencies for pip
- Finished processing dependencies for pip
- C:\Python27\Scripts>pip install pika==0.9.5
- Downloading/unpacking pika==0.9.5
- Downloading pika-0.9.5.tar.gz
- Running setup.py egg_info for package pika
- Installing collected packages: pika
- Running setup.py install for pika
- Successfully installed pika
- 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)
- #!/usr/bin/env python
- import pika
- connection = pika.BlockingConnection(pika.ConnectionParameters(
- host='localhost'))
- channel = connection.channel()
- channel.queue_declare(queue='hello')
- channel.basic_publish(exchange='',
- routing_key='hello',
- body='Hello World!')
- print " [x] Sent 'Hello World!'"
- connection.close()
- #!/usr/bin/env python
- import pika
- connection = pika.BlockingConnection(pika.ConnectionParameters(
- host='localhost'))
- channel = connection.channel()
- channel.queue_declare(queue='hello')
- print ' [*] Waiting for messages. To exit press CTRL+C'
- def callback(ch, method, properties, body):
- print " [x] Received %r" % (body,)
- channel.basic_consume(callback,
- queue='hello',
- no_ack=True)
- channel.start_consuming()
效果如下:
阅读(1420) | 评论(0) | 转发(0) |