← Back to the chapter · Next detail →
Technical detail · AMQP Frames: Routing and Reliability
RabbitMQ identity, TLS and resource permissions
The username/password example connects app_user to /production on broker.example.com. The TLS example loads a client certificate, private key and trusted CA and uses port 5671. The port is a convention; the SSL options establish protected transport. The commands apply the table’s configure, write and read permissions in /iot. These snippets illustrate independent configuration steps, not a complete application.
credentials = pika.PlainCredentials('app_user', 'secure_password')
parameters = pika.ConnectionParameters(
host='broker.example.com',
credentials=credentials,
virtual_host='/production'
)
connection = pika.BlockingConnection(parameters)
import ssl
ssl_context = ssl.create_default_context()
ssl_context.load_cert_chain(
certfile='/path/to/client.crt',
keyfile='/path/to/client.key'
)
ssl_context.load_verify_locations('/path/to/ca.crt')
parameters = pika.ConnectionParameters(
host='broker.example.com',
port=5671, # AMQPS port
credentials=credentials,
ssl_options=pika.SSLOptions(ssl_context)
)
# RabbitMQ permission commands
rabbitmqctl set_permissions -p /iot sensor_app "^sensor\\..*" "^sensor\\..*" ""
rabbitmqctl set_permissions -p /iot dashboard "" "" "^sensor\\..*"