Go messaging library
goevents allows to dispatch events between applications.
An application produces events based on actions. Another application consume these events and maybe create new events.
Scenario: If an application produces an events "payment-received", another application may want to delivery the product to the buyer.
- AMQP
The consumer
conn, err := NewConnection("amqp://guest:guest@127.0.0.1:5672/")
if err != nil {
panic(err)
}
c, err := NewConsumer(conn, false, "events-exchange", "events-queue")
if err != nil {
panic(err)
}
c.Subscribe("object.*", func(body []byte) bool {
fmt.Println(body)
return true
})
go c.Consume()
conn.WaitUntilConnectionClose()The producer
conn, err := NewConnection("amqp://guest:guest@127.0.0.1:5672/")
if err != nil {
panic(err)
}
p, err := NewProducer(conn, "events-exchange", "events-queue")
if err != nil {
panic(err)
}
err = p.Publish("object.my_action", []byte("message"))
if err != nil {
panic(err)
}The action can be a full word, a wildcard (*) or multiple words or wildcards delimited by dots (.)
Look the examples below:
- The action handler
my_actionwill match onlymy_actionevent. - The action handler
my_action.foowill match onlymy_action.fooevent. - The action handler
my_action.*will matchmy_action.foo,my_action.barand allmy_action.*events. - The action handler
my_action.foo.barwill match onlymy_action.foo.barevent. - The action handler
my_action.*.barwill matchmy_action.foo.bar,my_action.bar.barand allmy_action.*.barevents. - The action handler
*will match all events.