# `BullMQ.QueueEvents.Handler`
[🔗](https://github.com/taskforcesh/bullmq/blob/v2.2.3/lib/bullmq/queue_events.ex#L466)

Behaviour for queue event handlers.

Implement this behaviour to create structured event handlers.

## Example

    defmodule MyApp.QueueHandler do
      use BullMQ.QueueEvents.Handler

      @impl true
      def init(opts) do
        {:ok, %{count: 0}}
      end

      @impl true
      def handle_event(:completed, %{"jobId" => id}, state) do
        Logger.info("Job completed: #{id}")
        {:ok, %{state | count: state.count + 1}}
      end

      @impl true
      def handle_event(_event, _data, state) do
        {:ok, state}
      end
    end

# `handle_event`

```elixir
@callback handle_event(event :: atom(), data :: map(), state :: term()) ::
  {:ok, new_state :: term()} | {:error, reason :: term()}
```

# `init`

```elixir
@callback init(opts :: keyword()) :: {:ok, state :: term()} | {:error, reason :: term()}
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
