Connecting with MQTT without WebSockets

Hello everyone,
I’m getting started with Solace, and I am trying to write a simple Python program that publishes a message to a broker topic using the MQTT protocol.
I have issues establishing a connection with the broker service without using Web Sockets. My program does not seem to get any connack message.
I was wondering if any broker configuration step is needed to be able to connect over TLS.
Thanks :slight_smile:

Hi! You will need to configure a server certificate on solace broker to activate SSL/TLS ports. Documentation section for the procedure is here: Managing Server Certificates
If network security allows it, try connecting first to non-ssl port to confirm the problem is with TLS configuration.

@Aleksei Thank you for the info!

I’ll configure the server certificate and see if it works. Thank you!

Hey @ludobar! I wrote a bolg post a while back on how to use Python MQTT to establish a connection with a Solace Broker , you will find it interesting you can check it out here How I used COVID Tracking data to build an event-driven application and learn more Python 🤓 - DEV Community. In a nutshell, I used the paho.mqtt.client as follows

import paho.mqtt.client as mqtt
import json

def on_connect(client, data, flags, rc):
    assert (rc == 0), "Error Connecting. Return code: " + str(rc)
    print("Connected to PubSub+ Solace Broker!")

    for t in topics:
        print("Subscribing to: " + t)
        client.subscribe(t)

def on_message(client, data, msg):
    msg_json_object = json.loads(msg.payload.decode('ascii'))
    msg_json_pretty = json.dumps(msg_json_object, indent=2)
    print("Received message on: %s\n %s" % (msg.topic, msg_json_pretty))

# Broker Info
url = <host_name>
username = <username>
password = <password>

topics = [
    "topic/v1/sample",
    "topic/v2/sample/#",
]

client = mqtt.Client()
client.username_pw_set(username=username, password=password)

client.on_connect = on_connect
client.on_message = on_message

client.connect(url)
client.loop_forever()

You can also check this thread Send json object to Solace queue using Python — Solace Community
Also, are you aware of the Solace Python API? It is still in beta early access, let me know if you’re interested to be invited to a group and try it out!

@Tamimi thank you for the code snippet and for the post. It really helps me speeding up at coding!
Right now I’m focusing on MQTT, but I might be interested in exploring Solace APIs in the future. I will keep it in mind!

Hey @ludobar ! I just came across this again and wanted to follow up, do you still have any issues with TLS connection with the broker?

Hey @Tamimi ! At the end I figured everything out. I shared my program on the community in this post Python program connecting over TLS/SSL to PubSub+ Cloud — Solace Community, in the hope of helping anyone struggling with it :slight_smile: