forked from vert-x3/vertx-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
736 changed files
with
15,207 additions
and
1,815 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
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
2 changes: 1 addition & 1 deletion
2
amqp-bridge-examples/src/main/groovy/io/vertx/example/amqp/receiver.groovy
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
2 changes: 1 addition & 1 deletion
2
amqp-bridge-examples/src/main/groovy/io/vertx/example/amqp/sender.groovy
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
File renamed without changes.
File renamed without changes.
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
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
2 changes: 1 addition & 1 deletion
2
circuit-breaker-examples/src/main/groovy/io/vertx/example/circuit/breaker/client.groovy
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
40 changes: 40 additions & 0 deletions
40
circuit-breaker-examples/src/main/kotlin/io/vertx/example/circuit/breaker/Client.kt
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.vertx.example.circuit.breaker | ||
|
||
import io.vertx.circuitbreaker.CircuitBreaker | ||
import io.vertx.circuitbreaker.CircuitBreakerOptions | ||
import io.vertx.kotlin.circuitbreaker.* | ||
|
||
class Client : io.vertx.core.AbstractVerticle() { | ||
override fun start() { | ||
var options = CircuitBreakerOptions( | ||
maxFailures = 5, | ||
timeout = 5000, | ||
fallbackOnFailure = true) | ||
|
||
var breaker = CircuitBreaker.create("my-circuit-breaker", vertx, options).openHandler({ v -> | ||
println("Circuit opened") | ||
}).closeHandler({ v -> | ||
println("Circuit closed") | ||
}) | ||
|
||
var result = breaker.executeWithFallback({ future -> | ||
vertx.createHttpClient().getNow(8080, "localhost", "/", { response -> | ||
if (response.statusCode() != 200) { | ||
future.fail("HTTP error") | ||
} else { | ||
response.exceptionHandler({ future.fail(it) }).bodyHandler({ buffer -> | ||
future.complete(buffer.toString()) | ||
}) | ||
} | ||
}) | ||
}, { v -> | ||
// Executed when the circuit is opened | ||
return "Hello (fallback)" | ||
}) | ||
|
||
result.setHandler({ ar -> | ||
// Do something with the result | ||
println("Result: ${ar.result()}") | ||
}) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
circuit-breaker-examples/src/main/kotlin/io/vertx/example/circuit/breaker/Server.kt
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.vertx.example.circuit.breaker | ||
|
||
|
||
class Server : io.vertx.core.AbstractVerticle() { | ||
override fun start() { | ||
vertx.createHttpServer().requestHandler({ req -> | ||
req.response().end("Bonjour") | ||
}).listen(8080) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
= Vert.x Consul Client examples | ||
|
||
== Start Consul instance | ||
|
||
To run this example, you need a running Consul instance | ||
|
||
[source,bash] | ||
---- | ||
consul agent -data-dir=/tmp/kekeke -server -ui -bootstrap=1 | ||
---- | ||
|
||
== Languages | ||
|
||
The example is available in several languages: | ||
|
||
* Java: link:src/main/java/io/vertx/examples/consul/ConsulClientVerticle.java[ConsulClientVerticle.java] | ||
* Kotlin: link:src/main/kotlin/io/vertx/examples/consul/ConsulClientVerticle.kt[ConsulClientVerticle.kt] | ||
* JavaScript: link:src/main/js/io/vertx/examples/consul/consul_client_verticle.js[consul_client_verticle.js] | ||
* Groovy: link:src/main/groovy/io/vertx/examples/consul/consul_client_verticle.groovy[consul_client_verticle.groovy] | ||
* Ruby: link:src/main/ruby/io/vertx/examples/consul/consul_client_verticle.rb[consul_client_verticle.rb] | ||
|
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>io.vertx</groupId> | ||
<artifactId>consul-examples</artifactId> | ||
<version>3.4.0</version> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.vertx</groupId> | ||
<artifactId>vertx-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.vertx</groupId> | ||
<artifactId>vertx-consul-client</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.vertx</groupId> | ||
<artifactId>examples-utils</artifactId> | ||
<version>${project.version}</version> | ||
<optional>true</optional> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.1</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
<compilerArgs> | ||
<arg>-Acodetrans.output=${project.basedir}/src/main</arg> | ||
</compilerArgs> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
<id>staging</id> | ||
<repositories> | ||
<repository> | ||
<id>staging</id> | ||
<url>https://oss.sonatype.org/content/repositories/iovertx-3671/</url> | ||
</repository> | ||
</repositories> | ||
</profile> | ||
</profiles> | ||
|
||
</project> |
17 changes: 17 additions & 0 deletions
17
consul-examples/src/main/groovy/io/vertx/examples/consul/consul_client_verticle.groovy
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import io.vertx.ext.consul.ConsulClient | ||
def consulClient = ConsulClient.create(vertx) | ||
consulClient.putValue("key11", "value11", { putResult -> | ||
if (putResult.succeeded()) { | ||
println("KV pair saved") | ||
consulClient.getValue("key11", { getResult -> | ||
if (getResult.succeeded()) { | ||
println("KV pair retrieved") | ||
println(getResult.result().value) | ||
} else { | ||
getResult.cause().printStackTrace() | ||
} | ||
}) | ||
} else { | ||
putResult.cause().printStackTrace() | ||
} | ||
}) |
39 changes: 39 additions & 0 deletions
39
consul-examples/src/main/java/io/vertx/examples/consul/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.vertx.examples.consul; | ||
|
||
import io.vertx.core.AbstractVerticle; | ||
import io.vertx.core.Launcher; | ||
import io.vertx.ext.consul.ConsulClient; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Ruslan Sennov</a> | ||
*/ | ||
public class ConsulClientVerticle extends AbstractVerticle { | ||
|
||
/** | ||
* Convenience method so you can run it in your IDE | ||
*/ | ||
public static void main(String[] args) { | ||
Launcher.main(new String[]{"run", ConsulClientVerticle.class.getName()}); | ||
} | ||
|
||
|
||
@Override | ||
public void start() throws Exception { | ||
ConsulClient consulClient = ConsulClient.create(vertx); | ||
consulClient.putValue("key11", "value11", putResult -> { | ||
if (putResult.succeeded()) { | ||
System.out.println("KV pair saved"); | ||
consulClient.getValue("key11", getResult -> { | ||
if (getResult.succeeded()) { | ||
System.out.println("KV pair retrieved"); | ||
System.out.println(getResult.result().getValue()); | ||
} else { | ||
getResult.cause().printStackTrace(); | ||
} | ||
}); | ||
} else { | ||
putResult.cause().printStackTrace(); | ||
} | ||
}); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
consul-examples/src/main/js/io/vertx/examples/consul/consul_client_verticle.js
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var ConsulClient = require("vertx-consul-js/consul_client"); | ||
var consulClient = ConsulClient.create(vertx); | ||
consulClient.putValue("key11", "value11", function (putResult, putResult_err) { | ||
if (putResult_err == null) { | ||
console.log("KV pair saved"); | ||
consulClient.getValue("key11", function (getResult, getResult_err) { | ||
if (getResult_err == null) { | ||
console.log("KV pair retrieved"); | ||
console.log(getResult.value); | ||
} else { | ||
getResult_err.printStackTrace(); | ||
} | ||
}); | ||
} else { | ||
putResult_err.printStackTrace(); | ||
} | ||
}); |
Oops, something went wrong.