STOMP - Python - SSL

Updated on 20 Sep 2023

I am using the Python library to send a message.

  • I am referencing the SSL certificate and ca-certificate files that we created earlier on lines 10, 11.
  • I am using a slightly different technique for connection so that I can pass in the certificate files
  • this example also uses a different approach by having the user/pass in the rabbitmq.conf file, so I don’t need to specify it in the code.
#!/usr/bin/env python3

import stomp
import sys

if len(sys.argv) > 1:

    conn = stomp.Connection([('localhost', 61614)], vhost='demo_host')
    conn.set_ssl(for_hosts=[('localhost', 61614)], 
    #-- I can have this set in the /etc/rabbitmq/rabbitmq.conf file.
    #--stomp.default_user = demo_user
    #--stomp.default_pass = demo_pass

    #--and I wont have to pass the user / pass credentials to the connect method
    #conn.connect('demo_user', 'demo_pass', wait=True)
    conn.send(body=sys.argv[1], destination='/queue/q1')

Sending the message

I will also make this file executable, and to call this code, I simply do the following.

./ "hello world from Python - ssl"


I can use rabbitmqadmin to check the message

rabbitmqadmin list vhosts

And to see the message, I can use the following command.

rabbitmqadmin get queue=q1 --vhost=demo_host -u guest -p guest

I am using guest username because I have assigned the appropriate privileges to that account.