问题
I just set up a RabbitMQ add-on in heroku. After developing my app to queue up and consume messages running on a local instance, I deployed it to Heroku and have not been able to connect successfully yet. The username/password & hostname/port/vhost are all from heroku config
. If I change the username or password, the error changes to ProbableAuthenticationError
which makes me believe the authentication is at least correct, but likely an issue with my vhost or some other missing configuration. I haven't seen any similar questions on SO or after an hour of Googling that didn't address my issue.
I have tried both the RABBITMQ_BIGWIG_RX_URL
and RABBITMQ_BIGWIG_TX_URL
environment variables for both sending and consuming, and no combination seems to work. Below is the code I have for attempting to connect.
url = 'small-laurel-24.bigwig.lshift.net'
port = 10019
vhost = '/notmyrealvhost'
credentials = pika.PlainCredentials('username', 'password')
parameters = pika.ConnectionParameters(url, port, vhost, credentials=credentials)
connection = pika.BlockingConnection(parameters)
Is there something I'm missing or any way to figure out what specifically is configured wrong? I'm at a loss here. Much thanks in advance!
I am running pika 0.9.14, python 2.7.3.
回答1:
The problem was most likely that you added the forward slash character in your virtual-host. Many users confuse this with the forward slash being the root directory, but it is actually just the default virtual-host name.
Unless you actually named the virtual-host using a forward slash, the name will always be identical to the name you see in the management console, e.g:
- my_virtualhost and not /my_virtualhost
This is why your solution worked as you did not add the extra forward slash when using URLParameters.
Your original code would have looked like this using URLParameters:
amqp://username:password@small-laurel-24.bigwig.lshift.net:10018/%2Fnotmyrealvhost
While the working version you mentioned in your answer above does not have the forward slash (%2F
) character.
amqp://username:password@small-laurel-24.bigwig.lshift.net:10018/notmyrealvhost
回答2:
I ended up solving my problem by using the URLParameters
class on pika to parse the URL from Heroku's environment variable.
This takes the string like
amqp://username:password@small-laurel-24.bigwig.lshift.net:10018/notmyrealvhost
and parses everything as needed. I was unnecessarily complicating things by doing it myself.
来源:https://stackoverflow.com/questions/25619945/cannot-connect-to-rabbitmq-on-heroku-with-pika-due-to-probableaccessdeniederror