pub struct KafkaProducer {
inner: FutureProducer,
}
Expand description
Wrapper around an [rdkafka::producer::FutureProducer
].
The producer is configured once and can then be cheaply cloned thanks to
the internal Arc
in rdkafka’s handle.
Fields§
§inner: FutureProducer
Implementations§
Source§impl KafkaProducer
impl KafkaProducer
Sourcepub fn new(config: ClientConfig) -> Result<Self>
pub fn new(config: ClientConfig) -> Result<Self>
Explicit configuration.
§Arguments
config
- The configuration to use for the producer.username
- The username to use for authenticationpassword
- The password to use for authentication
§Returns
Result<Self, SDKError>
- The result of the operation
§Errors
SDKError::Producer
- If the producer fails to create.
Sourcepub fn default(
bootstrap_servers: &str,
credentials: &ClientCredentials,
) -> Result<Self>
pub fn default( bootstrap_servers: &str, credentials: &ClientCredentials, ) -> Result<Self>
Default configuration.
§Arguments
bootstrap_servers
- The bootstrap servers to use for the producer.username
- The username to use for authenticationpassword
- The password to use for authentication
§Returns
Result<Self, SDKError>
- The result of the operation
§Errors
SDKError::Producer
- If the producer fails to create.
Sourcepub async fn send_event(
&self,
topic: &Topic,
key: &str,
payload: &EventStream,
queue_timeout: Option<Duration>,
) -> Result<()>
pub async fn send_event( &self, topic: &Topic, key: &str, payload: &EventStream, queue_timeout: Option<Duration>, ) -> Result<()>
Sends a key‑ed JSON message to topic
.
payload
must be anEventStream
object that implementsserde::Serialize
.key
is used for partitioning; choose a deterministic key for exactly once‑per‑key semantics.queue_timeout
is optional; defaults to 5000ms if not provided.
The function is instrumented with [tracing
]; any error bubbles up as
Arguments
topic
- The topic to send the message tokey
- The key to send the message topayload
- The payload to send the message toqueue_timeout
- The timeout to send the message to
Returns
Result<()>
- The result of the operation
Errors
SDKError::Producer
- If the producer fails to send the message.
Sourcepub fn serialize_message(&self, msg: &EventStream) -> Result<Vec<u8>>
pub fn serialize_message(&self, msg: &EventStream) -> Result<Vec<u8>>
Serializes an EventStream<T>
into a Kafka message.
T
must implementserde::Serialize
.
§Arguments
msg
- The message to serialize
§Returns
Result<Vec<u8>, SDKError>
- The result of the operation
§Errors
SDKError::Producer
- If the producer fails to serialize the message.
Trait Implementations§
Source§impl Clone for KafkaProducer
impl Clone for KafkaProducer
Source§fn clone(&self) -> KafkaProducer
fn clone(&self) -> KafkaProducer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for KafkaProducer
impl !RefUnwindSafe for KafkaProducer
impl Send for KafkaProducer
impl Sync for KafkaProducer
impl Unpin for KafkaProducer
impl !UnwindSafe for KafkaProducer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more