com.englishtown:vertx-mod-when

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

License

License

GroupId

GroupId

com.englishtown
ArtifactId

ArtifactId

vertx-mod-when
Last Version

Last Version

3.0.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-mod-when
Project Organization

Project Organization

Englishtown
Source Code Management

Source Code Management

https://github.com/englishtown/vertx-mod-when

Download vertx-mod-when

How to add to project

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

Dependencies

compile (1)

Group / Artifact Type Version
com.englishtown : when.java jar 3.0.0

provided (4)

Group / Artifact Type Version
com.englishtown : vertx-mod-hk2 jar 1.7.0
com.englishtown : vertx-mod-guice jar 1.3.0-final
io.vertx : vertx-core jar 2.1.2
io.vertx : vertx-platform jar 2.1.2

test (4)

Group / Artifact Type Version
org.mockito : mockito-all jar 1.9.5
com.englishtown : when.java-testtools jar 3.0.0
junit : junit jar 4.11
io.vertx : testtools jar 2.0.3-final

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

Labs @ EF Education First

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

Versions

Version
3.0.1
3.0.0
3.0.0-RC1
2.0.1
2.0.0
1.2.0-final
1.1.2-final
1.1.1-final
1.1.0-final
1.0.0-final