Hello, 

I am new in Akka and I am trying to develop some mini project to test some 
things (akka, rx, cqrs, es etc..)

I think I understand the concept of cqrs/es and how it fit to akka. My 
problem is probably more theoretical than technical.

Let's say, I have class Player, which has several Attribute[T] attributes 
... these attributes can be for example player's current health, vitality, 
experience, level etc ... These attributes have dependencies ... for 
example currentHealth is defined as 10 * vitality ... if experience is > 
100 new level is earns, which causes to add 1 vitality, which causes to add 
10 health ... Hopefully, you get the point.

I like the idea to implement this using reactive streams. Each Attribute[T] 
should be considered as Observable[T] and with all these excellent 
operators I can model dependencies I have described before.

Now I am trying to model each Player as actor, which can handle commands 
(AddExperience(...), AddVitality(...) etc...) and produce events 
(ExperienceAdded(...), LevelEarned(...)) which should be event sourced.

Problem is, that when I am handling command I directly don't know what 
events should be generated ... for example AddExperience(100) is handled 
and after some validation ExperienceAdded(100) should be persisted to event 
store. When it success, it should be applied to my domain, which emit value 
change in that attribute observable and new level can be earned ... but how 
can I persist that event?

I try to write some pseudo-code

class ExamplePersistentActor extends PersistentActor {
  val Player player = ... // domain

  val subscription = player.observable.subscribe {
// here I get asynchronously information about that level is increased ... 
should I call persist here?
}

val receiveCommand: Receive = {
case AddExperience(xp: Int) => {
     persist(ExperienceAdded(xp)) { event =>
  player.addExperience(xp) // should produce LevelEarned(1) event, which 
should be also persisted
}   
  }
}

So I have reference to Player which has observable of all events that are 
produced ... but I don't how to persist them :/

-- 
>>>>>>>>>>      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.

Reply via email to