def run(argv):
pub_ip = ""
l.info("JOB RUN : " + pformat(argv))
if len(argv) > 1:
pub_ip = argv[1]
if not pub_ip:
raise Exception("Rmq-sub needs a pub server to subscribe to, pub_ip"
" can not be empty pub_ip[%s]" % (pub_ip))
# Initalize HDaemonRepSrv
sub_rep_port = os.environ.get('PORT0')
hd = HDRmqsRepSrv(sub_rep_port)
hd.reset_stats()
hd.run()
l.info("RabbitMQ SUB client connecting to RabbitMQ PUB server at [%s]" % (pub_ip))
credentials = pika.PlainCredentials('hydra', 'hydra')
connection = pika.BlockingConnection(pika.ConnectionParameters(host=pub_ip, credentials=credentials))
channel = connection.channel()
channel.exchange_declare(exchange='pub', type='fanout')
result = channel.queue_declare(exclusive=True)
queue_name = result.method.queue
channel.queue_bind(exchange='pub', queue=queue_name)
l.info("RabbitMQ SUB client succesfully connected to RabbitMQ PUB server at [%s]" % (pub_ip))
hd.msg_cnt = 0
channel.basic_consume(hd.callback, queue=queue_name, no_ack=True)
channel.start_consuming()
评论列表
文章目录