如何将鼠兔连接到rabbitMQ远程服务器? (蟒蛇、鼠兔)
How to connect pika to rabbitMQ remote server? (python, pika)
在我的本地机器上我可以有:
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
对于两个脚本(send.py 和 recv.py)以建立正确的通信,但是如何建立从 12.23.45.67 到 132.45.23.14 的通信呢?我知道 ConnectionParameters() 采用的所有参数,但我不确定将什么传递给主机或将什么传递给客户端。如果有人能给出主机脚本和客户端脚本的示例,我们将不胜感激。
参见 http://pika.readthedocs.org/en/latest/modules/parameters.html,其中说 'rabbit-server1'
您应该输入 IP 的远程主机名。
请注意 guest
帐户只能通过本地主机连接 https://www.rabbitmq.com/access-control.html
第一步是将另一个帐户添加到您的 rabbitMQ 服务器。要在 windows...
中执行此操作
- 打开命令提示符window(windows key->cmd->enter)
- 导航到 "C:\Program Files\RabbitMQ Server\rabbitmq_server-3.6.2\sbin" 目录(键入 "cd \Program Files\RabbitMQ Server\rabbitmq_server-3.6.2\sbin" 并按回车键)
- 启用管理插件(键入 "rabbitmq-plugins enable rabbitmq_management" 并按回车键)
- 打开浏览器 window 到管理控制台并导航到管理部分(http://localhost:15672/#/users 使用凭据 "guest" - "guest")
- 添加新用户(例如 "the_user" 密码 "the_pass"
- 授予该用户对虚拟主机“/”的权限(单击用户名,然后单击 "set permission")
现在,如果您按照 send.py 的以下修改方式修改连接信息,您应该会成功:
#!/usr/bin/env python
import pika
credentials = pika.PlainCredentials('the_user', 'the_pass')
parameters = pika.ConnectionParameters('132.45.23.14',
5672,
'/',
credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.queue_declare(queue='hello')
channel.basic_publish(exchange='',
routing_key='hello',
body='Hello W0rld!')
print(" [x] Sent 'Hello World!'")
connection.close()
希望对您有所帮助
在我的本地机器上我可以有:
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
对于两个脚本(send.py 和 recv.py)以建立正确的通信,但是如何建立从 12.23.45.67 到 132.45.23.14 的通信呢?我知道 ConnectionParameters() 采用的所有参数,但我不确定将什么传递给主机或将什么传递给客户端。如果有人能给出主机脚本和客户端脚本的示例,我们将不胜感激。
参见 http://pika.readthedocs.org/en/latest/modules/parameters.html,其中说 'rabbit-server1'
您应该输入 IP 的远程主机名。
请注意 guest
帐户只能通过本地主机连接 https://www.rabbitmq.com/access-control.html
第一步是将另一个帐户添加到您的 rabbitMQ 服务器。要在 windows...
中执行此操作- 打开命令提示符window(windows key->cmd->enter)
- 导航到 "C:\Program Files\RabbitMQ Server\rabbitmq_server-3.6.2\sbin" 目录(键入 "cd \Program Files\RabbitMQ Server\rabbitmq_server-3.6.2\sbin" 并按回车键)
- 启用管理插件(键入 "rabbitmq-plugins enable rabbitmq_management" 并按回车键)
- 打开浏览器 window 到管理控制台并导航到管理部分(http://localhost:15672/#/users 使用凭据 "guest" - "guest")
- 添加新用户(例如 "the_user" 密码 "the_pass"
- 授予该用户对虚拟主机“/”的权限(单击用户名,然后单击 "set permission")
现在,如果您按照 send.py 的以下修改方式修改连接信息,您应该会成功:
#!/usr/bin/env python
import pika
credentials = pika.PlainCredentials('the_user', 'the_pass')
parameters = pika.ConnectionParameters('132.45.23.14',
5672,
'/',
credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.queue_declare(queue='hello')
channel.basic_publish(exchange='',
routing_key='hello',
body='Hello W0rld!')
print(" [x] Sent 'Hello World!'")
connection.close()
希望对您有所帮助