https://github.com/piquette/msgr
Beginner-friendly bindings for rabbitmq in go :rabbit: :zap:
https://github.com/piquette/msgr
amqp amqp-client go library messaging rabbitmq rabbitmq-client
Last synced: about 1 year ago
JSON representation
Beginner-friendly bindings for rabbitmq in go :rabbit: :zap:
- Host: GitHub
- URL: https://github.com/piquette/msgr
- Owner: piquette
- License: mit
- Created: 2019-11-12T05:54:17.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-13T00:56:57.000Z (over 6 years ago)
- Last Synced: 2024-06-20T01:50:20.490Z (about 2 years ago)
- Topics: amqp, amqp-client, go, library, messaging, rabbitmq, rabbitmq-client
- Language: Go
- Homepage: https://piquette.io/projects/msgr
- Size: 8.79 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# msgr | AMQP Client
[](http://godoc.org/github.com/piquette/msgr) [](https://travis-ci.org/piquette/msgr) [](https://coveralls.io/github/piquette/msgr?branch=master)
## Summary
This go module is a tiny wrapper around the [streadway/amqp](https://github.com/streadway/amqp), the standard low level golang client for [rabbitmq](https://www.rabbitmq.com/), the open source message broker.
`msgr` abstracts away a few of the complexities of rabbitmq and exposes a slightly friendlier interface, intended for simple applications.
## Documentation
For details on all the functionality in this library, see the [GoDoc][godoc] documentation.
## Installation
This project supports modules and Go 1.13+. Add `msgr` to your own project the usual way -
```sh
go get github.com/piquette/msgr
```
## Usage example
### Producer
```go
// Instantiate and connect to the server.
conf := &msgr.Config{
URI: "amqp://localhost:5672",
Channel: "queue_name",
}
producer = msgr.ConnectP(conf)
defer producer.Close()
// Send a message.
Enqueue:
{
success := producer.Post([]byte("hi")])
if !success {
// Retry for all eternity.
log.Println("could not enqueue msg")
time.Sleep(time.Second * 3)
goto Enqueue
}
}
```
### Consumer
```go
// Instantiate and connect to the server.
conf := &msgr.Config{
URI: "amqp://localhost:5672",
Channel: "queue_name",
}
consumer = msgr.ConnectC(conf)
defer consumer.Close()
// Receive messages.
open, messages := s.Consumer.Accept()
if !open {
return
}
// Range over the messages chan.
for recv := range messages {
// Got one.
fmt.Println(string(recv.Body)) // prints 'hi'.
// Don't forget to acknowledge.
recv.Ack(false)
}
```
## Contributing
This modules is a work in progress and needs a lot of refinement. Please [submit an issue][issues] if you need help!
[godoc]: http://godoc.org/github.com/piquette/msgr
[issues]: https://github.com/piquette/msgr/issues/new
[pulls]: https://github.com/piquette/msgr/pulls