moleculer

package module
v0.0.0-...-fd4d688 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2018 License: MIT Imports: 13 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

moleculer-go

This is Moleculer implementation for go (>=1.9.x). Currently only support NATS as transporter.

moleculer(nodejs) info :

Moleculer is a fast, modern and powerful microservices framework for NodeJS (>= v6.x).

Moleculer: https://github.com/ice-services/moleculer

Website: https://moleculer.services

Documentation: https://moleculer.services/docs

How to use, refer to example :

run:

go run .\examples\moleculer-go-demo.go -s nats://192.168.1.69:12008

output:

INFO[09-28 14:37:19.580887] broker.Call demoService.actionA start
INFO[09-28 14:37:19.581886] run actionA, req.Params = map[arg2:123 arg1:aaa]
INFO[09-28 14:37:19.582886] broker.Call demoService.actionA end, res: map[res1:AAA res2:123]
INFO[09-28 14:37:19.582886] broker.Call demoService.actionA end, err: <nil>
INFO[09-28 14:37:19.582886] broker.Call demoService.actionB start
INFO[09-28 14:37:19.582886] run actionB, req.Params = map[arg1:bbb arg2:456]
INFO[09-28 14:37:19.583886] broker.Call demoService.actionB end, res: map[res2:456 res1:BBB]
INFO[09-28 14:37:19.583886] broker.Call demoService.actionB end, err: <nil>
INFO[09-28 14:37:19.583886] broker.Emit user.create start
INFO[09-28 14:37:19.583886] broker.Emit user.create end, err: <nil>
INFO[09-28 14:37:19.583886] broker.Broadcast user.delete start
INFO[09-28 14:37:19.583886] broker.Broadcast user.delete end, err: <nil>
INFO[09-28 14:37:19.583886] run onEventUserCreate, req.Data = map[user:userA status:create]
INFO[09-28 14:37:19.583886] run onEventUserDelete, req.Data = map[user:userB status:delete]

Performance

ENV: one receiver process and one sender process on WIN10(i7-2600), NATS Server on Ubuntu Server 14.04(i7-4790K)

broker.Call demoService.bench goroutineNum[1] callCount[10000] use[6.0100862s] req/s[1663] minLatency[999.9µs] maxLatency[5.0021ms]
broker.Call demoService.bench goroutineNum[5] callCount[50000] use[5.9192496s] req/s[8447] minLatency[999.9µs] maxLatency[10.0015ms]
broker.Call demoService.bench goroutineNum[10] callCount[100000] use[6.3480519s] req/s[15752] minLatency[1.0002ms] maxLatency[12.0096ms]
broker.Call demoService.bench goroutineNum[50] callCount[500000] use[10.052548s] req/s[49738] minLatency[1ms] maxLatency[25.0064ms]

Status :

Not support REQB and EVENTB right now. Please KEEP disableBalancer: false in nodejs moleculer

v0.5.0

Now use Moleculer Protocol Version = "3"

  • MOL.DISCOVER
  • MOL.DISCOVER.nodeID
  • MOL.INFO
  • MOL.INFO.nodeID
  • MOL.HEARTBEAT
  • MOL.REQ.nodeID
  • MOL.REQB.action
  • MOL.RES.nodeID
  • MOL.EVENT.nodeID
  • MOL.EVENTB.event
  • MOL.PING
  • MOL.PING.nodeID
  • MOL.PONG.nodeID
  • MOL.DISCONNECT
  • internal $node.xxx

Documentation

Index

Constants

View Source
const (
	//MoleculerLibVersion = "0.5.0"
	MoleculerLibVersion = "0.5.0"
	//MoleculerProtocolVersion = "3" ~ 0.12 MoleculerJs
	MoleculerProtocolVersion = "3"
)
View Source
const (
	// PanicLevel level, highest level of severity. Logs and then calls panic with the
	// message passed to Debug, Info, ...
	PanicLevel uint32 = iota
	// FatalLevel level. Logs and then calls `os.Exit(1)`. It will exit even if the
	// logging level is set to Panic.
	FatalLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	ErrorLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// InfoLevel level. General operational entries about what's going on inside the
	// application.
	InfoLevel
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CallOptions

type CallOptions struct {
	Timeout    time.Duration
	RetryCount uint64 //not support now
	NodeID     string
	Meta       interface{}
}

CallOptions ...

type EventHandler

type EventHandler func(req *protocol.MsEvent)

EventHandler ...

type RequestHandler

type RequestHandler func(req *protocol.MsRequest) (interface{}, error)

RequestHandler NOTE that you should not modify req, just return data or error

type Service

type Service struct {
	ServiceName string
	Actions     map[string]RequestHandler
	Events      map[string]EventHandler
}

Service ...

type ServiceBroker

type ServiceBroker struct {
	// contains filtered or unexported fields
}

ServiceBroker ...

func NewServiceBroker

func NewServiceBroker(config *ServiceBrokerConfig) (*ServiceBroker, error)

NewServiceBroker ...

func (*ServiceBroker) Broadcast

func (broker *ServiceBroker) Broadcast(event string, params interface{}) (err error)

Broadcast ...

func (*ServiceBroker) Call

func (broker *ServiceBroker) Call(action string, params interface{}, opts *CallOptions) (data interface{}, err error)

Call you can set opts=nil, or custom opts.Timeout (default:5s)

func (*ServiceBroker) Emit

func (broker *ServiceBroker) Emit(event string, params interface{}) (err error)

Emit ...

func (*ServiceBroker) Start

func (broker *ServiceBroker) Start() (err error)

Start ...

func (*ServiceBroker) Stop

func (broker *ServiceBroker) Stop() (err error)

Stop ...

type ServiceBrokerConfig

type ServiceBrokerConfig struct {
	NatsHost              []string
	Hostname              string
	NodeID                string
	LogLevel              uint32        //default 0 (PanicLevel)
	DefaultRequestTimeout time.Duration //default 5s
	Services              map[string]Service
}

ServiceBrokerConfig ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址