I'd recommend looking into Akka Cluster Sharding. Even if you're not on a cluster, this is usually the most straightforward way to get messages routed consistently based on a key...
On Wed, Aug 30, 2017 at 5:37 AM, Wei Guo (SH-LTS) <[email protected]> wrote: > Hi everyone, > > I'm a newbie for Akka, for load balance consideration, I created 5 actors > to handle the incoming requests, but one important requirement is that > different types of objects with same key(Symbol of Quote/Trade/RefData in > my code below) should be routed to same actor, after searching Akka doc, > ConsistentHashingRoutingLogic > is a choice > > After running code with testing data, same type of objects were routed to > same actor, but for different types of objects(Quote,Trade, RefData with > same Symbol), it doesn't work as i expected, they were routed to different > actors > eg: > Quote quote1,quote2; > quote1.setSymbol("001"); // quote1 & quote2 were routed to same > actor(h0) -- no issue > quote2.setSymbol("001"); > > Trade trade; > trade.setSymbol("001"); // trade was sent to different actor (h1) > -- problem > > RefData refData; > refData.setSymbol("001"); // refData was sent to different actor (h2) > -- problem > > Can anyone provide any suggestion to route them into same actor ? Thanks a > lot. > > int nOfHisActor = 5; > > actorSystem = ActorSystem.create("lunar"); > String[] pathArray = new String[nOfHisActor]; > for (int i = 0; i < nOfHisActor; i++) { > String path = "h" + i; > pathArray[i] = "/user/" + path; > actorSystem.actorOf(Props.create(HisMarketDataActor.class), path); > } > List<String> paths = Arrays.asList(pathArray); > hisInfoActor = actorSystem.actorOf(new > ConsistentHashingGroup(paths).withHashMapper(o -> { > if (o instanceof Quote) { > return ((Quote) o).getSymbol(); > } else if (o instanceof Trade) { > return ((Trade) o).getSymbol(); > } else if (o instanceof RefData) { > return ((RefData) o).getSymbol(); > } > return null; > }).props(), "price"); > > -- > >>>>>>>>>> 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 https://groups.google.com/group/akka-user. > For more options, visit https://groups.google.com/d/optout. > -- >>>>>>>>>> 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 https://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
