python active 下載安裝測試

來源:互聯網
上載者:User

軟體版本:

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

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/worker'start = time.time()conn = stomp.Connection([('172.16.1.217', 61612)])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([('172.16.1.217', 61612)])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}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.