pub trait DynProducer<K, V>:
Sealed<K, V>
+ Send
+ Sync {
// Required methods
fn init_transactions<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>
where K: 'a,
V: 'a;
fn begin_transaction(&self) -> Result<(), Error>;
fn send_offsets_to_transaction<'a>(
&'a self,
offsets: HashMap<TopicPartition, OffsetAndMetadata>,
group_metadata: &'a dyn ConsumerGroupMetadata,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>
where K: 'a,
V: 'a;
fn commit_transaction<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>
where K: 'a,
V: 'a;
fn abort_transaction<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>
where K: 'a,
V: 'a;
fn send<'a>(
&'a self,
record: ProducerRecord<K, V>,
) -> Pin<Box<dyn Future<Output = Result<KafkaFuture<RecordMetadata>, Error>> + Send + 'a>>
where K: 'a,
V: 'a;
fn send_with_callback<'a>(
&'a self,
record: ProducerRecord<K, V>,
callback: Option<Box<dyn Callback>>,
) -> Pin<Box<dyn Future<Output = Result<KafkaFuture<RecordMetadata>, Error>> + Send + 'a>>
where K: 'a,
V: 'a;
fn flush<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>
where K: 'a,
V: 'a;
fn partitions_for<'a>(
&'a self,
topic: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Vec<PartitionInfo>, Error>> + Send + 'a>>
where K: 'a,
V: 'a;
fn metrics(&self) -> MetricsView;
fn close<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>
where K: 'a,
V: 'a;
fn close_with_timeout<'a>(
&'a self,
timeout: Duration,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>
where K: 'a,
V: 'a;
}Expand description
A dyn-compatible Producer, for holding different producer
implementations behind one type, e.g. Vec<Box<dyn DynProducer<K, V>>>.
Every Producer implements DynProducer automatically, and the trait is
sealed, so it cannot be implemented directly: implement Producer
instead. Each method forwards to the Producer method of the same name;
asynchronous methods return the future boxed, which costs one allocation per
call. dyn DynProducer<K, V> implements Producer in turn, so a boxed
producer can be passed as &*boxed to generic code taking
P: Producer<K, V> + ?Sized.
With both traits in scope a method call on a dyn DynProducer is ambiguous,
since both define it; call it as DynProducer::send(&*producer, record), or
import only one of the two traits.
use confluent_kafka::producer::{DynProducer, MockProducer};
let producers: Vec<Box<dyn DynProducer<String, String>>> = vec![
Box::new(MockProducer::<String, String>::with_auto_complete(true)),
Box::new(MockProducer::<String, String>::with_auto_complete(false)),
];
assert_eq!(2, producers.len());Required Methods§
Sourcefn init_transactions<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>where
K: 'a,
V: 'a,
fn init_transactions<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>where
K: 'a,
V: 'a,
Sourcefn begin_transaction(&self) -> Result<(), Error>
fn begin_transaction(&self) -> Result<(), Error>
Sourcefn send_offsets_to_transaction<'a>(
&'a self,
offsets: HashMap<TopicPartition, OffsetAndMetadata>,
group_metadata: &'a dyn ConsumerGroupMetadata,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>where
K: 'a,
V: 'a,
fn send_offsets_to_transaction<'a>(
&'a self,
offsets: HashMap<TopicPartition, OffsetAndMetadata>,
group_metadata: &'a dyn ConsumerGroupMetadata,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>where
K: 'a,
V: 'a,
See Producer::send_offsets_to_transaction.
§Arguments
offsets- asProducer::send_offsets_to_transaction.group_metadata- asProducer::send_offsets_to_transaction.
§Errors
Sourcefn commit_transaction<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>where
K: 'a,
V: 'a,
fn commit_transaction<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>where
K: 'a,
V: 'a,
Sourcefn abort_transaction<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>where
K: 'a,
V: 'a,
fn abort_transaction<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>where
K: 'a,
V: 'a,
Sourcefn send<'a>(
&'a self,
record: ProducerRecord<K, V>,
) -> Pin<Box<dyn Future<Output = Result<KafkaFuture<RecordMetadata>, Error>> + Send + 'a>>where
K: 'a,
V: 'a,
fn send<'a>(
&'a self,
record: ProducerRecord<K, V>,
) -> Pin<Box<dyn Future<Output = Result<KafkaFuture<RecordMetadata>, Error>> + Send + 'a>>where
K: 'a,
V: 'a,
See Producer::send.
§Arguments
record- asProducer::send.
§Returns
As Producer::send.
§Errors
As Producer::send.
Sourcefn send_with_callback<'a>(
&'a self,
record: ProducerRecord<K, V>,
callback: Option<Box<dyn Callback>>,
) -> Pin<Box<dyn Future<Output = Result<KafkaFuture<RecordMetadata>, Error>> + Send + 'a>>where
K: 'a,
V: 'a,
fn send_with_callback<'a>(
&'a self,
record: ProducerRecord<K, V>,
callback: Option<Box<dyn Callback>>,
) -> Pin<Box<dyn Future<Output = Result<KafkaFuture<RecordMetadata>, Error>> + Send + 'a>>where
K: 'a,
V: 'a,
See Producer::send_with_callback.
§Arguments
record- asProducer::send_with_callback.callback- asProducer::send_with_callback.
§Returns
As Producer::send_with_callback.
§Errors
Sourcefn flush<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>where
K: 'a,
V: 'a,
fn flush<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>where
K: 'a,
V: 'a,
Sourcefn partitions_for<'a>(
&'a self,
topic: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Vec<PartitionInfo>, Error>> + Send + 'a>>where
K: 'a,
V: 'a,
fn partitions_for<'a>(
&'a self,
topic: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Vec<PartitionInfo>, Error>> + Send + 'a>>where
K: 'a,
V: 'a,
Sourcefn metrics(&self) -> MetricsView
fn metrics(&self) -> MetricsView
Sourcefn close<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>where
K: 'a,
V: 'a,
fn close<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>where
K: 'a,
V: 'a,
Sourcefn close_with_timeout<'a>(
&'a self,
timeout: Duration,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>where
K: 'a,
V: 'a,
fn close_with_timeout<'a>(
&'a self,
timeout: Duration,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>where
K: 'a,
V: 'a,
Trait Implementations§
Source§impl<K, V> Producer<K, V> for dyn DynProducer<K, V> + '_
impl<K, V> Producer<K, V> for dyn DynProducer<K, V> + '_
Source§fn init_transactions(&self) -> impl Future<Output = Result<(), Error>> + Send
fn init_transactions(&self) -> impl Future<Output = Result<(), Error>> + Send
transactional.id
is set in the configuration. Read moreSource§fn begin_transaction(&self) -> Result<(), Error>
fn begin_transaction(&self) -> Result<(), Error>
init_transactions exactly one time. Read moreSource§async fn send_offsets_to_transaction(
&self,
offsets: HashMap<TopicPartition, OffsetAndMetadata>,
group_metadata: &dyn ConsumerGroupMetadata,
) -> Result<(), Error>
async fn send_offsets_to_transaction( &self, offsets: HashMap<TopicPartition, OffsetAndMetadata>, group_metadata: &dyn ConsumerGroupMetadata, ) -> Result<(), Error>
Source§fn commit_transaction(&self) -> impl Future<Output = Result<(), Error>> + Send
fn commit_transaction(&self) -> impl Future<Output = Result<(), Error>> + Send
Source§fn abort_transaction(&self) -> impl Future<Output = Result<(), Error>> + Send
fn abort_transaction(&self) -> impl Future<Output = Result<(), Error>> + Send
Source§fn send(
&self,
record: ProducerRecord<K, V>,
) -> impl Future<Output = Result<KafkaFuture<RecordMetadata>, Error>> + Send
fn send( &self, record: ProducerRecord<K, V>, ) -> impl Future<Output = Result<KafkaFuture<RecordMetadata>, Error>> + Send
send_with_callback(record, None). See
send_with_callback for details. Read moreSource§fn send_with_callback(
&self,
record: ProducerRecord<K, V>,
callback: Option<Box<dyn Callback>>,
) -> impl Future<Output = Result<KafkaFuture<RecordMetadata>, Error>> + Send
fn send_with_callback( &self, record: ProducerRecord<K, V>, callback: Option<Box<dyn Callback>>, ) -> impl Future<Output = Result<KafkaFuture<RecordMetadata>, Error>> + Send
Source§fn flush(&self) -> impl Future<Output = Result<(), Error>> + Send
fn flush(&self) -> impl Future<Output = Result<(), Error>> + Send
linger.ms is greater than 0) and blocks on the completion
of the requests associated with these records. The post-condition of
flush() is that any previously sent record will have completed (e.g.
its future is done and callbacks passed to Self::send_with_callback
have been called). A request is considered completed when it is
successfully acknowledged according to the acks configuration you have
specified or else it results in an error. Read more