Skip to content

Commit bdd816e

Browse files
authored
Merge pull request #162 from influxdata/dom/pub-client-trait
feat: pub ProducerClient for instrumentation hook
2 parents e34f6f4 + 9bf370a commit bdd816e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/client/producer.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,14 @@ pub struct BatchProducerBuilder {
240240
}
241241

242242
impl BatchProducerBuilder {
243-
/// Build a new `BatchProducer`
243+
/// Build a new `BatchProducer`.
244244
pub fn new(client: Arc<PartitionClient>) -> Self {
245245
Self::new_with_client(client)
246246
}
247247

248-
/// Internal API for creating with any `dyn ProducerClient`
249-
fn new_with_client(client: Arc<dyn ProducerClient>) -> Self {
248+
/// Construct a [`BatchProducer`] with a dynamically dispatched
249+
/// [`ProducerClient`] implementation.
250+
pub fn new_with_client(client: Arc<dyn ProducerClient>) -> Self {
250251
Self {
251252
client,
252253
linger: Duration::from_millis(5),
@@ -283,8 +284,18 @@ impl BatchProducerBuilder {
283284
}
284285
}
285286

286-
// A trait wrapper to allow mocking
287-
trait ProducerClient: std::fmt::Debug + Send + Sync {
287+
/// The [`ProducerClient`] provides an abstraction over a Kafka client than can
288+
/// produce a record.
289+
///
290+
/// Implementing this trait allows user code to inspect the low-level Kafka
291+
/// [`Record`] instances being published to Kafka, as well as the result of the
292+
/// produce call.
293+
///
294+
/// Most users will want to use the [`BatchProducer`] implementation of this
295+
/// trait.
296+
pub trait ProducerClient: std::fmt::Debug + Send + Sync {
297+
/// Write the set of `records` to the Kafka broker, using the specified
298+
/// `compression` algorithm.
288299
fn produce(
289300
&self,
290301
records: Vec<Record>,

0 commit comments

Comments
 (0)