Skip to content

davidscottmills/pubsub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PubSub

PubSub is a Go Package for in-memory publish/subscribe.

test and build Coverage Status Go Report Card Documentation GitHub issues license GitHub go.mod Go version of a Go module

Installation

go get github.com/davidscottmills/pubsub

Usage

package main()

import (
    "fmt"
    "github.com/davidscottmills/pubsub"
)

var ps *PubSub

func main() {
    ps := NewPubSub()

    handerFunc := func(m *pubsub.Msg) {
        fmt.Println(m.Data)
    }

    // Subscribe to a subject
    s, err := ps.Subscribe("subject.name", handerFunc)
    defer s.Unsubscribe()

    // Publish
    err := ps.Publish("subject.name", "Hello, world!")

    someStruct := struct{}{}

    // Publish any type you'd like
    ps.Publish("subject.name", someStruct)

    runAndBlock()
}

Subject Routing

Subject naming matches that of NATS.

Subject Names

  • All ascii alphanumeric characters except spaces/tabs and separators which are "." and ">" are allowed. Subject names can be optionally token-delimited using the dot character (.)
  • Subjects are case sensative

Subject Wildcards

  • The asterisk character (*) matches a single token at any level of the subject.
  • The greater than symbol (>), also known as the full wildcard, matches one or more tokens at the tail of a subject, and must be the last token. The wildcarded subject foo.> will match foo.bar or foo.bar.baz.1, but not foo.
  • Wildcards must be a separate token (foo..baz or foo.> are syntactically valid; foo.bar, fo.br and foo> are not)

TODO

  • Implement and test close or drain on PubSub
  • Implement and test errors

About

PubSub is a Go Package for in-memory publish/subscribe.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages