# EventBusHandler

Elixir EventBus helper that manages event handler supervision.

## Installation

The package can be installed by adding `event_bus_handler` to your
list of dependencies in `mix.exs`:

def deps do
    {:event_bus_handler, "~> 0.1.0"}

Documentation on [HexDocs](

## Usage

You just need to define a subscription handler module:

      defmodule MyApp.SomeEventHandler do
        use EventBusHandler, topics: ["some_topic_*"]
        # with :topics key you specify topics to which the handler will be
        # subscribed, i.e. to every topic, starting with "some_topic_".
        alias EventBus.Model.Event

        def handle(:some_topic_1, %Event{data: data} = event) do
          # Here goes your handling of an event on topic :your_topic_1
          # If you for some reason want to skip handling (i.e. mark the event as
          # skipped), return `:skip` or something. Then warning will appear that
          # an event with this topic was skipped, and the returned tag will be
          # shown. Otherwise, just return `:ok`.


Create a config module and start it from your application:

      defmodule MyApp.EventBusHandler do
        use EventBusHandler, handlers: [YourEventHandler]

      # ...
      def start(_type, _args) do
        children = [
          # In the code below, in key :handlers you specify all defined event
          # handlers.
      #  ...

All the tasks will be started in its own process under a supervisor.
For every handler module separate supervisor is created.