• Stars
    star
    97
  • Rank 348,505 (Top 7 %)
  • Language
    Go
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A tiny wrapper over amqp exchanges and queues ๐ŸšŒ โœจ

Rabbus ๐ŸšŒ โœจ

  • A tiny wrapper over amqp exchanges and queues.
  • In memory retries with exponential backoff for sending messages.
  • Protect producer calls with circuit breaker.
  • Automatic reconnect to RabbitMQ broker when connection is lost.
  • Go channel API.

Installation

go get -u github.com/rafaeljesus/rabbus

Usage

The rabbus package exposes an interface for emitting and listening RabbitMQ messages.

Emit

import (
	"context"
	"time"

	"github.com/rafaeljesus/rabbus"
)

func main() {
	timeout := time.After(time.Second * 3)
	cbStateChangeFunc := func(name, from, to string) {
		// do something when state is changed
	}
	r, err := rabbus.New(
		rabbusDsn,
		rabbus.Durable(true),
		rabbus.Attempts(5),
		rabbus.Sleep(time.Second*2),
		rabbus.Threshold(3),
		rabbus.OnStateChange(cbStateChangeFunc),
	)
	if err != nil {
		// handle error
	}

	defer func(r Rabbus) {
		if err := r.Close(); err != nil {
			// handle error
		}
	}(r)

	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	go r.Run(ctx)

	msg := rabbus.Message{
		Exchange: "test_ex",
		Kind:     "topic",
		Key:      "test_key",
		Payload:  []byte(`foo`),
	}

	r.EmitAsync() <- msg

	for {
		select {
		case <-r.EmitOk():
			// message was sent
		case <-r.EmitErr():
			// failed to send message
		case <-timeout:
			// handle timeout error
		}
	}
}

Listen

import (
	"context"
	"encoding/json"
	"time"

	"github.com/rafaeljesus/rabbus"
)

func main() {
	timeout := time.After(time.Second * 3)
	cbStateChangeFunc := func(name, from, to string) {
		// do something when state is changed
	}
	r, err := rabbus.New(
		rabbusDsn,
		rabbus.Durable(true),
		rabbus.Attempts(5),
		rabbus.Sleep(time.Second*2),
		rabbus.Threshold(3),
		rabbus.OnStateChange(cbStateChangeFunc),
	)
	if err != nil {
		// handle error
	}

	defer func(r Rabbus) {
		if err := r.Close(); err != nil {
			// handle error
		}
	}(r)

	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	go r.Run(ctx)

	messages, err := r.Listen(rabbus.ListenConfig{
		Exchange:    "events_ex",
		Kind:        "topic",
		Key:         "events_key",
		Queue:       "events_q",
		DeclareArgs: rabbus.NewDeclareArgs().WithMessageTTL(15 * time.Minute).With("foo", "bar"),
		BindArgs:    rabbus.NewBindArgs().With("baz", "qux"),
	})
	if err != nil {
		// handle errors during adding listener
	}
	defer close(messages)

	go func(messages chan ConsumerMessage) {
		for m := range messages {
			m.Ack(false)
		}
	}(messages)
}

Contributing

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request

Badges

Build Status Go Report Card Go Doc


GitHub @rafaeljesus ย ยทย  Medium @_jesus_rafael ย ยทย  Twitter @_jesus_rafael

More Repositories

1

nsq-event-bus

A tiny wrapper around NSQ topic and channel ๐Ÿš€
Go
79
star
2

retry-go

Retrying made simple and easy for golang ๐Ÿ”
Go
49
star
3

parallel-fn

Run functions in parallel โ˜„๏ธ
Go
36
star
4

cron

Cron like job scheduler
Go
33
star
5

cron_api

Cron-like job scheduler as a service.
Elixir
28
star
6

composing-go-example

Project example demonstrating interface segregation in go
Go
23
star
7

tempdb

Key-value store for temporary items ๐Ÿ“
Go
19
star
8

kafka-event-bus

A tiny wrapper around https://github.com/Shopify/sarama topic and consumer ๐ŸšŒ
Go
15
star
9

resilient-go-example

Making HTTP Client more Resilient inย Go example
Go
14
star
10

koa-bb

koa2, jwt, knex, ava and docker boilerplate
JavaScript
14
star
11

event-srv

A high performance event log as a service โŒ›
Go
11
star
12

easy-schedule

Flexible job scheduling
JavaScript
11
star
13

crony

Cron scheduler as a service ๐Ÿ• 
Go
10
star
14

gridfs-api

Exposes a REST API for MongoDB GridFS
JavaScript
9
star
15

srv-consumer

A recommendation for how a Rabbit consumer service should be designed in Go
Go
9
star
16

bank_ror

Simple Ruby on Rails Bank Account System
Ruby
9
star
17

event_track

Record any actions your system perform, along with any properties that describe the action.
Elixir
8
star
18

event-tracker

[DEPRECATED] This project is deprecated in favor of https://github.com/rafaeljesus/event-srv
Go
7
star
19

agile2go

Rails 4 - Backbone.js - SemanticUI
JavaScript
7
star
20

pagarme-node

Pagarme API http client ๐Ÿ’ธ
JavaScript
5
star
21

safe

Thread-safe for any value ๐Ÿ”’
Go
5
star
22

url-status-go

A URL status monitoring application
Go
4
star
23

wstats

Natural language TCP server
Go
4
star
24

rest-scheduler

Handles job scheduling by storing and managing events that correspond to actions to execute in the future
JavaScript
3
star
25

emitter

Node.js EventEmitter in Elixir
Elixir
3
star
26

koa-xml

XML request body parser for Koa
JavaScript
3
star
27

rust_cache

RR, MRU, LRU, LFU caches implemented in rust
Rust
2
star
28

newww

The npm website
JavaScript
2
star
29

kyp-env

Kyp Docker Development Environment
2
star
30

docker-mongodb

Dockerfile to build a MongoDB container image
2
star
31

events

Modular microservices in node.js, mongodb, rabbitmq, docker
2
star
32

event-track

Record any actions your system perform, along with any properties that describe the action.
JavaScript
2
star
33

maremar

Real Time App for http://www.maremar.tur.br/
JavaScript
2
star
34

rtrace

Async trace events micro services in ruby
Ruby
2
star
35

events-api

The public Events API
JavaScript
2
star
36

minitail

naive tail command in rust
Rust
2
star
37

kyp-users

Kyp Users API
Go
1
star
38

kyp-todo

Kyp Todo Api
Go
1
star
39

rorder

Orders micro services API
Ruby
1
star
40

wt-track-api

A simple webtask to record any actions your system perform
JavaScript
1
star
41

tags-api

JavaScript
1
star
42

kv

Ridiculous async key value store
Elixir
1
star
43

design-patterns-java

Design Patterns for good Java Developers
Java
1
star
44

gridfs-db

MongoDB GridFS
JavaScript
1
star
45

events-worker

Worker runs your Events logs
JavaScript
1
star
46

survey

Create Surveys with Rails
Ruby
1
star
47

events-core

Events core model and services shared by events api and worker
JavaScript
1
star
48

tracing-rest

[DEPRECATED] This project is deprecated in favor of https://github.com/rafaeljesus/event-srv
Go
1
star
49

event_worker

Consumes a event from rabbitmq and stores on mongodb.
Elixir
1
star
50

ac-api

JavaScript
1
star
51

elb_registrator

Register EC2 instances with an ELB
Elixir
1
star
52

todo

Todo is a sample praxis api server
Ruby
1
star
53

url-status

URL status monitoring application
JavaScript
1
star
54

shipping-api

The simple shipping API
JavaScript
1
star
55

rustbook

code exercises from the https://doc.rust-lang.org
Rust
1
star