You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduce consumers which are guaranteed to handle an event exactly one time, based on their name (or class name if it is a class):
structUserCreatedincludeOnyx::EDA::Eventdefinitialize(@user_id : Int32, @registration_request_id : String)
endendstructRegistrationRequestincludeOnyx::EDA::Eventdefinitialize(@name : String)
endend# ---classRegistrarincludeOnyx::EDA::Consumer(RegistrationRequest)
defconsume(event)
user =Onyx.query(User.new(name: event.name).insert.returning(:id))
Onyx.emit(UserCreated.new(user.id, event._event_id))
endendspawnRegistrar.new.listen # RFC on better name# OrOnyx.consume(RegistrationRequest, name:"registrar") do |event|
user =Onyx.query(User.new(name: event.name).insert.returning(:id))
Onyx.emit(UserCreated.new(user.id, registration_request_id: event._event_id))
end# ---
event_id =Onyx.emit(RegistrationRequest.new("John"))
Onyx.subscribe(self, UserCreated, event_id) do |event|
pp event.user_id
end
An event can be broadcast to an arbitrary amount subscribers, but only to one consumer of this name. However, there can be an arbitrary amount of consumers with different names, for example in addition to the example above:
BREAKING CHANGE: `Channel` is an abstract class now, use `Channel::Memory` and `Channel::Redis`.
BREAKING CHANGE: No need to pass a subscribing object to `Channel#subscribe` anymore. It returns `Channel::Subscription` instance which has `#unsubscribe` method.
BREAKING CHANGE: `Channel#subscribe` accepts `filter` or `consumer_id` arguments. The former enables event filtering and the latter enables consuming instead of subscribing. Closes#3 and also closes#4.
BREAKING CHANGE: `Channel#emit` returns the events themselves.
Added `Channel#await` method, which closes#5.
Events have an `#event_id` getter with random UUID by default, which closes#6.
Added `Subscriber` and `Consumer` modules.
Fixed requiring logic of events when using `Channel::Redis`, the requiring order should not matter anymore.
Also added triggering dependant Travis CI builds.
Introduce consumers which are guaranteed to handle an event exactly one time, based on their name (or class name if it is a class):
An event can be broadcast to an arbitrary amount subscribers, but only to one consumer of this name. However, there can be an arbitrary amount of consumers with different names, for example in addition to the example above:
The text was updated successfully, but these errors were encountered: