client

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2025 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncConsumer

type AsyncConsumer interface {
	Consumer

	// Start starts asynchronous message consumption with a handler
	Start(handler MessageHandler, opts ConsumerOptions) error

	// Stop stops asynchronous message consumption
	Stop() error
}

AsyncConsumer interface for asynchronous message consumption

func NewAsyncConsumer

func NewAsyncConsumer(id string, manager *queue.Manager, opts ...ClientOption) (AsyncConsumer, error)

NewAsyncConsumer creates a new asynchronous consumer

type Client

type Client interface {
	Producer
	Consumer

	// ID returns the client identifier
	ID() string

	// Close closes the client connection
	Close() error
}

Client interface combines Producer and Consumer

func NewClient

func NewClient(id string, manager *queue.Manager, opts ...ClientOption) (Client, error)

NewClient creates a new client

type ClientOption

type ClientOption func(*clientConfig)

ClientOption is a function that configures a client

func WithMetadata

func WithMetadata(key, value string) ClientOption

WithMetadata adds metadata to the client

type ConnectionInfo

type ConnectionInfo struct {
	ClientID      string
	Subscriptions []string
	LastActivity  string
	Metadata      map[string]string
}

ConnectionInfo provides information about a client connection

type Consumer

type Consumer interface {
	// Subscribe subscribes to one or more topics
	Subscribe(ctx context.Context, topics ...string) error

	// Unsubscribe unsubscribes from one or more topics
	Unsubscribe(ctx context.Context, topics ...string) error

	// Receive receives messages (blocking with timeout)
	Receive(ctx context.Context, limit int) ([]*types.Message, error)

	// Ack acknowledges successful message processing
	Ack(ctx context.Context, messageID string) error

	// Nack acknowledges failed message processing
	Nack(ctx context.Context, messageID string, reason string) error
}

Consumer interface for receiving messages

type ConsumerOptions

type ConsumerOptions struct {
	// MaxConcurrency limits concurrent message processing
	MaxConcurrency int

	// PollInterval sets how often to poll for messages
	PollInterval int

	// BatchSize sets how many messages to fetch at once
	BatchSize int

	// AutoAck automatically acknowledges messages after handler returns nil
	AutoAck bool
}

ConsumerOptions configure a consumer

type MessageHandler

type MessageHandler func(ctx context.Context, msg *types.Message) error

MessageHandler is a callback for handling messages

type MessageOption

type MessageOption func(*types.Message)

MessageOption is a function that modifies message properties

func WithMaxRetries

func WithMaxRetries(maxRetries int) MessageOption

WithMaxRetries sets the maximum retry count

func WithMessageMetadata

func WithMessageMetadata(key, value string) MessageOption

WithMessageMetadata adds metadata to the message

func WithPriority

func WithPriority(priority int) MessageOption

WithPriority sets the message priority

func WithTTL

func WithTTL(ttl time.Duration) MessageOption

WithTTL sets the message TTL

type Producer

type Producer interface {
	// SubmitTask submits a task to a topic
	SubmitTask(ctx context.Context, topic string, payload []byte, opts ...MessageOption) (*types.Message, error)

	// SendDirect sends a direct message to another client
	SendDirect(ctx context.Context, to string, payload []byte, opts ...MessageOption) (*types.Message, error)
}

Producer interface for sending messages

Jump to

Keyboard shortcuts

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