onyx-eda
Onyx::Event
An Event-Driven Architecture framework for Crystal.
About
Onyx::Event
brings the Event-Driven Architecture to the Crystal Language, making it possible to build event-driven applications fast. It allows to emit events and attach subscribers (and also consumers) to these events, via multiple channels.
Features comparison
Onyx Framework is an open-core software, which ensures its long-term support and development. Purchasing a commercial license gives you a Github team membership with an access to private repositories containing extra features and also an access to private Twist team for extened support. Read more at Commercial FAQ.
Feature | Open Source (this repo) | Pro | Enterprise --- | :---: | :---: | :---: Subscribers | β | β | β Memory channel | β | β | β Redis channel | β | β | β Consumers | β | β | β Redis store | β | β | β DB store | β | β | β Kafka channel | β | β | β RabbitMQ channel | β | β | β On-demand custom channels | β | β | β On-demand custom stores | β | β | β License | BSD 3-Clause | Commercial | Custom Price | Free | ~~$100~~ $50/month* | Contact us
* A 50% discount is applicable until version 1.0 of this software.
Installation
Add this to your application's shard.yml
:
dependencies:
+ onyx-event:
+ github: onyxframework/event
+ version: ~> 0.0.1
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
Documentation
For a deeper information on usage, please visit:
- docs.onyxframework.org/event β handcrafted documentation and guides
- api.onyxframework.org/event β auto-generated API documentation
Example
First of all, define some events for your application:
require "onyx-event"
struct MyEvent < Onyx::Event
getter foo
def initialize(@foo : String)
end
end
event.cr
Then define an event generator:
require "onyx-event/channel/redis"
require "./event"
channel = Onyx::Event::Channel::Redis.new
loop do
sleep(1)
channel.send(MyEvent.new(Time.now.to_s))
puts "Sent MyEvent"
end
generator.cr
And a consumer:
require "onyx-event/channel/redis"
require "./event"
channel = Onyx::Event::Channel::Redis.new
channel.subscribe(MyEvent) do |event|
puts "Got #{typeof(event)}: #{event.foo}"
end
sleep
consumer.cr
Then launch the generator and arbitrary amount of consumers:
$ crystal generator.cr
Sent MyEvent
Sent MyEvent
$ crystal consumer.cr
Got MyEvent: 2019-01-09 17:20:10 +03:00
Got MyEvent: 2019-01-09 17:20:11 +03:00
Contributing
- Fork it (https://github.com/onyxframework/rest/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'feat: new feature'
) using angular-style commits - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Licensing
This software is licensed under BSD 3-Clause License.