github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/docs/v2/plugins/plugins.md (about)

     1  ---
     2  title: Plugins
     3  keywords: plugins
     4  tags: [plugins]
     5  sidebar: home_sidebar
     6  permalink: /plugins
     7  summary: 
     8  ---
     9  
    10  Micro provides a pluggable architecture for all tooling. This means underlying implementations can be swapped out.
    11  
    12  Go Micro and the Micro toolkit include separate types of plugins. Navigate from the sidebar to learn more about each.
    13  
    14  ## Overview
    15  
    16  At a high level plugins provide the opportunity to swap out underlying infrastructure and dependencies. This means 
    17  a microservice can be written in one way and run locally with zero dependencies but then equally run as a highly 
    18  resilient system in the cloud when using distributed systems to underpin its usage.
    19  
    20  ## Usage
    21  
    22  By default go-micro only provides a few implementation of each interface at the core but it's completely pluggable. 
    23  There's already dozens of plugins which are available at [github.com/micro/go-plugins](https://github.com/micro/go-plugins). 
    24  Contributions are welcome! Plugins ensure that your Go Micro services live on long after technology evolves.
    25  
    26  If you want to integrate plugins simply link them in a separate file and rebuild.
    27  
    28  Create a plugins.go file and import the plugins you want:
    29  
    30  ```go
    31  package main
    32  
    33  import (
    34          // consul registry
    35          _ "github.com/micro/go-plugins/registry/consul"
    36          // rabbitmq transport
    37          _ "github.com/micro/go-plugins/transport/rabbitmq"
    38          // kafka broker
    39          _ "github.com/micro/go-plugins/broker/kafka"
    40  )
    41  ```
    42  
    43  ## Write Plugins
    44  
    45  Plugins are a concept built on Go's interface. Each package maintains a high level interface abstraction. 
    46  Simply implement the interface and pass it in as an option to the service.
    47  
    48  The service discovery interface is called [Registry](https://pkg.go.dev/github.com/micro/go-micro/v2/registry#Registry). 
    49  Anything which implements this interface can be used as a registry. The same applies to the other packages.
    50  
    51  ```go
    52  type Registry interface {
    53      Register(*Service, ...RegisterOption) error
    54      Deregister(*Service) error
    55      GetService(string) ([]*Service, error)
    56      ListServices() ([]*Service, error)
    57      Watch() (Watcher, error)
    58      String() string
    59  }
    60  ```
    61  
    62  Browse [go-plugins](https://github.com/micro/go-plugins) to get a better idea of implementation details.
    63  
    64  ## Examples
    65  
    66  ### Framework
    67  
    68  - [Consul Registry](https://github.com/micro/go-plugins/tree/master/registry/consul) - Service discovery using Consul
    69  - [K8s Registry](https://github.com/micro/go-plugins/tree/master/registry/kubernetes) - Service discovery using Kubernetes
    70  - [Kafka Broker](https://github.com/micro/go-plugins/tree/master/broker/kafka) - Kafka message broker
    71  
    72  ### Runtime
    73  
    74  - [Router](https://github.com/micro/go-plugins/tree/master/micro/router) - Configurable http routing and proxying
    75  - [AWS X-Ray](https://github.com/micro/go-plugins/tree/master/micro/trace/awsxray) - Tracing integration for AWS X-Ray
    76  - [IP Whitelist](https://github.com/micro/go-plugins/tree/master/micro/ip_whitelist) - Whitelisting IP address access
    77  
    78  ## Repository
    79  
    80  The open source plugins can be found at [github.com/micro/go-plugins](https://github.com/micro/go-plugins).
    81  
    82