From 761eedd7314185956196f463d7a768defdc3fa2a Mon Sep 17 00:00:00 2001 From: Tomasz Polgrabia Date: Fri, 27 Dec 2024 20:14:30 +0100 Subject: [PATCH] Small refactorings adding paths as mappings to channel. --- .../java/ch/polgrabia/demos/client/WebsocketClientApp.java | 2 +- .../ch/polgrabia/demos/client/WebsocketClientParticle.java | 5 ++--- .../ch/polgrabia/demos/server/WebsocketServerHandler.java | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/client/WebsocketClientApp.java b/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/client/WebsocketClientApp.java index 3faa91c..fa5d766 100644 --- a/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/client/WebsocketClientApp.java +++ b/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/client/WebsocketClientApp.java @@ -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 diff --git a/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/client/WebsocketClientParticle.java b/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/client/WebsocketClientParticle.java index 2ddc0a4..0909d7a 100644 --- a/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/client/WebsocketClientParticle.java +++ b/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/client/WebsocketClientParticle.java @@ -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; @@ -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(); diff --git a/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/server/WebsocketServerHandler.java b/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/server/WebsocketServerHandler.java index 75c952c..60c86a4 100644 --- a/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/server/WebsocketServerHandler.java +++ b/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/server/WebsocketServerHandler.java @@ -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 { @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 } }