Documentation
¶
Index ¶
- Constants
- func Methods(service string, v interface{}) (map[string]reflect.Value, map[string]reflect.Type, map[string]reflect.Type)
- type CallOption
- type Client
- func NewClient(name string, url string, opts ...ClientOpt) (*Client, error)
- func NewEventHandler(name string, url string, opts ...ClientOpt) (*Client, error)
- func NewService(name string, url string, opts ...ClientOpt) (*Client, error)
- func NewStreamHandler(name string, url string, opts ...ClientOpt) (*Client, error)
- func (c *Client) Call(ctx context.Context, target string, method string, payload interface{}, ...) (interface{}, error)
- func (c *Client) Close()
- func (c *Client) NewHandler(service string, v interface{})
- func (c *Client) Notify(target string, event string, payload interface{}) error
- func (c *Client) Register(address string, port int, tags map[string]string, ttl time.Duration) error
- func (c *Client) Respond(delivery amqp.Delivery, command string, payload interface{}) error
- func (c *Client) Run() error
- func (c *Client) RunWithContext(ctx context.Context) error
- type ClientOpt
- func SetBrokerTimeout(count, interval int) ClientOpt
- func SetHealthChecker(hc HealthChecker) ClientOpt
- func SetIdentifier(id Identifier) ClientOpt
- func SetInterets(topic ...string) ClientOpt
- func SetRegistrator(reg Registrator) ClientOpt
- func SetSerializer(ser Serializer) ClientOpt
- func SetTLSConfig(cfg *tls.Config) ClientOpt
- type DumbHealthChecker
- type HealthChecker
- type Identifier
- type InstanceSelector
- type JSONSerializer
- type NodeIdentifier
- type NoneIdentifier
- type PlainSerializer
- type PodIdentifier
- type ProtoSerializer
- type RandomHealthChecker
- type RandomIdentifier
- type Registrator
- type Request
- type Selector
- type Serializer
- type Service
- type Worker
Constants ¶
const ( // Type Command = "command" Event = "event" Result = "result" // Event Register = "Register" // Exchanges RPCExchange = "xing.rpc" EventExchange = "xing.event" // Client Types ProducerClient = "producer" ServiceClient = "service" EventHandlerClient = "event_handler" StreamHandlerClient = "stream_handler" // Defaults RPCTTL = int64(1) EVTTTL = int64(15 * 60 * 1000) // 15 minutes STRMTTL = int64(60 * 1000) // 1 minutes ResultQueueTTL = int64(10 * 60 * 1000) // 10 minutes QueueTTL = int64(3 * 60 * 60 * 1000) // 3 hours // Threshold MinHeatbeat = 3 // Threading PoolSize = 1000 NWorker = 5 )
Constants
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
Client is a wrapper struct for amqp client.
func NewClient ¶
NewClient creates a RPC/event client. FIXME: should restrict client name to be 3 segments
func NewEventHandler ¶
NewEventHandler creates a new event handler.
func NewService ¶
NewService creates a RPC service. If the name has only 2 segments, different service instances are balanced.
func NewStreamHandler ¶
NewStreamHandler creates a new data stream handler.
func (*Client) Call ¶
func (c *Client) Call(ctx context.Context, target string, method string, payload interface{}, sync bool) (interface{}, error)
Call invokes an remote method. Should not be called externally.
func (*Client) NewHandler ¶
NewHandler registers handler of protocol. Called from generated code.
func (*Client) Register ¶
func (c *Client) Register(address string, port int, tags map[string]string, ttl time.Duration) error
Register starts periodic registration to a database such as etcd or consul.
type ClientOpt ¶
type ClientOpt func(*Client)
ClientOpt ...
func SetBrokerTimeout ¶
SetBrokerTimeout set a timeout for a server to limit broker reconnect attempts. count: number of retries; interval: number of seconds between retries
func SetIdentifier ¶
func SetIdentifier(id Identifier) ClientOpt
SetIdentifier sets identifer of the instance. Default is random string
func SetInterets ¶
SetInterets subscribes to events. Must be called for event handler.
func SetSerializer ¶
func SetSerializer(ser Serializer) ClientOpt
SetSerializer sets data serializer. Default is protobuf.
func SetTLSConfig ¶
SetTLSConfig configures TLS connection to a server.
type InstanceSelector ¶
type InstanceSelector struct {
// contains filtered or unexported fields
}
InstanceSelector ...
func (*InstanceSelector) Select ¶
func (is *InstanceSelector) Select(services []*Service) *Service
Select ...
type JSONSerializer ¶
type JSONSerializer struct {
// contains filtered or unexported fields
}
JSONSerializer ...
func (*JSONSerializer) DefaultValue ¶
func (s *JSONSerializer) DefaultValue() interface{}
DefaultValue ...
func (*JSONSerializer) Marshal ¶
func (s *JSONSerializer) Marshal(data interface{}) ([]byte, error)
Marshal ...
func (*JSONSerializer) Unmarshal ¶
func (s *JSONSerializer) Unmarshal(data []byte, v interface{}) error
Unmarshal ...
type PlainSerializer ¶
type PlainSerializer struct {
// contains filtered or unexported fields
}
PlainSerializer ...
func (*PlainSerializer) ContentType ¶
func (s *PlainSerializer) ContentType() string
ContentType ...
func (*PlainSerializer) DefaultValue ¶
func (s *PlainSerializer) DefaultValue() interface{}
DefaultValue ...
func (*PlainSerializer) Marshal ¶
func (s *PlainSerializer) Marshal(data interface{}) ([]byte, error)
Marshal ...
func (*PlainSerializer) Unmarshal ¶
func (s *PlainSerializer) Unmarshal(data []byte, v interface{}) error
Unmarshal ...
type ProtoSerializer ¶
type ProtoSerializer struct {
// contains filtered or unexported fields
}
ProtoSerializer ...
func (*ProtoSerializer) ContentType ¶
func (s *ProtoSerializer) ContentType() string
ContentType ...
func (*ProtoSerializer) DefaultValue ¶
func (s *ProtoSerializer) DefaultValue() interface{}
DefaultValue ...
func (*ProtoSerializer) Marshal ¶
func (s *ProtoSerializer) Marshal(data interface{}) ([]byte, error)
Marshal ...
func (*ProtoSerializer) Unmarshal ¶
func (s *ProtoSerializer) Unmarshal(data []byte, v interface{}) error
Unmarshal ...
type Registrator ¶
type Registrator interface { Register(s *Service, ttl time.Duration) error Deregister(s *Service) error GetService(name string, selector Selector) (*Service, error) }
Registrator ...
func NewConsulRegistrator ¶
func NewConsulRegistrator(opts ...registry.Option) Registrator
NewConsulRegistrator ...
func NewEtcdRegistrator ¶
func NewEtcdRegistrator(opts ...registry.Option) Registrator
NewEtcdRegistrator ...
type Serializer ¶
type Serializer interface { ContentType() string Marshal(data interface{}) ([]byte, error) Unmarshal(data []byte, v interface{}) error DefaultValue() interface{} }
Serializer ...