文档
主要接口
服务发现
服务发现是每个分布式系统都需要解决的问题,go-micro将这个任务抽象到一个接口中,github.com/micro/go-micro/v2/registry/Registry
// The registry provides an interface for service discovery
// and an abstraction over varying implementations
// {consul, etcd, zookeeper, ...}
type Registry interface {
Init(...Option) error
Options() Options
Register(*Service, ...RegisterOption) error
Deregister(*Service, ...DeregisterOption) error
GetService(string, ...GetOption) ([]*Service, error)
ListServices(...ListOption) ([]*Service, error)
Watch(...WatchOption) (Watcher, error)
String() string
}
所有实现这个结构的插件都可以作服务发现的角色。事实上,在go-plugins上已经有很过实现,包括主流的etcd/consul/zookeeper。以及在内存中的轻量实现。默认实现基于mdns,无需配置,开箱即用。
异步消息
异步消息是构建松耦合与健壮系统的关键技术,相应的接口:
github.com/micro/go-micro/v2/broker/Broker
// Broker is an interface used for asynchronous messaging.
type Broker interface {
Init(...Option) error
Options() Options
Address() string