diff --git a/broker/broker.go b/broker/broker.go index 4e124fb1..649553fe 100644 --- a/broker/broker.go +++ b/broker/broker.go @@ -7,6 +7,7 @@ type Broker interface { Init() error Publish(string, *Message) error Subscribe(string, Handler) (Subscriber, error) + String() string } type Handler func(*Message) @@ -52,3 +53,7 @@ func Publish(topic string, msg *Message) error { func Subscribe(topic string, handler Handler) (Subscriber, error) { return DefaultBroker.Subscribe(topic, handler) } + +func String() string { + return DefaultBroker.String() +} diff --git a/broker/http_broker.go b/broker/http_broker.go index b9189082..19918967 100644 --- a/broker/http_broker.go +++ b/broker/http_broker.go @@ -237,3 +237,7 @@ func (h *httpBroker) Subscribe(topic string, handler Handler) (Subscriber, error return subscriber, nil } + +func (h *httpBroker) String() string { + return "http" +} diff --git a/client/client.go b/client/client.go index fdff08f7..7f02f2b3 100644 --- a/client/client.go +++ b/client/client.go @@ -35,6 +35,7 @@ type Client interface { Stream(ctx context.Context, req Request, opts ...CallOption) (Streamer, error) StreamRemote(ctx context.Context, addr string, req Request, opts ...CallOption) (Streamer, error) Publish(ctx context.Context, p Publication, opts ...PublishOption) error + String() string } type Publication interface { @@ -122,3 +123,7 @@ func NewProtoRequest(service, method string, request interface{}, reqOpts ...Req func NewJsonRequest(service, method string, request interface{}, reqOpts ...RequestOption) Request { return DefaultClient.NewJsonRequest(service, method, request, reqOpts...) } + +func String() string { + return DefaultClient.String() +} diff --git a/client/rpc_client.go b/client/rpc_client.go index 97e41120..fa49100f 100644 --- a/client/rpc_client.go +++ b/client/rpc_client.go @@ -258,3 +258,7 @@ func (r *rpcClient) NewProtoRequest(service, method string, request interface{}, func (r *rpcClient) NewJsonRequest(service, method string, request interface{}, reqOpts ...RequestOption) Request { return newRpcRequest(service, method, request, "application/json", reqOpts...) } + +func (r *rpcClient) String() string { + return "rpc" +} diff --git a/examples/client/dc_selector/dc_selector.go b/examples/client/dc_selector/dc_selector.go index ecc4a3f7..60669bd8 100644 --- a/examples/client/dc_selector/dc_selector.go +++ b/examples/client/dc_selector/dc_selector.go @@ -76,6 +76,10 @@ func (n *dcSelector) Close() error { return nil } +func (n *dcSelector) String() string { + return "dc" +} + // Return a new first node selector func DCSelector(opts ...selector.Option) selector.Selector { var sopts selector.Options diff --git a/examples/client/selector/selector.go b/examples/client/selector/selector.go index a2ef1c20..b5b3074f 100644 --- a/examples/client/selector/selector.go +++ b/examples/client/selector/selector.go @@ -66,6 +66,10 @@ func (n *firstNodeSelector) Close() error { return nil } +func (n *firstNodeSelector) String() string { + return "first" +} + // Return a new first node selector func FirstNodeSelector(opts ...selector.Option) selector.Selector { var sopts selector.Options diff --git a/registry/consul_registry.go b/registry/consul_registry.go index ea287642..7210a561 100644 --- a/registry/consul_registry.go +++ b/registry/consul_registry.go @@ -212,3 +212,7 @@ func (c *consulRegistry) ListServices() ([]*Service, error) { func (c *consulRegistry) Watch() (Watcher, error) { return newConsulWatcher(c) } + +func (c *consulRegistry) String() string { + return "consul" +} diff --git a/registry/mock/mock.go b/registry/mock/mock.go index 30ddae9b..796bd006 100644 --- a/registry/mock/mock.go +++ b/registry/mock/mock.go @@ -65,6 +65,10 @@ func (m *MockRegistry) Watch() (registry.Watcher, error) { return nil, nil } +func (m *MockRegistry) String() string { + return "mock" +} + func NewRegistry() *MockRegistry { return &MockRegistry{} } diff --git a/registry/registry.go b/registry/registry.go index 0f139993..0644bb0d 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -6,6 +6,7 @@ type Registry interface { GetService(string) ([]*Service, error) ListServices() ([]*Service, error) Watch() (Watcher, error) + String() string } type Option func(*Options) @@ -37,3 +38,7 @@ func ListServices() ([]*Service, error) { func Watch() (Watcher, error) { return DefaultRegistry.Watch() } + +func String() string { + return DefaultRegistry.String() +} diff --git a/selector/blacklist/black_list_selector.go b/selector/blacklist/black_list_selector.go index b33d5e4c..3769c0a4 100644 --- a/selector/blacklist/black_list_selector.go +++ b/selector/blacklist/black_list_selector.go @@ -143,6 +143,10 @@ func (r *blackListSelector) Close() error { return nil } +func (r *blackListSelector) String() string { + return "blacklist" +} + func NewSelector(opts ...selector.Option) selector.Selector { var sopts selector.Options diff --git a/selector/random_selector.go b/selector/random_selector.go index 03ae39cc..fd9f6f1d 100644 --- a/selector/random_selector.go +++ b/selector/random_selector.go @@ -74,6 +74,10 @@ func (r *randomSelector) Close() error { return nil } +func (r *randomSelector) String() string { + return "random" +} + func newRandomSelector(opts ...Option) Selector { var sopts Options diff --git a/selector/roundrobin/round_robin_selector.go b/selector/roundrobin/round_robin_selector.go index fa984afc..48a89874 100644 --- a/selector/roundrobin/round_robin_selector.go +++ b/selector/roundrobin/round_robin_selector.go @@ -73,6 +73,10 @@ func (r *roundRobinSelector) Close() error { return nil } +func (r *roundRobinSelector) String() string { + return "roundrobin" +} + func NewSelector(opts ...selector.Option) selector.Selector { var sopts selector.Options diff --git a/selector/selector.go b/selector/selector.go index 409549f5..8f729941 100644 --- a/selector/selector.go +++ b/selector/selector.go @@ -72,6 +72,8 @@ type Selector interface { Reset(service string) // Close renders the selector unusable Close() error + // Name of the selector + String() string } // Next is a function that returns the next node diff --git a/server/rpc_server.go b/server/rpc_server.go index 98a6a245..6436c673 100644 --- a/server/rpc_server.go +++ b/server/rpc_server.go @@ -185,6 +185,8 @@ func (s *rpcServer) Register() error { Metadata: config.Metadata(), } + node.Metadata["transport"] = config.transport.String() + s.RLock() var endpoints []*registry.Endpoint for _, e := range s.handlers { @@ -309,3 +311,7 @@ func (s *rpcServer) Stop() error { s.exit <- ch return <-ch } + +func (s *rpcServer) String() string { + return "rpc" +} diff --git a/server/server.go b/server/server.go index 7044da0d..b9844601 100644 --- a/server/server.go +++ b/server/server.go @@ -49,6 +49,7 @@ type Server interface { Deregister() error Start() error Stop() error + String() string } type Publication interface { @@ -183,3 +184,7 @@ func Stop() error { log.Infof("Stopping server") return DefaultServer.Stop() } + +func String() string { + return DefaultServer.String() +} diff --git a/transport/http_transport.go b/transport/http_transport.go index c2a2d770..59177806 100644 --- a/transport/http_transport.go +++ b/transport/http_transport.go @@ -308,6 +308,10 @@ func (h *httpTransport) Listen(addr string) (Listener, error) { }, nil } +func (h *httpTransport) String() string { + return "http" +} + func newHttpTransport(addrs []string, opt ...Option) *httpTransport { return &httpTransport{} } diff --git a/transport/transport.go b/transport/transport.go index 3981f8bc..361c712e 100644 --- a/transport/transport.go +++ b/transport/transport.go @@ -26,6 +26,7 @@ type Listener interface { type Transport interface { Dial(addr string, opts ...DialOption) (Client, error) Listen(addr string) (Listener, error) + String() string } type options struct{} @@ -59,3 +60,7 @@ func Dial(addr string, opts ...DialOption) (Client, error) { func Listen(addr string) (Listener, error) { return DefaultTransport.Listen(addr) } + +func String() string { + return DefaultTransport.String() +}