I'd like to write a simple smoke test that runs after deployment to verify that the RabbitMQ credentials are valid. What's the simplest way to check that rabbitmq username/password/vhost are valid?
Edit: Preferably, check using a bash script. Alternatively, using a Python script.
Open the RabbitMQ management console, http://localhost:15672 . Login as a guest. Enter guest as the Username and Password. Note: The default user “guest” is an administrative user and its login credentials are published on the official RabbitMQ web site.
For Linux/Unix/Mac: 0 you can use the RabbitMQ command line tool. You can also use the rabbitmq-diagnostics to check the server_version. It's a useful tool for diagnostics, health checks and monitoring. The command assumes that accessing your console requires sudo rights.
RabbitMQ supports multiple authentication mechanisms. Some of them use username/password pairs. These credential pairs are then handed over to authentication backends that perform authentication. One of the backends, known as internal or built-in, uses internal RabbitMQ data store to store user credentials.
Procedure: Log in to the RabbitMQ web-based management interface as admin admin using the default password of changeme.
As you haven't provided any details about language, etc.:
You could simply issue a HTTP GET request to the management api.
$ curl -i -u guest:guest http://localhost:15672/api/whoami
See RabbitMQ Management HTTP API
Here's a way to check using Python:
#!/usr/bin/env python import socket from kombu import Connection host = "localhost" port = 5672 user = "guest" password = "guest" vhost = "/" url = 'amqp://{0}:{1}@{2}:{3}/{4}'.format(user, password, host, port, vhost) with Connection(url) as c: try: c.connect() except socket.error: raise ValueError("Received socket.error, " "rabbitmq server probably isn't running") except IOError: raise ValueError("Received IOError, probably bad credentials") else: print "Credentials are valid"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With