stompest库的应用实例

来源:互联网 发布:美工是什么岗位 编辑:程序博客网 时间:2024/06/05 10:32

//该代码块完成本地文件数据发送到amq
import logging
from stompest.config import StompConfig
from stompest.sync import Stomp

class UpdateIndex():
def __init__(self):

    self.url = 'tcp://xxxx.org:61613'    self.queue='queue.web.update'    self.count = 0def producer(self,amqUrl,queue,jsonstr):    CONFIG = StompConfig(amqUrl)    client = Stomp(CONFIG)    client.connect()    client.send(queue,jsonstr)    client.disconnect()def sendData(self,file):    file=open(file,'r')    read_json=file.readlines()    #print read_json    if len(read_json):        for line in read_json:            self.count+=1            if self.count%200 == 0:                print self.count            if self.count == 2001:                break            print line            self.producer(self.url,self.queue,line)    else:        logging.error("there is no jsonstr in file")    file.close()

if __name__ == ‘__main__’:
aa=UpdateIndex()
for i in range(1,2):
aa.sendData(‘C:\xxx\xxx.txt’)

0 0