Upgraded kafka and zookeeper to 7.4.8 (last working before 7.5.0) + successfully sending to kafka topic.
This commit is contained in:
parent
affff394be
commit
e492b6df60
5 changed files with 28 additions and 8 deletions
|
@ -1,5 +1,6 @@
|
|||
package ch.polgrabia.demos.client;
|
||||
|
||||
import ch.polgrabia.demos.utils.TopicUtil;
|
||||
import io.vertx.core.AbstractVerticle;
|
||||
import io.vertx.core.AsyncResult;
|
||||
import io.vertx.core.buffer.Buffer;
|
||||
|
@ -18,6 +19,7 @@ public class WebsocketClientParticle extends AbstractVerticle {
|
|||
private final int port;
|
||||
// path maps to channel
|
||||
private final String path;
|
||||
private final String channel;
|
||||
private HttpClient client;
|
||||
private boolean isShuttingDownActivated = false;
|
||||
private final Object runningMonitor = new Object();
|
||||
|
@ -28,6 +30,7 @@ public class WebsocketClientParticle extends AbstractVerticle {
|
|||
this.hostname = hostname;
|
||||
this.port = port;
|
||||
this.path = path;
|
||||
this.channel = TopicUtil.convertTopicName(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,8 +54,6 @@ public class WebsocketClientParticle extends AbstractVerticle {
|
|||
}
|
||||
|
||||
logger.info("Successfully started websocket client command server");
|
||||
|
||||
HttpServer result = httpServerAsyncResult.result();
|
||||
}
|
||||
|
||||
private void handleCommandRequests(HttpServerRequest httpServerRequest) {
|
||||
|
@ -88,7 +89,7 @@ public class WebsocketClientParticle extends AbstractVerticle {
|
|||
));
|
||||
|
||||
webSocket
|
||||
.binaryMessageHandler(msg -> logger.info("[{}] Got message: {}", path, msg))
|
||||
.binaryMessageHandler(msg -> logger.info("[{}] Got message: {}", channel, msg))
|
||||
.closeHandler(unused -> {
|
||||
try {
|
||||
stop();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package ch.polgrabia.demos.server;
|
||||
|
||||
import ch.polgrabia.demos.utils.TopicUtil;
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.buffer.Buffer;
|
||||
import io.vertx.core.http.ServerWebSocket;
|
||||
|
@ -27,7 +28,7 @@ public class WebsocketServerHandler implements Handler<ServerWebSocket> {
|
|||
public void handle(ServerWebSocket serverWebSocket) {
|
||||
serverWebSocket.writeBinaryMessage(Buffer.buffer("Hello"));
|
||||
serverWebSocket.handler(new WebsocketMessageHandler(kafkaProducer, serverWebSocket));
|
||||
String channel = serverWebSocket.path();
|
||||
String channel = TopicUtil.convertTopicName(serverWebSocket.path());
|
||||
Set<ServerWebSocket> sockets = channelSocketMapping.computeIfAbsent(channel, (k) -> {
|
||||
Set<ServerWebSocket> s = new HashSet<>();
|
||||
s.add(serverWebSocket);
|
||||
|
@ -47,7 +48,7 @@ public class WebsocketServerHandler implements Handler<ServerWebSocket> {
|
|||
" It should never happen", channel);
|
||||
}
|
||||
} else {
|
||||
logger.warn("Channel {} not found. It should never happen", channel);
|
||||
logger.warn("Channel {} not found. It should never happen",channel);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -68,7 +69,7 @@ public class WebsocketServerHandler implements Handler<ServerWebSocket> {
|
|||
|
||||
@Override
|
||||
public void handle(Buffer s) {
|
||||
String channel = serverWebSocket.path();
|
||||
String channel = TopicUtil.convertTopicName(serverWebSocket.path());
|
||||
logger.info("[{}] Got message {}", channel, s);
|
||||
serverWebSocket.writeBinaryMessage(Buffer.buffer("Pong: " + s.toString() + "\n")); // TBD send to kafka
|
||||
if (kafkaProducer != null) {
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package ch.polgrabia.demos.utils;
|
||||
|
||||
import org.apache.kafka.common.internals.Topic;
|
||||
|
||||
public class TopicUtil {
|
||||
private TopicUtil() {
|
||||
|
||||
}
|
||||
|
||||
public static String convertTopicName(final String path) {
|
||||
return path.replaceAll("[^a-zA-Z0-9]", "");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue