Last active
December 5, 2018 09:27
-
-
Save matzew/9ac49ebd2ae2ec83a14a8fae48411b92 to your computer and use it in GitHub Desktop.
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
package com.example.helloworld; | |
import io.cloudevents.http.reactivex.vertx.VertxCloudEvents; | |
import io.vertx.core.http.HttpHeaders; | |
import io.vertx.reactivex.core.AbstractVerticle; | |
public class HelloWorld extends AbstractVerticle { | |
public void start() { | |
vertx.createHttpServer() | |
.requestHandler(req -> VertxCloudEvents.create().rxReadFromRequest(req) | |
.subscribe((receivedEvent, throwable) -> { | |
if (receivedEvent != null) { | |
// I got a cloud Event: Echo that | |
req.response() | |
.putHeader(HttpHeaders.CONTENT_LENGTH, HttpHeaders.createOptimized(String.valueOf(receivedEvent.getData().get().toString().length()))) | |
.putHeader(HttpHeaders.CONTENT_TYPE, HttpHeaders.createOptimized("application/json")) | |
.setStatusCode(200) | |
.end(receivedEvent.toString()); | |
} | |
})) | |
.rxListen(8080) | |
.subscribe(server -> { | |
System.out.println("Server running!"); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment