...

The Solace PubSub+ Messaging API for Go allows developers to create client-based messaging applications that connect and subscribe to in order to publish/consume messages from PubSub+ event brokers.

Installing the PubSub+ Messaging API for Go

Run the following to install the Messaging API to your project:

go get solace.dev/go/messaging

Using Secure Socket Layer with the Messaging API for Go

To use secure socket layer (SSL) endpoints, OpenSSL 1.1.1 must installed on the systems that run your client applications. Client applications use SSL endpoints to create secure connections to an event broker (or broker). For example, on PubSub+ event brokers, you can use SMF TLS/SSL (default port of 55443) and Web Transport TLS/SSL connectivity (default port 1443) for messaging. For more details, see the overview in the package solace.

Example: Publish a Message Application

This PubSub+ Messaging API uses the builder pattern. For simplicity, error checking has been removed from the following example that shows you:

import (
	"time"

	"solace.dev/go/messaging"
	"solace.dev/go/messaging/pkg/solace/config"
	"solace.dev/go/messaging/pkg/solace/resource"
)

func main() {
	// NOTE: All error checking has been removed below and is intended for
	//       to show how to use the API. In production systems, we highly
	//       recommmend you put proper error checking and handling in your code.
	
	// Create a new solace.MessagingServiceBuilder
	messagingServiceBuilder := messaging.NewMessagingServiceBuilder()
	// Configure and build a new solace.MessagingService
	// Each function returns a solace.MessagingServiceBuilder for chaining
	messagingService, _ := messagingServiceBuilder.
		FromConfigurationProvider(config.ServicePropertyMap{
			// Configure the host of the event broker to connect to.
			config.TransportLayerPropertyHost: "localhost",
			// Configure the Message VPN on the event broker for which to connect.
			// Most event brokers have a default Message VPN.
			config.ServicePropertyVPNName: "default",
		}).
		WithAuthenticationStrategy(config.BasicUserNamePasswordAuthentication(
			// In this case, we use basic authentication, so is configured
			// on your event broker (is this the client )
			"username",
			"password",
		)).
		Build()
	
	// Connect the solace.MessagingService using the configuation
	// This call connects this application to the event broker
	_ = messagingService.Connect()
	
	// Configure and build a new solace.DirectMessagePublisher to publish 
	// messages to the event broker
	publisher, _ := messagingService.CreateDirectMessagePublisherBuilder().Build()
	
	// Start the publisher to allow for publishing of outbound messages
	_ = publisher.Start()
	
	// Build a new outbound message
	msg, _ := messagingService.MessageBuilder().BuildWithStringPayload("hello world")
	// Publish the message to the topic my/topic/string
	publisher.Publish(msg, resource.TopicOf("my/topic/string"))
	
	// Terminate the publisher with a grace period of 10 seconds allowing buffered messages to be published
	_ = publisher.Terminate(10 * time.Second)
	
	// Disconnect from the event broker
	_ = messagingService.Disconnect()
}

Packages

Name Synopsis
solace.dev
go
messaging Package messaging contains the main entrypoint into the API via messaging.NewMessagingServiceBuilder(), which returns a builder implementation based on the Solace PubSub+ Messaging API for C.
pkg
solace Package solace contains the main type definitions for the various messaging services.
config Package config contains the following constructs used for configuration:
logging Package logging allows for configuration of the API's logging levels.
message Package message contains the type definitions of InboundMessage and OutboundMessage.
rgmid Package rgmid contains the ReplicationGroupMessageID interface.
sdt Package sdt contains the types needed to work with Structured Data on a message.
metrics Package metrics contains the various metrics that can be retrieved as well as the interface for retrieving the metrics.
resource Package resource contains types and factory functions for various broker resources such as topics and queues.
subcode Package subcode contains the subcodes returned from the Solace PubSub+ Messaging API for C. The subcodes are generated in subcode_generated.go.