Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hemerajs/go-hemera
🔬Writing reliable & fault-tolerant microservices with https://nats.io
https://github.com/hemerajs/go-hemera
golang hemera microservice pattern-matching rpc
Last synced: 2 months ago
JSON representation
🔬Writing reliable & fault-tolerant microservices with https://nats.io
- Host: GitHub
- URL: https://github.com/hemerajs/go-hemera
- Owner: hemerajs
- License: mit
- Created: 2017-08-03T09:36:14.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-27T15:37:46.000Z (almost 7 years ago)
- Last Synced: 2024-06-20T13:29:20.147Z (7 months ago)
- Topics: golang, hemera, microservice, pattern-matching, rpc
- Language: Go
- Homepage:
- Size: 68.4 KB
- Stars: 16
- Watchers: 8
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A Go microservices toolkit for the NATS messaging system**Status:** Experimental
## Install
```
go get ./..
go get github.com/nats-io/gnatsd/server
```### Example
```gotype MathPattern struct {
Topic string
Cmd string
}type RequestPattern struct {
Topic string
Cmd string
A int
B int
Meta server.Meta
Delegate server.Delegate
}type Response struct {
Result int
}nc, _ := nats.Connect(nats.DefaultURL)
hemera, _ := server.CreateHemera(nc, server.Timeout(2000), server.IndexingStrategy(DepthIndexing)...)
// Define the pattern of your action
pattern := MathPattern{Topic: "math", Cmd: "add"}
hemera.Add(pattern, func(req *RequestPattern, reply server.Reply, context *server.Context) {
// Build response
result := Response{Result: req.A + req.B}
// Add meta informations
context.Meta["key"] = "value"
// Send it back
reply.Send(result)
})// Define the call of your RPC
requestPattern := RequestPattern{
Topic: "math",
Cmd: "add",
A: 1,
B: 2,
Meta: server.Meta{ "Test": 1 },
Delegate: server.Delegate{ "Test": 2 },
}res := &Response{} // Pointer to struct
ctx := hemera.Act(requestPattern, res)res = &Response{}
ctx = hemera.Act(requestPattern, res, ctx)log.Printf("Response %+v", res)
```## Pattern matching
We implemented two indexing strategys
- `depth order` match the entry with the most properties first.
- `insertion order` match the entry with the least properties first. `(default)`## TODO
- [X] Setup nats server for testing
- [X] Implement Add and Act
- [X] Create Context (trace, meta, delegate) structures
- [X] Use tree for pattern indexing
- [X] Support indexing by depth order
- [X] Support indexing by insetion order
- [X] Clean request pattern from none primitive values
- [X] Meta & Delegate support
- [X] Implement basic pattern matching (router)
- [ ] Implement router `remove` method## Credits
- [Bloomrun](https://github.com/mcollina/bloomrun) the pattern matching library for NodeJs