Quantcast
Channel: Akka Libraries - Discussion Forum for Akka technologies
Viewing all articles
Browse latest Browse all 1362

How to keep track the id of entity between write side and read side?

$
0
0

I’m working on a project with CQRS pattern. By reading the Akka Guide :: Akka Guide (lightbend.com), I’m confused with keeping track the id of entity.

  1. In the Domain Layer, at the write side, I use EventSourcedBehavior to generate events, and use the id of entity and event class name as the tag. By this way, one id is corresponding to one entity (or one behavior object).

The id of entity is generated by myself in the Application Layer.

def apply(id: String): Behavior[Command] = {
  val starter = Starter(id)
  EventSourcedBehavior
    .withEnforcedReplies[Command, Event, Project](
      persistenceId = PersistenceId(entityTypeHint = EntityKey.name, entityId = id),
      emptyState = starter,
      commandHandler = (state, cmd) => state.onCommand(cmd),
      eventHandler = (state, event) => state.onEvent(event)
      )
    .withTagger(event => Set(id, event.getClass.toString)    
}
  1. At the read side, I want to build the material of entity by the projection. But I don’t know how to assign the param numberOfInstances of ShardedDaemonProcess.init() to create projection, because there are lots of instances of entity in the system, not only 5 shopping-carts in the guide. And the system will produce more entities later. Should the ShardedDaemonProcess.init() be called one more time?

  2. I suppose that one projection is corresponding to one tag, then one id of entity. By this way, one projection will handle all events of one entity.

  3. At the other side, if I take event class name as element of the tag set in the EventSourcedBehavior, should the projection corresponding to the event class name handle only the kind of event of any entity?

  4. Because nobody keeps the track to all ids of entities, should I keep them with a table by myself? Then either the sharding.entityRefFor(id) or EventSourcedProvider.eventsByTag(tag) can get the id.

Thanks.

3 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 1362

Trending Articles