Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Fede1024 Rust rdkafka FutureProducer Send Result

From Leeroopedia


Knowledge Sources
Domains Messaging, Async_Programming
Last Updated 2026-02-07 19:00 GMT

Overview

Concrete non-retrying message enqueue method provided by rust-rdkafka's FutureProducer.

Description

FutureProducer::send_result enqueues a message exactly once without retrying on queue-full. It returns a DeliveryFuture on success or the error and original FutureRecord on failure. The DeliveryFuture wraps a oneshot channel that completes when the broker acknowledges the message.

Unlike send(), this method is synchronous (not async) and returns immediately.

Usage

Use for non-retrying enqueue in testing or when implementing custom backpressure handling.

Code Reference

Source Location

  • Repository: rust-rdkafka
  • File: src/producer/future_producer.rs
  • Lines: L363-377

Signature

impl<C, R> FutureProducer<C, R>
where
    C: ClientContext + 'static,
    R: AsyncRuntime,
{
    pub fn send_result<'a, K, P>(
        &self,
        record: FutureRecord<'a, K, P>,
    ) -> Result<DeliveryFuture, (KafkaError, FutureRecord<'a, K, P>)>
    where
        K: ToBytes + ?Sized,
        P: ToBytes + ?Sized;
}

Import

use rdkafka::producer::{FutureProducer, FutureRecord, DeliveryFuture};

I/O Contract

Inputs

Name Type Required Description
record FutureRecord<'a, K, P> Yes Message record to enqueue

Outputs

Name Type Description
Ok(DeliveryFuture) DeliveryFuture Future resolving to OwnedDeliveryResult when broker acknowledges
Err((KafkaError, FutureRecord)) (KafkaError, FutureRecord) Error (e.g., QueueFull) and original record for retry

Usage Examples

Non-Retrying Send

use rdkafka::producer::{FutureProducer, FutureRecord};

let record = FutureRecord::to("test-topic")
    .payload("test data")
    .key("test-key");

match producer.send_result(record) {
    Ok(delivery_future) => {
        let result = delivery_future.await.expect("producer dropped");
        println!("Delivered: {:?}", result);
    }
    Err((err, _record)) => {
        eprintln!("Enqueue failed: {}", err);
    }
}

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment