pub struct ProducerBuilder { /* private fields */ }Expand description
A builder for creating a new Producer instance.
ProducerBuilder provides a fluent API for configuring and instantiating a Producer.
It allows you to set various properties that define how the producer will behave and interact with the message broker.
Implementations§
Source§impl ProducerBuilder
impl ProducerBuilder
pub fn new(client: &DanubeClient) -> Self
Sourcepub fn with_topic(self, topic: impl Into<String>) -> Self
pub fn with_topic(self, topic: impl Into<String>) -> Self
Sets the topic name for the producer. This is a required field.
This method specifies the topic that the producer will send messages to. It must be set before creating the producer.
§Parameters
topic: The name of the topic for the producer. This should be a non-empty string that corresponds to an existing or new topic.
Sourcepub fn with_name(self, producer_name: impl Into<String>) -> Self
pub fn with_name(self, producer_name: impl Into<String>) -> Self
Sets the name of the producer. This is a required field.
This method specifies the name to be assigned to the producer instance. It must be set before creating the producer.
§Parameters
producer_name: The name assigned to the producer instance. This should be a non-empty string used for identifying the producer.
Sourcepub fn with_schema(self, schema_name: String, schema_type: SchemaType) -> Self
pub fn with_schema(self, schema_name: String, schema_type: SchemaType) -> Self
Sets the schema for the producer, defining the structure of the messages.
This method configures the schema used by the producer to serialize messages. The schema specifies how messages are structured and interpreted. It is especially important for ensuring that messages adhere to a specific format and can be properly deserialized by consumers.
§Parameters
-
schema_name: The name of the schema. This should be a non-empty string that identifies the schema. -
schema_type: The type of the schema, which determines the format of the data:SchemaType::Bytes: Indicates that the schema uses raw byte data.SchemaType::String: Indicates that the schema uses string data.SchemaType::Int64: Indicates that the schema uses 64-bit integer data.SchemaType::Json(String): Indicates that the schema uses JSON data. TheStringcontains the JSON schema definition.
Sourcepub fn with_reliable_dispatch(self) -> Self
pub fn with_reliable_dispatch(self) -> Self
Sets the reliable dispatch options for the producer. This method configures the dispatch strategy for the producer, which determines how messages are stored and managed. The dispatch strategy defines how long messages are retained and how they are managed in the message broker.
§Parameters
No parameters; broker uses defaults for reliable topics.
Sourcepub fn with_options(self, options: ProducerOptions) -> Self
pub fn with_options(self, options: ProducerOptions) -> Self
Sets the configuration options for the producer, allowing customization of producer behavior.
This method allows you to specify various configuration options that affect how the producer operates. These options can control aspects such as retries, timeouts, and other producer-specific settings.
§Parameters
options: AProducerOptionsinstance containing the configuration options for the producer. This should be configured according to the desired behavior and requirements of the producer.
Sourcepub fn with_partitions(self, partitions: usize) -> Self
pub fn with_partitions(self, partitions: usize) -> Self
Sets the number of partitions for the topic.
This method specifies how many partitions the topic should have. Partitions are used to distribute the load of messages across multiple Danube brokers, which can help with parallel processing and scalability.
§Parameters
partitions: The number of partitions for the topic. This should be a positive integer representing the desired number of partitions. More partitions can improve parallelism and throughput. Default is 0 = non-partitioned topic.
Sourcepub fn build(self) -> Producer
pub fn build(self) -> Producer
Creates a new Producer instance using the settings configured in the ProducerBuilder.
This method performs validation to ensure that all required fields are set before creating the Producer. Once validation is successful, it constructs and returns a new Producer instance configured with the specified settings.
§Returns
- A
Producerinstance if the builder configuration is valid and the producer is created successfully.
§Example
let producer = ProducerBuilder::new() .with_topic(“my-topic”) .with_name(“my-producer”) .with_partitions(3) .with_schema(“my-schema”.to_string(), SchemaType::Json(“schema-definition”.to_string())) .build()?;
Trait Implementations§
Source§impl Clone for ProducerBuilder
impl Clone for ProducerBuilder
Source§fn clone(&self) -> ProducerBuilder
fn clone(&self) -> ProducerBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !Freeze for ProducerBuilder
impl !RefUnwindSafe for ProducerBuilder
impl Send for ProducerBuilder
impl Sync for ProducerBuilder
impl Unpin for ProducerBuilder
impl !UnwindSafe for ProducerBuilder
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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