Giter Club home page Giter Club logo

declarator's Introduction

GoLang RabbitMQ Declarator Package

Go Reference Go Report Card Go Version badge

The Project

This project is a simple package to help you to automate the creation of your message broker such as RabbitMQ, using the declarative way to create queues, exchanges and bindings.

Initially is only supported RabbitMQ, but I'm planning to add support to other message brokers in the future.

Why?

I created this package to help me to automate the creation of my message broker, because I have a lot of microservices and I need to create a lot of queues, exchanges and bindings. So, I created this package to help me to automate this process.

How it works?

Actually, this package has two ways to declare your message broker.

Using a file

This package will read a json file with the declarations and will create the queues, exchanges and bindings.

The format of declaration file is the same as RabbitMQ export file.

Has a example of declaration file is in the examples folder, If you want more information about the format of declaration file can be found in the RabbitMQ Documentation

Example

package main

import (
    "fmt"
    "log"

    "github.com/nicollaspetrelli/declarator/rabbitmq"
)

func main() {
    var rabbitConnection *amqp.Channel

    // Create a new declarator passing the connection
    declarator := rabbitmq.NewDeclarator(rabbitConnection)

    // Use declarator to declare from a json definitions file
    declarator.DeclareFromFile("examples/hello-world-broker.json")
}

Using separated functions

Also you can use the separated functions to declare in your code.

Example

package main

import (
    "fmt"
    "log"

    "github.com/nicollaspetrelli/declarator/rabbitmq"
)

func main() {
    var rabbitConnection *amqp.Channel

    // Create a new declarator passing the connection
    declarator := rabbitmq.NewDeclarator(rabbitConnection)

    // Declare a queue
    declarator.DeclareQueue(rabbitmq.Queue{
        Name: "hello-world-queue",
        Durable: true,
        AutoDelete: false,
        Exclusive: false,
        NoWait: false,
        Args: nil,
    })

    // Declare an exchange
    declarator.DeclareExchange(rabbitmq.Exchange{
        Name: "hello-world-exchange",
        Type: "direct",
        Durable: true,
        AutoDelete: false,
        Internal: false,
        NoWait: false,
        Args: nil,
    })

    // Declare a binding
    declarator.DeclareBinding(rabbitmq.Binding{
        Queue: "hello-world-queue",
        Exchange: "hello-world-exchange",
        RoutingKey: "hello-world-routing-key",
        NoWait: false,
        Args: nil,
    })
}

Installing

How to install the package?

go get github.com/nicollaspetrelli/declarator

Now you can use the package in your project following the examples above or in the main.go file in root of the project.

Also you can use the docker-compose file to run a RabbitMQ instance to test the package.

Future Work

  • Make RabbitMQ Connection optional, passing DSN and create a new connection
  • Add unit tests
  • Add integration tests

Contributing

Want to contribute? Great!

Just follow the steps below:

  • Fork the project
  • Create a branch with your feature
  • Commit your changes
  • Push your branch
  • Create a new Pull Request

Development

Requirements

Makefile

Please run the make target below to see the provided targets.

$ make help

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Authors

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.