Interface ConsumerBuilder


public interface ConsumerBuilder
API to configure and create a Consumer.
  • Method Details

    • queue

      ConsumerBuilder queue(String queue)
      The queue to consume from.
      Parameters:
      queue - queue
      Returns:
      this builder instance
    • messageHandler

      ConsumerBuilder messageHandler(Consumer.MessageHandler handler)
      The callback for inbound messages.
      Parameters:
      handler - callback
      Returns:
      this builder instance
    • initialCredits

      ConsumerBuilder initialCredits(int initialCredits)
      The initial number credits to grant to the AMQP receiver.

      The default is 100.

      Parameters:
      initialCredits - number of initial credits
      Returns:
      this builder instance
    • preSettled

      ConsumerBuilder preSettled()
      Configures the link to use At-Most-Once delivery by receiving messages in a "pre-settled" state.

      By default, the library uses At-Least-Once delivery, meaning you must explicitly acknowledge (settle) each message. Calling this method changes that behavior.

      How it works:

      When enabled, RabbitMQ considers the message successfully delivered the moment it is sent. The message arrives at your application already "settled." Consequently, the library will not send any acknowledgment (disposition frame) back to RabbitMQ, and you do not need to call any settle methods on the received message.

      Performance vs. Reliability:

      • Performance: This is the fastest consumption mode. It eliminates the network round-trip overhead of sending acknowledgments.
      • Reliability: If your application crashes or the connection fails while you are processing the message, the message is lost. RabbitMQ has already discarded it and will not redeliver it.

      Use this for high-throughput data where the loss of an occasional message is acceptable (e.g., log streaming, sensor telemetry).

      Returns:
      this builder instance
    • priority

      ConsumerBuilder priority(int priority)
      The consumer priority.
      Parameters:
      priority - consumer priority
      Returns:
      this builder instance
      See Also:
    • listeners

      ConsumerBuilder listeners(Resource.StateListener... listeners)
      Add Resource.StateListeners to the consumer.
      Parameters:
      listeners - listeners
      Returns:
      this builder instance
    • stream

      Options for a consumer consuming from a stream.
      Returns:
      stream options
      See Also:
    • subscriptionListener

      ConsumerBuilder subscriptionListener(ConsumerBuilder.SubscriptionListener subscriptionListener)
      Set a listener to customize the subscription before the consumer is created (or recovered).

      This callback is available for stream consumers.

      Parameters:
      subscriptionListener - subscription listener
      Returns:
      this builder instance
      See Also:
    • build

      Consumer build()
      Build the consumer.
      Returns:
      the configured consumer instance