Overview

Getting Started

Publish and consume your first event with Redelay in Go.
Go-only for the initial release. The Python and Node.js SDKs are in development — examples will appear here as soon as each SDK ships.

Prerequisites

  • Go 1.25+
  • Access to the Redelay GitHub repos — they are currently private, so you need a GitHub account that has been granted access, SSH set up for GitHub, and go env -w GOPRIVATE='github.com/redelay/*,github.com/flowdsl/*,github.com/FlowDSL/*,github.com/dreplyai/*' plus git config --global url."[email protected]:".insteadOf "https://github.com/". Check with git ls-remote [email protected]:redelay/go-framework.git HEAD.

No broker or database is needed for this page: the examples use the in-memory transport. A full app adds MongoDB and picks Kafka / NATS / Redis with the TRANSPORT env var.

1. Install

shellGo
go get github.com/redelay/go-framework@latest
go get github.com/redelay/go-events@latest

2. Define an event

goGo
// events.go
package main

import "github.com/redelay/go-events/typed"

var OrderCreatedEvent = typed.EventDefinition[OrderPayload]{
    Name:       "order.created",
    EntityType: "order",
    Action:     "created",
    Topic:      "order.created",
}

type OrderPayload struct {
    OrderID string  `json:"order_id"`
    Total   float64 `json:"total"`
}

3. Publish

goGo
// bus is an EventBus — step 4 shows the complete, runnable program.
msg, err := OrderCreatedEvent.NewMessage(
    "ord_1",
    typed.Actor{Type: typed.ActorTypeUser, ID: "user_42"},
    OrderPayload{OrderID: "ord_1", Total: 99.00},
)
if err != nil {
    log.Fatal(err)
}
if err := bus.Publish(ctx, msg); err != nil {
    log.Fatal(err)
}

4. Consume

goGo
// main.go — register consumers first, then Start, then publish.
package main

import (
    "context"
    "encoding/json"
    "fmt"
    "log"

    "github.com/redelay/go-events/core"
    "github.com/redelay/go-events/eventbus"
    "github.com/redelay/go-events/transport/memory"
    "github.com/redelay/go-events/typed"
)

func main() {
    ctx := context.Background()
    bus := eventbus.New(memory.New()) // in-process, synchronous — no broker

    bus.Register(&core.ConsumerRegistration{
        Topic:   "order.created",
        GroupID: "notifications",
        Handler: func(ctx context.Context, msg *core.EventMessage) error {
            var p OrderPayload
            if err := json.Unmarshal(msg.Payload, &p); err != nil {
                return err
            }
            fmt.Printf("Order: %s, total: %.2f\n", p.OrderID, p.Total)
            return nil
        },
    })
    // Registrations made after Start are not picked up.
    if err := bus.Start(ctx); err != nil {
        log.Fatal(err)
    }

    msg, err := OrderCreatedEvent.NewMessage(
        "ord_1",
        typed.Actor{Type: typed.ActorTypeUser, ID: "user_42"},
        OrderPayload{OrderID: "ord_1", Total: 99.00},
    )
    if err != nil {
        log.Fatal(err)
    }
    if err := bus.Publish(ctx, msg); err != nil {
        log.Fatal(err)
    }
}

go run . prints Order: ord_1, total: 99.00.

Inside a framework app you don't build the bus yourself: blank-import _ "github.com/redelay/go-events/module", set TRANSPORT=memory (or kafka / nats / redis), publish through deps.EventBus from your module factory, and return consumers from your module's Consumers() — the lifecycle module registers them and starts the bus.

Next steps