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
KafkaProxyInitializerthat initialises the downstream channel pipeline between client and kroxylicious - A
KafkaProxyFrontendHandlerthat establishes the upstream channel pipeline to the broker and forwards requests from the downstream channel to the upstream channel - A
KafkaProxyBackendHandlerthat 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
KafkaProxyFrontendHandlerto handle Kroxylicious business logic
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
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.-
ClassDescriptionThe state machine for a single client's proxy session.Enumeration of disconnect causes for tracking client to proxy disconnections.Allocates integer correlation IDs from a bounded circular range
[minInc, maxExc).AChannelInboundHandler(for handling requests from downstream) that applies a singleFilter.A channel handler that interceptsHAProxyMessageobjects emitted by Netty'sHAProxyMessageDecoderand stores the extracted context in theKafkaSession.UsesHAProxyMessageDecoder.detectProtocol(ByteBuf)on the first bytes of a connection to decide whether to install the PROXY protocol decoder.InternalRequestFrame<B extends org.apache.kafka.common.protocol.ApiMessage>InternalResponseFrame<B extends org.apache.kafka.common.protocol.ApiMessage>In the operation of the proxy there are various exceptions which are "anticipated" but not necessarily handled directly.Describes the possible states of a Kafka session as viewed from the proxy Generally we expect a Kafka Session to transition through one of the following sequences.Detects potential for port conflicts arising between virtual cluster configurations.While processing a request from a Client, we want to enable custom Protocol Filters to decide to send a response toward the Client instead of forwarding the message on towards the upstream broker.Short circuit respond with an error code if we encounter a SASL v0 handshake, logging a meaningful warning and closing the connection.Manages the lifecycle state of a single virtual cluster.Lifecycle states for a virtual cluster.New connections are rejected.Configuration was not viable.The cluster is being set up.The proxy has completed setup and is serving traffic for this cluster.Terminal state.Owns the virtual cluster configuration tree and lifecycle state.