Class RouterDispatchHandler

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
io.kroxylicious.proxy.internal.routing.RouterDispatchHandler
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, io.netty.channel.ChannelOutboundHandler

public class RouterDispatchHandler extends io.netty.channel.ChannelDuplexHandler
Sits at the end of the VC-level filter chain (instead of FilterChainCompletionHandler) when a virtual cluster uses a router.

Statically-routed requests are forwarded directly to the ClientConnectionStateMachine. Dynamically-routed requests are deserialised and dispatched to Router.onRequest(org.apache.kafka.common.protocol.ApiKeys, short, org.apache.kafka.common.message.RequestHeaderData, org.apache.kafka.common.protocol.ApiMessage, io.kroxylicious.proxy.router.RouterContext).

The write(io.netty.channel.ChannelHandlerContext, java.lang.Object, io.netty.channel.ChannelPromise) override applies node ID translation for statically-routed API keys whose responses carry broker node IDs.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

    io.netty.channel.ChannelHandler.Sharable
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Set<org.apache.kafka.common.protocol.ApiKeys>
    API keys whose responses carry node IDs that must be translated to virtual node IDs.
  • Constructor Summary

    Constructors
    Constructor
    Description
    RouterDispatchHandler(io.kroxylicious.proxy.router.Router router, Map<String,RouteDescriptor> routes, Map<org.apache.kafka.common.protocol.ApiKeys,String> staticRoutes, ClientConnectionStateMachine ccsm, String virtualClusterName, NodeIdMapping nodeIdMapping, Integer nodeId)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)
     
    void
    handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
     
    void
    handlerRemoved(io.netty.channel.ChannelHandlerContext ctx)
     
    resolveRouterNodeAddress(int virtualNodeId)
    Returns the upstream address for the given virtual node ID, as learned from the most recent internal METADATA response.
    void
    write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise)
     

    Methods inherited from class io.netty.channel.ChannelDuplexHandler

    bind, close, connect, deregister, disconnect, flush, read

    Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

    channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered

    Methods inherited from class io.netty.channel.ChannelHandlerAdapter

    ensureNotSharable, isSharable

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NODE_ID_TRANSLATION_APIS

      public static final Set<org.apache.kafka.common.protocol.ApiKeys> NODE_ID_TRANSLATION_APIS
      API keys whose responses carry node IDs that must be translated to virtual node IDs. These keys are always decoded (even when statically routed) so the response bodies are accessible for translation.
  • Constructor Details

  • Method Details

    • handlerAdded

      public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
      Specified by:
      handlerAdded in interface io.netty.channel.ChannelHandler
      Overrides:
      handlerAdded in class io.netty.channel.ChannelHandlerAdapter
    • handlerRemoved

      public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx)
      Specified by:
      handlerRemoved in interface io.netty.channel.ChannelHandler
      Overrides:
      handlerRemoved in class io.netty.channel.ChannelHandlerAdapter
    • resolveRouterNodeAddress

      public Optional<HostPort> resolveRouterNodeAddress(int virtualNodeId)
      Returns the upstream address for the given virtual node ID, as learned from the most recent internal METADATA response. Returns empty if the address has not been cached yet.
    • channelRead

      public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)
      Specified by:
      channelRead in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelRead in class io.netty.channel.ChannelInboundHandlerAdapter
    • write

      public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) throws Exception
      Specified by:
      write in interface io.netty.channel.ChannelOutboundHandler
      Overrides:
      write in class io.netty.channel.ChannelDuplexHandler
      Throws:
      Exception