repositorypackage
0.3.11
Repository: https://github.com/moleculer-go/moleculer.git
Documentation: pkg.go.dev
# Packages
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# README
Moleculer Go
š Progressive microservices framework for Go
Inspired and compatible with Moleculer JS
Simple, fast, light and fun to develop with. Also easy, very easy to test ;)
Get Started
Example
package main
import (
"fmt"
"github.com/moleculer-go/moleculer"
"github.com/moleculer-go/moleculer/broker"
)
type MathService struct {
}
func (s MathService) Name() string {
return "math"
}
func (s *MathService) Add(params moleculer.Payload) int {
return params.Get("a").Int() + params.Get("b").Int()
}
func (s *MathService) Sub(a int, b int) int {
return a - b
}
func main() {
var bkr = broker.New(&moleculer.Config{LogLevel: "error"})
bkr.Publish(&MathService{})
bkr.Start()
result := <-bkr.Call("math.add", map[string]int{
"a": 10,
"b": 130,
})
fmt.Println("result: ", result.Int())
//$ result: 140
bkr.Stop()
}
Features
- Service Broker
- Transit and Transport
- Actions (request-reply)
- Events
- Mixins
- Load balancing for actions and events (random round-robin)
- Service registry & dynamic service discovery
- Versioned services
- Middlewares
- NATS Streaming Transporter
- TCP Transporter
- Redis Transporter
- JSON Serializer
Installation
$ go get github.com/moleculer-go/moleculer
Running examples
# simple moleculer db example with memory adaptor
$ go run github.com/moleculer-go/store/examples/users
# simple moleculer db example with Mongo adaptor
$ go run github.com/moleculer-go/store/examples/usersMongo
# simple moleculer db example with SQLite adaptor
$ go run github.com/moleculer-go/store/examples/usersSQLite
# complex moleculer db example with population of fields by other services
$ go run github.com/moleculer-go/store/examples/populates
Running tests
# integration tests require mongo, nats streaming and rabbitmq
# run mongo
docker run -d -p 27017:27017 mongo
# run nats-streaming
docker run -d -p 4222:4222 nats-streaming -mc 0
# run rabbitmq
docker run -d -p 5672:5672 rabbitmq
# running all tests
go test ./...
# or
ginkgo -r