Clustering and Shared Data in Vert.x

前端 未结 5 416
无人共我
无人共我 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 07:43

    There are options for sharing data among vertx instances on different machines

    Option 1.

    You could use the Vert.x ClusterManager and it's maps:

    ClusterManager clusterManager = ((VertxInternal)vertx).clusterManager();
    Map map = clusterManager.getSyncMap("mapName"); // shared distributed map
    

    That map is backed by a Hazelcast IMap and is distributed. This assumes you're running vertx with the -cluster parameter and have configured clustering.

    However note that this is internal API and is not generally recommended for production. If you are doing a one time experiment then it could be useful.

    Option 2.

    You can get access to Hazelcast once vertx is started in clustered mode:

    Set instances = Hazelcast.getAllHazelcastInstances();
    HazelcastInstance hz = instances.stream().findFirst().get();
    Map map = hz.getMap("mapName"); // shared distributed map
    

提交回复
热议问题