Builder Pattern Usage in the Python API
The PubSub+ Messaging API for Python 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 PubSub+ 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 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 PubSub+ Python API to create instances of messages, publishers and receivers with the builder pattern:
For more information about the PubSub+ Messaging API for Python, see PubSub+ Messaging API for Python reference