Clustering and Shared Data in Vert.x

前端 未结 5 414
无人共我
无人共我 2021-02-01 07:09

I\'m developing in Vert.x (based on Netty and Hazelcast), and I\'m trying to share data between two server instances (eache of those instances in different machines, on the same

5条回答
  •  失恋的感觉
    2021-02-01 08:05

    With Vert.x 3 - if you configure your Vert.x instances into "clustered mode" (which can be as simple as adding -cluster to the command line of the Vert.x launcher, see here for details), then you can use the SharedData interface to get access to "distributed maps" which allows cluster members to read and write data across the cluster transparently.

    Example:

    if (vertx.isClustered()) {
        log.info("Using clustered data store");
        vertx.sharedData().getClusterWideMap("entities", 
                res -> {
                    AsyncMap dataMap = res.result();
                    setDataStore(dataMap);
                });
    }
    

提交回复
热议问题