6
0
mirror of https://git.mills.io/prologic/msgbus.git synced 2024-06-30 10:41:47 +00:00
prologic-msgbus/examples/hello.go
James Mills 01ab56f9b3 Fix Subscribe() deadlock (#34)
Fixes #139

This was caused by full subscriber buffers.

Co-authored-by: James Mills <prologic@shortcircuit.net.au>
Reviewed-on: https://git.mills.io/prologic/msgbus/pulls/34
2022-04-04 01:15:49 +00:00

29 lines
422 B
Go

package main
import (
"log"
"git.mills.io/prologic/msgbus"
)
func main() {
m, err := msgbus.NewMessageBus()
if err != nil {
log.Fatal(err)
}
t := m.NewTopic("foo")
m.Put(m.NewMessage(t, []byte("Hello World!")))
msg, ok := m.Get(t)
if !ok {
log.Printf("No more messages in queue: foo")
return
}
log.Printf(
"Received message: id=%d topic=%s payload=%s",
msg.ID, msg.Topic.Name, msg.Payload,
)
}