A event-driven framework for writing reliable and scalable system.
At a high level, it provides a few major components:
- Tools for core components with traits,
- Macros for processing events and commands
A Tour of Ruva
Ruva consists of a number of modules that provide a range of functionality essential for implementing messagebus-like applications in Rust. In this section, we will take a brief tour, summarizing the major APIs and their uses.
TCommand & Event
You can register any general struct with TCommand Derive Macro as follows:
As you attach TCommand derive macro, MessageBus now is going to be able to understand how and where it should dispatch the command to.
Likewise, you can do the same thing for Event:
Notice that internally_notifiable event doesn't require aggregate specification while externally_notifiable event does along with its id with identifier attribute.
internally_notifiableis marker to let the system know that the event should be handled within the applicationexternally_notifiableevent is stored asOutBox.
Initializing TCommand Handlers (Doc required)
Registering Event
Event is a side effect of TCommand or yet another [Event] processing.
You can register as many handlers as possible as long as they all consume same type of Event as follows:
Example
use init_event_handler;
init_event_handler!;
In the MakeOrder TCommand Handling, we have either OrderFailed or OrderSucceeded event with their own processing handlers.
Events are raised in the handlers that are thrown to MessageBus by Context.
MessageBus then loops through the handlers UNLESS StopSentinel is received.
Handler API Example(Doc required)
MessageBus
At the core is event driven library is MessageBus, which gets command and gets raised event from
UnitOfWork and dispatch the event to the right handlers.
As this is done only in framework side, the only way you can 'feel' the presence of messagebus is
when you invoke it. Everything else is done magically.
Example
async
Error from MessageBus
When command has not yet been regitered, it returns an error - BaseError::NotFound
Be mindful that bus does NOT return the result of event processing as in distributed event processing.