Interface ConsumerBuilder
public interface ConsumerBuilder
API to configure and create a
Consumer.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceFilter options for support of AMQP filter expressions.static interfaceFilter options for support of AMQP filter expressions.static enumOffset specification to start consuming from.static interfaceOptions for a consumer consuming from a stream.static interfaceCallback to modify a consumer subscription before the link creation. -
Method Summary
Modifier and TypeMethodDescriptionbuild()Build the consumer.initialCredits(int initialCredits) The initial number credits to grant to the AMQP receiver.listeners(Resource.StateListener... listeners) AddResource.StateListeners to the consumer.messageHandler(Consumer.MessageHandler handler) The callback for inbound messages.Configures the link to use At-Most-Once delivery by receiving messages in a "pre-settled" state.priority(int priority) The consumer priority.The queue to consume from.stream()Options for a consumer consuming from a stream.subscriptionListener(ConsumerBuilder.SubscriptionListener subscriptionListener) Set a listener to customize the subscription before the consumer is created (or recovered).
-
Method Details
-
queue
The queue to consume from.- Parameters:
queue- queue- Returns:
- this builder instance
-
messageHandler
The callback for inbound messages.- Parameters:
handler- callback- Returns:
- this builder instance
-
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
The consumer priority.- Parameters:
priority- consumer priority- Returns:
- this builder instance
- See Also:
-
listeners
AddResource.StateListeners to the consumer.- Parameters:
listeners- listeners- Returns:
- this builder instance
-
stream
ConsumerBuilder.StreamOptions stream()Options for a consumer consuming from a stream.- Returns:
- stream options
- See Also:
-
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
-