Vert.x中的群集和共享数据 [英] Clustering and Shared Data in Vert.x

查看:96
本文介绍了Vert.x中的群集和共享数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Vert.x(基于Netty和Hazelcast)进行开发,并且试图在两个服务器实例之间共享数据(这些实例分别位于同一台局域网中的不同机器中).

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 lan).

我的问题是我不知道如何配置vert.x服务器以允许它们共享并发内存映射(理论上说是可能的).

My problem is that I don't know how to configure the vert.x servers to allow them to share their concurrent memory maps (the theory says that's possible).

我已经阅读了Vert.x和Hazelcast的许多文档,但还没有得到结果. (我不知道如何强制vert.x加载hazelcast xml配置文件.)

I've read many documents off Vert.x and Hazelcast but I haven't had results yet. (I don't know how to force vert.x to load hazelcast xml configuration files).

提前谢谢!

推荐答案

有些选项可以在不同计算机上的vertx实例之间共享数据

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

选项1.

您可以使用Vert.x ClusterManager 及其地图:

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

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

该地图由Hazelcast IMap支持并已分发.假设您正在使用-cluster参数运行vertx,并且已经配置了集群.

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.

但是请注意,这是内部API ,通常不建议在生产中使用.如果您要进行一次实验,那么它可能会很有用.

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.

选项2.

在群集模式下启动vertx后,您就可以访问Hazelcast:

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

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

这篇关于Vert.x中的群集和共享数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆