You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Go library that provides a high-level wrapper around RabbitMQ (AMQP) with built-in OpenTelemetry tracing, Prometheus metrics, and flexible message serialization.
Features
Producer and Consumer abstractions over amqp091-go
Automatic reconnection with backoff on connection/channel loss
Publisher confirms to ensure delivery before returning
OpenTelemetry tracing with trace context propagated via AMQP headers
Prometheus metrics for message counts and processing latency
Pluggable serializers/deserializers: JSON, Protocol Buffers, ProtoJSON, raw bytes, or custom
Retry handling via a built-in RetryPublisher error handler
Functional options pattern for clean, composable configuration
Requirements
Go 1.22.2+
A running RabbitMQ instance (default: localhost:5672, credentials guest/guest)
Installation
go get github.com/patrickjmcd/bunny
Usage
Producer
import (
"context""github.com/patrickjmcd/bunny/producer"
)
p, err:=producer.NewRabbitProducer(
producer.WithConnectionString("amqp://guest:guest@localhost:5672/"),
producer.WithExchangeName("my-exchange"),
producer.WithExchangeType("topic"),
producer.WithQueueName("my-queue"),
producer.WithTopic("my.routing.key"),
producer.WithValueSerializer(producer.NewJsonSerializer[MyMessage]()),
)
iferr!=nil {
log.Fatal(err)
}
deferp.Close()
// Wait until the connection is ready<-p.Readyerr=p.ProduceMessage(context.Background(), "correlation-id", MyMessage{...}, "")
typeValueDeserializerinterface {
Deserialize(ctx context.Context, topicstring, data []byte) (interface{}, error)
DeserializeInto(ctx context.Context, topicstring, data []byte, destinterface{}) errorClose()
}
Observability
OpenTelemetry
Bunny creates spans for each produce and consume operation, propagating trace context through AMQP message headers. Pass your configured tracer and propagator via WithTracer and WithTracePropagator.
Prometheus Metrics
The following metrics are registered automatically:
Metric
Type
Labels
Description
bunny_produced_total
Counter
topic
Total messages produced
bunny_receive_latency_ms
Histogram
exchange, queue, topic
Time from message timestamp to receipt
bunny_processing_duration_ms
Histogram
exchange, queue, topic
Time to process each message
Packages
Package
Description
rabbit
Low-level AMQP client with reconnection logic
rabbit/options
Connection, exchange, queue, consumer, and publisher option types
producer
High-level message publisher
consumer
High-level message consumer
retry
MessageErrorHandler implementation that re-publishes failed messages