日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

rabbitmq安裝使用

系統 2133 0

使用 http://www.open-open.com/lib/view/open1325131828249.html

ubuntu:
apt-get install erlang-nox
sudo apt-get install rabbitmq-server
啟動
/etc/init.d/rabbitmq-server start|stop|restart (模式)

創建目錄
sudo rabbitmqctl add_vhost /pyhtest
創建用戶名
sudo rabbitmqctl add_user pyh pyh1234
設置用戶權限
sudo rabbitmqctl set_permissions -p /pyhtest pyh “.*” “.*” “.*”

啟動 sudo? ./bin/rabbitmq-server

python 調用
下載py-amqplib https://pypi.python.orgpypi?:action=display&name=amqplib
sudo chmod 777 setup.py
安裝
python setup.py install

生產者

      from amqplib import client_0_8 as amqp

import sys



filelist=[]



def readfiletolist(filename):

    file = open(filename)

    for line in file.readlines():

     line=line.strip('\n')

     filelist.append(line)

#     print "line" + line





conn = amqp.Connection(host="localhost:5672", userid="guest", password="guest", virtual_host="/", insist=False)

chan = conn.channel()



#readfiletolist("1.txt")

readfiletolist("/home/tanbo/stockdata/2014-06-27.txt")

for i in filelist:

        #msg = amqp.Message(i)

#msg = amsg = amqp.Message(sys.argv[1])

        msg = amqp.Message(i)

        msg.properties["delivery_mode"] = 2

        chan.basic_publish(msg,exchange="sorting_room",routing_key="jason")



chan.close() 

conn.close()


    

?

消費者

      from amqplib import client_0_8 as amqp



conn = amqp.Connection(host="localhost:5672", userid="guest", password="guest", virtual_host="/", insist=False)

chan = conn.channel()



chan.queue_declare(queue="po_box", durable=True, exclusive=False, auto_delete=False)

chan.exchange_declare(exchange="sorting_room", type="direct", durable=True, auto_delete=False,)



chan.queue_bind(queue="po_box", exchange="sorting_room", routing_key="jason")



def recv_callback(msg):

    print 'Received: ' + msg.body + ' from channel #' + str(msg.channel.channel_id)



chan.basic_consume(queue='po_box', no_ack=True, callback=recv_callback, consumer_tag="testtag")

while True:

    chan.wait()

chan.basic_cancel("testtag")





chan.close()

conn.close()


    

?

?

?

?

rabbitmq安裝使用


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 景泰县| 乐亭县| 鲁山县| 凤城市| 林口县| 手机| 澎湖县| 梅州市| 五指山市| 贡山| 疏勒县| 阳谷县| 奈曼旗| 台东市| 武义县| 全州县| 开封市| 广宁县| 林州市| 电白县| 临泽县| 东乡族自治县| 进贤县| 临武县| 凉城县| 兴城市| 宿松县| 桐柏县| 定结县| 宜君县| 开原市| 革吉县| 内江市| 梁平县| 平远县| 满城县| 乐亭县| 临邑县| 建湖县| 旬阳县| 南岸区|