Documentation
¶
Overview ¶
Package hop provides a simple and resilient RabbitMQ client for Go.
It offers automatic reconnection, graceful shutdown, and message consumption with built-in metrics support via Prometheus.
Index ¶
- Variables
- type Client
- type Consumer
- type ConsumerBuilder
- type Counter
- type Exchange
- type Gauge
- type Handler
- type Histogram
- type HopOption
- func WithBackoff(multiplier float64, initialDelay, maxDelay time.Duration) HopOption
- func WithConnectionName(connectionName string) HopOption
- func WithMetrics(collector MetricsCollector) HopOption
- func WithPrometheusMetrics(registry prometheus.Registerer) HopOption
- func WithServiceName(serviceName string) HopOption
- func WithTLS(tls *tls.Config) HopOption
- type Kind
- type Message
- type MetricsCollector
- type Queue
Constants ¶
This section is empty.
Variables ¶
var NopCollector = metrics.NopCollector
NopCollector is a no-op collector that discards all metrics. Useful for testing or when metrics are not needed.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
// Publish publishes a message to an exchange.
// NOTE: Not implemented yet.
Publish(ctx context.Context, exchange, key string, body []byte) error
// Consume registers a consumer configuration.
// The consumer will start processing when StartConsumers is called.
Consume(args Consumer) error
// StartConsumers begins message processing for all registered consumers.
// This spawns goroutines and returns immediately.
StartConsumers(ctx context.Context)
// Close terminates the connection immediately without waiting for consumers.
// For graceful shutdown, use Shutdown instead.
Close() error
// Shutdown gracefully stops all consumers and closes the connection.
// It waits for active message processing to complete.
Shutdown(ctx context.Context) error
}
Client is the main interface for interacting with RabbitMQ.
type ConsumerBuilder ¶ added in v0.1.0
type ConsumerBuilder = protocol.ConsumerBuilder
type Histogram ¶ added in v0.1.0
Histogram represents a histogram metric for measuring value distributions.
type HopOption ¶ added in v0.1.0
HopOption configures a hop connection using the functional options pattern.
func WithBackoff ¶ added in v0.1.0
WithBackoff configures the reconnection backoff strategy. - multiplier: exponential factor (e.g., 2.0 doubles delay each attempt) - initialDelay: starting delay before first retry - maxDelay: maximum delay between retries (ceiling)
func WithConnectionName ¶ added in v0.1.0
WithConnectionName sets a custom name for the AMQP connection. This name appears in RabbitMQ management UI and logs. Useful for identifying connections in a multi-service environment.
func WithMetrics ¶ added in v0.1.0
func WithMetrics(collector MetricsCollector) HopOption
WithMetrics enables metrics collection using the provided collector. Pass a MetricsCollector implementation (e.g., PrometheusCollector, MultiCollector). If nil is passed, metrics will be disabled.
func WithPrometheusMetrics ¶ added in v0.1.0
func WithPrometheusMetrics(registry prometheus.Registerer) HopOption
WithPrometheusMetrics is a convenience wrapper for backward compatibility. It creates a PrometheusCollector with the given registry.
func WithServiceName ¶ added in v0.1.0
WithServiceName sets the service_name property on the AMQP connection. This metadata helps with monitoring and debugging in distributed systems.
type Kind ¶ added in v0.1.0
const ( Fanout Kind = "fanout" // Fanout exchange broadcasts to all bound queues Topic Kind = "topic" // Topic exchange routes based on pattern matching Direct Kind = "direct" // Direct exchange routes by exact routing key Default Kind = "" // Default exchange (amq.direct) )
Supported exchange types.
type MetricsCollector ¶ added in v0.1.0
type MetricsCollector = metrics.MetricsCollector
MetricsCollector defines the interface for metrics collection. Implementations can be Prometheus, OpenTelemetry, or any other system.
func NewMultiCollector ¶ added in v0.1.0
func NewMultiCollector(collectors ...MetricsCollector) MetricsCollector
NewMultiCollector combines multiple collectors into one. Metrics are sent to all provided collectors.
func NewOpenTelemetryCollector ¶ added in v0.1.0
func NewOpenTelemetryCollector(serviceName string) MetricsCollector
NewOpenTelemetryCollector creates an OpenTelemetry-backed metrics collector. It uses the provided service name for metric identification.
func NewPrometheusCollector ¶ added in v0.1.0
func NewPrometheusCollector(registry prometheus.Registerer) MetricsCollector
NewPrometheusCollector creates a Prometheus-backed metrics collector. It registers metrics with the provided prometheus.Registerer.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
consumer_example
command
|
|
|
examples
|
|
|
advanced
command
|
|
|
basic
command
|
|
|
internal
|
|
|
resilience
resilience/backoff.go
|
resilience/backoff.go |