mosquitto

package module
v0.44.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithConfigFile

func WithConfigFile(cfgHostPath string) testcontainers.CustomizeRequestOption

WithConfigFile mounts a custom mosquitto.conf, replacing the default embedded configuration. The provided file must contain at least a "listener 1883" directive.

Types

type Container

type Container struct {
	testcontainers.Container
}

Container represents the Mosquitto container type used in the module.

func Run

Run creates an instance of the Mosquitto container type.

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/testcontainers/testcontainers-go"
	"github.com/testcontainers/testcontainers-go/modules/mosquitto"
)

func main() {
	// runMosquittoContainer {
	ctx := context.Background()

	mosquittoContainer, err := mosquitto.Run(ctx, "eclipse-mosquitto:2")
	defer func() {
		if err := testcontainers.TerminateContainer(mosquittoContainer); err != nil {
			log.Printf("failed to terminate container: %s", err)
		}
	}()
	if err != nil {
		log.Printf("failed to start container: %s", err)
		return
	}
	// }

	state, err := mosquittoContainer.State(ctx)
	if err != nil {
		log.Printf("failed to get container state: %s", err)
		return
	}

	fmt.Println(state.Running)

}
Output:
true

func (*Container) BrokerURL

func (c *Container) BrokerURL(ctx context.Context) (string, error)

BrokerURL returns the MQTT broker URL (mqtt://host:1883).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL