• Stars
    star
    79
  • Rank 408,196 (Top 9 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 8 years ago
  • Updated almost 7 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 around NSQ topic and channel ๐Ÿš€

Event Bus NSQ

  • A tiny wrapper around go-nsq topic and channel.
  • Protect nsq calls with gobreaker.

Installation

go get -u github.com/rafaeljesus/nsq-event-bus

Usage

The nsq-event-bus package exposes a interface for emitting and listening events.

Emitter

import "github.com/rafaeljesus/nsq-event-bus"

topic := "events"
emitter, err := bus.NewEmitter(bus.EmitterConfig{
  Address: "localhost:4150",
  MaxInFlight: 25,
})

e := event{}
if err = emitter.Emit(topic, &e); err != nil {
  // handle failure to emit message
}

// emitting messages on a async fashion
if err = emitter.EmitAsync(topic, &e); err != nil {
  // handle failure to emit message
}

Listener

import "github.com/rafaeljesus/nsq-event-bus"

if err = bus.On(bus.ListenerConfig{
  Topic:              "topic",
  Channel:            "test_on",
  HandlerFunc:        handler,
  HandlerConcurrency: 4,
}); err != nil {
  // handle failure to listen a message
}

func handler(message *Message) (reply interface{}, err error) {
  e := event{}
  if err = message.DecodePayload(&e); err != nil {
    message.Finish()
    return
  }

  if message.Attempts > MAX_DELIVERY_ATTEMPTS {
    message.Finish()
    return
  }

  err, _ = doWork(&e)
  if err != nil {
    message.Requeue(BACKOFF_TIME)
    return
  }

  message.Finish()
  return
}

Request (Request/Reply)

import "github.com/rafaeljesus/nsq-event-bus"

topic := "user_signup"
emitter, err = bus.NewEmitter(bus.EmitterConfig{})

e := event{Login: "rafa", Password: "ilhabela_is_the_place"}
if err = bus.Request(topic, &e, handler); err != nil {
  // handle failure to listen a message
}

func handler(message *Message) (reply interface{}, err error) {
  e := event{}
  if err = message.DecodePayload(&e); err != nil {
    message.Finish()
    return
  }

  reply = &Reply{}
  message.Finish()
  return
}

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

rabbus

A tiny wrapper over amqp exchanges and queues ๐ŸšŒ โœจ
Go
97
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