1
0
mirror of https://github.com/eventials/goevents.git synced 2025-04-24 13:48:53 +08:00
eventials.goevents/README.md

79 lines
2.1 KiB
Markdown
Raw Normal View History

2016-12-01 16:17:55 -02:00
# goevents [![Build Status](https://travis-ci.org/eventials/goevents.svg?branch=master)](https://travis-ci.org/eventials/goevents) [![GoDoc](https://godoc.org/github.com/eventials/goevents?status.svg)](http://godoc.org/github.com/eventials/goevents) [![Go Report Card](https://goreportcard.com/badge/github.com/eventials/goevents)](https://goreportcard.com/report/github.com/eventials/goevents)
Go messaging library
## About
`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.
## Supported Transport
- AMQP
## How to use
**The consumer**
```go
2016-12-28 09:20:29 -02:00
conn, err := NewConnection("amqp://guest:guest@127.0.0.1:5672/")
2016-12-01 16:17:55 -02:00
if err != nil {
panic(err)
}
2016-12-28 09:20:29 -02:00
c, err := NewConsumer(conn, false, "events-exchange", "events-queue")
2016-12-01 16:17:55 -02:00
if err != nil {
panic(err)
}
2016-12-01 16:58:20 -02:00
c.Subscribe("object.*", func(body []byte) bool {
2016-12-01 16:17:55 -02:00
fmt.Println(body)
return true
})
2016-12-28 09:20:29 -02:00
go c.Consume()
conn.WaitUntilConnectionClose()
2016-12-01 16:17:55 -02:00
```
**The producer**
```go
2016-12-28 09:20:29 -02:00
conn, err := NewConnection("amqp://guest:guest@127.0.0.1:5672/")
2016-12-01 16:17:55 -02:00
if err != nil {
panic(err)
}
2016-12-28 09:20:29 -02:00
p, err := NewProducer(conn, "events-exchange", "events-queue")
2016-12-01 16:17:55 -02:00
if err != nil {
panic(err)
}
2016-12-01 16:58:20 -02:00
err = p.Publish("object.my_action", []byte("message"))
2016-12-01 16:17:55 -02:00
if err != nil {
panic(err)
}
```
2016-12-01 16:56:44 -02:00
### Actions
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_action` will match only `my_action` event.
- The action handler `my_action.foo` will match only `my_action.foo` event.
- The action handler `my_action.*` will match `my_action.foo`, `my_action.bar` and all `my_action.*` events.
- The action handler `my_action.foo.bar` will match only `my_action.foo.bar` event.
- The action handler `my_action.*.bar` will match `my_action.foo.bar`, `my_action.bar.bar` and all `my_action.*.bar` events.
- The action handler `*` will match all events.