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