How do I connect pika to a remote rabbitMQ server? (python, pica)

In my local machine, I can:

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

      

for both scripts (send.py and recv.py) to communicate correctly, but how to communicate from 12.23.45.67 to 132.45.23.14? I know about all the parameters that ConnectionParameters () takes, but I'm not sure what to pass to the host or what to pass to the client. It would be nice if someone could provide an example for the host and client script.

+3


source to share


2 answers


See http://pika.readthedocs.org/en/latest/modules/parameters.html where it says 'rabbit-server1'

you have to enter the IP remote hostname.



Remember that account guest

can only connect via localhost https://www.rabbitmq.com/access-control.html

+1


source


the first step is to add another account to your rabbitMQ server. To do this in the windows ...

  • open a command prompt window (windows key-> cmd-> enter)
  • go to the directory "C: \ Program Files \ RabbitMQ Server \ rabbitmq_server-3.6.2 \ sbin" (enter "cd \ Program Files \ RabbitMQ Server \ rabbitmq_server-3.6.2 \ sbin" and press enter)
  • enable management plugin (type "rabbitmq-plugins enable rabbitmq_management" and press enter)
  • open the browser control window on the control console and go to the administrator section ( http: // localhost: 15672 / # / users with the credentials "guest" - "guest")
  • add a new user (eg "the_user" with password "the_pass"
  • grant this user permission to the virtual host "/" (click the username, then click set permission)

Now, if you change the connection information as in the following modification of send.py, you should find success:



#!/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()

      

Hope it helps

+9


source







All Articles