Package io.kroxylicious.proxy.internal


@ReturnValuesAreNonnullByDefault @DefaultAnnotationForParameters(edu.umd.cs.findbugs.annotations.NonNull.class) @DefaultAnnotation(edu.umd.cs.findbugs.annotations.NonNull.class) package io.kroxylicious.proxy.internal
io.kroxylicious.proxy.internal contains Kroxylicious internal code implementing Proxying functionality using Netty.

Understanding the Kroxylicious Pipeline

The Kroxylicious pipeline for a client connection is composed of:
  • A KafkaProxyInitializer that initialises the downstream channel pipeline between client and kroxylicious
  • A KafkaProxyFrontendHandler that establishes the upstream channel pipeline to the broker and forwards requests from the downstream channel to the upstream channel
  • A KafkaProxyBackendHandler that writes responses read from the upstream channel back to the downstream channel

KafkaProxyInitializer

KafkaProxyInitializer is the ChannelInitializer for Kroxylicious. It is responsible for installing Handlers into the pipeline to implement behaviours including:
  • Decode SNI hostname
  • Resolve VirtualCluster for the channel
  • Decode Kafka Request messages
  • Encode Kafka Response messages
  • KafkaProxyFrontendHandler to handle Kroxylicious business logic
Note that for this downstream Channel, the inbound direction carries Requests (we read requests from the channel) and the outbound direction carries Responses from the backend server (response are written to the channel). So Handlers are invoked first-to-last for Requests, and last-to-first for Responses.

KafkaProxyFrontendHandler

KafkaProxyFrontendHandler handles the proxy lifecycle, it:
  • Initiates a Channel connection to the selected backend server
  • Creates a KafkaProxyBackendHandler
  • Writes messages read from the downstream channel to the upstream channel
  • Installs handlers into the backend channel pipeline, including the Users configured Custom Protocol Filters as well as Kafka Request Encoding and Response Decoding handlers
  • Configures a predicate for the channel, based on the installed Filters, to determine when to decode Kafka messages
Note that for the upstream Channel, the outbound direction carries Requests (we write requests to the channel) and the inbound direction carries Responses from the backend server (we read responses from the channel). So Filters are installed into the pipeline in the reverse order that they are declared in the Kroxylicious configuration YAML. Pipeline Handlers are invoked last-to-first for Requests, and first-to-last for Responses.

KafkaProxyBackendHandler

KafkaProxyBackendHandler signals to the Frontend Handler when the upstream channel is ready to be written to, and it writes Responses to the downstream channel after it has read them from the upstream channel.