//該代碼塊完成本地文件數據發送到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%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’)