In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "what is the model of event-sourcing-cqrs". In the daily operation, I believe that many people have doubts about the model of event-sourcing-cqrs. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "what is the model of event-sourcing-cqrs?" Next, please follow the editor to study!
Eventpublic abstract class Event {private final UUID aggregateId; private final ZonedDateTime timest private final int version; protected Event (UUID aggregateId, ZonedDateTime timestamp, int version) {this.aggregateId = checkNotNull (aggregateId); this.timestamp = checkNotNull (timestamp); this.version = version;} public UUID getAggregateId () {return aggregateId;} public ZonedDateTime getTimestamp () {return this.timest} public int getVersion () {return version;}}
Event defines aggregateId, timestamp, version attributes
EventStorepublic interface EventStore {void store (UUID aggregateId, List newEvents, int baseVersion) throws OptimisticLockingException; List load (UUID aggregateId);}
The EventStore interface defines store and load methods.
Aggregatepublic abstract class Aggregate {private UUID id; private int baseVersion; private List newEvents; protected Aggregate (UUID id) {this (id, emptyList ());} protected Aggregate (UUID id, List eventStream) {checkNotNull (id); checkNotNull (eventStream); this.id = id; eventStream.forEach (e-> {apply (e); this.baseVersion = e.getVersion ();}); this.newEvents = new ArrayList () } protected void applyNewEvent (Event event) {checkArgument (event.getVersion () = = getNextVersion (), "New event version'% s' does not match expected next version'% s'", event.getVersion (), getNextVersion ()); apply (event); newEvents.add (event);} private void apply (Event event) {try {Method method = this.getClass (). GetDeclaredMethod ("apply", event.getClass ()); method.setAccessible (true) Method.invoke (this, event);} catch (InvocationTargetException e) {Throwables.propagate (e.getCause ());} catch (NoSuchMethodException | IllegalAccessException e) {throw new UnsupportedOperationException (format ("Aggregate'% s' doesn't apply event type'% s'", this.getClass (), event.getClass ()), e);} public UUID getId () {return id } public int getBaseVersion () {return baseVersion;} public List getNewEvents () {return ImmutableList.copyOf (newEvents);} protected int getNextVersion () {return baseVersion + newEvents.size () + 1;}}
Aggregate defines id, baseVersion, and newEvents attributes; its applyNewEvent method executes apply (event) and newEvents.add (event); the apply method executes the apply method of event through reflection
ValueObjectpublic abstract class ValueObject {@ Override public boolean equals (Object o) {return EqualsBuilder.reflectionEquals (this, o);} @ Override public int hashCode () {return HashCodeBuilder.reflectionHashCode (this);} @ Override public String toString () {return ToStringBuilder.reflectionToString (this, ToStringStyle.SHORT_PREFIX_STYLE);}}
ValueObject overrides equals, hashCode, toString methods
Specificationpublic interface Specification {boolean isSatisfiedBy (T value);}
The Specification interface defines the isSatisfiedBy method
At this point, the study of "what are the model of event-sourcing-cqrs" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.