See: Description
| Class | Description |
|---|---|
| HazelcastClusterManager |
A cluster manager that uses Hazelcast
|
examples.Examples#example1()
----
== Configuring this cluster manager
Usually the cluster manager is configured by a file
https://github.com/vert-x3/vertx-hazelcast/blob/master/src/main/resources/default-cluster.xml[`default-cluster.xml`]
which is packaged inside the jar.
If you want to override this configuration you can provide a file called `cluster.xml` on your classpath and this
will be used instead. If you want to embed the `cluster.xml` file in a fat jar, it must be located at the root of the
fat jar. If it's an external file, the **directory** containing the file must be added to the classpath. For
example, if you are using the _launcher_ class from Vert.x, the classpath enhancement can be done as follows:
[source]
----
# If the cluster.xml is in the current directory:
java -jar ... -cp . -cluster
vertx run MyVerticle -cp . -cluster
# If the cluster.xml is in the conf directory
java -jar ... -cp conf -cluster
----
Another way to override the configuration is by providing the system property `vertx.hazelcast.config` with a
location:
[source]
----
# Use a cluster configuration located in an external file
java -Dvertx.hazelcast.config=./config/my-cluster-config.xml -jar ... -cluster
# Or use a custom configuration from the classpath
java -Dvertx.hazelcast.config=classpath:my/package/config/my-cluster-config.xml -jar ... -cluster
----
The `vertx.hazelcast.config` system property, when present, overrides any `cluster.xml` on the classpath, but if
loading
from this system property fails, then loading falls back to either `cluster.xml` or the Hazelcast default configuration.
CAUTION: Configuration of Hazelcast the `-Dhazelcast.config` system property is not supported by Vert.x and should
not be used.
The xml file is a Hazelcast configuration file and is described in detail in the documentation on the Hazelcast
web-site.
You can also specify configuration programmatically if embedding:
[source,$lang]
----
examples.Examples#example2()
----
Hazelcast supports several different transports including multicast and TCP. The default configuration uses
multicast so you must have multicast enabled on your network for this to work.
For full documentation on how to configure the transport differently or use a different transport please consult the
Hazelcast documentation.
== Using an existing Hazelcast cluster
You can pass an existing `HazelcastInstance` in the cluster manager to reuse an existing cluster:
[source,$lang]
----
examples.Examples#example3(com.hazelcast.core.HazelcastInstance)
----
In this case, vert.x is not the cluster owner and so do not shutdown the cluster on close.
Notice that the custom Hazelcast instance need to be configured with:
[source, xml]
----
VertxOptions.setClusterHost(java.lang.String).
=== Using a VPN
This is a variation of the above case. VPN software often works by creating a virtual network interface which often
doesn't support multicast. If you have a VPN running and you do not specify the correct interface to use in both the
hazelcast configuration and to Vert.x then the VPN interface may be chosen instead of the correct interface.
So, if you have a VPN running you may have to configure both the Hazelcast and Vert.x to use the correct interface as
described in the previous section.
=== When multicast is not available
In some cases you may not be able to use multicast as it might not be available in your environment. In that case
you should configure another transport, e.g. TCP to use TCP sockets, or AWS when running on Amazon EC2.
For more information on available Hazelcast transports and how to configure them please consult the Hazelcast
documentation.
=== Enabling logging
When trouble-shooting clustering issues with Hazelcast it's often useful to get some logging output from Hazelcast
to see if it's forming a cluster properly. You can do this (when using the default JUL logging) by adding a file
called `vertx-default-jul-logging.properties` on your classpath. This is a standard java.util.logging (JUL)
configuration file. Inside it set:
----
com.hazelcast.level=INFO
----
and also
----
java.util.logging.ConsoleHandler.level=INFO
java.util.logging.FileHandler.level=INFO
----
== Hazelcast logging
The logging backend used by Hazelcast is `jdk` by default (understand JUL). If you want to redirect the logging to
another library, you need to set the `hazelcast.logging.type` system property such as in:
----
-Dhazelcast.logging.type=slf4j
----
See the http://docs.hazelcast.org/docs/3.6.1/manual/html-single/index.html#logging-configuration[hazelcast documentation] for more details.
== Using a different Hazelcast version
You may want to use a different version of Hazelcast. The default version is `${hazelcast.version}`. To do so, you
need to:
* put the version you want in the application classpath
* if you are running a fat jar, configure your build manager to use the right version
In this later case, you would need in Maven:
[source,xml,subs="+attributes"]
----
Copyright © 2016. All rights reserved.