Documentation ¶
Overview ¶
Package v2 implements clients supporting lumberjack protocol version 2.
This package provides the low level `Client` handling the wire-format only, plus `SyncClient` and AsyncClient. SyncClient and AsyncClient do provide protocol compliant communication and error handling with lumberjack server.
Index ¶
- Variables
- type AsyncClient
- func AsyncDial(address string, inflight int, opts ...Option) (*AsyncClient, error)
- func AsyncDialWith(dial func(network, address string) (net.Conn, error), address string, ...) (*AsyncClient, error)
- func NewAsyncClientWith(cl *Client, inflight int) (*AsyncClient, error)
- func NewAsyncClientWithConn(c net.Conn, inflight int, opts ...Option) (*AsyncClient, error)
- type AsyncSendCallback
- type Client
- type Option
- type SyncClient
- func NewSyncClientWith(c *Client) (*SyncClient, error)
- func NewSyncClientWithConn(c net.Conn, opts ...Option) (*SyncClient, error)
- func SyncDial(address string, opts ...Option) (*SyncClient, error)
- func SyncDialWith(dial func(network, address string) (net.Conn, error), address string, ...) (*SyncClient, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrProtocolError is returned if an protocol error was detected in the // conversation with lumberjack server. ErrProtocolError = errors.New("lumberjack protocol error") )
Functions ¶
This section is empty.
Types ¶
type AsyncClient ¶
type AsyncClient struct {
// contains filtered or unexported fields
}
AsyncClient asynchronously publishes events to lumberjack endpoint. On ACK a provided callback function will be called. The number of in-flight publish requests is configurable but limited. Once the limit has been reached, the client will block publish requests until the lumberjack server did ACK some queued publish requests.
func AsyncDial ¶
func AsyncDial(address string, inflight int, opts ...Option) (*AsyncClient, error)
AsyncDial connects to lumberjack server and returns new AsyncClient. On error no AsyncClient is being created.
func AsyncDialWith ¶
func AsyncDialWith( dial func(network, address string) (net.Conn, error), address string, inflight int, opts ...Option, ) (*AsyncClient, error)
AsyncDialWith uses provided dialer to connect to lumberjack server. On error no AsyncClient is being returned.
func NewAsyncClientWith ¶
func NewAsyncClientWith(cl *Client, inflight int) (*AsyncClient, error)
NewAsyncClientWith creates a new AsyncClient from low-level lumberjack v2 Client. The inflight argument sets number of active publish requests.
func NewAsyncClientWithConn ¶
NewAsyncClientWithConn creates a new AsyncClient from an active connection.
func (*AsyncClient) Close ¶
func (c *AsyncClient) Close() error
Close closes the client, so no new events can be published anymore. The underlying network connection will be closed too. Returns an error if underlying net.Conn errors on Close.
All inflight requests will be cancelled, returning EOF if no other error has been encountered due to underlying network connection being closed.
The client gives no guarantees regarding published events. There is a chance events will be processed by server, even though connection has been closed.
func (*AsyncClient) Send ¶
func (c *AsyncClient) Send(cb AsyncSendCallback, data []interface{}) error
Send publishes a new batch of events by JSON-encoding given batch. Send blocks if maximum number of allowed asynchrounous calls is still active. Upon completion cb will be called with last ACKed index into active batch. Returns error if communication or serialization to JSON failed.
type AsyncSendCallback ¶
AsyncSendCallback callback function. Upon completion seq contains the last ACKed event's index. The count starts with 1. The err argument contains the latest error encountered by lumberjack client.
Note: The callback MUST not block. In case callback is trying to republish not ACKed events, care must be taken not to deadlock the AsyncClient when calling Send.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements the low-level lumberjack wire protocol. SyncClient and AsyncClient should be used for publishing events to lumberjack endpoint.
func Dial ¶
Dial connects to the lumberjack server and returns new Client. Returns an error if connection attempt fails.
func DialWith ¶
func DialWith( dial func(network, address string) (net.Conn, error), address string, opts ...Option, ) (*Client, error)
DialWith uses provided dialer to connect to lumberjack server returning a new Client. Returns error if connection attempt fails.
func NewWithConn ¶
NewWithConn create a new lumberjack client with an existing and active connection.
func (*Client) AwaitACK ¶
AwaitACK waits for count elements being ACKed. Returns last known ACK on error.
func (*Client) ReceiveACK ¶
ReceiveACK awaits and reads next ACK response or error. Note: Server might send partial ACK, in which case client must continue reading ACKs until last send window size is matched. Use AwaitACK when waiting for a known sequence number.
type Option ¶
type Option func(*options) error
Option type to be passed to New/Dial functions.
func CompressionLevel ¶
CompressionLevel client option setting the gzip compression level (0 to 9).
func JSONEncoder ¶
JSONEncoder client option configuring the encoder used to convert events to json. The default is `json.Marshal`.
type SyncClient ¶
type SyncClient struct {
// contains filtered or unexported fields
}
SyncClient synchronously publishes events to lumberjack endpoint waiting for ACK before allowing another send request. The client is not thread-safe.
func NewSyncClientWith ¶
func NewSyncClientWith(c *Client) (*SyncClient, error)
NewSyncClientWith creates a new SyncClient from low-level lumberjack v2 Client.
func NewSyncClientWithConn ¶
func NewSyncClientWithConn(c net.Conn, opts ...Option) (*SyncClient, error)
NewSyncClientWithConn creates a new SyncClient from an active connection.
func SyncDial ¶
func SyncDial(address string, opts ...Option) (*SyncClient, error)
SyncDial connects to lumberjack server and returns new SyncClient. On error no SyncClient is being created.
func SyncDialWith ¶
func SyncDialWith( dial func(network, address string) (net.Conn, error), address string, opts ...Option, ) (*SyncClient, error)
SyncDialWith uses provided dialer to connect to lumberjack server. On error no SyncClient is being returned.
func (*SyncClient) Close ¶
func (c *SyncClient) Close() error
Close closes the client, so no new events can be published anymore. The underlying network connection will be closed too. Returns an error if underlying net.Conn errors on Close.
func (*SyncClient) Send ¶
func (c *SyncClient) Send(data []interface{}) (int, error)
Send publishes a new batch of events by JSON-encoding given batch. Send blocks until the complete batch has been ACKed by lumberjack server or some error happened.