Builder Pattern Usage in the Solace Go API
The Solace Go 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 */
messageBuilder := messagingService.MessageBuilder()
message, err := messageBuilder.
FromConfigurationProvider(configProfile). // For example TTL, Sender ID, Sequence Number etc.
WithExpiration(time.Now().Add(10 * time.Second)). // Expire the message in 10 seconds.
BuildWithStringPayload("My_Message") // Builds the message.
The previous code shows what each function is doing. This pattern also allows the creation of message instances with different numbers of parameters through functions that can be called in any order.
The diagram below illustrates the primary functions used in the Solace Go API to create instances of messages, publishers and receivers with the builder pattern:
For more information about the Solace Go API, see Solace Go API reference.
