Synchronous publish in python ?

uherbst Member, Employee Posts: 121 Solace Employee
edited March 2023 in General Discussions #1

Hi all,

what is the easiest, most clean code to publish ONE guaranteed message in python and only proceed after the ACK from the broker has arrived ?

(I know, that this usage pattern is not performant, if I have many messages to publish. My use is different).

Thank you




  • Tamimi
    Tamimi Member, Administrator, Employee Posts: 491 admin

    Hey @uherbst if you want to only wait for an ack from the broker that it received the message you can simply use publish_await_acknowledgement and you can use it as follows:

    publisher.publish_await_acknowledgement(outbound_msg, topic)

    was this what you were looking for?

  • tiwaabh
    tiwaabh Member Posts: 5

    Hi @Tamimi - I am looking for the same thing in node.js. I need to await the ack/nack of published message. Currently I am using solclient.js. Any suggestions?

  • Aaron
    Aaron Member, Administrator, Moderator, Employee Posts: 522 admin

    Just thought I'd post up my suggestion here for consideration: if looking to publish just one message, wait for confirm, and then disconnect, why not use the REST Messaging API? Just POST your message to the broker on the correct REST port (default 9000), with the topic as the URL, and the body as the payload. When you get the 200 OK, you know it's been successfully received by the broker. This just seems easier than creating a connection, waiting for connection, publishing message, waiting for acknowledgement, then disconnecting.

    Note: using a message broker for "one at a time" messaging is kind of an anti-pattern. As setting up the connection (TCP, TLS, etc.) is kind of expensive. Typically an app would connect, stay connected, and do lots of pubbing and subbing during its lifetime.