Giter Club home page Giter Club logo

erl-vent's Introduction

vent

Hex pm

An application that simplifies writing RabbitMQ producers and consumers.

Typically, a client workflow is as follows:

  • Establish a connection to a broker
  • Create a new channel within the open connection
  • Execute AMQP commands with a channel such as sending and receiving messages, creating exchanges and queue or defining routing rules between exchanges and queues
  • When no longer required, close the channel and the connection

Vent encapsulates this workflow and delegates the consumer specific-logic to a custom handler behaviour.

Configuration

RabbitMQ configuration:

{host, "localhost"},                                # defaults to 'localhost'
{port, 5672},                                       # defaults to 5672
{username, "user"},                                 # optional
{password, "pass"},                                 # optional
{virtual_host, <<"prod">>},                         # required
{publish_exchange, <<"publish_exchange">>}          # required

Publishers

The serialization format is assumed to be JSON.

To publish a message:

vent_publisher:publish(Exchange, Topic, Payload, Opts).

Opts is a proplist that currently consists of the following options:

{durable, boolean()}                                # exchange is durable or transient

Publisher configuration:

{publish_chunk_size, 20}                            # defaults to 20

Subscribers

A subscriber handler should be created for every subscription. The behaviour consists of the following callbacks:

callback init() ->
   {ok, state()}.
callback handle(term(), state()) ->
   {ok, state()} |
   {requeue, term(), state()} |
   {requeue, number(), term(), state()} |
   {drop, term(), state()}.
callback terminate(state()) ->
   ok.

An inert vent_debug_handler is already provided that will log every message that it consumes.

Every subscription should be configured together with its handler:

{name, "subscription_name"},                        # required, unique
{n_workers, 1},                                     # defaults to 1
{n_overflow, 1},                                    # defaults to 1
{prefetch_count, 2},                                # defaults to 2
{exchange, <<"exchange">>},                         # required
{dead_letter_exchange, <<"dl_exchange">>},          # required
{error_exchange, <<"errors">>},                     # required
{error_routing_key, <<"error_routing_key">>},       # required
{queue, <<"vent:queue">>},                          # required
{message_ttl, 300000},                              # defaults to infinite
{handler, vent_debug_handler}]                      # defaults to vent_debug_handler

Note that more than one subscriber may be registered.

 {subscribers,
     [{vent_subscriber, ...config for 1st subscriber},
      {vent_subscriber, ...config for 2nd subscriber}]}

Each subscription is supervised by a pool supervisor. This pool supervisor starts a Poolboy pool of workers, and a subscriber supervisor. The subscribers delegate the handling of a message to a handler worker, that they obtain from a worker pool. This separation between subscriber and worker protects the subscription against failures in handler modules, to prevent expensive restarts.

Build

$ rebar3 compile

In order to run tests...{to do}

Release

$ rebar3 release

erl-vent's People

Contributors

aymanosman avatar davecromberge avatar starstuck avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.