rmq_sub.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:hydra 作者: lake-lerna 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号