Skip to main content

confluent_kafka/
lib.rs

1// Copyright 2025 Confluent Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// Fail on warnings in development
16#![deny(warnings)]
17// The public-surface leak detector: a `pub` item inside a `pub(crate)` module
18// that still escapes through a public signature. `private_interfaces` misses
19// that shape, and `xtask`'s `check-public-audience` relies on this lint for it.
20#![warn(unnameable_types)]
21
22pub mod admin;
23// The `org.apache.kafka.clients` classes below are not
24// `@InterfaceAudience.Public`, so they are crate-private. They are translated
25// in full (DoD #2) though the client calls only part of them, hence the
26// `dead_code` allowances.
27#[cfg(test)]
28mod api_promises;
29#[expect(dead_code)]
30mod api_versions;
31mod bootstrap_configuration;
32mod client_dns_lookup;
33mod client_request;
34mod client_response;
35mod client_utils;
36#[cfg_attr(not(test), expect(dead_code))]
37mod cluster_connection_states;
38pub mod common;
39mod common_client_configs;
40mod connection_state;
41pub mod consumer;
42mod default_host_resolver;
43mod fetch_session_handler;
44mod host_resolver;
45#[cfg_attr(not(test), expect(dead_code))]
46mod in_flight_requests;
47#[cfg_attr(not(test), expect(dead_code))]
48mod kafka_client;
49mod least_loaded_node;
50#[expect(dead_code)]
51mod metadata;
52mod metadata_recovery_strategy;
53mod metadata_snapshot;
54mod metadata_updater;
55#[cfg(test)]
56mod mock_client;
57mod network_client;
58mod network_client_utils;
59#[cfg_attr(not(test), expect(dead_code))]
60mod node_api_versions;
61pub mod producer;
62#[cfg(test)]
63mod test_alloc_tracker;
64#[cfg(test)]
65mod test_fake_broker;
66#[cfg(test)]
67mod test_log_capture;
68#[cfg(test)]
69mod test_thread_safety;
70
71#[cfg(feature = "ffi")]
72pub mod ffi;
73
74/// Callback type for request completion.
75///
76/// Replaces Java's `RequestCompletionHandler` callback interface. Per CLAUDE.md
77/// rule 9, Java callbacks are replaced with closures executed after awaiting the
78/// corresponding call.
79///
80/// The callback receives a mutable reference to the [`client_response::ClientResponse`]
81/// so it can inspect the response (e.g., extract the response body).
82#[doc(alias = "org.apache.kafka.clients.RequestCompletionHandler")]
83pub(crate) type RequestCompletionHandler = Box<dyn FnOnce(&mut client_response::ClientResponse) + Send>;
84
85pub(crate) use api_versions::ApiVersions;
86pub(crate) use bootstrap_configuration::BootstrapConfiguration;
87pub(crate) use client_dns_lookup::ClientDnsLookup;
88pub(crate) use client_request::ClientRequest;
89pub(crate) use client_response::ClientResponse;
90pub(crate) use client_utils::ClientUtils;
91pub(crate) use cluster_connection_states::ClusterConnectionStates;
92pub(crate) use common_client_configs::CommonClientConfigs;
93pub(crate) use connection_state::ConnectionState;
94pub(crate) use default_host_resolver::DefaultHostResolver;
95pub(crate) use host_resolver::HostResolver;
96pub(crate) use in_flight_requests::{InFlightRequest, InFlightRequests};
97pub(crate) use kafka_client::KafkaClient;
98pub(crate) use least_loaded_node::LeastLoadedNode;
99pub(crate) use metadata::Metadata;
100pub(crate) use metadata_recovery_strategy::MetadataRecoveryStrategy;
101pub(crate) use metadata_snapshot::MetadataSnapshot;
102pub(crate) use metadata_updater::MetadataUpdater;
103pub(crate) use node_api_versions::NodeApiVersions;
104// Only the outer class is re-exported: `FetchRequestData` (Rust
105// `FetchSessionRequestData`) and `Builder` are Java nested classes
106// (`org.apache.kafka.clients.FetchSessionHandler.FetchRequestData` and
107// `org.apache.kafka.clients.FetchSessionHandler.Builder`), so per CLAUDE.md ยง2 they keep the
108// file-module path that plays the outer-class qualifier.
109#[expect(unused_imports)]
110pub(crate) use fetch_session_handler::FetchSessionHandler;
111#[cfg(test)]
112pub(crate) use mock_client::{MockClient, RequestMatcher};
113pub(crate) use network_client::{NetworkClient, NetworkClientStatics};
114pub(crate) use network_client_utils::NetworkClientUtils;
115#[cfg(test)]
116pub(crate) use test_alloc_tracker::AllocTrackingGuard;
117
118// Include generated message definitions. They translate Java's generated
119// `org.apache.kafka.common.message` classes, whose package is not Public API.
120#[expect(dead_code, unused_imports, clippy::all)]
121pub(crate) mod generated {
122    include!(concat!(env!("OUT_DIR"), "/generated/mod.rs"));
123}
124
125pub(crate) use generated::*;
126
127// Test-only message definitions from `generator/test-messages/`, for in-crate
128// tests that also need `pub(crate)` types (e.g. `common::message`'s
129// `RecordsSerdeTest`). `build.rs` always generates them.
130#[cfg(test)]
131#[expect(unused_imports, clippy::all)]
132pub(crate) mod test_generated {
133    include!(concat!(env!("OUT_DIR"), "/test_generated/mod.rs"));
134}
135
136// Docker-backed integration tests that need crate-internal types; see the
137// module docs. The public-API suites stay in `tests/integration`.
138#[cfg(all(test, feature = "integration-tests"))]
139mod integration_tests;
140// The shared `tests/common` harness, compiled into `integration_tests` by path,
141// names the crate `confluent_kafka::` as the external `tests/integration` binary
142// does; this alias resolves those paths inside the crate's own test binary.
143#[cfg(all(test, feature = "integration-tests"))]
144extern crate self as confluent_kafka;