ProducerBuilder

Struct ProducerBuilder 

Source
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

Source

pub fn new(client: &DanubeClient) -> Self

Source

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.
Source

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.
Source

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. The String contains the JSON schema definition.
Source

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.

Source

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: A ProducerOptions instance containing the configuration options for the producer. This should be configured according to the desired behavior and requirements of the producer.
Source

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.
Source

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 Producer instance 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

Source§

fn clone(&self) -> ProducerBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProducerBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more