7.2. Asynchronous Sending
7.2.1. Synchronous and Asynchronous Send
When a sender sends synchronously over a reliable link, execution in the sender's thread is blocked until the sender receives an acknowledgement from the broker. This is useful for testing and troubleshooting, but by introducing a round-trip for every message, this reduces the potential throughput of the system.
When using the C++ API, all calls are asynchronous by default. When using the Python API, however, the opposite is true - by default, a sender sends a message synchronously.
You can send messages asynchronously, which allows you to maximise your network bandwidth usage and throughput. When invoked asynchronously, a send call will return immediately, without waiting for a receipt from the broker.
For example, the following call to the
send()
method of a send
object is asynchronous - it returns immediately, without waiting for a receipt from the broker:
- Python
sender.send(message, sync = False)
- C++
sender.send(message, false)
Note that this is the default behavior for the C++ API.