Builder Pattern Usage in the Solace Python API

The Solace Python API uses the builder design pattern to create instances of messages, messaging services, publishers and receivers. Here's an example usage of the Builder pattern to create a Solace message:

# Builder for creation of similarly configured messages. 
message = messaging_service.message_builder()   \
               .with_application_message_id(message_id) \
               .with_expiration(int(time.time()) + 60) \
               .with_property("key","value") \
               .build(message_body)

The builder design pattern allows the Solace Python API to build custom message objects with readable function calls. This pattern also allows the creation of message objects with different numbers of parameters through functions that can be called in any order.

The diagram below illustrates the primary functions used by the Solace Python API to create instances of messages, publishers and receivers with the builder pattern:

Illustration depicting the relationship between interfaces in the API

For more information about the Solace Python API, see Solace Python API reference