An Event-Driven Architecture framework to build reactive apps.
Thanks to all my patrons, I can continue working on beautiful Open Source Software! 🙏
You can become a patron too in exchange of prioritized support and other perks
Onyx::EDA is an Event-Driven Architecture framework. It allows to emit certain events and subscribe to them.
It has several channels implemented:
Add this to your application's
dependencies: onyx-eda: github: onyxframework/eda version: ~> 0.2.0
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:
All subscribers will asynchronously notified of the new event. You can then unsubscribe:
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,
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)
There are multiple places to talk about this particular shard and about other ones as well:
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! 📣
This software is licensed under MIT License.