Try PubSub+

Send json object to Solace queue using Python

pr320235pr320235 Member Posts: 9

Dear All,
Could you please help me to achieve this.
I need to send json object to Solace Queue using Python programming language.
I am looking for a python library to get this done. Is there any such Python library?
If yes, Please let me know how to use it.
Thanks in advance.

Tagged:

Comments

  • marcmarc Member, Administrator, Moderator, Employee Posts: 207 admin

    Hi @pr320235,
    Welcome to the Solace Developer Community! When you get a chance it would be great if you could introduce yourself in the intro thread

    As for your question, let me take a shot at it:
    The simplest option for using Python with Solace right now is to use the paho library (docs here, Solace Example Here) which will publish to Solace over the mqtt protocol. Keep in mind that Solace Event Brokers do protocol translation for you so other apps can still receive this messages using other protocols (SMF, AMQP, MQTT, REST, etc.).

    A few other things to keep in mind:
    1. Our best practices recommend publishing to a topic instead of a queue. A queue can then be created for your consumer ( or group of consumers) and have one or many topic subscriptions assigned to it. This allows you to have a better decoupling between your publishers and consumers.
    2. We are currently developing a Python SDK for Solace that will use SMF (Solace Message Format). More info will be coming soon, but in the mean time let me know if you'd like to be involved as an early access reviewer of it.

    Hope that helps!

  • pr320235pr320235 Member Posts: 9

    Dear marc,
    Thanks for your answer.
    I'm facing some issues to connect to my Solace queue. It would be great if you can helpm] me.
    In example - https://github.com/SolaceLabs/makeuoft-hackathon/blob/master/raspberrypi2solace/publish/virtual_solace_publish_json.py
    I have a doubt in below part -

    def main():
        # Connection parms for Solace Event broker
        solace_url = ""
        solace_port = 1883
        solace_user = ""
        solace_passwd = ""
        solace_clientid = "vats_id"
    

    What to put in solace url, port, and clientid?
    I have below information about my solace queue-

    Could you please tell me what port should I use - the default one(1883) or 8883?
    also, should I use solace_url with port or without port ?
    do I need to keep ssl:// in the beginning of solace_url?

    Kindly answer above questions. It's urgent.
    Thank you very much.
    -Praveen Kumar
    mob +91 7395947424

  • TamimiTamimi Member, Administrator, Employee Posts: 75 admin

    Hi Praveen!

    For your solace_url param, don’t include the protocol and the port in your url string, so you can do something along the lines of

    url = "<your_domain_name>.solace.cloud"
    username = "solace-cloud-client"
    password = "<password>"
    PORT=1883
    client = mqtt.Client()
    client.username_pw_set(username=username, password=password)
      #      client.on_connect = on_connect
      #      client.on_message = on_message
    client.connect(url, port=PORT )
      #      client.loop_forever()
    

    And a quick side note regarding terminology, using solace you don’t publish to a queue. You connect to the solace broker, publish on a topic and you configure a queue on the broker to subscribe to that topic. Your consuming application will bind to the queue consuming the messages.

    Hope this helps! let me know if it doesn’t work (or if it works too) 😄

  • TamimiTamimi Member, Administrator, Employee Posts: 75 admin

    Also, i see that you’re a python enthusiast (welcome to the club!) We have some good news coming up with a brand new native Solace Python API which will allow you to do a whole lot more with the broker and access a bunch of functionalities.

    Let me know here if you’re interested to be one of the first to try it out! https://solace.community/discussion/336/python-whos-in-for-a-real-treat

  • marcmarc Member, Administrator, Moderator, Employee Posts: 207 admin

    To follow up on what @Tamimi said you'll want to use the port specified in your connect info, not the default of 1883.

    Also note that this sample is not configured for using TLS so you'll want to use the MQTT Host info from the Connection Details. Looks like Paho has some TLS options here that you can use to configure TLS

  • pr320235pr320235 Member Posts: 9

    Thanks @marc & @tamimi !
    I was able to connect to my Solace broker and publish the messages.
    Appreciate your support :)

Sign In or Register to comment.