我有一个运行python script.The脚本的docker容器,提供了一个AMQP url,Pika使用它作为BlockingConnection.When的pika.URLParameters。我在我的计算机上运行脚本,它工作正常。我将其停靠并监视容器的日志,我看到当连接为attempted.Here时,脚本jangs是我在脚本中使用的代码:
AMQP_URL = __prefix__ + __username__ + ":" + __password__ + __virtual__host + session
("The programm hangs here")
connection = pika.BlockingConnection(pika.URLParameters(AMQP_URL))
channel = connection.channel()
channel.exchange_declare(
exchange = "tmp.topic_2",
exchange_type = "topic"
)
result = channel.queue_declare(exclusive = True)
queue_name = result.method.queue
channel.queue_bind(
exchange = "amq.topic",
queue = queue_name,
routing_key = "ui.#"
)
channel.basic_consume(
UiCallback,
queue= queue_name,
no_ack=True
)
channel.start_consuming()
我已经在需求中包含了pika,我想知道问题是什么:也许容器不能访问web?也许我需要在这个或另一个容器中设置rabbitmq服务器?谢谢你的帮助
发布于 2018-07-04 17:31:37
您需要将环境变量RABBIT_HOST_IP设置为运行docker容器的“主机”的IP。
我的理解是,阻塞连接将值发送回调用它的机器,这可以很好地工作,但如果您在容器中,则发送回的消息将发送到docker容器的IP,该容器在机器之外无法访问。
https://stackoverflow.com/questions/50357000
复制相似问题