Go Event Bus

A modular, in-process and distributed event bus abstraction for Go, designed for high-throughput systems with strong observability, resilience, and extensibility.

Get Started View on GitHub


Overview

Go Event Bus provides a clean abstraction for event-driven architectures in Go, with pluggable transports, an explicit execution pipeline, and production-grade resilience patterns.

Key Features

  • LocalBus for in-process events with sync/async dispatch
  • NatsBus for fire-and-forget distributed messaging
  • JetStreamBus for durable, distributed events with replay
  • Invoker Chain for composable cross-cutting concerns
  • Built-in invokers for tracing, metrics, retry, circuit breaking, rate limiting, idempotency, and DLQ
  • Redis stores for distributed idempotency and rate limiting
  • OpenTelemetry tracing and Prometheus metrics out of the box

Quick Example

package main

import (
    "context"
    "fmt"

    event "github.com/isaquesb/go-event-bus"
    "github.com/isaquesb/go-event-bus/invoker"
)

type UserCreated struct {
    UserID string
    Email  string
}

func (e UserCreated) Name() string { return "user.created" }

func main() {
    bus := event.NewLocalBus(event.LocalBusOptions{
        Invoker:       invoker.NewChain(invoker.NewMetrics(nil)),
        MaxConcurrent: 10,
    })

    ctx := context.Background()

    bus.Subscribe(ctx, "user.created", func(ctx context.Context, evt event.Event) error {
        e := evt.(UserCreated)
        fmt.Printf("Welcome %s!\n", e.Email)
        return nil
    }, event.WithHandlerName("send-welcome"))

    bus.EmitSync(ctx, UserCreated{UserID: "123", Email: "john@example.com"})
}

Architecture at a Glance

The library is composed of three orthogonal layers:

  1. Event Definition & Serialization - Events, Registry, Envelopes
  2. Execution Pipeline (Invoker Chain) - Cross-cutting concerns as composable middleware
  3. Transport / Delivery - LocalBus, NATS Core, JetStream

These layers are intentionally decoupled, so you can mix and match based on your needs.


Back to top

Copyright © 2025 Isaque de Souza Barbosa. Distributed under the MIT License.