Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

生产者产生消息后在rabbitmq后台怎么看不到消息? #2

Open
Belee05 opened this issue Mar 22, 2021 · 0 comments
Open

Comments

@Belee05
Copy link

Belee05 commented Mar 22, 2021

我在生产者产生的消息推送到rabbitmq上(我指定了队列名),此时消费者尚未消费,但是在界面的rabbitmq后台获取不了消息。先运行消费者程序就能够正常获取到消息。

# 生产者代码
import pika
import sys

credentials = pika.PlainCredentials('admin', 'admin')  # mq用户名和密码
# 虚拟队列需要指定参数 virtual_host,如果是默认的可以不填。
connection = pika.BlockingConnection(pika.ConnectionParameters(host='127.0.0.1',
                                                               port=5672,
                                                               virtual_host='rabbitmq',
                                                               credentials=credentials))
channel = connection.channel()
channel.queue_declare(queue='wx_message', durable=False)
# channel.queue_bind(exchange='direct_logs',
#                    queue='wx_message')

# 声明一个名为direct_logs的direct类型的exchange
# direct类型的exchange
channel.exchange_declare(exchange='direct_logs',
                         exchange_type='direct')

# 从命令行获取basic_publish的配置参数
severity = sys.argv[1] if len(sys.argv) > 1 else 'info'
message = ' '.join(sys.argv[2:]) or 'Hello World!'

# 向名为direct_logs的exchage按照设置的routing_key发送message
channel.basic_publish(exchange='direct_logs',
                      routing_key=severity,
                      body=message
                      )

print(" [x] Sent %r:%r" % (severity, message))
connection.close()

在wx_message队列里面并没有获取消息,请问这是什么原因?
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant