https://github.com/sticksnleaves/greyhound
:bus:Extensible event bus platform
https://github.com/sticksnleaves/greyhound
distributed elixir eventbus extensible
Last synced: 12 months ago
JSON representation
:bus:Extensible event bus platform
- Host: GitHub
- URL: https://github.com/sticksnleaves/greyhound
- Owner: sticksnleaves
- License: mit
- Created: 2018-05-18T13:10:18.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-05T02:10:10.000Z (almost 8 years ago)
- Last Synced: 2025-06-11T05:53:27.559Z (about 1 year ago)
- Topics: distributed, elixir, eventbus, extensible
- Language: Elixir
- Homepage:
- Size: 17.6 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Greyhound
## Installation
```elixir
def deps do
[
{:greyhound, "~> 0.1.0"}
]
end
```
## Define a bus
```elixir
defmodule MyProject.Bus do
use Greyhound.Bus, otp_app: :my_project
end
```
## Listener
```elixir
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
```elixir
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