v2

package
v0.0.0-...-23fbfb3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func NewAsyncClientWithConn(c net.Conn, inflight int, opts ...Option) (*AsyncClient, error)

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

type AsyncSendCallback func(seq uint32, err error)

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

func Dial(address string, opts ...Option) (*Client, error)

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

func NewWithConn(c net.Conn, opts ...Option) (*Client, error)

NewWithConn create a new lumberjack client with an existing and active connection.

func (*Client) AwaitACK

func (c *Client) AwaitACK(count uint32) (uint32, error)

AwaitACK waits for count elements being ACKed. Returns last known ACK on error.

func (*Client) Close

func (c *Client) Close() error

Close closes underlying network connection

func (*Client) ReceiveACK

func (c *Client) ReceiveACK() (uint32, error)

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.

func (*Client) Send

func (c *Client) Send(data []interface{}) error

Send attempts to JSON-encode and send all events without waiting for ACK. Returns error if sending or serialization fails.

type Option

type Option func(*options) error

Option type to be passed to New/Dial functions.

func CompressionLevel

func CompressionLevel(l int) Option

CompressionLevel client option setting the gzip compression level (0 to 9).

func JSONEncoder

func JSONEncoder(encoder func(interface{}) ([]byte, error)) Option

JSONEncoder client option configuring the encoder used to convert events to json. The default is `json.Marshal`.

func Timeout

func Timeout(to time.Duration) Option

Timeout client option configuring read/write timeout.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL