~sbinet/msgbus

A simple in-memory message bus
d2725ac8 — Sebastien Binet 4 months ago
all: first import

clone

read-only
https://git.sr.ht/~sbinet/msgbus
read/write
git@git.sr.ht:~sbinet/msgbus

You can also use your local clone with git send-email.

#msgbus

Build status GoDoc

msgbus is a simple message bus for Go.

#Example

func main() {
    bus := msgbus.New[string]()

    ch1 := bus.Subscribe("topic1")
    ch2 := bus.Subscribe("topic2", msgbus.WithTimeout[string](1*time.Second))
    ch3 := bus.Subscribe("topic2", msgbus.WithSize[string](5))

    defer bus.Unsubscribe("topic1", ch1)
    defer bus.Unsubscribe("topic2", ch2)
    defer bus.Unsubscribe("topic2", ch3)

    go func() {
        for v := range ch1 {
            fmt.Printf("ch1: %q\n", v)
        }
    }()

    go func() {
        for v := range ch2 {
            fmt.Printf("ch2: %q\n", v)
        }
    }()

    go func() {
        for v := range ch3 {
            fmt.Printf("ch3: %q\n", v)
        }
    }()

    bus.Publish("topic1", "msg-A")
    bus.Publish("topic2", "msg-1")
    bus.Publish("topic2", "msg-2")
    bus.Publish("topic1", "msg-B")
    bus.Publish("topic2", "msg-3")
}

#License

  • msgbus is released under the BSD-3 license.