go-micro.dev/v5@v5.12.0/internal/website/docs/registry.md (about)

     1  ---
     2  layout: default
     3  ---
     4  
     5  # Registry
     6  
     7  The registry is responsible for service discovery in Go Micro. It allows services to register themselves and discover other services.
     8  
     9  ## Features
    10  - Service registration and deregistration
    11  - Service lookup
    12  - Watch for changes
    13  
    14  ## Implementations
    15  Go Micro supports multiple registry backends, including:
    16  - MDNS (default)
    17  - Consul
    18  - Etcd
    19  - NATS
    20  
    21  You can configure the registry when initializing your service.
    22  
    23  ## Plugins Location
    24  
    25  Registry plugins live in this repository under `go-micro.dev/v5/registry/<plugin>` (e.g., `consul`, `etcd`, `nats`). Import the desired package and pass it via `micro.Registry(...)`.
    26  
    27  ## Configure via environment
    28  
    29  ```
    30  MICRO_REGISTRY=etcd MICRO_REGISTRY_ADDRESS=127.0.0.1:2379 micro server
    31  ```
    32  
    33  Common variables:
    34  - `MICRO_REGISTRY`: selects the registry implementation (`mdns`, `consul`, `etcd`, `nats`).
    35  - `MICRO_REGISTRY_ADDRESS`: comma-separated list of registry addresses.
    36  
    37  Backend-specific variables:
    38  - Etcd: `ETCD_USERNAME`, `ETCD_PASSWORD` for authenticated clusters.
    39  
    40  ## Example Usage
    41  
    42  Here's how to use a custom registry (e.g., Consul) in your Go Micro service:
    43  
    44  ```go
    45  package main
    46  
    47  import (
    48      "go-micro.dev/v5"
    49      "go-micro.dev/v5/registry/consul"
    50  )
    51  
    52  func main() {
    53      reg := consul.NewRegistry()
    54      service := micro.NewService(
    55          micro.Registry(reg),
    56      )
    57      service.Init()
    58      service.Run()
    59  }
    60  ```