go-plugins

module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: Apache-2.0

README

Plugins License GoDoc Travis CI Go Report Card

A repository for micro plugins

Overview

Micro tooling is built on a powerful pluggable architecture. Plugins can be swapped out with zero code changes. This repository contains plugins for all micro related tools. Read on for further info.

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

Follow us on Twitter or join the Slack community.

Getting Started

Contents

Contents of this repository:

Directory Description
Broker PubSub messaging; NATS, NSQ, RabbitMQ, Kafka
Client RPC Clients; gRPC, HTTP
Codec Message Encoding; BSON, Mercury
KV Key-Value; Memcached, Redis
Metrics Instrumentation; Statsd, Telegraf, Prometheus
Micro Micro Toolkit Plugins
Registry Service Discovery; Etcd, Gossip, NATS
Selector Load balancing; Label, Cache, Static
Server RPC Servers; gRPC, HTTP
Sync Locking/Leadership election; Consul, Etcd
Trace Distributed Tracing; Zipkin
Transport Bidirectional Streaming; NATS, RabbitMQ
Wrappers Middleware; Circuit Breakers, Rate Limiting, Tracing

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

An anti-pattern is modifying the main.go file to include plugins. Best practice recommendation is to include plugins in a separate file and rebuild with it included. This allows for automation of building plugins and clean separation of concerns.

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

MICRO_BROKER=rabbitmq \
MICRO_REGISTRY=kubernetes \
MICRO_TRANSPORT=nats \
service

Contributions

A few contributions by others

Feature Description Author
Registry/Kubernetes Service discovery via the Kubernetes API @nickjackson
Registry/Zookeeper Service discovery using Zookeeper @HeavyHorst

Directories

Path Synopsis
broker
nats
Package nats provides a NATS broker
Package nats provides a NATS broker
micro
gzip
Package gzip is a micro plugin for gzipping http response
Package gzip is a micro plugin for gzipping http response

Jump to

Keyboard shortcuts

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