Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/uudashr/rebound
https://github.com/uudashr/rebound
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/uudashr/rebound
- Owner: uudashr
- License: apache-2.0
- Created: 2024-02-23T23:38:24.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-06-28T06:45:04.000Z (7 months ago)
- Last Synced: 2024-06-28T07:59:42.562Z (7 months ago)
- Language: Go
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[![Go Reference](https://pkg.go.dev/badge/github.com/uudashr/rebound.svg)](https://pkg.go.dev/github.com/uudashr/rebound)
# Rebound
Rebound is simple event handling based on registered name. The handling is automatically unmarshaled to the registered type.Think like: you want to dispatch a serialized event, then you want to handle it in a type-safe way.
It can be use to
1. Send and consume through the messaging/streaming service
2. Store/retrieve the event to and from the database (outbox pattern)## Installation
```shell
go get github.com/uudashr/rebound
```## Usage
```go
package mainimport (
"fmt""github.com/uudashr/rebound"
)type OrderCompleted struct {
OrderID string
}func main() {
rb := &rebound.Rebound{}// Register the event
rb.ReactTo("order.completed", func(event OrderCompleted) error {
// Handle the "order.completed" event
fmt.Printf("Order %q is completed\n", event.OrderID)
return nil
})// Dispatch the "order.completed" event
rb.Dispatch("order.completed", []byte(`{"OrderID":"123"}`))
}
```