Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/febytanzil/gobroker
golang wrapper for all (to-be) kinds of message brokers
https://github.com/febytanzil/gobroker
amqp cloud-pubsub go golang google-pubsub messaging nsq nsq-client pubsub queue rabbitmq
Last synced: about 2 months ago
JSON representation
golang wrapper for all (to-be) kinds of message brokers
- Host: GitHub
- URL: https://github.com/febytanzil/gobroker
- Owner: febytanzil
- License: mit
- Created: 2018-11-01T10:17:06.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-05-02T10:44:26.000Z (almost 3 years ago)
- Last Synced: 2024-07-30T20:06:22.426Z (6 months ago)
- Topics: amqp, cloud-pubsub, go, golang, google-pubsub, messaging, nsq, nsq-client, pubsub, queue, rabbitmq
- Language: Go
- Homepage:
- Size: 140 KB
- Stars: 15
- Watchers: 3
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://circleci.com/gh/febytanzil/gobroker.svg?style=shield)](https://circleci.com/gh/febytanzil/gobroker)
[![GitHub release](https://img.shields.io/github/release/febytanzil/gobroker.svg)](https://GitHub.com/febytanzil/gobroker/releases/)
[![GitHub license](https://img.shields.io/github/license/febytanzil/gobroker.svg)](https://github.com/febytanzil/gobroker/blob/master/LICENSE)
# gobroker
wrapper for all (to-be) kinds of message brokers (go v1.16.x)## Supported message brokers & patterns
### PubSub
- RabbitMQ (*fanout*)
- Google Cloud Pub/Sub
- NSQ## Intentions & Features
- Generic terms & functions to use message brokers
- Auto reconnection
- Limit & requeue messages*
- Concurrent subscribers
- Support for mockgen unit-testing## Install
```bash
# go get
$ go get github.com/febytanzil/gobroker
```## Usage
Complete examples are provided in `examples` folder/ package
### RabbitMQ
```go
// initialize publisher RabbitMQ
p := pubsub.NewPublisher(gobroker.RabbitMQ, pubsub.RabbitMQAMQP("amqp://guest:guest@localhost:5672/", "vhost"))p.Publish("test.fanout", "msg"+t.String())
```
```go
// register RabbitMQ subscriber(s) & run it
s := pubsub.NewSubscriber(gobroker.RabbitMQ, []*pubsub.SubHandler{
{
Name: "test.consumer",
Topic: "test.fanout",
Handler: testRMQ,
MaxRequeue: 10,
Concurrent: 2,
MaxInFlight: 3,
},
}, pubsub.RabbitMQAMQP("amqp://guest:guest@localhost:5672/", "vhost"))s.Start()
```
```go
// initialize publisher Google
p := pubsub.NewPublisher(gobroker.Google, pubsub.GoogleJSONFile("gcp-project-id", "cluster-name", "/path/to/google/application/credentials/cred.json"))p.Publish("test", "msg"+t.String())
```
```go
// register Google subscriber(s) & run it
s := pubsub.NewSubscriber(gobroker.Google, []*pubsub.SubHandler{
{
Name: "consumer-test",
Topic: "test-topic",
Handler: testGoogle,
MaxRequeue: 10,
Concurrent: 3,
Timeout: 10 * time.Minute,
MaxInFlight: 1,
},
},
pubsub.GoogleJSONFile("gcp-project-id", "cluster-name", "/path/to/google/application/credentials/cred.json"))
s.Start()
```
### Creating subcriber/ consumer
```go
// subcriber function format
// return nil will ack the message as success
// return error will requeue based on configfunc testRMQ(msg *gobroker.Message) error {
var encoded string
gobroker.StdJSONCodec.Decode(msg.Body, &encoded)
log.Println("consume rabbitmq:", encoded)
return nil
}
func testGoogle(msg *gobroker.Message) error {
var encoded string
gobroker.StdJSONCodec.Decode(msg.Body, &encoded)
log.Println("consume google pubsub", encoded)
return errors.New("requeue msg body: " + encoded)
}
```## Notes
Due to requeue limiter, the behavior both in RabbitMQ & Google Pub/Sub is changed to republish to the topic with additional header that contains counter to make this possible## Contributing
Please use a fork to create a pull request## Contributors
- [ichsanrp](https://github.com/ichsanrp)
- [jonathanhaposan](https://github.com/jonathanhaposan)
- [budiryan](https://github.com/budiryan)
- [utomorezeki](https://github.com/utomorezeki)