• This repository has been archived on 27/Nov/2023
  • Stars
    star
    183
  • Rank 210,106 (Top 5 %)
  • Language
    Elixir
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

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

Repository Details

Elixir AMQP consumer and publisher behaviours

Build Status Hex Version Coverage Status Hex.pm Download Total Dependabot Status

GenRMQ

GenRMQ is a set of behaviours meant to be used to create RabbitMQ consumers and publishers, as fully OTP compliant GenServers.

Internally it is using the AMQP elixir RabbitMQ client. The idea is to reduce boilerplate consumer / publisher code, which usually includes:

  • creating connection / channel and keeping it in a state
  • creating and binding queue
  • handling reconnections / consumer cancellations

GenRMQ provides the following functionality:

  • GenRMQ.Consumer - a behaviour for implementing RabbitMQ consumers (example)
  • GenRMQ.Publisher - a behaviour for implementing RabbitMQ publishers (example)
  • GenRMQ.Processor - a behaviour for implementing RabbitMQ message processors (this is useful to separate out business logic from your consumer) (example)
  • GenRMQ.Consumer.Telemetry - telemetry events emitted by a GenRMQ consumer
  • GenRMQ.Publisher.Telemetry - telemetry events emitted by a GenRMQ publisher
  • GenRMQ.RabbitCase - test utilities for RabbitMQ (example)

Installation

GenRMG requires Elixir 1.11 or newer, running on at least OTP 22.

def deps do
  [{:gen_rmq, "~> 4.0"}]
end

Migrations

Version 4.0.0 has been released. Please check how to migrate to gen_rmq 4.0.0.

Examples

More thorough examples for using GenRMQ.Consumer, GenRMQ.Publisher, and GenRMQ.Processor can be found under documentation.

Consumer

defmodule Consumer do
  @behaviour GenRMQ.Consumer

  @impl GenRMQ.Consumer
  def init() do
    [
      queue: "gen_rmq_in_queue",
      exchange: "gen_rmq_exchange",
      routing_key: "#",
      prefetch_count: "10",
      connection: "amqp://guest:guest@localhost:5672",
      retry_delay_function: fn attempt -> :timer.sleep(2000 * attempt) end
    ]
  end

  @impl GenRMQ.Consumer
  def consumer_tag() do
    "test_tag"
  end

  @impl GenRMQ.Consumer
  def handle_message(message) do
    ...
  end

  @impl GenRMQ.Consumer
  def handle_error(message, _reason) do
    GenRMQ.Consumer.reject(message, true)
  end
end
GenRMQ.Consumer.start_link(Consumer, name: Consumer)

This will result in:

  • durable gen_rmq_exchange.deadletter exchange created or redeclared
  • durable gen_rmq_in_queue_error queue created or redeclared. It will be bound to gen_rmq_exchange.deadletter
  • durable topic gen_rmq_exchange exchange created or redeclared
  • durable gen_rmq_in_queue queue created or redeclared. It will be bound to gen_rmq_exchange exchange and has a deadletter exchange set to gen_rmq_exchange.deadletter
  • every handle_message callback will be executed in a separate supervised Task. This can be disabled by setting concurrency: false in init callback
  • on failed rabbitmq connection it will wait for a bit and then reconnect

There are many options to control the consumer setup details, please check the c:GenRMQ.Consumer.init/0 docs for all available settings.

Publisher

defmodule Publisher do
  @behaviour GenRMQ.Publisher

  def init() do
    [
      exchange: "gen_rmq_exchange",
      connection: "amqp://guest:guest@localhost:5672"
    ]
  end
end
GenRMQ.Publisher.start_link(Publisher, name: Publisher)
GenRMQ.Publisher.publish(Publisher, Jason.encode!(%{msg: "msg"}))

Documentation

Examples

Guides

Metrics

Migrations

Running Tests

You need docker-compose installed.

$ make test

How to Contribute

Please see our Contribution Guidelines.

Are you using GenRMQ in Production? Please let us know, we are curious to learn about your experiences!

Maintainers

The maintainers are responsible for the general project oversight, and empowering further trusted committers (see below).

The maintainers are the ones that create new releases of GenRMQ.

Trusted Committers

Trusted Committers are members of our community who we have explicitly added to our GitHub repository. Trusted Committers have elevated rights, allowing them to send in changes directly to branches and to approve Pull Requests. For details see TRUSTED-COMMITTERS.md.

Note: Maintainers and Trusted Committers are listed in .github/CODEOWNERS in order to automatically assign PR reviews to them.

License

The MIT License.

Copyright (c) Meltwater Inc. underthehood.meltwater.com

More Repositories

1

served

A C++11 RESTful web server library
C++
709
star
2

docker-cleanup

DEPRECATED Automatic Docker image, container and volume cleanup
Shell
586
star
3

drone-cache

A Drone plugin for caching current workspace files between builds to reduce your build times
Go
335
star
4

drone-convert-pathschanged

Drone conversion extension to include/exclude pipelines and pipeline steps based on paths changed
Go
133
star
5

secretary

DEPRECATED Secrets management for dynamic environments
Go
94
star
6

terraform-aws-asg-dns-handler

Terraform module for dynamically setting hostnames following a pattern on instances in AWS Auto Scaling Groups
Python
75
star
7

rabbitio

RabbitIO is used to move data in and out of RabbitMQ
Go
70
star
8

elasticsearch-batch-percolator

(deprecated) High performance Elasticsearch percolator
Java
48
star
9

lighter

DEPRECATED Marathon deployment automation tool
Python
43
star
10

awsudo

A simple utility for executing cli commands with an assumed role.
JavaScript
41
star
11

docker-mesos

Mesos, Marathon and Chronos using Docker Compose
Shell
39
star
12

jugri

The JUpyter-GRemlin Interface
Python
35
star
13

rxrabbit

RabbitMQ Java client built on RxJava
Java
33
star
14

ex_lsh

A configurable implementation of locality-sensitive hashing in Elixir
Elixir
25
star
15

proxymatic

DEPRECATED Marathon service discovery proxy
Python
24
star
16

quitsies

A persisted drop-in replacement for Memcached, respecting the rules of quitsies.
C++
16
star
17

api-gateway-demo

Nginx application showcasing how to do lightweight tests with ruby rspec
Ruby
15
star
18

kotlin-compose

Docker-compose wrapper for the JVM
Kotlin
12
star
19

rabbit-puppy

Configures RabbitMQ server based on YAML configuration
Kotlin
7
star
20

docker-elasticsearch-aws

Elasticsearch Docker image with the Amazon EC2 plugin
7
star
21

MeltwaterEng-public-presentations

List of public talks by Meltwater Engineering: meetup presentations, recorded conference talks, slides.
7
star
22

tau

Functional time and date JavaScript library.
JavaScript
6
star
23

puppet-marathon

Puppet Module for Mesos Marathon
Ruby
6
star
24

puppet-cobbler

Fork of https://bitbucket.org/jsosic/puppet-cobbler
HTML
5
star
25

puppet-incron

Puppet module to provide an incron resource type
Ruby
4
star
26

sparkline

ANSI Sparklines for Elixir
Elixir
4
star
27

supervisor_health

Elixir
4
star
28

meltwater-elasticsearch-queries

Java
3
star
29

phi

Functional tools for JavaScript inspired by Ramda and Ramda Adjunct.
JavaScript
3
star
30

confex_config_provider

Confex runtime configuration provider for Distillery
Elixir
3
star
31

vagrant-coreos

Vagrant infrastructure for CoreOS on Amazon AWS
HTML
3
star
32

underthehood-blog-tests-examples

Examples for blog post "Using Selenium-Server on Docker to run your Browser Tests"
Ruby
3
star
33

mlabs-health

Health monitor for Node.js microservices.
JavaScript
3
star
34

makenew-koa-service

Bootstrap a new Node.js Koa microservice in five minutes or less.
Shell
2
star
35

esi-include-webpack-plugin

Webpack 4 plugin to inject an esi comment for prod OR fetch and do the injection in dev
JavaScript
2
star
36

mlabs-aws

Convenient wrappers around the AWS SDK to keep code DRY.
JavaScript
2
star
37

threaded-logstasher

DEPRECATED Threaded logstash handler and formatter in Python.
Python
2
star
38

makenew-node-lib

Bootstrap a new Node.js npm package in five minutes or less.
Shell
2
star
39

docker-foundation-terraform

Repo to use when building terraforming docker image
2
star
40

node-examplr

Example runner for Node.js packages.
JavaScript
2
star
41

mlabs-graphql

Node.js GraphQL client and server toolkit.
JavaScript
2
star
42

docker-aws-cli

Custom Docker build of the AWS CLI
Dockerfile
1
star
43

the-orchard

A CLI tool to generate the markup for including web dependencies
JavaScript
1
star
44

puppet-erlang

puppet module to install erlang from source
Puppet
1
star
45

puppet-python

Installation of python from source via puppet
Puppet
1
star
46

mlabs-http

Node.js HTTP client wrapper around Got
JavaScript
1
star
47

puppet-monit

HTML
1
star
48

puppet-newrelic_agent

Puppet Module for Installing & Managing the various NewRelic server monitoring agents
Puppet
1
star
49

docker-nginx-http-https-reverse-proxy

Nginx HTTP server which proxies an external SSL host
Dockerfile
1
star
50

pagerduty-campfire

Polls Pagerduty for new stuff, posts it to Campfire
1
star
51

meltwater-ruby

(deprecated) Ruby Client for the Meltwater API
Ruby
1
star
52

terraform-provider-meltwater

A Terraform provider for Meltwater based on the persistent/infrastructure parts of the Meltwater API. Such as setting up webhooks and recurring exports.
Go
1
star
53

puppet-es

Puppet module for Elastic Search as a Defined Type
HTML
1
star
54

mlabs-logger

Structured logging for Node.js services.
JavaScript
1
star
55

mlabs-koa

Koa middleware suite and server bootstrapper.
JavaScript
1
star
56

docker-awscli

Docker image of Amazon AWS Command Line Interface
Shell
1
star
57

meltwater-killercoda

Meltwater Engineering's Public / Shared Training Center
Shell
1
star
58

meltwater-php

(deprecated) PHP Client for the Meltwater API
PHP
1
star
59

.github

Meltwater's community health files
1
star