Builder Pattern Usage in the Go API

The PubSub+ 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 PubSub+ 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 PubSub+ Go API to create instances of messages, publishers and receivers with the builder pattern:

Illustration depicting the relationship between interfaces in Java API.

For more information about the PubSub+ Messaging API for Go, see PubSub+ Messaging API for Go reference.