Python API Developer's Guide
The PubSub+ Messaging API for Python (version 1.9) provides modern development patterns and usability. The PubSub+ Python API allows your applications to take full advantage of the Solace event broker's feature set.
The PubSub+ Messaging API for Python utilizes the builder pattern, which allows you to easily create a MessagingService
instance with a custom configuration that then connects to an event broker. After a successful connection is established, you can send and receive messages using the Python API.
Here's an overview of how to use the PubSub+ Messaging API for Python after you've set-up your environment:
- Build a
MessagingService
instance and configure it using properties to:- connect to an event broker, such as the Hostname and Message VPN
- connect to a host event broker using a proxy, such as HTTP or SOCKS5.
- set the connection properties, such as TLS or compression
- choose an authentication scheme to authenticate to the event broker
-
Send messages to or receive messages from an event broker as follows using:
During the creation of the message publishers or message consumers, you can configure how to handle when back-pressure occurs. See each section below for more information.
-
A
DirectMessagePublisher
to publish direct messages. For more information, see Publishing Direct Messages Using the Python API. -
A
PersistentMessagePublisher
to publish persistent messages (guaranteed messages). For more information, Publishing Persistent Messages Using the Python API . -
A
DirectMessageReceiver
to consume direct messages from an event broker. For more information, see Consuming Direct Messages Using the Python API . -
A
PersistentMessageReceiver
to consume persistent messages (guaranteed messages) , see Consuming Persistent Messages Using the Python API.
-
- As part of publishing or consuming messages, use
OutboundMessage
andInboundMessage
(via event handlers), and handle errors as required via event handlers.
Message publishers in the PubSub+ Messaging APIs also allow you to handle scenarios where messages accumulate on internal buffers, referred to as back-pressure. For example, on a client application that sends messages, it is possible to have a scenario where the client application is generating messages faster than the messages can be sent to the event broker, which can happen due to factors such as network congestion. Direct message receivers in the PubSub+ Messaging APIs cannot apply back pressure but can choose how they react to slow applications. When too many messages accumulate on an internal buffer, you can tell your direct message receivers to either drop the oldest or latest messages emitted from a publisher.
You can reference various sample applications to understand how to use our Python API. For more information, review sections of this guide along with the PubSub+ Messaging API for Python reference and Python sample code on the Solace Python API GitHub page.