Skip to content
Event-Driven Architecture framework to build reactive apps 💣
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
spec
src
.editorconfig
.gitignore
.travis.yml
LICENSE
README.md
shard.yml

README.md

Onyx::EDA

Built with Crystal Travis CI build API docs Latest release

An Event-Driven Architecture framework to build reactive apps.

Supporters ❤️

Thanks to all my patrons, I can continue working on beautiful Open Source Software! 🙏

Lauri Jutila, Alexander Maslov, Dainel Vera

You can become a patron too in exchange of prioritized support and other perks

About 👋

Onyx::EDA is an Event-Driven Architecture framework. It allows to emit certain events and subscribe to them.

It has several channels implemented:

Installation 📥

Add this to your application's shard.yml:

dependencies:
  onyx-eda:
    github: onyxframework/eda
    version: ~> 0.2.0

This shard follows Semantic Versioning v2.0.0, so check releases and change the version accordingly. Please visit github.com/crystal-lang/shards to know more about Crystal shards.

Usage 💻

First of all, you need to create a channel:

require "onyx-eda"
channel = Onyx::EDA::Channel.new

# or
#

require "onyx-eda"
require "onyx-eda/channel/redis"

channel = Onyx::EDA::Channel::Redis.new("redis://localhost:6379")

Then define events to emit:

struct MyEvent
  include Onyx::EDA::Event

  getter foo

  def initialize(@foo : String)
  end
end

Subscribe an object to the event:

# Top-level subscription
channel.subscribe(Object, MyEvent) do |event|
  pp event.foo
end

# Object-level subscriptions
#

class Notifier
  def initialize(channel)
    channel.subscribe(self, MyEvent) do |event|
      pp event.foo
    end
  end
end

notifier = Notifier.new(channel)

Then emit the event:

channel.emit(MyEvent.new("bar"))

All subscribers will asynchronously notified of the new event. You can then unsubscribe:

channel.unsubscribe(notifier)

Using with Onyx top-level macros

Onyx shard has convenient macros to reduce boilerplate code. Once "onyx/eda" is required, a singleton Onyx.channel is defined. You can then specify which channel to use, for example, Onyx.channel(:redis).

require "onyx/eda"

struct MyEvent
  # ditto
end

Onyx.channel(:redis)

Onyx.subscribe(Object, MyEvent) do |event|
  # ditto
end

Onyx.emit(MyEvent.new("bar"))
# or
Onyx.channel.emit(MyEvent.new("bar"))

sleep(0.1)

Onyx.unsubscibe(Object)

Community 🍪

There are multiple places to talk about this particular shard and about other ones as well:

Support ❤️

This shard is maintained by me, Vlad Faust, a passionate developer with years of programming and product experience. I love creating Open-Source and I want to be able to work full-time on Open-Source projects.

I will do my best to answer your questions in the free communication channels above, but if you want prioritized support, then please consider becoming my patron. Your issues will be labeled with your patronage status, and if you have a sponsor tier, then you and your team be able to communicate with me in private or semi-private channels such as e-mail and Twist. There are other perks to consider, so please, don't hesistate to check my Patreon page:

You could also help me a lot if you leave a star to this GitHub repository and spread the world about Crystal and Onyx! 📣

Contributing

  1. Fork it ( https://github.com/onyxframework/eda/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'feat: some feature') using Angular style commits
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Licensing

This software is licensed under MIT License.

Open Source Initiative

You can’t perform that action at this time.