Giter VIP home page Giter VIP logo

go-consumer's Introduction

Go Consumer

GoConsumer is a wrapper around amqp that allows you to easily write applications that consume AMQP queues. Exchange, Queue and bindings are defined in a simple configuration file. GoConsumer handles plumbing those together allowing you to focus on writing great consumer code.

This project borrows many ideas from sparkplug

Configuration

Configuration is done through an ini style file. In this file you define the connection, exchange and queue(s) you want to bind into. Once your file has been loaded and parsed you can attach your consumer function in. The following is an simple configuration file:

[connection]
host = localhost
virtual_host = '/'
user = guest
password = guest
ssl = False

[exchange]
name = grand
type = direct
durable = True
auto_delete = False

[queue]
name = hose
durable = True
auto_delete = True
exclusive = False
routing_key = fire

You can also configure your consumer to draw from multiple queues as well:

[connection]
host = localhost
virtual_host = '/'
user = guest
password = guest
ssl = False

[exchange-app]
name = app
type = direct
durable = True
auto_delete = False

[queue-app]
name = app
durable = True
auto_delete = True
exclusive = False
routing_key = app-event

[exchange-backend]
name = backend
type = direct
durable = True
auto_delete = False

[queue-backend]
name = backend
durable = True
auto_delete = True
exclusive = False
routing_key = backend-event

When multiple queues are being bound, each exchange and queue section should be suffixed with the same value. This defines the binding between the exchange and queue.

Consumers

Consuming functions need to have the following signature:

func(*consumer.Message)

A simple example application would look like:

import (
	"github.com/markstory/go-consumer"
	"log"
)

c, err = consumer.LoadConfig("./consumer.ini")
if err != nil {
	log.Fatalf("Unable to create consumer. Error: %v", err)
}
err = c.Consume(func(msg *consumer.Message) {
	log.Print("Got a message")
	msg.Ack(true)
})

Your consumer function will receive message types that can be acked or nacked as you see fit.

Signals

GoConsumer handles SIGINT, SIGTERM and SIGQUIT. In all cases the it attempts to shutdown the AMQP connection and finish consuming any buffered messages.

go-consumer's People

Contributors

markstory avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

go-consumer's Issues

Allow queues to use multiple routing keys

It is sometimes useful to bind a single queue to an exchange using multiple routing keys. This makes it more efficient to use direct exchanges as fewer queues are needed.

In the config file, a list of routing keys should be possible by comma separating the keys. Whitespace will be trimmed off from the words.

Add ability to consume from multiple queues/exchanges

It would be nice to allow a single consumer to read messages from more than one queue/exchange. Perhaps the configuration could look like:

    [connection]
    host = localhost
    virtual_host = '/'
    user = guest
    password = guest
    ssl = False

    [exchange-app]
    name = app
    type = direct
    durable = True
    auto_delete = False

    [queue-app]
    name = app
    durable = True
    auto_delete = True
    exclusive = False
    routing_key = app-event

    [exchange-backend]
    name = backend
    type = direct
    durable = True
    auto_delete = False

    [queue-backend]
    name = backend
    durable = True
    auto_delete = True
    exclusive = False
    routing_key = backend-event

When multiple queues are being bound, each exchange and queue section should be suffixed with the same value. This defines the binding between the exchange and queue.

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.