sdk-java/http/vertx
Fabio José 361a34cc63 🔖 Set versions to 1.3.0
Signed-off-by: Fabio José <fabiojose@gmail.com>
2020-03-04 20:48:47 -03:00
..
src Use of marshallers and unmarshallers for HTTP 2019-09-16 21:43:40 -03:00
README.md 🔖 Set versions to 1.3.0 2020-03-04 20:48:47 -03:00
pom.xml 🔖 Set versions to 1.3.0 2020-03-04 20:48:47 -03:00

README.md

HTTP Transport Util for Eclipse Vert.x

Receiving CloudEvents

For Maven based projects, use the following to configure the CloudEvents Vertx HTTP Transport:

<dependency>
    <groupId>io.cloudevents</groupId>
    <artifactId>http-vertx</artifactId>
    <version>1.3.0</version>
</dependency>

Below is a sample on how to use Vert.x API for RxJava 2 for reading CloudEvents from an HttpServerRequest:

import io.cloudevents.http.reactivex.vertx.VertxCloudEvents;
import io.vertx.core.http.HttpHeaders;
import io.vertx.reactivex.core.AbstractVerticle;

public class CloudEventVerticle extends AbstractVerticle {

  public void start() {

    vertx.createHttpServer()
      .requestHandler(req -> { 
        VertxCloudEvents.create().rxReadFromRequest(req)
          .subscribe((receivedEvent, throwable) -> {
            if (receivedEvent != null) {
              // I got a CloudEvent object:
              System.out.println("The event type: " + receivedEvent.getEventType());
            }
          });
          req.response().end();
        }
      )
      .rxListen(8080)
      .subscribe(server -> {
        System.out.println("Server running!");
    });
  }
}

Sending CloudEvents

Below is a sample on how to use the client to send a CloudEvent:

final HttpClientRequest request = vertx.createHttpClient().post(8080, "localhost", "/");

// add a client response handler
request.handler(resp -> {
    // react on the server response
});

// write the CloudEvent to the given HTTP Post request object
VertxCloudEvents.create().writeToHttpClientRequest(cloudEvent, request);
request.end();