vinculum-mqtt

module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: Apache-2.0

README

vinculum-mqtt

MQTT 5.0 client packages for vinculum, implemented using paho.golang with autopaho for automatic reconnection.

Packages

publisher

MQTTPublisher implements bus.Subscriber. It serializes vinculum events and publishes them to an MQTT broker via a shared connection.

  • Per-pattern topic mappings (first match wins) with optional QoS, retain, and topic rename per pattern.
  • Default transform when no mapping matches: verbatim, error, or ignore.
  • Payload serialization: cty.Valuego2cty2go → JSON; []byte passthrough; other → JSON.
  • vinculum fields encoded as MQTT 5 user properties.
  • Metrics: messages sent, errors, publish duration.
p, err := publisher.NewPublisher().
    WithDefaultQoS(1).
    WithTopicMapping(publisher.TopicMapping{
        Pattern: "alerts/#",
        QoS:     1,
        Retain:  true,
    }).
    Build()

SetPublishFunc must be called before OnEventclient.MQTTClient does this automatically during Start.

subscriber

MQTTSubscriber receives MQTT messages and dispatches them as vinculum events to a bus.Subscriber.

  • Named wildcard field extraction: +deviceId in a pattern extracts the matched segment into fields["deviceId"].
  • Optional VinculumTopicFunc for dynamic vinculum topic mapping.
  • Retained message handling: configurable handleRetained flag; retained messages add fields["$retained"] = "true".
  • MQTT 5 user properties → vinculum fields (last-value-wins for duplicates).
  • Shared subscription support ($share/<group>/<topic>).
  • Metrics: messages received, errors, process duration.
s, err := subscriber.NewSubscriber().
    WithSubscription(subscriber.TopicSubscription{
        MQTTPattern: "sensors/+deviceId/data",
        QoS:         1,
    }).
    WithSubscriber(myBusSubscriber).
    Build()
client

MQTTClient wraps an autopaho.ConnectionManager and manages the shared connection lifecycle for a set of publishers and subscribers.

  • All publishers and subscribers share one connection.
  • Start(ctx) blocks until the first connection is established and all subscriptions are registered. Publishers receive their publish function during Start.
  • Re-subscribes automatically on every reconnect.
  • Configurable reconnect backoff, TLS, credentials, LWT, and lifecycle callbacks.
  • Metrics: connected gauge, reconnect counter.
c, err := client.NewClient(client.ClientConfig{
    ServerURLs: []*url.URL{u},
    ClientID:   "my-client",
    KeepAlive:  30 * time.Second,
})
c.AddPublisher(pub)
c.AddSubscriber(sub)
if err := c.Start(ctx); err != nil { ... }
defer c.Stop(ctx)

VCL configuration

When used via vinculum, these packages are wired by client "mqtt" blocks in VCL config files. See the vinculum MQTT client documentation.

License

BSD 2-Clause. See LICENSE.

Directories

Path Synopsis
Package carrier implements propagation.TextMapCarrier over MQTT 5 user properties.
Package carrier implements propagation.TextMapCarrier over MQTT 5 user properties.
Package client manages a single autopaho.ConnectionManager shared by all publishers and subscribers within a vinculum MQTT client block.
Package client manages a single autopaho.ConnectionManager shared by all publishers and subscribers within a vinculum MQTT client block.
Package publisher provides MQTTPublisher, a bus.Subscriber that forwards vinculum events to an MQTT broker.
Package publisher provides MQTTPublisher, a bus.Subscriber that forwards vinculum events to an MQTT broker.
Package subscriber provides MQTTSubscriber, which receives MQTT messages and dispatches them as vinculum events via a bus.Subscriber.
Package subscriber provides MQTTSubscriber, which receives MQTT messages and dispatches them as vinculum events via a bus.Subscriber.

Jump to

Keyboard shortcuts

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