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

Cluster Sharding with Persistent Entities

$
0
0

@alan.brewster73 wrote:

Hello,

I have a two node cluster using persistent actors with sharding. The nodes are exposed to the external world using AKKA HTTP routes. if I get a request for an entity to a node that is hosting its shard, I obviously get the data. However, if the request comes to the other node, I get an ask timeout. What is the best way to ensure I can access entity state regardless of the node that serves the HTTP request. The snippet below is how I initialize the entity reference.

    val sharding = ClusterSharding(context.system)

    sharding.init(Entity(typeKey = ShoppingCartActor.TypeKey) { entityContext =>
      ShoppingCartActor(entityContext.entityId, PersistenceId(entityContext.entityTypeKey.name, entityContext.entityId))
    })
    val shoppingCartActor = sharding.entityRefFor(ShoppingCartActor.TypeKey, "Cart")
    val routes = new ShopingCartRoute(shoppingCartActor)(context.system).routes

    startHttpServer(routes, context.system)

Kind regards

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 1362

Trending Articles