Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/armon/relay
Golang framework for simple message passing using an AMQP broker
https://github.com/armon/relay
Last synced: about 2 months ago
JSON representation
Golang framework for simple message passing using an AMQP broker
- Host: GitHub
- URL: https://github.com/armon/relay
- Owner: armon
- License: mit
- Created: 2013-08-06T01:59:56.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2020-08-05T09:53:48.000Z (over 4 years ago)
- Last Synced: 2024-08-02T13:17:07.438Z (4 months ago)
- Language: Go
- Size: 75.2 KB
- Stars: 132
- Watchers: 8
- Forks: 21
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - relay - framework for simple message passing using an AMQP broker (Message brokers)
README
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](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()
}