/broker

A message broker in go

Primary LanguageGoMIT LicenseMIT

broker

A message broker in go. A toy project.

fun parts

  • using closures instead of mutexes
  • trying to make the broker interface as simple as a client just providing an io.Reader and an io.Writer (not there just yet) which means you can add the broker atop any valid implementation - not just a tcp server like in this repo.
  • figuring out if the store can be a interface

usage

The message protocol is ping|<op>;<queue>;[<text>]

# run server
$ go run main.go
# run client
$ nc localhost 12001
pub;cats;bixa is a kitty
ok
sub;cats;
ok
bixa is a kitty
ping # extends the timeout
ok

tests

$ go test ./pkg/broker/... [-race -bench=. -cover]

todos

  • pub
  • sub
  • create queues on the fly
  • persistance and ack
  • msg max len
  • less messy msg protocol
  • handle empty msg text
  • concurrent delivery to subscriber
  • avoid sub dupes
  • add server component
  • add brokerConf
  • replace net.Conn with io.Writer
  • add benchmark for NewId
  • try reading [1]byte to check connection before write - requires a io.ReadWriter
  • store refs to subscribed queues to make the blocking op to remove subscriber faster
  • add ping
  • detach server component from broker
  • change broker interface to a client with an io.Reader and an io.Writer

license

MIT