Connecting to RabbitMQ Server via Python
In order to access the data inside aRabbitMQ, you first need to connect to the RabbitMQ server. We will show you the sample codes to connect your Apache RabbitMQ via Python.
Connecting via Python
Demo code for connecting to RabbitMQ with SSL certificate
import ssl
import pika
context = ssl.create_default_context(cafile="/client/ca_certificate.pem")
context.load_cert_chain("/client/client_cluster_certificate.pem", "/client/client_cluster_key.pem")
ssl_options = pika.SSLOptions(context, 'cloudclusters')
credentials = pika.PlainCredentials('admin', 'rabbitmq admin password')
host = "your rabbitmq host"
ssl_port = 12345 # your rabbitmq ssl port
conn_params = pika.ConnectionParameters(host=host, port=ssl_port, ssl_options=ssl_options, credentials=credentials)
conn = pika.BlockingConnection(conn_params)
Demo code for connecting to RabbitMQ without SSL certificate
import pika
password = "rabbitmq admin password"
host = "your rabbitmq host"
port = 12344 # your rabbitmq port
rabbitmq_url = "amqp://admin:{password}@{host}:{port}/?connection_attempts=3&blocked_connection_timeout=30".format(password=password, host=host, port=port)
conn = pika.BlockingConnection(pika.URLParameters(rabbitmq_url))