onyx-eda

Event-Driven Architecture framework to build reactive apps πŸ’£ shard onyxframework events event-driven
0.2.0 released
onyxframework/eda
8 2 1
Onyx Framework

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

onyx-eda:
  github: onyxframework/eda
  version: ~> 0.2.0
License MIT
Crystal 0.27.2

Authors

Dependencies 2

  • mini_redis ~> 0.1.0
    {'github' => 'vladfaust/mini_redis', 'version' => '~> 0.1.0'}
  • msgpack ~> 0.14.0
    {'github' => 'crystal-community/msgpack-crystal', 'version' => '~> 0.14.0'}

Development Dependencies 0

Dependents 1

Last synced .
search fire star recently