https://github.com/jakoblorz/brokerutil
brokerutil provides a common interface to message-brokers for pub-sub applications
https://github.com/jakoblorz/brokerutil
golang message-queue messaging networking pubsub realtime-messaging redis
Last synced: 5 months ago
JSON representation
brokerutil provides a common interface to message-brokers for pub-sub applications
- Host: GitHub
- URL: https://github.com/jakoblorz/brokerutil
- Owner: jakoblorz
- License: mit
- Created: 2018-05-25T07:58:27.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-10T09:12:00.000Z (about 8 years ago)
- Last Synced: 2026-01-15T06:03:47.500Z (5 months ago)
- Topics: golang, message-queue, messaging, networking, pubsub, realtime-messaging, redis
- Language: Go
- Homepage: https://godoc.org/github.com/jakoblorz/brokerutil
- Size: 357 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [brokerutil](https://github.com/jakoblorz/brokerutil)
brokerutil provides a common interface to message-brokers for pub-sub applications.
[](https://godoc.org/github.com/jakoblorz/brokerutil)
[](https://travis-ci.com/jakoblorz/brokerutil)
[](https://codecov.io/gh/jakoblorz/brokerutil)
Use brokerutil to be able to build pub-sub applications which feature interopability with message-brokers drivers.
brokerutil provides a abstract and extendible interface which enables developers to switch or mix
message brokers without having to rewrite major parts of the applications
pub-sub logic.
## Features
- sync / async subscription
- multi-driver support - subscribe to messages from multiple brokers
- simple yet extendible pub sub interface
- simple driver interface to implement own drivers
### Preinstalled Drivers
- loopback
- [redis](https://redis.io/) based on [github.com/go-redis/redis](http://github.com/go-redis/redis)
- [kafka](https://kafka.apache.org/) (soon [#1](https://github.com/jakoblorz/brokerutil/pull/1)) based on [github.com/Shopify/sarama](https://github.com/Shopify/sarama)
## Installation
`go get github.com/jakoblorz/brokerutil`
Use the package drivers or implement your own.
## Example
This example will use redis as message-broker. It uses the package redis driver which
extends on the [github.com/go-redis/redis](http://github.com/go-redis/redis) driver.
```go
package main
import (
"flag"
"github.com/jakoblorz/brokerutil"
"github.com/jakoblorz/brokerutil/redis"
r "github.com/go-redis/redis"
)
var (
raddr = flag.String("raddr", ":6379", "redis address to connect to")
channel = flag.String("channel", "brokerutil", "redis message channel")
)
func main() {
flag.Parse()
// create redis driver to support pub-sub
driver, err := redis.NewRedisPubSubDriver([]string{*channel}, &r.Options{
Addr: *raddr,
})
if err != nil {
log.Fatalf("could not create redis driver: %v", err)
}
// create new pub sub using the initialized redis driver
ps, err := brokerutil.NewPubSubFromDriver(driver)
if err != nil {
log.Fatalf("could not create pub sub: %v", err)
}
// run blocking subscribe as go routine
go ps.SubscribeSync(func(msg interface{}) error {
fmt.Printf("%v", msg)
return nil
})
// start controller routine which blocks execution
if err := ps.ListenSync(); err != nil {
log.Fatalf("could not listen: %v", err)
}
}
```