Communication between Entities (routing)

(Andrey Ladniy) #1

I have product properties (PropertyEntity) and some matchers (MatcherEntity) for they. MatcherEntity must listen for PropertyEntity and react on changes.
Simple way is handling MatcherIds in PropertyEntity, match on the modification and write modification event + matching event with PropertyEntity command handler. After I can get PropertyEntity stream and filter needed events. But Matcher may have short life, all the Matchers will be a lot, but active a little (inactive ones will never be used again). So I will need a some clean up, which will not be able with one stream.
I have the idea: not write matching event but route to other PersistenceActor with persistenceId = MatcherId and store event. So I will can delete all messages by persistenceId for inactive Matchers.
Question: how can I call async in entity command handler
Future.sequence(matchers.forEach(matcher => refForMatcher ? UpdateMatching)) and then on success ctx.thenPersist(event) { _ => ctx.reply(Done) }