pythonrabbitmqpika

rabbitmq credential issue. only works with localhost


I have a question regarding rabbitmq. I am trying to set up a messaging system based off the queue name and so far everything has been good with localhost. As soon as I set some credentials for local connection, I get a timeout error. (I have lengthened the timeout time as well.) I have also gave the user administrative privileges and the guest account administrative privileges. I get this error when ran with both the consume and produce script. Port 5672 is open as well. This is all being done on a ubuntu 14.04 LTS machine and python 2.7.14. Guest and my other rabbit user are both allowed to use the default vhost too.

import pika, json

credentials = pika.credentials.PlainCredentials('guest', 'guest')
connection = pika.BlockingConnection(pika.ConnectionParameters('<ip here>', 
5672, '/', credentials))
channel = connection.channel()

result = channel.queue_declare(queue='hello', durable=True)  

def callback(ch, method, properties, body):
        print "localhost received %r" % json.loads(body)


channel.basic_consume(callback,
                  queue='hello')


print 'localhost waiting for messages. To exit press CTRL+C'
channel.start_consuming()
channel.close()

Here is my error message too. Just a timeout method which would make me think that the connection is failing and this is a network problem but when I replace my ip in the credentials with 'localhost', everything works fine. Any ideas?

pika.exceptions.ConnectionClosed: Connection to <ip here>:5672 failed: timeout

Solution

  • You are probably running into multiple issues.

    First of all, the guest user can only connect via localhost by default. This document goes into detail. FWIW that document is the first hit when site:rabbitmq.com localhost guest are used as search terms on google.

    Second, timeout means that the TCP connection can't be established. Please see this document for a step-by-step guide to diagnosis.