Solace Pubsub+¶
Since v0.39.0
Introduction¶
The Testcontainers module for Solace Pubsub+.
Adding this module to your project dependencies¶
Please run the following command to add the Solace Pubsub+ module to your Go dependencies:
go get github.com/testcontainers/testcontainers-go/modules/solace
Usage example¶
ctx := context.Background()
ctr, err := sc.Run(ctx, "solace/solace-pubsub-standard:latest",
sc.WithCredentials("admin", "admin"),
sc.WithServices(sc.ServiceAMQP, sc.ServiceManagement),
testcontainers.WithEnv(map[string]string{
"username_admin_globalaccesslevel": "admin",
"username_admin_password": "admin",
}),
sc.WithShmSize(1<<30),
)
defer func() {
if err := testcontainers.TerminateContainer(ctr); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
fmt.Println(err)
Module Reference¶
Run function¶
- Since v0.39.0
The Solace Pubsub+ module exposes one entrypoint function to create the Solace Pubsub+ container, and this function receives three parameters:
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*SolaceContainer, error)
context.Context, the Go context.string, the Docker image to use.testcontainers.ContainerCustomizer, a variadic argument for passing options.
Image¶
Use the second argument in the Run function to set a valid Docker image.
In example: Run(context.Background(), "solace/solace-pubsub-standard:latest").
Container Options¶
When starting the Solace Pubsub+ container, you can pass options in a variadic way to configure it.
WithCredentials¶
- Since v0.39.0
WithCredentials(username, password string): sets the client credentials for authentication
WithVpn¶
- Since v0.39.0
WithVpn(vpn string): sets the VPN name (defaults to "default")
WithQueue¶
- Since v0.39.0
WithQueue(queueName, topic string): subscribes a given topic to a queue (for SMF/AMQP testing)
WithShmSize¶
- Since v0.39.0
WithShmSize(size int64): sets the shared memory size (defaults to 1 GiB)
WithServices¶
- Since v0.39.0
The WithServices option is the recommended way to configure which Solace services should be exposed and made available in your container. This option automatically handles port exposure and sets up wait strategies for each specified service.
Available services:
ServiceAMQP- AMQP service (port 5672)ServiceMQTT- MQTT service (port 1883)ServiceREST- REST service (port 9000)ServiceManagement- Management service (port 8080)ServiceSMF- SMF service (port 55555)ServiceSMFSSL- SMF SSL service (port 55443)
By default, when no WithServices option is specified, the container will expose AMQP, SMF, REST, and MQTT services.
The following options are exposed by the testcontainers package.
Basic Options¶
WithExposedPortsSince v0.37.0WithEnvSince v0.29.0WithWaitStrategySince v0.20.0WithAdditionalWaitStrategySince v0.38.0WithWaitStrategyAndDeadlineSince v0.20.0WithAdditionalWaitStrategyAndDeadlineSince v0.38.0WithEntrypointSince v0.37.0WithEntrypointArgsSince v0.37.0WithCmdSince v0.37.0WithCmdArgsSince v0.37.0WithLabelsSince v0.37.0
Lifecycle Options¶
WithLifecycleHooksSince v0.38.0WithAdditionalLifecycleHooksSince v0.38.0WithStartupCommandSince v0.25.0WithAfterReadyCommandSince v0.28.0
Files & Mounts Options¶
WithFilesSince v0.37.0WithMountsSince v0.37.0WithTmpfsSince v0.37.0WithImageMountSince v0.37.0
Build Options¶
WithDockerfileSince v0.37.0
Logging Options¶
WithLogConsumersSince v0.28.0WithLogConsumerConfigSince v0.38.0WithLoggerSince v0.29.0
Image Options¶
WithAlwaysPullSince v0.38.0WithImageSubstitutorsSince v0.26.0WithImagePlatformSince v0.38.0
Networking Options¶
WithNetworkSince v0.27.0WithNetworkByNameSince v0.38.0WithBridgeNetworkSince v0.38.0WithNewNetworkSince v0.27.0
Advanced Options¶
WithHostPortAccessSince v0.31.0WithConfigModifierSince v0.20.0WithHostConfigModifierSince v0.20.0WithEndpointSettingsModifierSince v0.20.0CustomizeRequestSince v0.20.0WithNameSince v0.38.0WithNoStartSince v0.38.0WithProviderSince v0.39.0
Experimental Options¶
WithReuseByNameSince v0.37.0
Container Methods¶
The Solace Pubsub+ container exposes the following methods:
BrokerURLFor¶
- Since v0.39.0
BrokerURLFor(ctx context.Context, service Service) (string, error) - returns the connection URL for a given Solace service.
This method allows you to retrieve the connection URL for specific Solace services. The available services are:
ServiceAMQP- AMQP service (port 5672, protocol: amqp)ServiceMQTT- MQTT service (port 1883, protocol: tcp)ServiceREST- REST service (port 9000, protocol: http)ServiceManagement- Management service (port 8080, protocol: http)ServiceSMF- SMF service (port 55555, protocol: tcp)ServiceSMFSSL- SMF SSL service (port 55443, protocol: tcps)
// Get the AMQP connection URL
amqpURL, err := container.BrokerURLFor(ctx, solace.ServiceAMQP)
if err != nil {
log.Fatal(err)
}
// amqpURL will be something like: amqp://localhost:32768
// Get the management URL
mgmtURL, err := container.BrokerURLFor(ctx, solace.ServiceManagement)
if err != nil {
log.Fatal(err)
}
// mgmtURL will be something like: http://localhost:32769
Username¶
- Since v0.39.0
Username() string - returns the configured username for authentication
Password¶
- Since v0.39.0
Password() string - returns the configured password for authentication
VPN¶
- Since v0.39.0
VPN() string - returns the configured VPN name