Plugins

Micro provides a pluggable architecture for all tooling. This means underlying implementations can be swapped out.

Go Micro and the Micro toolkit include separate types of plugins. Navigate from the sidebar to learn more about each.

Overview

At a high level plugins provide the opportunity to swap out underlying infrastructure and dependencies. This means a microservice can be written in one way and run locally with zero dependencies but then equally run as a highly resilient system in the cloud when using distributed systems to underpin its usage.

Usage

By default go-micro only provides a few implementation of each interface at the core but it’s completely pluggable. There’s already dozens of plugins which are available at github.com/micro/go-plugins. Contributions are welcome! Plugins ensure that your Go Micro services live on long after technology evolves.

If you want to integrate plugins simply link them in a separate file and rebuild.

Create a plugins.go file and import the plugins you want:

  1. package main
  2. import (
  3. // consul registry
  4. _ "github.com/micro/go-plugins/registry/consul"
  5. // rabbitmq transport
  6. _ "github.com/micro/go-plugins/transport/rabbitmq"
  7. // kafka broker
  8. _ "github.com/micro/go-plugins/broker/kafka"
  9. )

Write Plugins

Plugins are a concept built on Go’s interface. Each package maintains a high level interface abstraction. Simply implement the interface and pass it in as an option to the service.

The service discovery interface is called Registry. Anything which implements this interface can be used as a registry. The same applies to the other packages.

  1. type Registry interface {
  2. Register(*Service, ...RegisterOption) error
  3. Deregister(*Service) error
  4. GetService(string) ([]*Service, error)
  5. ListServices() ([]*Service, error)
  6. Watch() (Watcher, error)
  7. String() string
  8. }

Browse go-plugins to get a better idea of implementation details.

Examples

Framework

Runtime

  • Router - Configurable http routing and proxying
  • AWS X-Ray - Tracing integration for AWS X-Ray
  • IP Whitelist - Whitelisting IP address access

Repository

The open source plugins can be found at github.com/micro/go-plugins.