【问题标题】:RabbitMQ does not print any message to consoleRabbitMQ 不会向控制台打印任何消息
【发布时间】:2026-02-23 22:35:02
【问题描述】:

我正在按照文档使用rabbitmq,并且我正在执行文档中指定的操作,没有错误,我有我的send.py 和receive.py 文件,我运行receive.py 然后send.py 并且没有打印任何消息在控制台中。我将不胜感激。链接到教程https://www.rabbitmq.com/tutorials/tutorial-one-python.html 谢谢

send.py 

import pika

connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()

channel.queue_declare(queue='Hello')

channel.basic_publish(exchange='',
                      routing_key='hello',
                      body='Hello World!')
print(" [x] Sent 'Hello World!'")
connection.close()


receive.py 

import pika

connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()

channel.queue_declare(queue='Hello')

def callback(ch, method, properties, body):
    print('[x] Recieved %s' % body)


channel.basic_consume(queue='Hello', auto_ack=True, on_message_callback=callback)
print(' [*] Waiting for messages. To exit press CTRL+C')

channel.start_consuming()


logs 
crash.log
2019-04-11 16:17:52 =SUPERVISOR REPORT====
     Supervisor: {<0.443.0>,rabbit_channel_sup_sup}
     Context:    shutdown_error
     Reason:     shutdown
     Offender:   [{nb_children,1},{name,channel_sup},{mfargs,{rabbit_channel_sup,start_link,[]}},{restart_type,temporary},{shutdown,infinity},{child_type,supervisor}]

rabbit@admin-PC.log

2019-04-11 13:28:36.448 [info] <0.8.0> Log file opened with Lager
2019-04-11 13:28:37.558 [info] <0.215.0> 
 Starting RabbitMQ 3.7.14 on Erlang 21.3
 Copyright (C) 2007-2019 Pivotal Software, Inc.
 Licensed under the MPL.  See https://www.rabbitmq.com/
2019-04-11 13:28:37.558 [info] <0.215.0> 
 node           : rabbit@admin-PC
 home dir       : C:\Windows\system32\config\systemprofile
 config file(s) : c:/Users/admin/AppData/Roaming/RabbitMQ/advanced.config
 cookie hash    : A0gjH122k0i5UCJhqrPbcQ==
 log(s)         : C:/Users/admin/AppData/Roaming/RabbitMQ/log/RABBIT~1.LOG
                : C:/Users/admin/AppData/Roaming/RabbitMQ/log/rabbit@admin-PC_upgrade.log
 database dir   : c:/Users/admin/AppData/Roaming/RabbitMQ/db/RABBIT~1
2019-04-11 13:28:40.824 [info] <0.215.0> Running boot step pre_boot defined by app rabbit
2019-04-11 13:28:40.824 [info] <0.215.0> Running boot step rabbit_core_metrics defined by app rabbit
2019-04-11 13:28:40.824 [info] <0.215.0> Running boot step rabbit_alarm defined by app rabbit
2019-04-11 13:28:40.839 [info] <0.223.0> Memory high watermark set to 789 MiB (827885158 bytes) of 1973 MiB (2069712896 bytes) total
2019-04-11 13:28:41.402 [info] <0.225.0> Enabling free disk space monitoring
2019-04-11 13:28:41.402 [info] <0.225.0> Disk free limit set to 50MB
2019-04-11 13:28:41.418 [info] <0.215.0> Running boot step code_server_cache defined by app rabbit
2019-04-11 13:28:41.418 [info] <0.215.0> Running boot step file_handle_cache defined by app rabbit
2019-04-11 13:28:41.433 [info] <0.228.0> Limiting to approx 8092 file handles (7280 sockets)
2019-04-11 13:28:41.433 [info] <0.229.0> FHC read buffering:  OFF
2019-04-11 13:28:41.433 [info] <0.229.0> FHC write buffering: ON
2019-04-11 13:28:41.433 [info] <0.215.0> Running boot step worker_pool defined by app rabbit
2019-04-11 13:28:41.433 [info] <0.215.0> Running boot step database defined by app rabbit
2019-04-11 13:28:41.433 [info] <0.215.0> Node database directory at c:/Users/admin/AppData/Roaming/RabbitMQ/db/RABBIT~1 is empty. Assuming we need to join an existing cluster or initialise from scratch...
2019-04-11 13:28:41.433 [info] <0.215.0> Configured peer discovery backend: rabbit_peer_discovery_classic_config
2019-04-11 13:28:41.433 [info] <0.215.0> Will try to lock with peer discovery backend rabbit_peer_discovery_classic_config
2019-04-11 13:28:41.433 [info] <0.215.0> Peer discovery backend does not support locking, falling back to randomized delay
2019-04-11 13:28:41.433 [info] <0.215.0> Peer discovery backend rabbit_peer_discovery_classic_config does not support registration, skipping randomized startup delay.
2019-04-11 13:28:41.433 [info] <0.215.0> All discovered existing cluster peers: 
2019-04-11 13:28:41.433 [info] <0.215.0> Discovered no peer nodes to cluster with
2019-04-11 13:28:41.433 [info] <0.43.0> Application mnesia exited with reason: stopped
2019-04-11 13:28:42.574 [info] <0.215.0> Waiting for Mnesia tables for 30000 ms, 9 retries left
2019-04-11 13:28:42.636 [info] <0.215.0> Waiting for Mnesia tables for 30000 ms, 9 retries left
2019-04-11 13:28:42.761 [info] <0.215.0> Waiting for Mnesia tables for 30000 ms, 9 retries left
2019-04-11 13:28:42.761 [info] <0.215.0> Peer discovery backend rabbit_auth_mechanism_amqplain defined by app rabbit
 (127.0.0.1:49841 -> 127.0.0.1:5672, vhost: '/', user: 'guest')

【问题讨论】:

  • 快控题;你确定你已经安装了 RabbitMQ 并且服务器在后台运行?
  • 是的,我已经安装并运行了
  • 没有足够的信息来提供帮助。我是 Pika 的维护者,我已经多次测试教程代码 - 我知道它有效。您能否提供来自 RabbitMQ 的日志消息来证明这两个应用程序已连接? RabbitMQ 记录每个传入的连接。
  • 感谢Luke Bakken的回复,我已经添加了上面的日志

标签: python rabbitmq


【解决方案1】:

这可能与PYTHONUNBUFFERED=1 环境变量有关。 至少那是我遇到的。

【讨论】:

    最近更新 更多