简体   繁体   English

尝试将消息发布到Rabbit MQ服务器

[英]Trying to publish messages to rabbit mq server

This isn't working 这不行

#!/usr/bin/python

import pika

credentials = pika.PlainCredentials('user', 'user')

parameters = pika.ConnectionParameters('rabbitmqqa2.server.com',
                                   15672,
                                   '/',
                                   credentials)

connection = pika.BlockingConnection(parameters)

channel = connection.channel()

channel.queue_declare(queue='zabbix-mail')

message = 'Python Queue - Message Sent from sender.py {N|T}'

channel.basic_publish(exchange='zabbix',
                      routing_key='zabbix-mail-route',
                      body=message)
print(" [x] Sent 'Hello World!'")

connection.close()

As You've not mentioned error, I can advise you to check following points. 由于您没有提到错误,因此我建议您检查以下几点。

  1. is rabbitmq working on connected machine ? Rabbitmq在连接的机器上工作吗?
  2. you are using port 15672 but default port for sending message is 5672 您正在使用端口15672,但用于发送消息的默认端口是5672
  3. default credentials (username,password) of rabbitmq is "guest" and "guest" respectively. Rabbitmq的默认凭据(用户名,密码)分别为“ guest”和“ guest”。
  4. Since you are not declaring exchange or binding to queue, you should manually make them from rabbitmq panel ( by default running on 15672) 由于您未声明交换或绑定到队列,因此应从rabbitmq面板手动进行设置(默认情况下在15672上运行)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM