python active 下载安装测试

来源:互联网 发布:js设置标签属性值 编辑:程序博客网 时间:2024/05/21 19:43

软件版本:

apache-activemq-5.7.0-bin.tar.gz

stomp.py-3.1.1.tar.gz

下载地址:

http://activemq.apache.org/download.html

http://code.google.com/p/stomppy/downloads/list

(http://code.google.com/p/stomppy/downloads/detail?name=stomp.py-3.1.1.tar.gz&can=1&q=)

activemq安装:

tar -zxvf apache-activemq-5.7.0-bin.tar.gz

mv apache-activemq-5.7.0 /usr/local/activemq/

改配置:

vi /usr/local/activemq/conf/activemq.xml 

chmod -R 777 /usr/local/activemq/

添加一句

<transportConnectors>            <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->            <transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&wireformat.maxFrameSize=104857600"/>            <transportConnector name="stomp+nio" uri="stomp+nio://0.0.0.0:61613"/></transportConnectors>

启动服务:

/usr/local/activemq/bin/activemq start

检查:

[root@localhost pythontest]# netstat -an | grep 61616
tcp        0      0 :::61616                    :::*                        LISTEN      
[root@localhost pythontest]# netstat -an | grep 61613
tcp        0      0 :::61613                    :::*                        LISTEN     

http://192.168.10.62:8161/admin

stomp安装:

tar -zxvf stomp.py-3.1.1.tar.gz

cd stomp.py-3.1.1

python setup.py install --prefix=/usr/local/python27 (python安装目录)

完成。

python demo

以下转自:http://blog.csdn.net/xiarendeniao/article/details/7053958#comments

#!/usr/bin/python## Usage: stomp_send.py <msize> <nmsgs>#import sysimport osimport loggingimport stompimport timeimport jsonlogging.basicConfig()nmsgs = int(sys.argv[1])msg = {'pid':1,'id':1,'start_at':"time",'type':'parse_title','articleid':0, 'from':1, 'to':361}dest = '/queue/test1'start = time.time()conn = stomp.Connection([('192.168.42.38', 61613)])conn.start()conn.connect(wait=True)for i in range(nmsgs):msg['articleid'] = iconn.send(json.write(msg), destination=dest)print "send one"conn.disconnect()print "OK Finished msgs %d time %f" % (nmsgs, (time.time()-start))

mq_rective.py

import sysimport osimport loggingimport stompimport jsonimport timeclass MyListener(object):def on_error(self, headers, message):print 'received an error %s' % messagedef on_message(self, headers, message):print 'received a message %s' % message#print headers['message-id']#sys.exit(0)conn.ack({'message-id':headers['message-id']})dest = '/queue/test1'logging.basicConfig()conn = stomp.Connection([('192.168.42.38', 61613)])conn.set_listener('', MyListener())conn.start()conn.connect(wait=True)conn.subscribe(destination=dest, ack='client')while True:try:time.sleep(1)except:break

运行:

[root@localhost pythontest]# python mq_send.py 4
send one
send one
send one
send one
OK Finished msgs 4 time 0.015546
[root@localhost pythontest]#


[root@localhost pythontest]# python mq_receive.py
received a message {"start_at": "time", "pid": 1, "to": 361, "articleid": 0, "from": 1, "type": "parse_title", "id": 1}
received a message {"start_at": "time", "pid": 1, "to": 361, "articleid": 1, "from": 1, "type": "parse_title", "id": 1}
received a message {"start_at": "time", "pid": 1, "to": 361, "articleid": 2, "from": 1, "type": "parse_title", "id": 1}
received a message {"start_at": "time", "pid": 1, "to": 361, "articleid": 3, "from": 1, "type": "parse_title", "id": 1}





原创粉丝点击