internal/website/docs/registry.md
The registry is responsible for service discovery in Go Micro. It allows services to register themselves and discover other services.
Go Micro supports multiple registry backends, including:
You can configure the registry when initializing your service.
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(...).
MICRO_REGISTRY=etcd MICRO_REGISTRY_ADDRESS=127.0.0.1:2379 micro server
Common variables:
MICRO_REGISTRY: selects the registry implementation (mdns, consul, etcd, nats).MICRO_REGISTRY_ADDRESS: comma-separated list of registry addresses.Backend-specific variables:
ETCD_USERNAME, ETCD_PASSWORD for authenticated clusters.Here's how to use a custom registry (e.g., Consul) in your Go Micro service:
package main
import (
"go-micro.dev/v5"
"go-micro.dev/v5/registry/consul"
)
func main() {
reg := consul.NewRegistry()
service := micro.NewService(
micro.Registry(reg),
)
service.Init()
service.Run()
}