Created
April 16, 2021 10:57
-
-
Save aludwiko/caf8c3371dc32ce15538cffbcaf6260b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UserEntity extends EventSourcedBehavior<UserCommand, UserEvent, User> { | |
@Override | |
public CommandHandler<UserCommand, UserEvent, User> commandHandler() { | |
return newCommandHandlerBuilder().forAnyState() | |
.onCommand(UserCommand.class, (user, command) -> { | |
List<UserEvent> events = user.process(command); | |
return Effect() | |
.persist(events) | |
.thenReply(command.replyTo(), user -> CommandProcessed.of()); | |
}) | |
.build(); | |
} | |
@Override | |
public EventHandler<User, UserEvent> eventHandler() { | |
return newEventHandlerBuilder().forAnyState() | |
.onEvent(UserEvent.class, (user, event) -> user.apply(event)) | |
.build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment