This project shows how you can setup a clustered Vert.x embedded in Spring Boot, having the Spring container managing Hazelcast.
It consists of two verticles.
The first one starts an HTTP server, expecting a name query parameter, and sending it on the event bus.
The second one listens to names sent on the event bus, and replies with a formatted message.
Eventually the message goes to the client in the HTTP response body.
In the io.vertx.examples.spring.clustering.hazelcast.VertxProducer class, a clustered Vert.x instance is created.
It uses a Spring-managed com.hazelcast.core.HazelcastInstance.
There are multiple ways to configure it, but a simple one is to put a hazelcast.xml file at the root of the classpath.
The Hazelcast instance will be created before and destroyed after Vert.x.
|
Important
|
the Hazelcast shutdown hook must be disabled. |
To disable it, simply add this to the hazelcast.xml file:
<properties>
<!-- ... other properties ... -->
<property name="hazelcast.shutdownhook.enabled">false</property>
</properties>To see clustering in action, you should start multiple instances of this application.
The HTTP server will be setup only if you provide an httpPort system property.
So you can start the first instance with an HTTP server on port 8081:
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-DhttpPort=8081"And then start the other instances without the HTTP server:
mvn spring-boot:runIt’s time for testing now:
seq 10 | while read i; do curl http://localhost:8081/?name=Thomas${i}; echo; done