Code Monkey home page Code Monkey logo

relay's Introduction

relay

Relay is a Go framework for task queues, and makes writing code for publishers and consumers very simple. It is a wrapper around the AMQP protocol, and relies on a message broker like RabbitMQ.

The reason Relay exists is that AMQP is a tedious protocol to deal with, and the high level abstraction of a task queue is often something that is desirable. With Relay, you simply Publish objects into task queues, and Consume them on the other end.

Features

  • Simple to use, hides the AMQP details
  • Flexible encoding and decoding support
  • Configuration changes instead of code changes

Documentation

See the online documentation here: http://godoc.org/github.com/armon/relay.

Example

Here is an example of a simple publisher:

conf := &relay.Config{Addr: "rabbitmq"}
conn, err := relay.New(conf)
defer conn.Close()

pub, err := conn.Publisher("tasks")
defer pub.Close()

pub.Publish("this is a test message")

Here is an example of a simple consumer:

conf := &relay.Config{Addr: "rabbitmq"}
conn, err := relay.New(conf)
defer conn.Close()

cons, err := conn.Consumer("tasks")
defer cons.Close()

var msg string
for {
    cons.ConsumeAck(&msg)
    fmt.Printf("Got msg: %s\n", msg)
}

Here is an example of a consumer using prefetching and multi Acks:

conf := &relay.Config{Addr: "rabbitmq", PrefetchCount: 5, EnableMultiAck: true}
conn, err := relay.New(conf)
defer conn.Close()

cons, err := conn.Consumer("tasks")
defer cons.Close()

var msg string
for {
    // Consume 5 messages
    for i := 0; i < 5; i++ {
        cons.Consume(&msg)
        fmt.Printf("Got msg: %s\n", msg)
    }

    // Acks the last 5 messages
    cons.Ack()
}

relay's People

Contributors

armon avatar ryanuber avatar wolfeidau avatar gaffneyc avatar

Watchers

James Cloos avatar

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.