Important
While from my perspective the library is working just fine, I am still changing things here and there. Even tough the library is tagged as semver, I will start respecting it after the v1.0.0
, and I won't guarantee backwards compatibility before that.
Easy setup: Bunnify is designed to be easy to set up and use. Simply reference the library and start publishing and consuming events.
Automatic payload marshaling and unmarshaling: You can consume the same payload you published, without worrying about the details of marshaling and unmarshaling. Bunnify handles these actions for you, abstracting them away from the developer.
Automatic reconnection: If your connection to the AMQP server is interrupted, Bunnify will automatically handle the reconnection for you. This ensures that your events are published and consumed without interruption.
Built-in event metadata handling: The library automatically handles event metadata, including correlation IDs and other important details.
Retries and dead lettering: You can configure how many times an event can be retried and to send the event to a dead letter queue when the processing fails.
Tracing out of the box: Automatically injects and extracts traces when publishing and consuming. Minimal setup required is shown on the tracer test.
Prometheus metrics: Prometheus gatherer will collect automatically the following metrics:
amqp_events_received
amqp_events_without_handler
amqp_events_not_parsable
amqp_events_nack
amqp_events_processed_duration
amqp_events_publish_succeed
amqp_events_publish_failed
Only dependencies needed: The intention of the library is to avoid having lots of unneeded dependencies. I will always try to triple check the dependencies and use the least quantity of libraries to achieve the functionality required.
github.com/rabbitmq/amqp091-go
: Handles the connection with AMQP protocol.github.com/google/uuid
: Generates UUID for events ID and correlation ID.go.uber.org/goleak
: Used on tests to verify that there are no leaks of routines on the handling of channels.go.opentelemetry.io/otel
: Handles the injection and extraction of the traces on the events.github.com/prometheus/client_golang
: Used in order to export metrics to Prometheus.
Outbox publisher: There is a submodule that you can refer with go get github.com/pmorelli92/bunnify/outbox
. This publisher is wrapping the default bunnify publisher and stores all events in a database table which will be looped in an async way to be published to AMQP. You can read more here.
Every workplace I have been had their own AMQP library. Most of the time the problems that they try to solve are reconnection, logging, correlation, handling the correct body type for events and dead letter. Most of this libraries are good but also built upon some other internal libraries and with some company's specifics that makes them impossible to open source.
Some developers are often spoiled with these as they provide a good dev experience and that is great; but if you cannot use it in side projects or if you start your own company, what is the point?
Bunnify aims to provide a flexible and adaptable solution that can be used in a variety of environments and scenarios. By abstracting away many of the technical details of AMQP publishing and consumption, Bunnify makes it easy to get started with event-driven architecture without needing to be an AMQP expert.
go get github.com/pmorelli92/bunnify
You can find all the working examples under the tests
folder.
Consumer
Dead letter consumer
Using a default handler
Publisher
Enable Prometheus metrics
Enable tracing
Retries
Configuration
Both the connection and consumer structs can be configured with the typical functional options. You can find the options below:
When publishing an event, you can override the event or the correlation ID if you need. This is also achievable with options: