Skip to content
generated from dogmatiq/template-go

A very small in-memory message bus for Go.

License

Notifications You must be signed in to change notification settings

dogmatiq/minibus

Repository files navigation

Minibus

Minibus is a very small in-memory message bus for Go.

Documentation Latest Version Build Status Code Coverage

Minibus executes a set of functions concurrently and exchanges messages between them. You can think of it like an errgroup.Group with a built-in message bus.

Example

A more detailed version of this example annotated with comments is available here.

type SayHello struct {
    Name string
}

minibus.Run(
    context.Background(),
    minibus.WithFunc(
        func(ctx context.Context) error {
            minibus.Subscribe[SayHello](ctx)
            minibus.Ready(ctx)

            for m := range minibus.Inbox(ctx) {
                switch m := m.(type) {
                case SayHello:
                    fmt.Printf("Hello, %s!\n", m.Name)
                }
            }

            return nil
        },
    ),
    minibus.WithFunc(
        func(ctx context.Context) error {
            minibus.Ready(ctx)
            return minibus.Send(ctx, SayHello{"world"})
        },
    ),
)

About

A very small in-memory message bus for Go.

Resources

License

Stars

Watchers

Forks

Packages

No packages published