com.englishtown.vertx:vertx-when

Provides when.java wrappers for standard vert.x objects to return promises.

License

License

GroupId

GroupId

com.englishtown.vertx
ArtifactId

ArtifactId

vertx-when
Last Version

Last Version

4.3.1
Release Date

Release Date

Type

Type

jar
Description

Description

Provides when.java wrappers for standard vert.x objects to return promises.
Project URL

Project URL

https://github.com/englishtown/vertx-when
Project Organization

Project Organization

Englishtown

Download vertx-when

How to add to project

<!-- https://jarcasting.com/artifacts/com.englishtown.vertx/vertx-when/ -->
<dependency>
    <groupId>com.englishtown.vertx</groupId>
    <artifactId>vertx-when</artifactId>
    <version>4.3.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.englishtown.vertx/vertx-when/
implementation 'com.englishtown.vertx:vertx-when:4.3.1'
// https://jarcasting.com/artifacts/com.englishtown.vertx/vertx-when/
implementation ("com.englishtown.vertx:vertx-when:4.3.1")
'com.englishtown.vertx:vertx-when:jar:4.3.1'
<dependency org="com.englishtown.vertx" name="vertx-when" rev="4.3.1">
  <artifact name="vertx-when" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.englishtown.vertx', module='vertx-when', version='4.3.1')
)
libraryDependencies += "com.englishtown.vertx" % "vertx-when" % "4.3.1"
[com.englishtown.vertx/vertx-when "4.3.1"]

Dependencies

compile (5)

Group / Artifact Type Version
com.englishtown : when.java jar 3.1.0
com.englishtown.vertx : vertx-hk2 Optional jar 2.4.0
com.englishtown.vertx : vertx-guice Optional jar 2.3.0
com.englishtown : when.java test-jar 3.1.0
io.vertx : vertx-core jar 3.3.0

test (3)

Group / Artifact Type Version
org.mockito : mockito-core jar 1.10.19
junit : junit jar 4.12
io.vertx : vertx-core test-jar 3.3.0

Project Modules

There are no modules declared in this project.

vertx-when

Provides when.java wrappers for standard vert.x 3 objects to return promises.

Build Status Maven Central

Getting Started

Add a dependency to vertx-when

<dependency>
    <groupId>com.englishtown.vertx</groupId>
    <artifactId>vertx-when</artifactId>
    <version>4.0.0</version>
</dependency>

Dependency Injection

Use dependency injection to get an instance of:

  • com.englishtown.promises.When
  • com.englishtown.vertx.promises.WhenEventBus
  • com.englishtown.vertx.promises.WhenHttpClient
  • com.englishtown.vertx.promises.WhenVertx

HK2 and Guice binders are provided

  • com.englishtown.vertx.promises.hk2.HK2WhenBinder
  • com.englishtown.vertx.promises.guice.GuiceWhenBinder

Manual Dependency Creation

If not using DI, you can manually construct the default implementations like this:

        // Create the vert.x executor for callbacks to run on the vert.x event loop
        VertxExecutor executor = new VertxExecutor(vertx);
        when = WhenFactory.createFor(() -> executor);

        whenVertx = new DefaultWhenVertx(vertx, when);
        whenEventBus = new DefaultWhenEventBus(vertx, when);
        whenHttpClient = new DefaultWhenHttpClient(vertx, when);

(See the com.englishtown.vertx.promises.integration.simple.NoDIIntegrationTest integration test for an example.)

Vert.x 2.x

If running vert.x 2.x, then you should use module vertx-mod-when 3.0.1. See earlier README.md files for details.

<dependency>
    <groupId>com.englishtown</groupId>
    <artifactId>vertx-mod-when</artifactId>
    <version>3.0.1</version>
</dependency>

WhenVertx Examples

Deploy 1 Verticle

whenVertx.deployVerticle("com.englishtown.vertx.TestVerticle")
    .then(deploymentID -> {
        // On success
        return null;
    })
    .otherwise(t -> {
        // On fail
        return null;
    });

Deploy 2 Verticles

List<Promise<String>> promises = new ArrayList<>();

promises.add(vertxWhen.deployVerticle("com.englishtown.vertx.TestVerticle1"));
promises.add(vertxWhen.deployVerticle("com.englishtown.vertx.TestVerticle2"));

when.all(promises)
    .then(deploymentIDs -> {
        // Handle success
        return null;
    })
    .otherwise(t -> {
        // Handle failure
        return null;
    });

WhenEventBus Examples

Send 2 messages

List<Promise<Message<JsonObject>>> promises = new ArrayList<>();

promises.add(whenEventBus.<JsonObject>send("et.vertx.eb.1", new JsonObject().putString("message", "hello")));
promises.add(whenEventBus.<JsonObject>send("et.vertx.eb.2", new JsonObject().putString("message", "world")));

when.all(promises).then(
        replies -> {
            // On success
            return null;
        },
        t -> {
            // On fail
            return null;
        });

WhenHttpClient Examples

Send 2 http requests

List<Promise<HttpClientResponse>> promises = new ArrayList<>();

promises.add(whenHttpClient.requestAbs(HttpMethod.GET, "http://test.englishtown.com/test1", new RequestOptions()));
promises.add(whenHttpClient.requestAbs(HttpMethod.POST, "http://test.englishtown.com/test2", new RequestOptions()));

when.all(promises).then(
        responses -> {
            // On success
            return null;
        },
        t -> {
            // On fail
            return null;
        }
);

Get a response and body

RequestOptions options = new RequestOptions().setPauseResponse(true);
whenHttpClient.requestAbs(HttpMethod.GET, "http://localhost:8081/test", options)
    .then(response -> {
        return whenHttpClient.body(response);
    })
    .then(body -> {
        // Do something with the body
        return null;
    })
    .otherwise(t ->
        // On fail
        return null;
    });
com.englishtown.vertx

Labs @ EF Education First

Repositories moving to https://github.com/ef-labs

Versions

Version
4.3.1
4.3.0
4.2.0
4.1.1
4.1.0
4.0.0
4.0.0-RC5
4.0.0-RC4
4.0.0-RC3
4.0.0-RC2
4.0.0-RC1