Giter VIP home page Giter VIP logo

moleculer's Introduction

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

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

moleculer's People

Contributors

casskir avatar clicklord avatar dependabot[bot] avatar pentateu avatar slaterx avatar vpashka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

moleculer's Issues

AMQ fails intermittently in the CI

@casskir the tests for AMQ fails intermittently in the CI
Check:
https://cloud.drone.io/moleculer-go/moleculer
Builds #400 and #401 failed at different points and #402 passed.
No code changes, I just manually restarted the build. So test sometimes pass and sometimes fails. On my local machine passed every-time, so it could be that in the CI server is a bit slower and cause these inconsistencies.

MoleculerJS v0.14.x and protocol V4 compatibility.

Hi guys, I hope all things are going well. I wish there is a definite goal toward MoleculerJS v0.14.x and protocol V4 and further compatibility. But I know there is not enough time for this currently.

So I want to suggest that how about to publicize moleculer-go project and gather some contributors from 'moleculer' community?

MolecuerJS has released v0.14.0-beta1 in July, and now -beta3.
Also now Moleculer protocol has been arrived to V4. ref.

I think the time has come to keep up with moleculerJS. I know making an open source polyglot is not easy but just can't stop worrying that it would be too far apart from the moleculerJS specially in core modules (transit, metrics, tracing, protocol, etc ...)
When this problem is resolved, I think moleculer-go version API gateway and other duplicate modules could be non-mandatory work .

For example, moleculer-web released a new features recently.. ref. and many of moleculer users already have been using it. I think inducing developers to Golang version API Gateway would be hard and will not be economic.

And me and others are working on so many other moleculer modules, We can just embrace all the MoleculerJS module/services. I don't want to be rude and I am not disregarding your amzaing works, but I think moleculer-go can focus on 'moleculer' itself rather than adaptive module and plugins which have replacements. Because as you know MSA can accept Node.js and Golang together!

I know you guys working too hard for moleculer-go and whole community. As a big fan of Moleculer and Golang, I really appreciate to it. Also I hope that the time when Golang users get noticed about the power of moleculer comes faster. I think moleculer-go should be ready for that.

So, are you in #moleculer Discord channel? It would be amazing if you open and manage #moleculer-go channel. I want to discuss about it more and hope you have same idea. Also please tell me anything I can help, now I have a little time for contribution.

Moleculerjs and moleculer-go compatibility issue

Current Behavior

Call moleculerjs => moleculer-go throws error on moleculerjs side. But calling moleculer-go => moleculerjs works as expected

Console output

[2020-03-05T19:44:41.385Z] WARN  imac-denis.local-9788/BROKER: Service 'goMath.add' is not available.
(node:9788) UnhandledPromiseRejectionWarning: ServiceNotAvailableError: Service 'goMath.add' is not available.
    at ServiceBroker.findNextActionEndpoint (/Users/denis/go/src/github.com/nnqq/moleculer-go-and-js/js/node_modules/moleculer/src/service-broker.js:857:13)
    at ServiceBroker.call (/Users/denis/go/src/github.com/nnqq/moleculer-go-and-js/js/node_modules/moleculer/src/service-broker.js:876:25)
    at Timeout._onTimeout (/Users/denis/go/src/github.com/nnqq/moleculer-go-and-js/js/server.js:21:37)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)

Expected Behavior

Expected to get response from moleculer-go service

Console output

Response from Golang service => 3

Failure Information

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. clone https://github.com/nnqq/moleculer-go-and-js
  2. run make bug on master branch
  3. watch for console output (error)

Reproduce code snippet

Repository https://github.com/nnqq/moleculer-go-and-js

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

  • Moleculerjs version: v0.13.13
  • Moleculer-go version: v0.2.1
  • NodeJS version: v12.13.1
  • Golang version: v1.14
  • Operating System: macOS v10.15.3

Failure Logs

[2020-03-05T19:44:41.385Z] WARN  imac-denis.local-9788/BROKER: Service 'goMath.add' is not available.
(node:9788) UnhandledPromiseRejectionWarning: ServiceNotAvailableError: Service 'goMath.add' is not available.
    at ServiceBroker.findNextActionEndpoint (/Users/denis/go/src/github.com/nnqq/moleculer-go-and-js/js/node_modules/moleculer/src/service-broker.js:857:13)
    at ServiceBroker.call (/Users/denis/go/src/github.com/nnqq/moleculer-go-and-js/js/node_modules/moleculer/src/service-broker.js:876:25)
    at Timeout._onTimeout (/Users/denis/go/src/github.com/nnqq/moleculer-go-and-js/js/server.js:21:37)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)

authorization options for NATS transport

Hello,

nats.Options have User, Password (Token, TLSConfig etc).
How can I transfer authorization parameters when creating a broker?

	var brk = broker.New(&moleculer.Config{
                ...
		Transporter:        "nats://localhost:6222",
	})

Does the current version support Redis as a transporter

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is.

Describe the solution you'd like
A clear and concise description of what you want to happen.
Example usage, example API, etc.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Release preparation: 0.2.0

List of tasks for releasing 0.2.0:

  • 1) Developer Contribution Guidelines
  • 2) Feature roadmap
    • 2.1) Action validators
    • 2.2) Stream support
    • 2.3) Additional load balancing implementations
    • 2.4) Additional fault-tolerance features
    • 2.5) Caching implementations
    • 2.6) Additional transporters
    • 2.7) Serializer implementations
  • 3) Integrate building systems with chatting community
  • 4) Improve badges on repositories
  • 5) Improve docs translation js->golang
  • 6) Improve website DNS and CDN
  • 7) Improve GitHub features on repositories

Broker hang if multiple goroutines make calls

Describe the bug
Sometimes when we make calls from multiple goroutines broker is hanged. Also, a timeout error is not fired.

To Reproduce
Make calls from multiple goroutines. Often reproduced on a slow machine.

broker := broker.New(config)

for t := 0; t < 10000; t++ {
		wg := sync.WaitGroup{}
		wg.Add(3)

		go func() {
			defer wg.Done()

			<-broker.Call(action, params)
			log.Info("first done")
		}()

		go func() {
			defer wg.Done()

			<-broker.Call(action, params)
			log.Info("second done")
		}()

		go func() {
			defer wg.Done()

			<-broker.Call(action, params)
			log.Info("third done")
		}()

		wg.Wait()
	}

Expected behavior
All requests successfully finished or execution timeout error returned.

Additional context
My investigation showed that multiple async calls generate requests with the same ID:
image

And the main problem in:

id := util.RandomString(12)

This function using random generator that unsafe for multiple goroutines:

// NewSource returns a new pseudo-random Source seeded with the given value.
// Unlike the default Source used by top-level functions, this source is not
// safe for concurrent use by multiple goroutines.

Another way how reproduce:

t := make([]string, 1000)

	wg := sync.WaitGroup{}
	wg.Add(1000)

	for i := 0; i < 1000; i++ {
		go func(idx int) {
			defer wg.Done()
			t[idx] = util.RandomString(12)
		}(i)
	}

	wg.Wait()

	v := map[string]interface{}{}
	for i := 0; i < len(t); i++ {
		v[t[i]] = nil
	}

	fmt.Printf("Uniq: %d", len(v))

generates less than 1000 unique strings.

Moleculer JS compatibility

@dehypnosis had the following issues while trying to integrate with Moleculer JS.

Current moleculer-go seems that has not exactly same protocol with moelculer-js. For example, moelculer-go discovers remote actions as []interfaces{} type assertion, but moleculer-js services reply as map[string]interfaces{}. And there are some issues while discovering, and call each others between different moleculer client library.

Protocol v4 not supported

Describe the bug
I'm using nodejs moleculer implementation v0.14 and the protocol version is 4. When I tried to run moleculer-go with the same NATS server it just reports ProtocolVersionMismatch error which I think is normal as for instance, this go implementation is still on version 3 of the protocol

To Reproduce
Run a moleculer js (use docker to make it faster, and expose the NATS port to the host), then run the example in the readme of this repo -> ProtocolVersionMissmatchError

Expected behavior
Protocol version 4 supported

Additional context
Maybe a comparison of both protocol should be established first in order to have a good background of what should be done. Also I'm not sure if all pending issues are required or not.

I'm willing to make progress on this section if anyone can help me to get started in better condition

is NATS supported currently?

var serviceBrokerConfig = &moleculer.Config{
	LogLevel: "info",
	Transporter: "nats://dev.nats.svc:4222",
}

Above configuration is ignored and just created MEMORY transporter, should i wait for the feature?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.