Documentation
¶
Overview ¶
Package stompx provides a high-level wrapper over the STOMP protocol, implementing convenient tools for creating message consumers and publishers, with support for middleware, logging, retries, and management of consumer and publisher groups.
Index ¶
- func ConsumerLog(logger log.Logger, logBody bool) consumer.Middleware
- func ConsumerRequestId() consumer.Middleware
- func DefaultConsumer(cfg ConsumerConfig, handler consumer.Handler, logger log.Logger, ...) consumer.Config
- func DefaultPublisher(cfg PublisherConfig, restMiddlewares ...publisher.Middleware) *publisher.Publisher
- func NewResultHandler(logger log.Logger, adapter handler.HandlerAdapter) handler.ResultHandler
- func PublisherLog(logger log.Logger, logBody bool) publisher.Middleware
- func PublisherPersistent() publisher.Middleware
- func PublisherRequestId() publisher.Middleware
- func PublisherRetry(retrier Retrier) publisher.Middleware
- type Client
- type Config
- type ConfigOption
- type ConsumerConfig
- type LogObserver
- type PublisherConfig
- type Retrier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConsumerLog ¶
func ConsumerLog(logger log.Logger, logBody bool) consumer.Middleware
ConsumerLog logs incoming message consumption.
func ConsumerRequestId ¶
func ConsumerRequestId() consumer.Middleware
ConsumerRequestId extracts or generates a Request-Id and saves it in the request context.
func DefaultConsumer ¶
func DefaultConsumer(cfg ConsumerConfig, handler consumer.Handler, logger log.Logger, restMiddlewares ...consumer.Middleware) consumer.Config
DefaultConsumer creates a consumer configuration with logging, middleware, and connection support based on the provided parameters.
func DefaultPublisher ¶
func DefaultPublisher(cfg PublisherConfig, restMiddlewares ...publisher.Middleware) *publisher.Publisher
DefaultPublisher creates a message publisher with middleware and connection settings.
func NewResultHandler ¶
func NewResultHandler(logger log.Logger, adapter handler.HandlerAdapter) handler.ResultHandler
NewResultHandler creates a result handler with logging and panic recovery.
func PublisherLog ¶
func PublisherLog(logger log.Logger, logBody bool) publisher.Middleware
PublisherLog logs message publishing events.
func PublisherPersistent ¶
func PublisherPersistent() publisher.Middleware
PublisherPersistent adds a `persistent=true` header to all outgoing messages.
func PublisherRequestId ¶
func PublisherRequestId() publisher.Middleware
PublisherRequestId adds a Request-Id to message headers.
func PublisherRetry ¶ added in v1.50.0
func PublisherRetry(retrier Retrier) publisher.Middleware
PublisherRetry creates a middleware for retrying message publications. It is recommended to use this middleware after logging middleware to avoid duplicate logging of publication attempts.
Types ¶
type Client ¶ added in v1.58.0
type Client struct {
// contains filtered or unexported fields
}
Client manages a group of consumers and publishers, capable of updating connections and restarting when configuration changes.
func (*Client) Shutdown ¶ added in v1.58.0
func (c *Client) Shutdown()
Shutdown gracefully shuts down all consumers and publishers.
func (*Client) Upgrade ¶ added in v1.58.0
Upgrade updates the configuration and synchronously initializes the client with a guarantee that all components are ready. It returns the first error encountered during initialization, or nil if successful.
func (*Client) UpgradeAndServe ¶ added in v1.58.0
UpgradeAndServe updates the configuration and restarts connections. It stops old connections, initializes new consumers and publishers, and starts message processing. This method blocks and serves indefinitely.
type Config ¶ added in v1.58.0
type Config struct {
// Consumers contains the list of message consumers.
Consumers []*consumer.Watcher
// Publishers contains the list of message publishers.
Publishers []*publisher.Publisher
}
Config represents the configuration for a stompx client.
func NewConfig ¶ added in v1.58.0
func NewConfig(opts ...ConfigOption) Config
NewConfig creates a new Config with the provided options.
type ConfigOption ¶ added in v1.58.0
type ConfigOption func(c *Config)
ConfigOption is a function that applies options to a Config.
func WithConsumers ¶ added in v1.58.0
func WithConsumers(consumers ...*consumer.Watcher) ConfigOption
WithConsumers adds consumer clients to the client configuration.
func WithPublishers ¶ added in v1.58.0
func WithPublishers(publishers ...*publisher.Publisher) ConfigOption
WithPublishers adds publisher clients to the client configuration.
type ConsumerConfig ¶
type ConsumerConfig struct {
// Address is the broker address (required).
Address string `validate:"required" schema:"Адрес брокера"`
// Queue is the queue name (required).
Queue string `validate:"required" schema:"Очередь"`
// Concurrency is the number of handlers (default 1).
Concurrency int `schema:"Кол-во обработчиков,по умолчанию 1"`
// PrefetchCount is the number of preloaded messages.
PrefetchCount int `schema:"Кол-во предзагруженных сообщений,по умолчанию не используется"`
// Username is the username for authentication.
Username string `schema:"Имя пользователя"`
// Password is the password for authentication.
Password string `schema:"Пароль"`
// ConnHeaders are additional connection headers.
ConnHeaders map[string]string `schema:"Дополнительные параметры подключения"`
}
ConsumerConfig holds the configuration for a message consumer.
type LogObserver ¶
type LogObserver struct {
// contains filtered or unexported fields
}
LogObserver observes events in the consumer lifecycle (errors, startup, shutdown).
func NewLogObserver ¶
func NewLogObserver(logger log.Logger) LogObserver
NewLogObserver creates an observer for lifecycle events with the specified logger.
func (LogObserver) BeginConsuming ¶
func (l LogObserver) BeginConsuming(c *consumer.Consumer)
BeginConsuming logs the start of message consumption.
func (LogObserver) CloseDone ¶
func (l LogObserver) CloseDone(c *consumer.Consumer)
CloseDone logs the completion of the shutdown process.
func (LogObserver) CloseStart ¶
func (l LogObserver) CloseStart(c *consumer.Consumer)
CloseStart logs the start of the shutdown process.
type PublisherConfig ¶
type PublisherConfig struct {
// Address is the broker address (required).
Address string `validate:"required" schema:"Адрес брокера"`
// Queue is the queue name (required).
Queue string `validate:"required" schema:"Очередь"`
// Username is the username for authentication.
Username string `schema:"Имя пользователя"`
// Password is the password for authentication.
Password string `schema:"Пароль"`
// ConnHeaders are additional connection headers.
ConnHeaders map[string]string `schema:"Дополнительные параметры подключения"`
}
PublisherConfig holds the configuration for a message publisher.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package consumer provides functionality for consuming messages from a STOMP broker.
|
Package consumer provides functionality for consuming messages from a STOMP broker. |
|
Package handler provides functionality for processing STOMP messages and handling results.
|
Package handler provides functionality for processing STOMP messages and handling results. |
|
Package publisher provides functionality for publishing messages to a STOMP broker.
|
Package publisher provides functionality for publishing messages to a STOMP broker. |