Interface ProducerBuilder


public interface ProducerBuilder
API to create and configure a Producer.
  • Method Details

    • name

      ProducerBuilder name(String name)
      The producer name for deduplication (read the documentation before use).

      There must be only one producer instance at the same time using a given name.

      Parameters:
      name -
      Returns:
      this builder instance
      See Also:
    • stream

      ProducerBuilder stream(String stream)
      The stream to send messages to.
      Parameters:
      stream -
      Returns:
      this builder instance
    • superStream

      ProducerBuilder superStream(String superStream)
      The super stream to send messages to.

      This is an experimental API, subject to change.

      Parameters:
      superStream -
      Returns:
      this builder instance
      See Also:
    • subEntrySize

      ProducerBuilder subEntrySize(int subEntrySize)
      The number of messages to put in a sub-entry of a publish frame.

      The default is 1 (no sub-entry batching).

      Parameters:
      subEntrySize -
      Returns:
      this builder instance
    • compression

      ProducerBuilder compression(Compression compression)
      Compression algorithm to use to compress a batch of sub-entries.

      Compression can take advantage of similarity in messages to significantly reduce the size of the sub-entry batch. This translates to less bandwidth and storage used, at the cost of more CPU usage to compress and decompress on the client side. Note the server is not involved in the compression/decompression process.

      Default is no compression.

      Parameters:
      compression -
      Returns:
      this builder instance
      See Also:
    • batchSize

      ProducerBuilder batchSize(int batchSize)
      The maximum number of messages to accumulate before sending them to the broker.

      Default is 100.

      Parameters:
      batchSize -
      Returns:
      this builder instance
    • batchPublishingDelay

      ProducerBuilder batchPublishingDelay(Duration batchPublishingDelay)
      Period to send a batch of messages.

      Default is 100 ms.

      Parameters:
      batchPublishingDelay -
      Returns:
      this builder instance
    • dynamicBatch

      ProducerBuilder dynamicBatch(boolean dynamicBatch)
      Adapt batch size depending on ingress rate.

      A dynamic-batch approach improves latency for low ingress rates.

      Set this flag to true if you want as little delay as possible between calling Producer.send(Message, ConfirmationHandler) and the message being sent to the broker. Consumers should provide enough initial credits (between 5 and 10, depending on the workload), see ConsumerBuilder.flow() and ConsumerBuilder.FlowConfiguration.initialCredits(int).

      Set this flag to false if latency is not critical for your use case and you want the highest throughput possible for both publishing and consuming. Consumers can provide 1 initial credit (depending on the workload), see ConsumerBuilder.flow() and ConsumerBuilder.FlowConfiguration.initialCredits(int).

      Dynamic batch is activated by default (dynamicBatch = true).

      Parameters:
      dynamicBatch -
      Returns:
      this builder instance
      Since:
      0.20.0
      See Also:
    • maxUnconfirmedMessages

      ProducerBuilder maxUnconfirmedMessages(int maxUnconfirmedMessages)
      The maximum number of unconfirmed outbound messages.

      Producer.send(Message, ConfirmationHandler) will start blocking when the limit is reached.

      Default is 10,000.

      Parameters:
      maxUnconfirmedMessages -
      Returns:
      this builder instance
    • confirmTimeout

      ProducerBuilder confirmTimeout(Duration timeout)
      Time before the client calls the confirm callback to signal outstanding unconfirmed messages timed out.

      Default is 30 seconds.

      Parameters:
      timeout -
      Returns:
      this builder instance
    • enqueueTimeout

      ProducerBuilder enqueueTimeout(Duration timeout)
      Time before enqueueing of a message fail when the maximum number of unconfirmed is reached.

      Default is 10 seconds.

      Set the value to Duration.ZERO if there should be no timeout.

      Parameters:
      timeout -
      Returns:
      this builder instance
    • retryOnRecovery

      ProducerBuilder retryOnRecovery(boolean retryOnRecovery)
      Whether to republish unconfirmed messages after recovery.

      Default is true (unconfirmed messages are republished after recovery).

      Set to false to not republish unconfirmed messages and get a negative ConfirmationStatus for unconfirmed messages.

      Note setting this flag to false translates to at-most-once semantics, that is published messages may be lost, unless the publishing application retries publishing them.

      Parameters:
      retryOnRecovery - retry flag
      Returns:
      this builder instance
      Since:
      0.19.0
    • filterValue

      ProducerBuilder filterValue(Function<Message,String> filterValueExtractor)
      Logic to extract a filter value from a message.

      RabbitMQ 3.13 or more is required.

      Parameters:
      filterValueExtractor -
      Returns:
      this builder instance
    • build

      Producer build()
      Create the Producer instance.
      Returns:
      the configured producer
    • routing

      Configure the routing for super streams (partitioned streams).

      This is an experimental API, subject to change.

      The to-be-created producer will be a composite producer when this method is called. It will use the routing configuration to find out where a message should be routed. The application developer must provide the logic to extract a "routing key" from a message, which will decide the destination(s) of the message.

      The default routing strategy hashes the routing key to choose the stream (partition) to send the message to.

      Note the routing key extraction logic is required only when the built-in routing strategies are used. It can set to null when a custom RoutingStrategy is set with routing(Function).

      Parameters:
      routingKeyExtractor - the logic to extract a routing key from a message
      Returns:
      the routing configuration instance
      See Also: