Skip to content

Latest commit

 

History

History
60 lines (43 loc) · 1.03 KB

README.md

File metadata and controls

60 lines (43 loc) · 1.03 KB

Greyhound

Installation

def deps do
  [
    {:greyhound, "~> 0.1.0"}
  ]
end

Define a bus

defmodule MyProject.Bus do
  use Greyhound.Bus, otp_app: :my_project
end

Listener

defmodule MyProject.MyListener do
  use GenServer

  def start_link([]) do
    GenServer.start_link(__MODULE__, %{}, name: __MODULE__)
  end

  def init(state) do
    MyProject.Bus.subscribe("a_topic")

    {:ok, state}
  end

  def handle_info({:perform, topic, message}, state) do
    IO.puts topic
    IO.inspect message

    {:noreply, state}
  end
end

Dispatch Event

MyProject.Bus.dispatch("a_topic", "a message")

# listener should print "a_topic" and "a message"

Middleware

All dispatching logic is handled by middleware. Middleware can be customized by overriding the __middleware__/0 function on a bus. The default middleware dispatches events sequentially to all listeners on the local node.

https://github.com/sticksnleaves/greyhound/blob/master/lib/greyhound/middleware/dispatch/local.ex