1.1.1. Transort通信接口
通信相关接口
type Socket interface {Recv(*Message) errorSend(*Message) errorClose() error}type Client interface {Socket}type Listener interface {Addr() stringClose() errorAccept(func(Socket)) error}type Transport interface {Dial(addr string, opts ...DialOption) (Client, error)Listen(addr string, opts ...ListenOption) (Listener, error)String() string}
1.1.2. Codec编码接口
编解码,底层也是protobuf
type Codec interface {ReadHeader(*Message, MessageType) errorReadBody(interface{}) errorWrite(*Message, interface{}) errorClose() errorString() string}
1.1.3. Registry注册接口
服务注册发现的实现:etcd、consul、mdns、kube-DNS、zk
type Registry interface {Register(*Service, ...RegisterOption) errorDeregister(*Service) errorGetService(string) ([]*Service, error)ListServices() ([]*Service, error)Watch(...WatchOption) (Watcher, error)String() stringOptions() Options}
1.1.4. Selector负载均衡
根据不同算法请求主机列表
type Selector interface {Init(opts ...Option) errorOptions() Options// Select returns a function which should return the next nodeSelect(service string, opts ...SelectOption) (Next, error)// Mark sets the success/error against a nodeMark(service string, node *registry.Node, err error)// Reset returns state back to zero for a serviceReset(service string)// Close renders the selector unusableClose() error// Name of the selectorString() string}
1.1.5. Broker发布订阅接口
pull push watch
type Broker interface {Options() OptionsAddress() stringConnect() errorDisconnect() errorInit(...Option) errorPublish(string, *Message, ...PublishOption) errorSubscribe(string, Handler, ...SubscribeOption) (Subscriber, error)String() string}
1.1.6. Client客户端接口
type Client interface {Init(...Option) errorOptions() OptionsNewMessage(topic string, msg interface{}, opts ...MessageOption) MessageNewRequest(service, method string, req interface{}, reqOpts ...RequestOption) RequestCall(ctx context.Context, req Request, rsp interface{}, opts ...CallOption) errorStream(ctx context.Context, req Request, opts ...CallOption) (Stream, error)Publish(ctx context.Context, msg Message, opts ...PublishOption) errorString() string}
1.1.7. Server服务端接口
type Server interface {Options() OptionsInit(...Option) errorHandle(Handler) errorNewHandler(interface{}, ...HandlerOption) HandlerNewSubscriber(string, interface{}, ...SubscriberOption) SubscriberSubscribe(Subscriber) errorRegister() errorDeregister() errorStart() errorStop() errorString() string}
1.1.8. Serveice接口
type Service interface {Init(...Option)Options() OptionsClient() client.ClientServer() server.ServerRun() errorString() string}
