pub struct Producer { /* private fields */ }Expand description
Represents a message producer responsible for sending messages to partitioned or non-partitioned topics distributed across message brokers.
The Producer struct is designed to handle the creation and management of a producer instance that sends messages to either partitioned or non-partitioned topics.
It manages the producer’s state and ensures that messages are sent according to the configured settings.
Implementations§
Source§impl Producer
impl Producer
Sourcepub async fn create(&mut self) -> Result<()>
pub async fn create(&mut self) -> Result<()>
Initializes the producer and registers it with the message brokers.
This asynchronous method sets up the producer by establishing connections with the message brokers and configuring it for sending messages to the specified topic. It is responsible for creating the necessary resources for producers handling partitioned topics.
Sourcepub async fn send(
&self,
data: Vec<u8>,
attributes: Option<HashMap<String, String>>,
) -> Result<u64>
pub async fn send( &self, data: Vec<u8>, attributes: Option<HashMap<String, String>>, ) -> Result<u64>
Sends a message to the topic associated with this producer.
It handles the serialization of the payload and any user-defined attributes. This method assumes that the producer has been successfully initialized and is ready to send messages.
§Parameters
data: The message payload to be sent. This should be aVec<u8>representing the content of the message.attributes: Optional user-defined properties or attributes associated with the message. This is aHashMap<String, String>where keys and values represent the attribute names and values, respectively.
§Returns
Ok(u64): The sequence ID of the sent message if the operation is successful. This ID can be used for tracking and acknowledging the message.Err(e): An error if message sending fails. Possible reasons for failure include network issues, serialization errors, or broker-related problems.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Producer
impl !RefUnwindSafe for Producer
impl Send for Producer
impl Sync for Producer
impl Unpin for Producer
impl !UnwindSafe for Producer
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request