use of io.vertx.ext.bridge.BridgeEventType in project vertx-tcp-eventbus-bridge by vert-x3.
the class TcpEventBusBridgeImpl method handler.
private void handler(NetSocket socket) {
final Map<String, MessageConsumer<?>> registry = new ConcurrentHashMap<>();
final Map<String, Message<?>> replies = new ConcurrentHashMap<>();
// create a protocol parser
final FrameParser parser = new FrameParser(res -> {
if (res.failed()) {
// could not parse the message properly
log.error(res.cause());
return;
}
final JsonObject msg = res.result();
// short reference
// default to message
final String type = msg.getString("type", "message");
final String address = msg.getString("address");
BridgeEventType eventType = parseType(type);
checkCallHook(() -> new BridgeEventImpl(eventType, msg, socket), () -> {
if (eventType != BridgeEventType.SOCKET_PING && address == null) {
sendErrFrame("missing_address", socket);
log.error("msg does not have address: " + msg);
return;
}
doSendOrPub(socket, address, msg, registry, replies);
}, () -> sendErrFrame("blocked by bridgeEvent handler", socket));
});
socket.handler(parser);
socket.exceptionHandler(t -> {
log.error(t.getMessage(), t);
registry.values().forEach(MessageConsumer::unregister);
registry.clear();
socket.close();
});
socket.endHandler(v -> {
registry.values().forEach(MessageConsumer::unregister);
registry.clear();
});
}
Aggregations