client

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBatchPublisherClosed = errors.New("client: batch publisher closed")

ErrBatchPublisherClosed is returned by Publish after Close.

Functions

This section is empty.

Types

type AsyncPublishResult

type AsyncPublishResult struct {
	Result broker.PublishResult
	Error  error
}

type AsyncResponse

type AsyncResponse struct {
	Error error
}

type BatchPublisher

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

BatchPublisher turns many concurrent single-message Publish calls into a few frame-batch requests. Each caller still returns only after the broker has durably accepted its own message, with its own error, so durability and error semantics match one request per message while the request, header and fsync overhead is shared. There is no timer: while a batch is in flight, later messages accumulate and go out together, exactly like WAL group commit. A lone caller is sent immediately and never waits for company.

func (*BatchPublisher) Close

func (p *BatchPublisher) Close()

Close stops accepting messages, sends everything already queued and waits.

func (*BatchPublisher) Publish

func (p *BatchPublisher) Publish(ctx context.Context, msg broker.Message) error

Publish sends one message and waits for the broker's durable acknowledgement of that message. Set msg.ID to make retries idempotent; with return=minimal the broker does not echo ids back. If ctx ends while waiting, the message may still be accepted by the broker.

type BatchPublisherConfig

type BatchPublisherConfig struct {
	// MaxBatch caps messages per request. Default 512.
	MaxBatch int
	// MaxInFlight is how many batch requests may be outstanding at once, so a
	// new batch fills while earlier ones wait on the broker's fsync. Default 4.
	MaxInFlight int
	// QueueSize bounds messages waiting to be batched; Publish blocks (or
	// honors ctx) when it is full. Default 8192.
	QueueSize int
}

BatchPublisherConfig tunes request coalescing. Zero values pick defaults.

type Client

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

func New

func New(cfg Config) *Client

func (*Client) Ack

func (c *Client) Ack(ctx context.Context, m broker.Message) error

func (*Client) CancelTask

func (c *Client) CancelTask(ctx context.Context, id, reason string) error

func (*Client) Command

func (c *Client) Command(ctx context.Context, subject string, payload any, response any, timeout time.Duration) error

func (*Client) CommitStreamOffset

func (c *Client) CommitStreamOffset(ctx context.Context, stream, group string, offset uint64) error

func (*Client) CommitStreamTransaction

func (c *Client) CommitStreamTransaction(ctx context.Context, stream string, tx broker.StreamTransactionHTTPPayload) ([]broker.PublishResult, error)

CommitStreamTransaction publishes outputs and advances the input offset in one operation. ErrOffsetConflict means another commit changed the expected offset.

func (*Client) Complete

func (c *Client) Complete(ctx context.Context, m broker.Message, result any) error

func (*Client) Config

func (c *Client) Config() Config

func (*Client) Consumers

func (c *Client) Consumers(ctx context.Context) ([]broker.ConsumerInfo, error)

func (*Client) DLQ

func (c *Client) DLQ(ctx context.Context, queue string, limit int) ([]broker.Message, error)

func (*Client) Events

func (c *Client) Events(ctx context.Context, after string, wait time.Duration) ([]broker.Notification, error)

func (*Client) Extend

func (c *Client) Extend(ctx context.Context, m broker.Message, d time.Duration) error

func (*Client) Fail

func (c *Client) Fail(ctx context.Context, m broker.Message, e error) error

func (*Client) Heartbeat

func (c *Client) Heartbeat(ctx context.Context) (broker.ConsumerInfo, error)

func (*Client) Nack

func (c *Client) Nack(ctx context.Context, m broker.Message, opts ...NackOption) error

func (*Client) NewBatchPublisher

func (c *Client) NewBatchPublisher(cfg BatchPublisherConfig) *BatchPublisher

NewBatchPublisher starts a coalescing publisher on top of c.

func (*Client) Poll

func (c *Client) Poll(ctx context.Context, queue string, limit int) ([]broker.Message, error)

func (*Client) PollFrames

func (c *Client) PollFrames(ctx context.Context, queue string, limit int) ([]broker.Message, error)

func (*Client) Progress

func (c *Client) Progress(ctx context.Context, m broker.Message, p broker.Progress) error

func (*Client) Publish

func (c *Client) Publish(ctx context.Context, topic string, payload any, opts ...PublishOption) (broker.PublishResult, error)

func (*Client) PublishAsync

func (c *Client) PublishAsync(ctx context.Context, topic string, payload any, opts ...PublishOption) <-chan AsyncPublishResult

func (*Client) PublishBatch

func (c *Client) PublishBatch(ctx context.Context, topic string, payloads []any, opts ...PublishOption) (broker.BatchPublishResult, error)

func (*Client) PublishFrame

func (c *Client) PublishFrame(ctx context.Context, msg broker.Message) (broker.PublishResult, error)

func (*Client) ReadStream

func (c *Client) ReadStream(ctx context.Context, stream, group string, after uint64, limit int) ([]broker.Message, error)

func (*Client) Register

func (*Client) Reject

func (c *Client) Reject(ctx context.Context, m broker.Message, reason string) error

func (*Client) ReplayDLQ

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

func (*Client) Request

func (c *Client) Request(ctx context.Context, subject string, payload any, response any, timeout time.Duration) error

func (*Client) RequestAsync

func (c *Client) RequestAsync(ctx context.Context, subject string, payload any, response any, timeout time.Duration) <-chan AsyncResponse

func (*Client) Respond

func (c *Client) Respond(ctx context.Context, m broker.Message, response any, ack bool) error

func (*Client) RespondError

func (c *Client) RespondError(ctx context.Context, m broker.Message, e error, ack bool) error

func (*Client) RetryTask

func (c *Client) RetryTask(ctx context.Context, id string) error

func (*Client) StreamOffset

func (c *Client) StreamOffset(ctx context.Context, stream, group string) (uint64, error)

func (*Client) SubmitTask

func (c *Client) SubmitTask(ctx context.Context, name string, payload any, opts ...TaskOption) (broker.TaskInfo, error)

func (*Client) Subscribe

func (*Client) Task

func (c *Client) Task(ctx context.Context, id string) (broker.TaskInfo, error)

func (*Client) TaskResult

func (c *Client) TaskResult(ctx context.Context, id string) (broker.TaskInfo, []byte, error)

type Config

type Config struct {
	BrokerURL, Token, ConsumerID, Group, Name, Version string
	BrokerURLs                                         []string
	Concurrency, MaxInFlight, PollLimit                int
	HeartbeatInterval, VisibilityTimeout, PollWait     time.Duration
	DisableAutoExtendLeases                            bool
	LeaseExtensionInterval                             time.Duration
	MaxLeaseExtensions                                 int
	HTTPClient                                         *http.Client
	Pool                                               *fw.Pool
	Hooks                                              Hooks
	FrameCodec                                         broker.FrameCodec
	// TLSCertFile is the path to the client TLS certificate for mTLS.
	TLSCertFile string
	// TLSKeyFile is the path to the client TLS private key for mTLS.
	TLSKeyFile string
	// TLSCACertFile is the path to the CA certificate to verify the server.
	TLSCACertFile string
	// InsecureSkipVerify skips server certificate verification (dev only).
	InsecureSkipVerify bool
}

type Delivery

type Delivery struct {
	Message broker.Message
	// contains filtered or unexported fields
}

func (Delivery) Ack

func (d Delivery) Ack(ctx context.Context) error

func (Delivery) Complete

func (d Delivery) Complete(ctx context.Context, result any) error

func (Delivery) Decode

func (d Delivery) Decode(out any) error

func (Delivery) Extend

func (d Delivery) Extend(ctx context.Context, v time.Duration) error

func (Delivery) Fail

func (d Delivery) Fail(ctx context.Context, err error) error

func (Delivery) Nack

func (d Delivery) Nack(ctx context.Context, opts ...NackOption) error

func (Delivery) Progress

func (d Delivery) Progress(ctx context.Context, p broker.Progress) error

func (Delivery) Reject

func (d Delivery) Reject(ctx context.Context, reason string) error

func (Delivery) Respond

func (d Delivery) Respond(ctx context.Context, response any, ack bool) error

func (Delivery) RespondError

func (d Delivery) RespondError(ctx context.Context, err error, ack bool) error

type Event

type Event struct {
	ConsumerID, Group string
	State             broker.ConsumerState
	Error             error
	Time              time.Time
}

type Handler

type Handler func(context.Context, Delivery) error

type Hooks

type Hooks struct {
	OnConnecting, OnConnected, OnAuthenticated, OnRegistered, OnSubscribed, OnPollStart, OnHeartbeat, OnReconnect, OnDrain, OnStopped func(Event)
	OnNotification                                                                                                                    func(NotificationEvent)
	OnMessageReceived, AfterHandle, OnHandlerError, OnAck, OnNack, OnReject, OnProgress, OnLeaseExtended                              func(MessageEvent)
	BeforeHandle                                                                                                                      func(MessageEvent) error
}

func LoggingHooks

func LoggingHooks(prefix string) Hooks

LoggingHooks returns lifecycle hooks that log structured remote-consumer events.

func LoggingHooksWith

func LoggingHooksWith(prefix string) Hooks

type MessageEvent

type MessageEvent struct {
	Message broker.Message
	Queue   string
	Error   error
	Time    time.Time
}

type NackOption

type NackOption func(*NackOptions)

func NackDLQ

func NackDLQ(v string) NackOption

func NackDelay

func NackDelay(v time.Duration) NackOption

func NackError

func NackError(v string) NackOption

func NackReason

func NackReason(v string) NackOption

type NackOptions

type NackOptions struct {
	Action             broker.NackAction
	Delay              time.Duration
	DLQ, Reason, Error string
}

type NotificationEvent

type NotificationEvent struct {
	Notification broker.Notification
	Time         time.Time
}

type PublishOption

type PublishOption func(*PublishOptions)

func WithCausationID

func WithCausationID(v string) PublishOption

func WithContentType

func WithContentType(v string) PublishOption

func WithCorrelationID

func WithCorrelationID(v string) PublishOption

func WithDeduplication

func WithDeduplication(id string, window time.Duration) PublishOption

func WithDelay

func WithDelay(v time.Duration) PublishOption

func WithHeaders

func WithHeaders(v map[string]string) PublishOption

func WithIdempotencyKey

func WithIdempotencyKey(v string) PublishOption

func WithKey

func WithKey(v string) PublishOption

func WithMaxAttempts

func WithMaxAttempts(v int) PublishOption

func WithMessageID

func WithMessageID(v string) PublishOption

func WithMetadata

func WithMetadata(v map[string]string) PublishOption

func WithPriority

func WithPriority(v int) PublishOption

func WithProducerID

func WithProducerID(v string) PublishOption

func WithQueue

func WithQueue(v string) PublishOption

func WithRoutingKey

func WithRoutingKey(v string) PublishOption

func WithSchema

func WithSchema(name, version string) PublishOption

func WithStrategy

func WithStrategy(v broker.StrategyType) PublishOption

func WithStream

func WithStream(v string) PublishOption

func WithTTL

func WithTTL(v time.Duration) PublishOption

func WithTenantID

func WithTenantID(v string) PublishOption

func WithTraceID

func WithTraceID(v string) PublishOption

func WithType

func WithType(v string) PublishOption

type PublishOptions

type PublishOptions struct {
	Queue, Stream, Type, Key, RoutingKey, TenantID, IdempotencyKey string
	Headers, Metadata                                              map[string]string
	Priority                                                       int

	ContentType         string
	Schema              string
	SchemaVersion       string
	MessageID           string
	CorrelationID       string
	CausationID         string
	TraceID             string
	DeduplicationID     string
	DeduplicationWindow time.Duration
	TTL                 time.Duration
	Delay               time.Duration
	MaxAttempts         int
	ProducerID          string
	Strategy            broker.StrategyType
}

PublishOptions mirrors the broker's PublishOptions. It previously carried only seven fields, so the client could not reach content_type, schema, ttl, delay, trace propagation, deduplication, max_attempts or a producer-chosen message id, all of which the embedded API supported.

type RequestHandler

type RequestHandler func(context.Context, Delivery) (any, error)

type TaskHandler

type TaskHandler func(context.Context, Delivery) (any, error)

type TaskOption

type TaskOption func(*TaskOptions)

func WithTaskMaxAttempts

func WithTaskMaxAttempts(v int) TaskOption

func WithTaskMetadata

func WithTaskMetadata(v map[string]string) TaskOption

func WithTaskPriority

func WithTaskPriority(v int) TaskOption

func WithTaskQueue

func WithTaskQueue(v string) TaskOption

func WithTaskTenantID

func WithTaskTenantID(v string) TaskOption

type TaskOptions

type TaskOptions struct {
	Queue, TenantID       string
	Priority, MaxAttempts int
	Metadata              map[string]string
}

type Worker

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

func NewWorker

func NewWorker(cfg Config) (*Worker, error)

func (*Worker) Client

func (w *Worker) Client() *Client

func (*Worker) HandleCommand

func (w *Worker) HandleCommand(s string, h RequestHandler)

func (*Worker) HandleCommandQueue

func (w *Worker) HandleCommandQueue(s, queue string, h RequestHandler)

func (*Worker) HandlePattern

func (w *Worker) HandlePattern(p string, h Handler)

func (*Worker) HandleQueue

func (w *Worker) HandleQueue(q string, h Handler)

func (*Worker) HandleRequest

func (w *Worker) HandleRequest(s string, h RequestHandler)

func (*Worker) HandleRequestQueue

func (w *Worker) HandleRequestQueue(s, queue string, h RequestHandler)

func (*Worker) HandleTask

func (w *Worker) HandleTask(n string, h TaskHandler)

func (*Worker) HandleTaskQueue

func (w *Worker) HandleTaskQueue(n, queue string, h TaskHandler)

func (*Worker) HandleTopic

func (w *Worker) HandleTopic(t string, h Handler)

func (*Worker) Run

func (w *Worker) Run(ctx context.Context) error

Jump to

Keyboard shortcuts

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