Using Kafka Bridge
Kafka Bridge is a Strimzi component that provides HTTP access to Kafka. Applications can use the Kafka Bridge REST API to send messages to Kafka topics and consume messages from Kafka topics without using native Kafka client libraries.
Use Kafka Bridge when a client application must interact with Kafka through HTTP. For long-running data integration with source and sink connectors, use Kafka Connect instead.
This document describes how to create a Kafka Bridge resource, expose the HTTP endpoint, and use common Kafka Bridge API operations.
The examples in this document use default as the namespace. In production environments, deploy Kafka Bridge in a dedicated namespace. Replace default with the namespace used in your environment.
TOC
PrerequisitesCreate a Kafka BridgeCreate a Kafka Bridge with TLS and SCRAMConfigure Consumer and Producer DefaultsConfigure LoggingConfigure MetricsConfigure Distributed TracingConfigure JVM OptionsConfigure Health ChecksVerify Kafka BridgeUse the Kafka Bridge APISend JSON RecordsSend Binary RecordsCreate a ConsumerSubscribe to TopicsRetrieve RecordsCommit OffsetsDelete a ConsumerCreate a TopicCommon Content TypesExpose Kafka Bridge by ServiceClusterIPNodePortOpenShift RouteIngressKey Configuration ParametersConfigure CORSBest PracticesTroubleshootingPrerequisites
Before creating Kafka Bridge, ensure that the following conditions are met:
- The Strimzi operator is installed and watching the namespace where Kafka Bridge will be created.
- A Kafka cluster is running and reachable from the Kafka Bridge pods.
- Kafka topics used by HTTP clients are created or can be created according to your Kafka cluster policy.
- Kafka users, ACLs, and TLS certificates are prepared if the target Kafka cluster enables authentication or TLS.
- The network exposure method for the Kafka Bridge HTTP API is defined, such as internal
ClusterIPaccess, externalNodePortaccess, or OpenShiftRoute.
Create a Kafka Bridge
The following example creates a Kafka Bridge named my-bridge and connects it to a Kafka cluster named my-cluster through the internal plain bootstrap service.
Kafka Bridge stores consumer instances in memory. If you run multiple Kafka Bridge replicas, all requests for the same consumer instance must be routed to the same bridge pod. Use session affinity or another stable routing strategy. If the bridge pod restarts, the consumer instance must be recreated. Default to replicas: 1 unless your routing layer guarantees consumer affinity.
Create a Kafka Bridge with TLS and SCRAM
If the Kafka cluster requires TLS and SCRAM-SHA-512 authentication, configure tls and authentication in the KafkaBridge resource.
Configure Consumer and Producer Defaults
Use spec.consumer and spec.producer to set default consumer and producer configurations for all requests handled by the Kafka Bridge.
These settings apply as defaults for all consumers and producers created through the Bridge API. Individual API requests can override some values where the API supports it.
Configure Logging
Kafka Bridge uses log4j2. Use spec.logging to configure log levels. Both inline and external configuration follow the log4j2 property syntax.
Inline logging:
Each custom logger requires a logger.<key>.name line that declares the target package or logger, plus a logger.<key>.level line that sets the level. The <key> is an arbitrary identifier used only inside the loggers map.
External logging using a ConfigMap:
Configure Metrics
Enable Prometheus metrics collection using spec.metricsConfig.
Create the metrics ConfigMap with JMX exporter rules before applying the KafkaBridge resource. After metrics are enabled, configure a Prometheus ServiceMonitor or PodMonitor to scrape the metrics endpoint.
Configure Distributed Tracing
Enable OpenTelemetry distributed tracing to track messages through Kafka Bridge.
Configure JVM Options
Tune JVM memory allocation for Kafka Bridge pods using spec.jvmOptions.
Set -Xms and -Xmx according to the spec.resources memory values. Leave enough memory for non-heap usage.
Configure Health Checks
Customize liveness and readiness probe settings if the default values do not match your environment.
Verify Kafka Bridge
Check the Kafka Bridge status:
Check bridge pods:
Forward the Kafka Bridge service for local testing:
Check the API endpoint:
Use the Kafka Bridge API
The examples below use http://localhost:8080 as the bridge endpoint.
Send JSON Records
Use application/vnd.kafka.json.v2+json for JSON records.
Send Binary Records
Use application/vnd.kafka.binary.v2+json for binary records. Keys and values must be Base64 encoded.
Create a Consumer
Create a consumer instance under a consumer group.
The response contains the consumer instance URL. Use that URL for subsequent subscription, polling, commit, and delete operations.
Subscribe to Topics
Subscribe the consumer instance to one or more topics.
Retrieve Records
Poll records from the subscribed topics.
If the response is empty, verify that the topic contains records and that the consumer offset is correct. The first poll can also return an empty array immediately after subscription while the consumer group assignment is still completing. Wait a few seconds and retry.
Commit Offsets
If enable.auto.commit is false, commit offsets after records are processed.
Delete a Consumer
Delete the consumer instance when it is no longer needed.
Always delete unused consumer instances. Consumer instances that are not deleted remain allocated until they expire.
Create a Topic
Use the admin API to create a topic through the Kafka Bridge.
Only topic_name is required. If partitions_count or replication_factor is omitted, the Kafka cluster defaults are used.
Common Content Types
Expose Kafka Bridge by Service
For internal testing, port forwarding is usually enough. For application access, you can expose Kafka Bridge through a Kubernetes Service, OpenShift Route, or Ingress.
ClusterIP
Use ClusterIP when client applications run inside the cluster.
NodePort
Use NodePort when external clients need direct access through node addresses.
OpenShift Route
On OpenShift, use a Route to expose Kafka Bridge externally with TLS termination.
Ingress
On Kubernetes clusters without OpenShift, use an Ingress resource.
After the Service, Route, or Ingress is created, configure clients to use the corresponding endpoint as the Kafka Bridge HTTP URL.
Do not expose Kafka Bridge without authentication, authorization, and network access control. Kafka Bridge provides HTTP access to Kafka operations and should only be reachable by trusted clients. Consider the following measures:
- Use
NetworkPolicyresources to restrict which pods or namespaces can reach the Kafka Bridge service. - On OpenShift, use OAuth Proxy as a sidecar or use the Route TLS termination with client certificate authentication.
- Place an API gateway or reverse proxy in front of the Kafka Bridge to enforce authentication and rate limiting.
- Use Kafka ACLs to limit which topics the bridge user can read from or write to.
Key Configuration Parameters
Configure CORS
If browser-based clients need to access Kafka Bridge, configure CORS according to your allowed origins and HTTP methods.
Best Practices
- Use Kafka Bridge for HTTP integration and lightweight clients, not as the default path for high-throughput Kafka applications.
- Use native Kafka clients for services that require maximum throughput, partition-level tuning, or advanced Kafka client features.
- Restrict network access to Kafka Bridge using
NetworkPolicyand apply platform-level authentication and rate limiting. - Use Kafka ACLs to limit which topics the bridge user can read from or write to.
- Enable Prometheus metrics and configure dashboards to monitor HTTP request latency, error rate, pod restarts, and Kafka authentication failures.
- Configure logging at an appropriate level. Use
WARNorINFOin production andDEBUGonly for troubleshooting. - Default to a single Kafka Bridge replica for mixed producer and consumer workloads unless your routing layer guarantees consumer affinity.
- If you scale Kafka Bridge for consumer traffic, ensure requests for each consumer instance stay pinned to the same bridge pod.
- Set
spec.consumerandspec.producerdefaults to enforce consistent behavior across all Bridge API requests. - On OpenShift, prefer
Routewith TLS termination overNodePortfor external access.