Compare commits

..

2 Commits

3 changed files with 6 additions and 8 deletions

View File

@ -9,7 +9,7 @@ public class WebsocketClientApp {
public static void main(String[] args) {
var vertx = Vertx.vertx();
logger.info("Deploying websocket particle");
WebsocketClientParticle websocketClientParticle = new WebsocketClientParticle("localhost", 8080, "/");
WebsocketClientParticle websocketClientParticle = new WebsocketClientParticle("localhost", 8080, "/test");
vertx.deployVerticle(websocketClientParticle);
logger.info("Deployed websocket particle");
websocketClientParticle

View File

@ -11,18 +11,17 @@ import io.vertx.core.impl.VertxInternal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayOutputStream;
import java.util.concurrent.CompletableFuture;
public class WebsocketClientParticle extends AbstractVerticle {
private static final Logger logger = LoggerFactory.getLogger(WebsocketClientParticle.class);
private final String hostname;
private final int port;
// path maps to channel
private final String path;
private HttpClient client;
private boolean isShuttingDownActivated = false;
private final Object runningMonitor = new Object();
private ByteArrayOutputStream clientTextInput;
public WebsocketClientParticle(String hostname, int port, String path) {
this.hostname = hostname;
@ -31,7 +30,7 @@ public class WebsocketClientParticle extends AbstractVerticle {
}
@Override
public void start() throws Exception {
public void start() {
this.client = getVertx()
.createHttpClient();
new WebSocketClientImpl((VertxInternal) getVertx(), new HttpClientOptions(), new CloseFuture())
@ -56,7 +55,7 @@ public class WebsocketClientParticle extends AbstractVerticle {
));
webSocket
.binaryMessageHandler(msg -> logger.info("Got message: {}", msg))
.binaryMessageHandler(msg -> logger.info("[{}] Got message: {}", path, msg))
.closeHandler(unused -> {
try {
stop();
@ -68,7 +67,7 @@ public class WebsocketClientParticle extends AbstractVerticle {
}
@Override
public void stop() throws Exception {
public void stop() {
isShuttingDownActivated = true;
client.close();
synchronized (runningMonitor) {

View File

@ -1,6 +1,5 @@
package ch.polgrabia.demos.server;
import ch.polgrabia.demos.client.WebsocketClientApp;
import io.vertx.core.Handler;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.ServerWebSocket;
@ -27,7 +26,7 @@ public class WebsocketServerHandler implements Handler<ServerWebSocket> {
@Override
public void handle(Buffer s) {
logger.info("Got message {}", s);
logger.info("[{}] Got message {}", serverWebSocket.path(), s);
serverWebSocket.writeBinaryMessage(Buffer.buffer("Pong: " + s.toString() + "\n")); // TBD send to kafka
}
}