Hi Roland, Thanks heaps for looking at my repo. I've made the changes you suggested and they did simplify things a lot. Here is the old and new code based on your suggestions:
One thing that might be refactored is that applyEvent should only manage the state (i.e. only be S => S) New - https://github.com/simerplaha/akka-typed-eventsourcing/blob/master/src/main/scala/aggregate/user/UserAggregate.scala#L27 Old - https://github.com/simerplaha/akka-typed-eventsourcing/blob/cba3e794a662aa4f982587be12ea3e954982a3bd/src/main/scala/aggregate/user/UserAggregate.scala#L28 and then there should be another method that turns a state into a behavior https://github.com/simerplaha/akka-typed-eventsourcing/blob/master/src/main/scala/aggregate/user/UserAggregate.scala#L43 This way the last step of processing commands could simply be `persist(...)` without the trailing `.behavior` New - https://github.com/simerplaha/akka-typed-eventsourcing/blob/master/src/main/scala/aggregate/user/UserAggregate.scala#L86 Old - https://github.com/simerplaha/akka-typed-eventsourcing/blob/cba3e794a662aa4f982587be12ea3e954982a3bd/src/main/scala/aggregate/user/UserAggregate.scala#L79 and the replay would also be simplified New - https://github.com/simerplaha/akka-typed-eventsourcing/blob/master/src/main/scala/aggregate/base/Aggregate.scala#L83 Old - https://github.com/simerplaha/akka-typed-eventsourcing/blob/cba3e794a662aa4f982587be12ea3e954982a3bd/src/main/scala/aggregate/base/Aggregate.scala#L74 Ideally we’d have asynchronous persistence APIs to work with, in which case we’d also need to figure out stashing for Akka Typed Yep! I will try to make the persistence API async soon :-) ... I don't really know much about stashing in Akka yet, but I will read up on it. Thank you so much :-D Simer On Wednesday, November 25, 2015 at 9:30:50 PM UTC+11, rkuhn wrote: > > Thanks for exploring this connection, Simer! One thing that might be > refactored is that applyEvent should only manage the state (i.e. only be S > => S) and then there should be another method that turns a state into a > behavior. This way the last step of processing commands could simply be > `persist(...)` without the trailing `.behavior` and the replay would also > be simplified—plus it would not compute all those useless behaviors along > the way. > > Ideally we’d have asynchronous persistence APIs to work with, in which > case we’d also need to figure out stashing for Akka Typed (which is on my > list, but everyone can easily beat me to it ;-) ). > > Regards, > > Roland > > > 21 nov 2015 kl. 13:23 skrev Simer <[email protected] <javascript:>>: > > Thanks for looking at it Patrik. I just moved the EventDAO's blocking call > inside the actor like it says in the link you shared. > > "Do the blocking call within an actor ..." > > Please correct me if I'm understanding this incorrectly :) > > > https://github.com/simerplaha/akka-typed-eventsourcing/blob/master/src/main/scala/database/EventDAO.scala#L16 > > https://github.com/simerplaha/akka-typed-eventsourcing/blob/master/src/main/scala/aggregate/base/Aggregate.scala#L78 > > And I've added some code for CQRS's read side implementation using > EventBus. > > > https://github.com/simerplaha/akka-typed-eventsourcing/blob/master/src/main/scala/aggregate/base/Aggregate.scala#L47 > > https://github.com/simerplaha/akka-typed-eventsourcing/blob/master/src/main/scala/read/UserListener.scala > > Thanks heaps. > Simer > > On Thursday, November 19, 2015 at 3:30:41 AM UTC+11, Patrik Nordwall wrote: >> >> Thanks for sharing. Looks nice. I noticed that the EventDAO has blocking >> methods so make sure that the actors that are using those are running on a >> dedicated dispatcher. See Blocking Needs Careful Management >> <http://www.google.com/url?q=http%3A%2F%2Fdoc.akka.io%2Fdocs%2Fakka%2F2.4.0-RC1%2Fgeneral%2Factor-systems.html%23Blocking_Needs_Careful_Management&sa=D&sntz=1&usg=AFQjCNFxKVOEHQwQh_KFNoq4tpd762Ik1A> >> . >> >> Cheers, >> Patrik >> >> On Sun, Nov 15, 2015 at 3:36 AM, Simer <[email protected]> wrote: >> >>> Hey Guys, >>> >>> I've implemented a simple template to try out Eventsourcing with >>> Akka-typed. >>> >>> Here is the project: >>> https://github.com/simerplaha/akka-typed-eventsourcing >>> >>> Hoping someone would give me some feedback as I'm still trying to wrap >>> my head around Eventsourcing/CQRS style coding :) >>> >>> Thanks >>> Simer >>> >>> -- >>> >>>>>>>>>> Read the docs: http://akka.io/docs/ >>> >>>>>>>>>> Check the FAQ: >>> http://doc.akka.io/docs/akka/current/additional/faq.html >>> >>>>>>>>>> Search the archives: >>> https://groups.google.com/group/akka-user >>> --- >>> You received this message because you are subscribed to the Google >>> Groups "Akka User List" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To post to this group, send email to [email protected]. >>> Visit this group at http://groups.google.com/group/akka-user. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> >> -- >> >> Patrik Nordwall >> Typesafe <http://typesafe.com/> - Reactive apps on the JVM >> Twitter: @patriknw >> >> > -- > >>>>>>>>>> Read the docs: http://akka.io/docs/ > >>>>>>>>>> Check the FAQ: > http://doc.akka.io/docs/akka/current/additional/faq.html > >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user > --- > You received this message because you are subscribed to the Google Groups > "Akka User List" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] <javascript:>. > To post to this group, send email to [email protected] > <javascript:>. > Visit this group at http://groups.google.com/group/akka-user. > For more options, visit https://groups.google.com/d/optout. > > > > > *Dr. Roland Kuhn* > *Akka Tech Lead* > Typesafe <http://typesafe.com/> – Reactive apps on the JVM. > twitter: @rolandkuhn > <http://twitter.com/#!/rolandkuhn> > > -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
