stompest库的应用实例

xiaoxiao2021-02-28  84

//该代码块完成本地文件数据发送到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 = 0 def 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 0 == 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’)

转载请注明原文地址: https://www.6miu.com/read-33567.html

最新回复(0)