-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use test containers for Consul examples
- Loading branch information
Showing
3 changed files
with
19 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,6 @@ | ||
= Vert.x Consul Client examples | ||
== Vert.x Consul Client examples | ||
|
||
== Start Consul instance | ||
This example consists of saving and retrieving a key/value pair in Consul. | ||
|
||
To run this example, you need a running Consul instance | ||
|
||
[source,bash] | ||
---- | ||
consul agent -data-dir=/tmp/kekeke -server -ui -bootstrap=1 | ||
---- | ||
|
||
== Languages | ||
|
||
* link:src/main/java/io/vertx/examples/consul/ConsulClientVerticle.java[ConsulClientVerticle.java] | ||
link:src/main/java/io/vertx/examples/consul/ConsulClientVerticle.java[ConsulClientVerticle.java] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,25 +3,35 @@ | |
import io.vertx.core.Future; | ||
import io.vertx.core.VerticleBase; | ||
import io.vertx.ext.consul.ConsulClient; | ||
import io.vertx.ext.consul.ConsulClientOptions; | ||
import io.vertx.launcher.application.VertxApplication; | ||
|
||
import org.testcontainers.consul.ConsulContainer; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Ruslan Sennov</a> | ||
*/ | ||
public class ConsulClientVerticle extends VerticleBase { | ||
|
||
private static final ConsulContainer CONSUL_CONTAINER = new ConsulContainer("hashicorp/consul:1.15"); | ||
|
||
/** | ||
* Convenience method so you can run it in your IDE | ||
*/ | ||
public static void main(String[] args) { | ||
CONSUL_CONTAINER.start(); | ||
VertxApplication.main(new String[]{ConsulClientVerticle.class.getName()}); | ||
} | ||
|
||
private ConsulClient consulClient; | ||
|
||
@Override | ||
public Future<?> start() { | ||
consulClient = ConsulClient.create(vertx); | ||
ConsulClientOptions options = new ConsulClientOptions(); | ||
options.setHost(CONSUL_CONTAINER.getHost()); | ||
options.setPort(CONSUL_CONTAINER.getFirstMappedPort()); | ||
consulClient = ConsulClient.create(vertx, options); | ||
|
||
return consulClient.putValue("key11", "value11") | ||
.compose(v -> { | ||
System.out.println("KV pair saved"); | ||
|