An minimalist event bus subway library for Elixir. (UNDER DEVELOPMENT)
defmodule YourApplication.UserEvents do
use Subway
defevent "listing_favorited" do # <- You can have multiple events like this
field :user_id, :integer # <- Ecto.Schema api (id an timestamps are automatically defined)
field :listing_id, :integer
end
end
defmodule YourApplication.UserEvents do
alias YourApplication.Events.Subscribers
use Subway,
subscribers: [
# Subscribers are simple modules that implement supported_event?/1 and handle_event/1
Subscribers.PersistOnMongoDB,
Subscribers.SendToHubspot,
Subscribers.TriggerClientWebhook,
Subscribers.EnqueueToRedis,
]
# These fields will be merged to the event's fields defined in this context.
@common_fields %{
user_id: :integer
}
defevent ListingFavorited do
field :listing_id, :integer, required: true
end
defevent SupportMessageSent do
field :subject, :string
field :content, :string
end
end
alias YourApplication.UserEvents
# params = %{ user_id: 1, listing_id: 1 })
case UserEvents.notify("listing_favorited", params) do
{:ok, payload} -> "Yay! The event was broadcasted successfully"
{:error, errors} -> "Could be validation errors"
end
If available in Hex, the package can be installed
by adding subway
to your list of dependencies in mix.exs
:
def deps do
[
{:subway, "~> 0.1.0"}
]
end