mqutils

1 min read Original article ↗

mqutils

The Most Complete Go Message Queue Library

Stop rewriting message queue code. One unified API for 6 major systems with enterprise-grade features, production-proven reliability.

6 Message Systems

99.99% Reliability

62%+ Test Coverage

0 Production Issues

Quick Start

package main

import ( “context” “log” “github.com/spf13/viper” “go.digitalxero.dev/mqutils” “go.digitalxero.dev/mqutils/types” // Import the specific message queue system you want to use _ “go.digitalxero.dev/mq-amqp” )

func main() { // Register a message handler globally types.RegisterHandler(“process”, func(ctx context.Context, msg types.Message) error { log.Printf(“Received: %s”, string(msg.Body())) return nil })

// Create configuration
config := viper.New()
config.Set("url", "amqp://localhost:5672/myqueue")
config.Set("handler", "process")

// Works with any supported message queue system
ctx := context.Background()
consumer, err := mqutils.NewConsumer(ctx, config)
if err != nil {
    log.Fatal(err)
}

// Start consuming messages
if err := consumer.Run(ctx); err != nil {
    log.Fatal(err)
}

}

That’s it! The same code works with Kafka, NATS, SQS, Pub/Sub, and Redis by simply changing the URL scheme.