Comments (2)
Implementation work is being done here:
https://github.com/strongtyped/fun-cqrs/tree/feature/binding-dsl
from fun-cqrs.
After discussing with some DDD/CQRS experts, we decided to change the naming of method to come closer to the common CQRS vocabulary.
The current implementation looks like:
describe[Lottery]
.whenCreating {
// creational command and event
handler { cmd: CreateLottery => LotteryCreated(cmd.name, metadata(id, cmd)) }
.listener { evt => Lottery(name = evt.name, id = id) }
// updates
} whenUpdating { lottery =>
// Select a winner when run!
tryHandler { cmd: Run.type =>
lottery.selectParticipant().map { winner => WinnerSelected(winner, metadata(id, cmd)) }
} listener { evt =>
lottery.copy(winner = Option(evt.winner))
}
} whenUpdating { lottery =>
tryHandler { cmd: AddParticipant =>
if (lottery.hasParticipant(cmd.name))
Failure(new IllegalArgumentException(s"Participant ${cmd.name} already added!"))
else
Success(ParticipantAdded(cmd.name, Lottery.metadata(id, cmd)))
} listener { evt =>
lottery.addParticipant(evt.name)
}
} whenUpdating { lottery =>
// handler produces more than one event
handler.manyEvents { cmd: Reset.type =>
lottery.participants.map { name => ParticipantRemoved(name, metadata(id, cmd)) }
} listener {
// listener must be a partial function
case evt: ParticipantRemoved => lottery.removeParticipant(evt.name)
}
}
Basically, we have the following methods:
Single events
- handler - defines a command handler that returns a raw Event (not wrapped)
- tryHandler - defines a command handler that returns a Try[Event]
- asyncHandler - defines a command handler that returns a Future[Event]
Whenever declaring a handler we must declare an event listener that can respond to the Event being generated.
In case of single events we must define a function from Event => Aggregate
Many Events
In some situations we may generate more than one event (also at construction time).
For commands generating many events we have the following operations.
- handler.manyEvents - defines a command handler that returns a raw
Seq[Event]
(not wrapped) - tryHandler.manyEvents - defines a command handler that returns a
Try[Seq[Event]]
- asyncHandler.manyEvents - defines a command handler that returns a
Future[Seq[Event]]
Whenever a handler returns a Seq of Events we must declare an event listener using a PartialFunction. The reason for that is that we need a function able to handle all possible events in the list.
from fun-cqrs.
Related Issues (20)
- Support for Scala 2.13 HOT 1
- Removal of `handleCommandAsync`, `tryToHandleCommand` and `manyEvents` methods
- timeout for applyCommand HOT 4
- Eventhandling idempotency possibly flawed HOT 5
- Simplifying Command and Events
- AkkaBackend: Sender doesn't get any notification in case of empty list of Events
- Make the InMemoryBackend more flexible HOT 3
- Improve error message when Aggregate is not configured HOT 1
- Support for Scala 2.12
- Upgrade EventsSourceProvider to use akka.persistence.query.EventEnvelope2 in Akka 2.4 HOT 3
- Actor is not unique exception when configuring two backends in the same actor system. HOT 2
- Replace type projections by path dependent types
- Command and Event Handlers as PartialFunction HOT 1
- RxScala dependency for 2.11 HOT 7
- PersistedOffsetAkka mechanism inefficient HOT 6
- The EventsMonitorActor is hardcoded to timeout after 10 seconds
- AggregateActor "pipeTo self" bypasses termination logic of AggregateManager HOT 3
- Future of fun-cqrs HOT 5
- Multiple aggregates per actor system? HOT 4
- Would you be willing to accept a pull request for the Projection trait to have a additional method handler when event is successfully handled? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fun-cqrs.