Documentation
¶
Index ¶
- Constants
- func FormatTraceInfo(ti *proto.TraceInfo, indent int) string
- type AsyncClient
- type Callback
- type Client
- func (client *Client) Destroy()
- func (client *Client) IsHealthy() bool
- func (client *Client) IsHealthyWithin(d time.Duration) bool
- func (client *Client) NewRequest(service, endpoint string) *Request
- func (cl *Client) Request(data []byte, service, endpoint string, trace_dest *proto.TraceInfo) ([]byte, error)
- func (cl *Client) RequestProtobuf(request, reply pb.Message, service, endpoint string, ...) error
- func (client *Client) SetTimeout(d time.Duration, propagate bool)
- type ClientFilter
- type ConnectionCache
- type PeerAddress
- type Request
- type RequestParams
- type Response
- func DebugFilter(rq *Request, next int) Response
- func RedirectFilter(rq *Request, next int) Response
- func RetryFilter(rq *Request, next int) Response
- func SendFilter(rq *Request, next int) Response
- func TimeoutFilter(rq *Request, next int) Response
- func TraceMergeFilter(rq *Request, next int) Response
- type RpcChannel
Constants ¶
const TRACE_INFO_TIME_FORMAT = "Mon Jan _2 15:04:05.999 2006"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AsyncClient ¶
type AsyncClient struct {
// contains filtered or unexported fields
}
func NewAsyncClient ¶
func NewAsyncClient(client_name string, addr PeerAddress, queue_length uint, security_manager *smgr.ClientSecurityManager) (*AsyncClient, error)
Create an asynchronous client. An AsyncClient is also called using Request(), but it queues the request (in a buffered channel with the length queue_length). The requests themselves are sent synchronously (REQ/REP), but the Request() function returns immediately if the channel queue is not full yet. The queuing avoids a too high CPU use on both server and client; higher parallelism can simply be achieved by using multiple AsyncClients.
client_name is an arbitrary name that can be used to identify this client at the server (e.g. in logs)
func (*AsyncClient) Close ¶
func (cl *AsyncClient) Close()
func (*AsyncClient) Request ¶
func (cl *AsyncClient) Request(data []byte, service, endpoint string, cb Callback)
func (*AsyncClient) SetTimeout ¶
func (cl *AsyncClient) SetTimeout(d time.Duration)
Set timeout for writes.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
A client contains a channel and some metadata, a state machine, and a stack of client filters.
func New ¶
func New(name string, channel *RpcChannel) Client
Creates a new client from the channel. Don't share a channel among two concurrently active clients.
func NewClient ¶
func NewClient(name string, channel *RpcChannel) Client
NewClient is deprecated; use New()
func (*Client) Destroy ¶
func (client *Client) Destroy()
Disconnects the channel and disables the client
func (*Client) IsHealthy ¶
Sends a request to the server, asking whether it accepts requests and testing general connectivity. Uses a timeout of 1 second.
func (*Client) IsHealthyWithin ¶
Same as IsHealthy(), but with a configurable timeout
func (*Client) NewRequest ¶
Create a Request to be sent by this client. If a previous request has not been finished, this method returns nil!
func (*Client) Request ¶
func (cl *Client) Request(data []byte, service, endpoint string, trace_dest *proto.TraceInfo) ([]byte, error)
Oneshot-API: Send a request with raw data to the connected RPC server.
type ClientFilter ¶
A ClientFilter is a function that is called with a request and fulfills a certain task. Filters are stacked in Client.filters; filters[0] is called first, and calls in turn filters[1] until the last filter sends the message off to the network.
type ConnectionCache ¶
type ConnectionCache struct {
// contains filtered or unexported fields
}
ConnectionCache is a pool of RPC connections. Applications call Connect() and get, transparently, either a cached connection or a newly created one. After being finished with using the connection, the application should call Return() with the connection if it wants to use it later again.
func NewConnCache ¶
func NewConnCache(client_name string) *ConnectionCache
func (*ConnectionCache) CleanOld ¶
func (cc *ConnectionCache) CleanOld(older_than time.Duration)
Remove and close all connections from the pool that are older than time.Now() - older_than. Also cleans up empty cache entries.
func (*ConnectionCache) Connect ¶
func (cc *ConnectionCache) Connect(peer PeerAddress, security_manager *smgr.ClientSecurityManager) (*Client, error)
Get a connection, either from the pool or a new one, depending on if there are connections available.
func (*ConnectionCache) Return ¶
func (cc *ConnectionCache) Return(clp **Client)
Return a connection into the pool. Argument is a pointer to a pointer to make sure that the client is not used by the calling function after this call.
type PeerAddress ¶
type PeerAddress struct {
// contains filtered or unexported fields
}
A TCP/IP or Unix socket address
func IPCPeer ¶
func IPCPeer(path string) PeerAddress
Construct a peer address for a unix socket peer.
func (*PeerAddress) GoString ¶
func (pa *PeerAddress) GoString() string
func (*PeerAddress) String ¶
func (pa *PeerAddress) String() string
func (*PeerAddress) ToUrl ¶
func (pa *PeerAddress) ToUrl() string
Convert a PeerAddress to a ZeroMQ URL.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
An RPC request that can be modified before it is sent.
func (*Request) SetParameters ¶
func (r *Request) SetParameters(p *RequestParams) *Request
type RequestParams ¶
type RequestParams struct {
// contains filtered or unexported fields
}
Various parameters determining how a request is executed. There are builder methods to set the various parameters.
func NewParams ¶
func NewParams() *RequestParams
func (*RequestParams) AcceptRedirects ¶
func (p *RequestParams) AcceptRedirects(b bool) *RequestParams
Whether to follow redirects issued by the server. May impact efficiency.
func (*RequestParams) DeadlinePropagation ¶
func (p *RequestParams) DeadlinePropagation(b bool) *RequestParams
Whether to enable deadline propagation; that is, tell the server the time beyond which it doesn't need to bother returning a response.
func (*RequestParams) Retries ¶
func (p *RequestParams) Retries(r uint) *RequestParams
How often a request is to be retried. Default: 0
func (*RequestParams) Timeout ¶
func (p *RequestParams) Timeout(d time.Duration) *RequestParams
Set the timeout; this is used as network timeout and for the deadline propagation, if enabled.
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
func DebugFilter ¶
func RedirectFilter ¶
Implements redirects: A server can tell us to follow a redirect. This is expensive in general because it involves setting up and tearing down a completely new client. It also doesn't work well with security-enabled RPCs.
func RetryFilter ¶
A filter that retries a request according to the request's parameters.
func SendFilter ¶
Send a request and wait for it to complete. Must be the last filter in the stack
func TimeoutFilter ¶
Sets appropriate timeouts on the socket, only for this request
func TraceMergeFilter ¶
Appends the received trace info to context or requested trace.
func (*Response) Error ¶
Get the error that has occurred.
Special codes are returned for RPC errors, which start with prefix "RPC:" and a code from the proto/rpc.proto enum RPCResponse.
func (*Response) GetResponseMessage ¶
Unmarshals the response into msg.
type RpcChannel ¶
type RpcChannel struct {
// contains filtered or unexported fields
}
A channel to an RPC server. It is threadsafe, but should not be shared among multiple clients.
TODO(lbo): Think about implementing a channel on top of DEALER, with a background goroutine delivering results to waiting requests.
func NewChannelAndConnect ¶
func NewChannelAndConnect(addr PeerAddress, security_manager *smgr.ClientSecurityManager) (*RpcChannel, error)
NewChannelAndConnect creates a new channel and connects it to `addr`.
func NewRpcChannel ¶
func NewRpcChannel(security_manager *smgr.ClientSecurityManager) (*RpcChannel, error)
Create a new RpcChannel. security_manager may be nil.
func (*RpcChannel) Connect ¶
func (c *RpcChannel) Connect(addr PeerAddress) error
Connect channel to adr. (This adds the server to the set of connections of this channel; connections are used in a round-robin fashion)
func (*RpcChannel) Disconnect ¶
func (c *RpcChannel) Disconnect(peer PeerAddress)
Disconnect the given peer (i.e., take it out of the connection pool)
func (*RpcChannel) Reconnect ¶
func (c *RpcChannel) Reconnect()
First disconnect, then reconnect to all peers.
func (*RpcChannel) SetTimeout ¶
func (c *RpcChannel) SetTimeout(d time.Duration)
Set send/receive timeout on this channel.