项目作者: moleculer-go

项目描述 :
🚀 Progressive microservices framework for Go - based and compatible with https://github.com/moleculerjs/moleculer
高级语言: Go
项目地址: git://github.com/moleculer-go/moleculer.git
创建时间: 2019-01-15T04:30:55Z
项目社区:https://github.com/moleculer-go/moleculer

开源协议:MIT License

下载


Moleculer Go

🚀 Progressive microservices framework for Go
Moleculer Gopher
Gopher

Inspired and compatible with Moleculer JS

Simple, fast, light and fun to develop with. Also easy, very easy to test ;)

Gitter
Drone.io Build Status
Go Report Card
Coverage -> Coveralls
Coverage -> Codecov

Get Started

Example

  1. package main
  2. import (
  3. "fmt"
  4. "github.com/moleculer-go/moleculer"
  5. "github.com/moleculer-go/moleculer/broker"
  6. )
  7. type MathService struct {
  8. }
  9. func (s MathService) Name() string {
  10. return "math"
  11. }
  12. func (s *MathService) Add(params moleculer.Payload) int {
  13. return params.Get("a").Int() + params.Get("b").Int()
  14. }
  15. func (s *MathService) Sub(a int, b int) int {
  16. return a - b
  17. }
  18. func main() {
  19. var bkr = broker.New(&moleculer.Config{LogLevel: "error"})
  20. bkr.Publish(&MathService{})
  21. bkr.Start()
  22. result := <-bkr.Call("math.add", map[string]int{
  23. "a": 10,
  24. "b": 130,
  25. })
  26. fmt.Println("result: ", result.Int())
  27. //$ result: 140
  28. bkr.Stop()
  29. }

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
  • JSON Serializer

Installation

  1. $ go get github.com/moleculer-go/moleculer

Running examples

  1. # simple moleculer db example with memory adaptor
  2. $ go run github.com/moleculer-go/store/examples/users
  3. # simple moleculer db example with Mongo adaptor
  4. $ go run github.com/moleculer-go/store/examples/usersMongo
  5. # simple moleculer db example with SQLite adaptor
  6. $ go run github.com/moleculer-go/store/examples/usersSQLite
  7. # complex moleculer db example with population of fields by other services
  8. $ go run github.com/moleculer-go/store/examples/populates

Running tests

  1. # integration tests require mongo, nats streaming and rabbitmq
  2. # run mongo
  3. docker run -d -p 27017:27017 mongo
  4. # run nats-streaming
  5. docker run -d -p 4222:4222 nats-streaming -mc 0
  6. # run rabbitmq
  7. docker run -d -p 5672:5672 rabbitmq
  8. # running all tests
  9. go test ./...
  10. # or
  11. ginkgo -r