Generic, transport-agnostic messaging patterns for Go.
Write business logic against core interfaces. Swap transports without touching handler code.
| Layer | What it provides |
|---|---|
| Core Interfaces | Publisher[T], Subscriber[T], Consumer[T], Requester[Req, Resp], Responder[Req, Resp], Message[T], Handler[T] |
| Transports | Channel (in-process), NATS, JetStream, HTTP — each implements the core interfaces |
| Middleware | Chain, Process, Peek, Distinct, Skip, Take, Throttle, AutoAck |
| Pipeline Operators | Pipe, PipeMap, FanOut, FanIn, RoundRobin, BoundPublisher |
| Telemetry | OpenTelemetry tracing and metrics built into every transport |
- Fire & Forget — publish with no delivery guarantee (channels, NATS core)
- At-Least-Once — ack/nak with auto-ack or manual control (JetStream)
- Pull Consumer — fetch messages on demand with explicit ack (JetStream)
- Request-Reply — typed request/response (NATS, HTTP)
- Queue Groups — competing consumers (NATS)
- Fan-Out / Fan-In — broadcast, merge, round-robin (any transport)
| Interface | Channel | NATS | JetStream | HTTP |
|---|---|---|---|---|
Publisher[T] |
yes | yes | yes | yes |
Subscriber[T] |
yes | yes | yes | yes |
Consumer[T] |
- | - | yes | - |
Requester[Req, Resp] |
- | yes | - | yes |
Responder[Req, Resp] |
- | yes | - | yes |
go get github.com/foomo/gofluxpackage main
import (
"context"
"fmt"
"github.com/foomo/goflux"
"github.com/foomo/goflux/transport/channel"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
bus := channel.NewBus[string]()
pub := channel.NewPublisher(bus)
sub, _ := channel.NewSubscriber(bus, 1)
go sub.Subscribe(ctx, "greetings", func(_ context.Context, msg goflux.Message[string]) error {
fmt.Println(msg.Subject, msg.Payload)
cancel()
return nil
})
_ = pub.Publish(ctx, "greetings", "Hello, goflux!")
<-ctx.Done()
}Swap to NATS by changing the import and constructor — the handler stays the same. See the Getting Started guide.
Full documentation: https://foomo.github.io/goflux/
make check # tidy + generate + lint + test + audit (full CI flow)See CONTRIBUTING.md for details.
Distributed under MIT License, see LICENSE for details.
