RabbitMQ (vi) Remote connection

Source: Internet
Author: User

RabbitMQ (vi) Remote connection by default, RabbitMQ uses ' guest ' to connect to a local (localhost) server, which is invalidated when a remote connection is required.

"Guest" user can only connect via localhost

Official document: Http://www.rabbitmq.com/access-control.html If you must use the ' guest ' user for remote login, you need to modify the configuration
[{rabbit, [{loopback_users, []}]}].
(1) First, you need to create and add a user ' test ' to have Administrator privileges
-p/root".*"" . *" ". *"
(2) Modify the configuration file
[{rabbit, [{loopback_users, ["root]}]}].
(3) Restart Rabbitmq-server
/etc/init.d/rabbitmq-server restart
(4) Modify host to modify the/etc/hosts on the remote client machine, add rabbit-server IP
xx.xx.xx.xx Rabbit-server
(5) Certified Original: Https://pika.readthedocs.org/en/0.9.14/modules/parameters.htmlpika provides two authentication methods: Connectinparameters and Urlparameters. Connectionparameters
ImportPika#Set The connection parameters to connect to Rabbit-server1 on port 5672# on the/virtual host using the username "gu EST "and password" guest "Credentials = Pika. Plaincredentials ('Root','Root') Parameters= Pika. Connectionparameters ('Rabbit-server1',                                       5672,                                       '/', credentials)
Urlparameters
Import Pika # Set The connection parameters to connect to Rabbit-server1 on port 5672# on the/virtual host using the username "gu EST "and password" Guest "parameters = Pika. Urlparameters ('amqp://guest:[email protected]:5672/%2f')
Example
ImportPikai= 1defCallback (ch, method, properties, body):GlobalI#print ' Receive%r '%body    Print 'Receive%s'%I i+ = 1F= Open ('%s'%i'w+') F.write (body) f.close ()#The first of these methods#credentials = Pika. Plaincredentials (' Mtest ', ' root ')#connection = Pika. Blockingconnection (Pika. Connectionparameters (' Rabbit-server ', 5672, '/', credentials))#The second method ofParameters = Pika. Urlparameters ('Amqp://mtest:[email protected]:5672/%2f') Connection=Pika. Blockingconnection (parameters) channel=Connection.channel () channel.queue_declare (Queue='Hello') Channel.basic_consume (callback, queue='Hello1', no_ack=True) channel.start_consuming ()

RabbitMQ (vi) Remote connection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.