• Stars
    star
    94
  • Rank 356,972 (Top 8 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated almost 2 years ago

Reviews

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

Repository Details

A lightweight transactional message bus on top of RabbitMQ

CircleCI Go Report Card Coverage Status GitHub release

grabbit

A lightweight transactional message bus on top of RabbitMQ supporting:

  1. Supported Messaging Styles
    • One Way (Fire and forget)
    • Publish/Subscribe
    • Aync Command/Reply
    • Blocking Command/Reply (RPC)
  2. Transactional message processing
  3. Message Orchestration via the Saga pattern
  4. At least once reliable messaging via Transaction Outbox and Publisher Confirms
  5. Retry and backoffs
  6. Structured logging
  7. Reporting Metrics via Prometheus
  8. Distributed Tracing via OpenTracing
  9. Extensible serialization with default support for gob, protobuf and avro

Stable release

the v1.x branch contains the latest stable releases of grabbit and one should track that branch to get point and minor release updates.

Supported transactional resources

  1. MySql > 8.0 (InnoDB)

Basic Usage

  • For a complete sample application see the vacation booking sample app in the examples directory

The following outlines the basic usage of grabbit. For a complete view of how you would use grabbit including how to write saga's and handle deadlettering refer to grabbit/tests package

import (
  "github.com/wework/grabbit/gbus"
  "github.com/wework/grabbit/gbus/builder"
)

Define a message

type SomeMessage struct {}

func(SomeMessage) SchemaName() string{
   return "some.unique.namespace.somemessage"
}

Creating a transactional GBus instance

gb := builder.
        New().
    Bus("connection string to RabbitMQ").
    Txnl("mysql", "connection string to mysql").
    WithConfirms().
    Build("name of your service")

Register a command handler

handler := func(invocation gbus.Invocation, message *gbus.BusMessage) error{
    cmd, ok := message.Payload.(*SomeCommand)
    if ok {
      fmt.Printf("handler invoked with  message %v", cmd)
            return nil
    }

        return fmt.Errorf("failed to handle message")
  }

gb.HandleMessage(SomeCommand{}, handler)

Register an event handler

eventHandler := func(invocation gbus.Invocation, message *gbus.BusMessage) {
    evt, ok := message.Payload.(*SomeEvent)
    if ok {
      fmt.Printf("handler invoked with event %v", evt)
            return nil
    }

        return fmt.Errorf("failed to handle event")
  }

gb.HandleEvent("name of exchange", "name of topic", SomeEvent{}, eventHandler)

Start the bus

gb.Start()
defer gb.Shutdown()

Send a command

gb.Send(context.Background(), "name of service you are sending the command to", gbus.NewBusMessage(SomeCommand{}))

Publish an event

gb.Publish(context.Background(), "name of exchange", "name of topic", gbus.NewBusMessage(SomeEvent{}))

RPC style call

request := gbus.NewBusMessage(SomeRPCRequest{})
reply := gbus.NewBusMessage(SomeRPCReply{})
timeOut := 2 * time.Second

reply, e := gb.RPC(context.Background(), "name of service you are sending the request to", request, reply, timeOut)

if e != nil{
  fmt.Printf("rpc call failed with error %v", e)
} else{
  fmt.Printf("rpc call returned with reply %v", reply)
}

Testing

  1. ensure that you have the dependencies installed: go get -v -t -d ./...
  2. make sure to first: docker-compose up -V -d
  3. then to run the tests: go test ./...

More Repositories

1

speccy

Well Spectually πŸ€“ Enforce quality rules on your OpenAPI 3.0.x specifications.
JavaScript
826
star
2

json-schema-to-openapi-schema

A little NodeJS package to convert JSON Schema to OpenAPI Schema Objects
JavaScript
205
star
3

we-call-gem

Making healthy, happy HTTP calls
Ruby
57
star
4

ray

Resources for building interfaces with WeWork's design system
JavaScript
54
star
5

plasma

JavaScript
47
star
6

rails-sunset

Mark an endpoint as deprecated so everyone knows its going away!
Ruby
27
star
7

we-github-stats

Ruby
23
star
8

we-js-logger

Universal logger with transports to Rollbar and Logentries. Uses bunyan under the hood.
JavaScript
14
star
9

faraday-sunset

Watch out for Sunset headers on HTTP responses, as they signify the deprecation (and eventual removal) of an endpoint.
Ruby
12
star
10

env-universal

Standard environment definition, utilities and constants for browser and node JavaScript applications
JavaScript
8
star
11

express-universal-query-validator

Express middleware to provide consistently parseable query parameters to universal applications.
JavaScript
4
star
12

lex_faq

This Is a sample application for a Ruby on Rails Application that acts as a CMS for an AWS Lex Bot
Ruby
3
star
13

wework.github.io

[DEPRECATED] WeWork Engineering Blog
CSS
3
star
14

monarch

Creates Contentful migrations by mapping over React component proptypes
JavaScript
3
star
15

eslint-config-wework

JavaScript
2
star
16

we-learn-react

JavaScript
2
star
17

dotenv-rails-safe

An extension of the dotenv-rails gem that ensures setting of required environment variables
Ruby
2
star
18

freeze-tag

A rails gem for a more "Stateless" tagging experience
Ruby
1
star