Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

README

        


Hemera


Build Status
License MIT


A Go microservices toolkit for the NATS messaging system

**Status:** Experimental

## Install

```
go get ./..
go get github.com/nats-io/gnatsd/server
```

### Example
```go

type 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