DEV Community

Alexander
Alexander

Posted on

1

VOLTA - RabbitMQ`s framework that I`m working on.

For the last couple of weeks, it has been a constant challenge to work with RabbitMQ in Golang. And during these couple of weeks I noticed that all existing libraries are super-verboose, and I found a solution to this problem - write my own microframework to create microservices with RabbitMQ.

The name of this project is VOLTA.

Repository
Docs

For the last year, for API development, I've been using a library called Fiber. I really like the way you work with it and the fact that it's similar to Express.js. So I decided to implement a similar usage pattern in Volta, you create simple handlers and just register them to a queue.

I want to roughly demonstrate how it works and ease of use.

func main() {
    app := volta.New(volta.Config{
        RabbitMQ:  "amqp://guest:guest@localhost:5672/",
    })

    app.AddExchanges(volta.Exchange{Name: "test", Type: "topic"})
    app.AddQueue(volta.Queue{Name: "test", RoutingKey: "test", Exchange: "test"})

    app.AddConsumer("test", Handler)

    if err := app.Listen(); err != nil {
        panic(err)
    }
}

func Handler(ctx *volta.Ctx) error {
    return ctx.Reply([]body("Hello, World!"))
}
Enter fullscreen mode Exit fullscreen mode

I also lacked the functionality of middlewares, so I had to implement those as well.

app.Use(func(ctx *volta.Ctx) error {
    fmt.Println("Before")
    return ctx.Next()
})

app.AddConsumer("testing", func(ctx *volta.Ctx) error {
    fmt.Println("Handler")
    return ctx.Reply([]body("Hello, World!"))
})

// Output:
// Before
// Handler
Enter fullscreen mode Exit fullscreen mode

Also, I like the ability in Fiber to change the serialization of JSON, so I brazenly stole their idea to Volta

app := volta.New(volta.Config{
     ...
     Marshal: sonic.Marshal,
     Unmarshal: sonic.Unmarshal,
     ...
})
Enter fullscreen mode Exit fullscreen mode

My project is only a couple days old and needs ideas and tweaks, I'd love if you could help with that :)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay