Categorygithub.com/andrew-jones/go-plugins
module
0.8.0
Repository: https://github.com/andrew-jones/go-plugins.git
Documentation: pkg.go.dev

# README

Go Plugins License GoDoc Travis CI Go Report Card

A repository for go-micro plugins.

Check out the Micro on NATS blog post to learn more about plugins.

Follow us on Twitter at @MicroHQ, join the Slack community here or check out the Mailing List.

What's here?

DirectoryDescription
BrokerAsynchronous Pub/Sub; NATS, NSQ, RabbitMQ, Kafka
ClientAlternative clients; gRPC, HTTP
CodecRPC Encoding; BSON, Mercury
KVKey-Value; Memcached, Redis
MetricsInstrumentation; Statsd, Telegraf, Prometheus
MicroMicro Toolkit Plugins
RegistryService Discovery; Etcd, Gossip, NATS
SelectorNode Selection; Label, Mercury
ServerAlternative servers; gRPC, HTTP
SyncLocking/Leadership election; Consul, Etcd
TraceDistributed tracing; Zipkin
TransportSynchronous Request/Response; NATS, RabbitMQ
WrappersClient/Server middleware; Circuit Breakers, Rate Limit

Community Contributions

FeatureDescriptionAuthor
Registry/KubernetesService discovery via the Kubernetes API@nickjackson
Registry/ZookeeperService discovery using Zookeeper@HeavyHorst

Usage

Plugins can be added to go-micro in the following ways. By doing so they'll be available to set via command line args or environment variables.

Import Plugins

import (
	"github.com/micro/go-micro/cmd"
	_ "github.com/micro/go-plugins/broker/rabbitmq"
	_ "github.com/micro/go-plugins/registry/kubernetes"
	_ "github.com/micro/go-plugins/transport/nats"
)

func main() {
	// Parse CLI flags
	cmd.Init()
}

The same is achieved when calling service.Init

import (
	"github.com/micro/go-micro"
	_ "github.com/micro/go-plugins/broker/rabbitmq"
	_ "github.com/micro/go-plugins/registry/kubernetes"
	_ "github.com/micro/go-plugins/transport/nats"
)

func main() {
	service := micro.NewService(
		// Set service name
		micro.Name("my.service"),
	)

	// Parse CLI flags
	service.Init()
}

Use via CLI Flags

Activate via a command line flag

go run service.go --broker=rabbitmq --registry=kubernetes --transport=nats

Use Plugins Directly

CLI Flags provide a simple way to initialise plugins but you can do the same yourself.

import (
	"github.com/micro/go-micro"
	"github.com/micro/go-plugins/registry/kubernetes"
)

func main() {
	registry := kubernetes.NewRegistry() //a default to using env vars for master API

	service := micro.NewService(
		// Set service name
		micro.Name("my.service"),
		// Set service registry
		micro.Registry(registry),
	)
}

Build Pattern

You may want to swap out plugins using automation or add plugins to the micro toolkit. An easy way to do this is by maintaining a separate file for plugin imports and including it during the build.

Create file plugins.go

package main

import (
	_ "github.com/micro/go-plugins/broker/rabbitmq"
	_ "github.com/micro/go-plugins/registry/kubernetes"
	_ "github.com/micro/go-plugins/transport/nats"
)

Build with plugins.go

go build -o service main.go plugins.go

Run with plugins

service --broker=rabbitmq --registry=kubernetes --transport=nats

# 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