Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clustering and Shared Data in Vert.x

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

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

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

Thanks in advance!

like image 965
castarco Avatar asked Sep 06 '12 11:09

castarco


People also ask

What is Vert X cluster?

Vertx is an asynchronuous framework for high load applications, it uses Netty, new I/O and Event bus. Vertx was designed to be used for microservices and a number of vertx instances may run in a cluster for high availability.

What is the use of Vert X?

x website (vertx.io) says, “Eclipse Vert. x is a toolkit for building reactive applications on the JVM.” It is event-driven, single-threaded, and non-blocking, which means you can handle many concurrent apps with a small number of threads. (If you know how the Node. js event loop works, Vert.


1 Answers

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<HazelcastInstance> instances = Hazelcast.getAllHazelcastInstances();
HazelcastInstance hz = instances.stream().findFirst().get();
Map map = hz.getMap("mapName"); // shared distributed map
like image 155
Andrejs Avatar answered Jan 16 '23 06:01

Andrejs