Small refactorings adding paths as mappings to channel.

master
Tomasz Polgrabia 2024-12-27 20:14:30 +01:00
parent baf413a063
commit 761eedd731
3 changed files with 4 additions and 6 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;
@ -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();

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
}
}