z4

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInterruptedFuture = errors.New("connection closed before future completion")
)
View Source
var (
	ErrNoLeader = errors.New("leader not found")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client provides access to the features of a z4 server.

func NewClient

func NewClient(ctx context.Context, opt ClientOptions) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) Consumer

func (c *Client) Consumer(ctx context.Context, queue string) (*Consumer, error)

func (*Client) StreamingProducer

func (c *Client) StreamingProducer(ctx context.Context) (*StreamingProducer, error)

func (*Client) UnaryProducer

func (c *Client) UnaryProducer() *UnaryProducer

type ClientOptions

type ClientOptions struct {
	// Addrs is a list of host:port targets that identify members
	// of a z4 cluster.
	Addrs []string
}

type Consumer

type Consumer struct {
	// contains filtered or unexported fields
}

Consumer reads tasks as they become available for consumption.

func (*Consumer) Consume

func (c *Consumer) Consume(f func(m Message) error) error

Consume invokes f on ready tasks.

type Message

type Message struct {
	// contains filtered or unexported fields
}

Message represents a task that is ready for consumption.

The Ack method must be invoked once the task is successfully processed. Failure to acknowledge a task will result in it being redelivered.

func (Message) Ack

func (m Message) Ack()

func (Message) Task

func (m Message) Task() *proto.Task

type StreamingProducer

type StreamingProducer struct {
	// contains filtered or unexported fields
}

StreamingProducer supports the creation of tasks using bidirectional streaming.

StreamingProducer offers better performance than UnaryProducer but at the cost of weaker consistency and a more complex interface.

Close() should be called when the producer object is no longer needed.

func (*StreamingProducer) Close

func (p *StreamingProducer) Close() error

Close releases resources allocated to the producer.

This method should be called when the producer is no longer needed.

func (*StreamingProducer) CreateTask

func (p *StreamingProducer) CreateTask(req *proto.PushTaskRequest) *TaskFuture

CreateTask sends a request to create a task to the stream.

Because this is a streaming producer, the server response may not be immediately available. The returned future will provide access to the task (or an error upon failure) once the response is received.

type TaskCreationError

type TaskCreationError struct {
	Status  uint32
	Message string
}

TaskCreationError represents an error encountered by the server while creating a task.

func (TaskCreationError) Error

func (e TaskCreationError) Error() string

type TaskFuture

type TaskFuture struct {
	// contains filtered or unexported fields
}

TaskFuture is an async response to creating a task.

To use objects of this type, first invoke the Error method. It will block until a response is received from the server. If the error is nil, the Task method will provide a non-nil task.

func (*TaskFuture) Error

func (f *TaskFuture) Error() error

func (*TaskFuture) Task

func (f *TaskFuture) Task() *proto.Task

type UnaryProducer

type UnaryProducer struct {
	// contains filtered or unexported fields
}

UnaryProducer supports the creation of tasks using the unary rpc.

This type is ideal for cases where the caller must immediately know whether a request succeeded or failed. Stronger consistency comes at the cost of slower performance. For high performance use cases, consider using StreamingProducer instead.

func (*UnaryProducer) CreateTask

func (p *UnaryProducer) CreateTask(ctx context.Context, req *proto.PushTaskRequest) (*proto.Task, error)

Jump to

Keyboard shortcuts

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