The service discovery has a plug-able backend using the
This is an implementation of the SPI based on Apache Zookeeper.
To use the Zookeeper backend, add the following dependency to the dependencies section of your build descriptor:
Maven (in your
<dependency> <groupId>io.vertx</groupId> <artifactId>vertx-service-discovery-backend-zookeeper-scala_2.12</artifactId> <version>3.4.2</version> </dependency>
Gradle (in your
Be aware that you can have only a single implementation of the SPI in your classpath. If none, the default backend is used.
There is a single mandatory configuration attribute:
connection. Connection is the Zookeeper connection string.
Here is an example:
ServiceDiscovery.create(vertx, ServiceDiscoveryOptions() .setBackendConfiguration(new io.vertx.core.json.JsonObject().put("connection", "127.0.0.1:2181")) )
Additionally you can configure:
maxRetries: the number of connection attempt, 3 by default
baseSleepTimeBetweenRetries: the amount of milliseconds to wait between retries (exponential backoff strategy).
1000 ms by default.
connectionTimeoutMs: the connection timeout in milliseconds. Defaults to 1000.
canBeReadOnly : whether or not the backend support the read-only mode (defaults to false)
basePath: the Zookeeper path in which the service records are stored. Default to
ephemeral: whether or not the created nodes are ephemeral nodes (see
false by default
guaranteed: whether or not to guarantee the node deletion even in case of failure.
false by default
ServiceDiscovery.create(vertx, ServiceDiscoveryOptions() .setBackendConfiguration(new io.vertx.core.json.JsonObject().put("connection", "127.0.0.1:2181").put("ephemeral", true).put("guaranteed", true).put("basePath", "/services/my-backend")) )
The records are stored in individual nodes structured as follows:
basepath (/services/) | |- record 1 registration id => the record 1 is the data of this node |- record 2 registration id => the record 2 is the data of this node