Interface DurableQueues
-
- All Superinterfaces:
Lifecycle
public interface DurableQueues extends Lifecycle
TheDurableQueuesconcept supports intra-service point-to-point messaging using durable Queues that guarantee At-Least-Once delivery of messages.
The only requirement is that message producers and message consumers can access the same underlying durable Queue storage.In a service oriented architecture it's common for all deployed instances of a given service (e.g. a Sales service) to share the same underlying database(s). As long as the different deployed (Sales) services instances can share the same underlying database, then you use the
DurableQueuesconcept for point to point messaging across all deployed (Sales service) instances in the cluster.
If you need cross-service point to point messaging support, e.g. across instances of different services (such as across Sales, Billing and Shipping services), then you need to use a dedicated distributed Queueing service such as RabbitMQ.This library focuses on providing a Durable Queue supporting message redelivery and Dead Letter Message functionality and comes in two flavours
PostgresqlDurableQueuesandMongoDurableQueueswhich both implement theDurableQueuesinterface.Durable Queue concept that supports queuing a message on to a named Queue. Each message is associated with a unique
QueueEntryId
Each Queue is uniquely identified by itsQueueName
Queued messages can, per Queue, asynchronously be consumed by aQueuedMessageHandler, by registering it as aDurableQueueConsumerusingconsumeFromQueue(QueueName, RedeliveryPolicy, int, QueuedMessageHandler)
The Durable Queue concept supports competing consumers guaranteeing that a message is only consumed by one message handler at a time
TheDurableQueueConsumersupports retrying failed messages, according to the specifiedRedeliveryPolicy, and ultimately marking a repeatedly failing message as a Poison-Message/Dead-Letter-Message.
TheRedeliveryPolicysupports fixed, linear and exponential backoff strategies. TheDurableQueuessupports delayed message delivery as well as Poison-Message/Dead-Letter-Messages, which are messages that have repeatedly failed processing.
Poison Messages/Dead-Letter-Messages won't be delivered to aDurableQueueConsumer, unless they're explicitly resurrected callresurrectDeadLetterMessage(QueueEntryId, Duration)
Ordered Messages
If you're queuing withOrderedMessagethen, IF and only IF, only a single cluster node is consuming from the Queue, such as with anInboxorOutboxconfigured withMessageConsumptionMode.SingleGlobalConsumer(which uses aFencedLockto coordinate message consumption across cluster nodes) in order to be able to guarantee thatOrderedMessage's are delivered inOrderedMessage.getOrder()perOrderedMessage.getKey()across as many parallel message consumers as you wish to use.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classDurableQueues.QueueingSortOrderThe sorting order for theQueuedMessage.getId()
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description booleanacknowledgeMessageAsHandled(AcknowledgeMessageAsHandled operation)Mark the message as acknowledged - this operation also deletes the messages from the Queue
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactionaldefault booleanacknowledgeMessageAsHandled(QueueEntryId queueEntryId)Mark the message as acknowledged - this operation deletes the messages from the Queue
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactionalDurableQueuesaddInterceptor(DurableQueuesInterceptor interceptor)Add aDurableQueuesInterceptorto thisDurableQueuesinstance
TheDurableQueuesInterceptorallows you to intercept all high level operationsdefault DurableQueuesaddInterceptors(List<DurableQueuesInterceptor> interceptors)AddDurableQueuesInterceptor's to thisDurableQueuesinstance
TheDurableQueuesInterceptorallows you to intercept all high level operationsDurableQueueConsumerconsumeFromQueue(ConsumeFromQueue operation)Start an asynchronous message consumer.
Note: There can only be oneDurableQueueConsumerperQueueNameperDurableQueuesinstancedefault DurableQueueConsumerconsumeFromQueue(QueueName queueName, RedeliveryPolicy redeliveryPolicy, int parallelConsumers, QueuedMessageHandler queueMessageHandler)Start an asynchronous message consumer.
Note: There can only be oneDurableQueueConsumerperQueueNameperDurableQueuesinstancedefault DurableQueueConsumerconsumeFromQueue(String consumerName, QueueName queueName, RedeliveryPolicy redeliveryPolicy, int parallelConsumers, QueuedMessageHandler queueMessageHandler)Start an asynchronous message consumer.
Note: There can only be oneDurableQueueConsumerperQueueNameperDurableQueuesinstancebooleandeleteMessage(DeleteMessage operation)Delete a message (Queued or Dead Letter Message)
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactionaldefault booleandeleteMessage(QueueEntryId queueEntryId)Delete a message (Queued or Dead Letter Message)
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactionalOptional<QueuedMessage>getDeadLetterMessage(GetDeadLetterMessage operation)Get a queued message that's marked as aQueuedMessage.isDeadLetterMessage()default Optional<QueuedMessage>getDeadLetterMessage(QueueEntryId queueEntryId)Get a queued message that's marked as aQueuedMessage.isDeadLetterMessage()List<QueuedMessage>getDeadLetterMessages(GetDeadLetterMessages operation)Query Dead Letter Messages (i.e.default List<QueuedMessage>getDeadLetterMessages(QueueName queueName, DurableQueues.QueueingSortOrder queueingSortOrder, long startIndex, long pageSize)Query Dead Letter Messages (i.e.Optional<QueuedMessage>getNextMessageReadyForDelivery(GetNextMessageReadyForDelivery operation)Query the next Queued Message (i.e.default Optional<QueuedMessage>getNextMessageReadyForDelivery(QueueName queueName)Query the next Queued Message (i.e.Optional<QueuedMessage>getQueuedMessage(GetQueuedMessage operation)Get a queued message that is NOT marked as aQueuedMessage.isDeadLetterMessage()default Optional<QueuedMessage>getQueuedMessage(QueueEntryId queueEntryId)Get a queued message that is NOT marked as aQueuedMessage.isDeadLetterMessage()List<QueuedMessage>getQueuedMessages(GetQueuedMessages operation)Query Queued Messages (i.e.default List<QueuedMessage>getQueuedMessages(QueueName queueName, DurableQueues.QueueingSortOrder queueingSortOrder, long startIndex, long pageSize)Query Queued Messages (i.e.longgetTotalMessagesQueuedFor(GetTotalMessagesQueuedFor operation)Get the total number of messages queued (i.e.default longgetTotalMessagesQueuedFor(QueueName queueName)Get the total number of messages queued (i.e.TransactionalModegetTransactionalMode()The transactional behaviour mode of thisDurableQueuesinstanceOptional<UnitOfWorkFactory<? extends UnitOfWork>>getUnitOfWorkFactory()booleanhasMessagesQueuedFor(QueueName queueName)Check if there are any messages queued (i.e.Optional<QueuedMessage>markAsDeadLetterMessage(MarkAsDeadLetterMessage operation)Mark an already Queued Message as a Dead Letter Message (or Poison Message).
Dead Letter Messages won't be delivered to anyDurableQueueConsumer(called by theDurableQueueConsumer)
To deliver a Dead Letter Message you must first resurrect the message usingresurrectDeadLetterMessage(QueueEntryId, Duration)
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactionaldefault Optional<QueuedMessage>markAsDeadLetterMessage(QueueEntryId queueEntryId, Exception causeForBeingMarkedAsDeadLetter)Mark an already Queued Message as a Dead Letter Message (or Poison Message).
Dead Letter Messages won't be delivered to anyDurableQueueConsumer(called by theDurableQueueConsumer)
To deliver a Dead Letter Message you must first resurrect the message usingresurrectDeadLetterMessage(QueueEntryId, Duration)
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactionalintpurgeQueue(PurgeQueue operation)Delete all messages (Queued or Dead letter Messages) in the given queuedefault intpurgeQueue(QueueName queueName)Delete all messages (Queued or Dead letter Messages) in the given queuedefault List<NextQueuedMessage>queryForMessagesSoonReadyForDelivery(QueueName queueName, int maxNumberOfMessagesToReturn)Query for the nextmaxNumberOfMessagesToReturnqueued messages that are soon ready to be delivered usingInstant.now()aswithNextDeliveryTimestampAfter
This is a useful method for a custom queue consumer to know if it's necessary to callgetNextMessageReadyForDelivery(GetNextMessageReadyForDelivery)List<NextQueuedMessage>queryForMessagesSoonReadyForDelivery(QueueName queueName, Instant withNextDeliveryTimestampAfter, int maxNumberOfMessagesToReturn)Query for the nextmaxNumberOfMessagesToReturnqueued messages that are soon ready to be delivered
This is a useful method for a custom queue consumer to know if it's necessary to callgetNextMessageReadyForDelivery(GetNextMessageReadyForDelivery)QueueEntryIdqueueMessage(QueueMessage operation)Queue a message for asynchronous delivery without delay to aDurableQueueConsumer
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactionaldefault QueueEntryIdqueueMessage(QueueName queueName, Message message)Queue a message for asynchronous delivery without delay to aDurableQueueConsumer
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactionaldefault QueueEntryIdqueueMessage(QueueName queueName, Message message, Exception causeOfEnqueuing, Duration deliveryDelay)Queue a message for asynchronous delivery optional delay to aDurableQueueConsumer
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactionaldefault QueueEntryIdqueueMessage(QueueName queueName, Message message, Duration deliveryDelay)Queue a message for asynchronous delivery optional delay to aDurableQueueConsumer
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactionaldefault QueueEntryIdqueueMessage(QueueName queueName, Message message, Optional<Exception> causeOfEnqueuing, Optional<Duration> deliveryDelay)Queue a message for asynchronous delivery optional delay to aDurableQueueConsumer
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactionaldefault QueueEntryIdqueueMessage(QueueName queueName, Message message, Optional<Duration> deliveryDelay)Queue a message for asynchronous delivery optional delay to aDurableQueueConsumer
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactionalQueueEntryIdqueueMessageAsDeadLetterMessage(QueueMessageAsDeadLetterMessage operation)Queue the message directly as a Dead Letter Message.default QueueEntryIdqueueMessageAsDeadLetterMessage(QueueName queueName, Message message, Exception causeOfError)Queue the message directly as a Dead Letter Message.List<QueueEntryId>queueMessages(QueueMessages operation)Queue multiple messages to the same queue.default List<QueueEntryId>queueMessages(QueueName queueName, List<? extends Message> messages)Queue multiple messages to the same queue.default List<QueueEntryId>queueMessages(QueueName queueName, List<? extends Message> messages, Duration deliveryDelay)Queue multiple messages to the same queue.default List<QueueEntryId>queueMessages(QueueName queueName, List<? extends Message> messages, Optional<Duration> deliveryDelay)Queue multiple messages to the same queue.DurableQueuesremoveInterceptor(DurableQueuesInterceptor interceptor)Optional<QueuedMessage>resurrectDeadLetterMessage(ResurrectDeadLetterMessage operation)Resurrect a Dead Letter Message for redelivery after the specifieddeliveryDelay
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactionaldefault Optional<QueuedMessage>resurrectDeadLetterMessage(QueueEntryId queueEntryId, Duration deliveryDelay)Resurrect a Dead Letter Message for redelivery after the specifieddeliveryDelay
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactionalOptional<QueuedMessage>retryMessage(RetryMessage operation)Schedule the message for redelivery after the specifieddeliveryDelay(called by theDurableQueueConsumer)
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactionaldefault Optional<QueuedMessage>retryMessage(QueueEntryId queueEntryId, Exception causeForRetry, Duration deliveryDelay)Schedule the message for redelivery after the specifieddeliveryDelay(called by theDurableQueueConsumer)
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional
-
-
-
Method Detail
-
addInterceptor
DurableQueues addInterceptor(DurableQueuesInterceptor interceptor)
Add aDurableQueuesInterceptorto thisDurableQueuesinstance
TheDurableQueuesInterceptorallows you to intercept all high level operations- Parameters:
interceptor- the interceptor to add- Returns:
- this
DurableQueuesinstance
-
addInterceptors
default DurableQueues addInterceptors(List<DurableQueuesInterceptor> interceptors)
AddDurableQueuesInterceptor's to thisDurableQueuesinstance
TheDurableQueuesInterceptorallows you to intercept all high level operations- Parameters:
interceptors- the interceptors to add- Returns:
- this
DurableQueuesinstance
-
removeInterceptor
DurableQueues removeInterceptor(DurableQueuesInterceptor interceptor)
- Parameters:
interceptor- the interceptor to remove- Returns:
- this
DurableQueuesinstance
-
getDeadLetterMessage
default Optional<QueuedMessage> getDeadLetterMessage(QueueEntryId queueEntryId)
Get a queued message that's marked as aQueuedMessage.isDeadLetterMessage()- Parameters:
queueEntryId- the messages unique queue entry id- Returns:
- the message wrapped in an
Optionalif the message exists andQueuedMessage.isDeadLetterMessage(), otherwiseOptional.empty()
-
getDeadLetterMessage
Optional<QueuedMessage> getDeadLetterMessage(GetDeadLetterMessage operation)
Get a queued message that's marked as aQueuedMessage.isDeadLetterMessage()- Parameters:
operation- theGetDeadLetterMessageoperation- Returns:
- the message wrapped in an
Optionalif the message exists andQueuedMessage.isDeadLetterMessage(), otherwiseOptional.empty()
-
getQueuedMessage
default Optional<QueuedMessage> getQueuedMessage(QueueEntryId queueEntryId)
Get a queued message that is NOT marked as aQueuedMessage.isDeadLetterMessage()- Parameters:
queueEntryId- the messages unique queue entry id- Returns:
- the message wrapped in an
Optionalif the message exists and NOT aQueuedMessage.isDeadLetterMessage(), otherwiseOptional.empty()
-
getQueuedMessage
Optional<QueuedMessage> getQueuedMessage(GetQueuedMessage operation)
Get a queued message that is NOT marked as aQueuedMessage.isDeadLetterMessage()- Parameters:
operation- theGetQueuedMessageoperation- Returns:
- the message wrapped in an
Optionalif the message exists and NOT aQueuedMessage.isDeadLetterMessage(), otherwiseOptional.empty()
-
getTransactionalMode
TransactionalMode getTransactionalMode()
The transactional behaviour mode of thisDurableQueuesinstance- Returns:
- The transactional behaviour mode of a
DurableQueuesinstance
-
getUnitOfWorkFactory
Optional<UnitOfWorkFactory<? extends UnitOfWork>> getUnitOfWorkFactory()
- Returns:
- If
getTransactionalMode()isTransactionalMode.FullyTransactionalthen it will return theUnitOfWorkFactorywrapped in anOptional, otherwise it will return anOptional.empty()
-
consumeFromQueue
default DurableQueueConsumer consumeFromQueue(String consumerName, QueueName queueName, RedeliveryPolicy redeliveryPolicy, int parallelConsumers, QueuedMessageHandler queueMessageHandler)
Start an asynchronous message consumer.
Note: There can only be oneDurableQueueConsumerperQueueNameperDurableQueuesinstance- Parameters:
consumerName- the name of the consumer (for logging purposes)queueName- the name of the queue that the consumer will be listening for queued messages ready to be delivered to theQueuedMessageHandlerprovidedredeliveryPolicy- the redelivery policy in case the handling of a message failsparallelConsumers- the number of parallel consumers (if number > 1 then you will effectively have competing consumers on the current node)queueMessageHandler- the message handler that will receiveQueuedMessage's. SeePatternMatchingQueuedMessageHandler- Returns:
- the queue consumer
-
consumeFromQueue
default DurableQueueConsumer consumeFromQueue(QueueName queueName, RedeliveryPolicy redeliveryPolicy, int parallelConsumers, QueuedMessageHandler queueMessageHandler)
Start an asynchronous message consumer.
Note: There can only be oneDurableQueueConsumerperQueueNameperDurableQueuesinstance- Parameters:
queueName- the name of the queue that the consumer will be listening for queued messages ready to be delivered to theQueuedMessageHandlerprovidedredeliveryPolicy- the redelivery policy in case the handling of a message failsparallelConsumers- the number of parallel consumers (if number > 1 then you will effectively have competing consumers on the current node)queueMessageHandler- the message handler that will receiveQueuedMessage's. SeePatternMatchingQueuedMessageHandler- Returns:
- the queue consumer
-
consumeFromQueue
DurableQueueConsumer consumeFromQueue(ConsumeFromQueue operation)
Start an asynchronous message consumer.
Note: There can only be oneDurableQueueConsumerperQueueNameperDurableQueuesinstance- Parameters:
operation- TheConsumeFromQueueoperation- Returns:
- the queue consumer
-
queueMessage
default QueueEntryId queueMessage(QueueName queueName, Message message)
Queue a message for asynchronous delivery without delay to aDurableQueueConsumer
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
queueName- the name of the Queue the message is added tomessage- the message- Returns:
- the unique entry id for the message queued
-
queueMessage
QueueEntryId queueMessage(QueueMessage operation)
Queue a message for asynchronous delivery without delay to aDurableQueueConsumer
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
operation- theQueueMessageoperation- Returns:
- the unique entry id for the message queued
-
queueMessage
default QueueEntryId queueMessage(QueueName queueName, Message message, Optional<Duration> deliveryDelay)
Queue a message for asynchronous delivery optional delay to aDurableQueueConsumer
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
queueName- the name of the Queue the message is added tomessage- the message (Message/OrderedMessage)deliveryDelay- Optional delay for the first delivery of the message to theDurableQueueConsumer- Returns:
- the unique entry id for the message queued
- See Also:
OrderedMessage
-
queueMessage
default QueueEntryId queueMessage(QueueName queueName, Message message, Duration deliveryDelay)
Queue a message for asynchronous delivery optional delay to aDurableQueueConsumer
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
queueName- the name of the Queue the message is added tomessage- the message (Message/OrderedMessage)deliveryDelay- Optional delay for the first delivery of the message to theDurableQueueConsumer- Returns:
- the unique entry id for the message queued
- See Also:
OrderedMessage
-
queueMessage
default QueueEntryId queueMessage(QueueName queueName, Message message, Optional<Exception> causeOfEnqueuing, Optional<Duration> deliveryDelay)
Queue a message for asynchronous delivery optional delay to aDurableQueueConsumer
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
queueName- the name of the Queue the message is added tomessage- the message (Message/OrderedMessage)causeOfEnqueuing- the optional reason for the message being queueddeliveryDelay- Optional delay for the first delivery of the message to theDurableQueueConsumer- Returns:
- the unique entry id for the message queued
- See Also:
OrderedMessage
-
queueMessage
default QueueEntryId queueMessage(QueueName queueName, Message message, Exception causeOfEnqueuing, Duration deliveryDelay)
Queue a message for asynchronous delivery optional delay to aDurableQueueConsumer
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
queueName- the name of the Queue the message is added tomessage- the message payload (Message/OrderedMessage)causeOfEnqueuing- the optional reason for the message being queueddeliveryDelay- Optional delay for the first delivery of the message to theDurableQueueConsumer- Returns:
- the unique entry id for the message queued
- See Also:
OrderedMessage
-
queueMessageAsDeadLetterMessage
default QueueEntryId queueMessageAsDeadLetterMessage(QueueName queueName, Message message, Exception causeOfError)
Queue the message directly as a Dead Letter Message. Dead Letter Messages won't be delivered to anyDurableQueueConsumer
To deliver a Dead Letter Message you must first resurrect the message usingresurrectDeadLetterMessage(QueueEntryId, Duration)- Parameters:
queueName- the name of the Queue the message is added tomessage- the message (Message/OrderedMessage)causeOfError- the reason for the message being queued directly as a Dead Letter Message- Returns:
- the unique entry id for the message queued
- See Also:
OrderedMessage
-
queueMessageAsDeadLetterMessage
QueueEntryId queueMessageAsDeadLetterMessage(QueueMessageAsDeadLetterMessage operation)
Queue the message directly as a Dead Letter Message. Dead Letter Messages won't be delivered to anyDurableQueueConsumer
To deliver a Dead Letter Message you must first resurrect the message usingresurrectDeadLetterMessage(QueueEntryId, Duration)- Parameters:
operation- theQueueMessageAsDeadLetterMessageoperation- Returns:
- the unique entry id for the message queued
-
queueMessages
default List<QueueEntryId> queueMessages(QueueName queueName, List<? extends Message> messages, Optional<Duration> deliveryDelay)
Queue multiple messages to the same queue. All the messages will receive the sameQueuedMessage.getNextDeliveryTimestamp()
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
queueName- the name of the Queue the messages will be added tomessages- the message to enqueue (Message/OrderedMessage)deliveryDelay- optional: how long will the queue wait until it delivers the messages to theDurableQueueConsumer- Returns:
- the unique entry id's for the messages queued ordered in the same order as the payloads that were queued
-
queueMessages
default List<QueueEntryId> queueMessages(QueueName queueName, List<? extends Message> messages, Duration deliveryDelay)
Queue multiple messages to the same queue. All the messages will receive the sameQueuedMessage.getNextDeliveryTimestamp()
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
queueName- the name of the Queue the messages will be added tomessages- the messages to enqueue (Message/OrderedMessage)deliveryDelay- optional: how long will the queue wait until it delivers the messages to theDurableQueueConsumer- Returns:
- the unique entry id's for the messages queued ordered in the same order as the payloads that were queued
-
queueMessages
default List<QueueEntryId> queueMessages(QueueName queueName, List<? extends Message> messages)
Queue multiple messages to the same queue. All the messages will receive the sameQueuedMessage.getNextDeliveryTimestamp()
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
queueName- the name of the Queue the messages will be added tomessages- the message to enqueue (Message/OrderedMessage)- Returns:
- the unique entry id's for the messages queued, ordered in the same order as the payloads that were queued
-
queueMessages
List<QueueEntryId> queueMessages(QueueMessages operation)
Queue multiple messages to the same queue. All the messages will receive the sameQueuedMessage.getNextDeliveryTimestamp()
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
operation- TheQueueMessagesoperation- Returns:
- the unique entry id's for the messages queued ordered in the same order as the payloads that were queued
-
retryMessage
default Optional<QueuedMessage> retryMessage(QueueEntryId queueEntryId, Exception causeForRetry, Duration deliveryDelay)
Schedule the message for redelivery after the specifieddeliveryDelay(called by theDurableQueueConsumer)
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
queueEntryId- the unique id of the message that must we will retry the delivery ofcauseForRetry- the reason why the message delivery has to be retrieddeliveryDelay- how long will the queue wait until it delivers the message to theDurableQueueConsumer- Returns:
- the
QueuedMessagemessage wrapped in anOptionalif the operation was successful, otherwise it returns anOptional.empty()
-
retryMessage
Optional<QueuedMessage> retryMessage(RetryMessage operation)
Schedule the message for redelivery after the specifieddeliveryDelay(called by theDurableQueueConsumer)
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
operation- theRetryMessageoperation- Returns:
- the
QueuedMessagemessage wrapped in anOptionalif the operation was successful, otherwise it returns anOptional.empty()
-
markAsDeadLetterMessage
default Optional<QueuedMessage> markAsDeadLetterMessage(QueueEntryId queueEntryId, Exception causeForBeingMarkedAsDeadLetter)
Mark an already Queued Message as a Dead Letter Message (or Poison Message).
Dead Letter Messages won't be delivered to anyDurableQueueConsumer(called by theDurableQueueConsumer)
To deliver a Dead Letter Message you must first resurrect the message usingresurrectDeadLetterMessage(QueueEntryId, Duration)
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
queueEntryId- the unique id of the message that must be marked as a Dead Letter MessagecauseForBeingMarkedAsDeadLetter- the reason for the message being marked as a Dead Letter Message- Returns:
- the
QueuedMessagemessage wrapped in anOptionalif the operation was successful, otherwise it returns anOptional.empty()
-
markAsDeadLetterMessage
Optional<QueuedMessage> markAsDeadLetterMessage(MarkAsDeadLetterMessage operation)
Mark an already Queued Message as a Dead Letter Message (or Poison Message).
Dead Letter Messages won't be delivered to anyDurableQueueConsumer(called by theDurableQueueConsumer)
To deliver a Dead Letter Message you must first resurrect the message usingresurrectDeadLetterMessage(QueueEntryId, Duration)
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
operation- theMarkAsDeadLetterMessageoperation- Returns:
- the
QueuedMessagemessage wrapped in anOptionalif the operation was successful, otherwise it returns anOptional.empty()
-
resurrectDeadLetterMessage
default Optional<QueuedMessage> resurrectDeadLetterMessage(QueueEntryId queueEntryId, Duration deliveryDelay)
Resurrect a Dead Letter Message for redelivery after the specifieddeliveryDelay
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
queueEntryId- the unique id of the Dead Letter Message that must we will retry the delivery ofdeliveryDelay- how long will the queue wait until it delivers the message to theDurableQueueConsumer- Returns:
- the
QueuedMessagemessage wrapped in anOptionalif the operation was successful, otherwise it returns anOptional.empty()
-
resurrectDeadLetterMessage
Optional<QueuedMessage> resurrectDeadLetterMessage(ResurrectDeadLetterMessage operation)
Resurrect a Dead Letter Message for redelivery after the specifieddeliveryDelay
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
operation- theResurrectDeadLetterMessageoperation- Returns:
- the
QueuedMessagemessage wrapped in anOptionalif the operation was successful, otherwise it returns anOptional.empty()
-
acknowledgeMessageAsHandled
default boolean acknowledgeMessageAsHandled(QueueEntryId queueEntryId)
Mark the message as acknowledged - this operation deletes the messages from the Queue
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
queueEntryId- the unique id of the Message to acknowledge- Returns:
- true if the operation went well, otherwise false
-
acknowledgeMessageAsHandled
boolean acknowledgeMessageAsHandled(AcknowledgeMessageAsHandled operation)
Mark the message as acknowledged - this operation also deletes the messages from the Queue
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
operation- theAcknowledgeMessageAsHandledoperation- Returns:
- true if the operation went well, otherwise false
-
deleteMessage
default boolean deleteMessage(QueueEntryId queueEntryId)
Delete a message (Queued or Dead Letter Message)
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
queueEntryId- the unique id of the Message to delete- Returns:
- true if the operation went well, otherwise false
-
deleteMessage
boolean deleteMessage(DeleteMessage operation)
Delete a message (Queued or Dead Letter Message)
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
operation- theDeleteMessageoperation- Returns:
- true if the operation went well, otherwise false
-
getNextMessageReadyForDelivery
default Optional<QueuedMessage> getNextMessageReadyForDelivery(QueueName queueName)
Query the next Queued Message (i.e. not including Dead Letter Messages) that's ready to be delivered to aDurableQueueConsumer
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
queueName- the name of the Queue where we will query for the next message ready for delivery- Returns:
- the next message ready to be delivered (wrapped in an
Optional) orOptional.empty()if no message is ready for delivery
-
getNextMessageReadyForDelivery
Optional<QueuedMessage> getNextMessageReadyForDelivery(GetNextMessageReadyForDelivery operation)
Query the next Queued Message (i.e. not including Dead Letter Messages) that's ready to be delivered to aDurableQueueConsumer
Note this method MUST be called within an existingUnitOfWorkIF usingTransactionalMode.FullyTransactional- Parameters:
operation- theGetNextMessageReadyForDeliveryoperation- Returns:
- the next message ready to be delivered (wrapped in an
Optional) orOptional.empty()if no message is ready for delivery
-
hasMessagesQueuedFor
boolean hasMessagesQueuedFor(QueueName queueName)
Check if there are any messages queued (i.e. not including Dead Letter Messages) for the given queue- Parameters:
queueName- the name of the Queue where we will query for queued messages- Returns:
- true if there are messages queued on the given queue, otherwise false
-
getTotalMessagesQueuedFor
default long getTotalMessagesQueuedFor(QueueName queueName)
Get the total number of messages queued (i.e. not including Dead Letter Messages) for the given queue- Parameters:
queueName- the name of the Queue where we will query for the number of queued messages- Returns:
- the number of queued messages for the given queue
-
getTotalMessagesQueuedFor
long getTotalMessagesQueuedFor(GetTotalMessagesQueuedFor operation)
Get the total number of messages queued (i.e. not including Dead Letter Messages) for the given queue- Parameters:
operation- theGetTotalMessagesQueuedForoperation- Returns:
- the number of queued messages for the given queue
-
getQueuedMessages
default List<QueuedMessage> getQueuedMessages(QueueName queueName, DurableQueues.QueueingSortOrder queueingSortOrder, long startIndex, long pageSize)
Query Queued Messages (i.e. not including any Dead Letter Messages) for the given Queue- Parameters:
queueName- the name of the Queue where we will query for queued messagesqueueingSortOrder- the sort order for theQueuedMessage.getId()startIndex- the index of the first message to include in the result (used for pagination)pageSize- how many messages to include in the result (used for pagination)- Returns:
- the messages matching the criteria
-
getQueuedMessages
List<QueuedMessage> getQueuedMessages(GetQueuedMessages operation)
Query Queued Messages (i.e. not including any Dead Letter Messages) for the given Queue- Parameters:
operation- theGetQueuedMessagesoperation- Returns:
- the messages matching the criteria
-
getDeadLetterMessages
default List<QueuedMessage> getDeadLetterMessages(QueueName queueName, DurableQueues.QueueingSortOrder queueingSortOrder, long startIndex, long pageSize)
Query Dead Letter Messages (i.e. not normal Queued Messages) for the given Queue- Parameters:
queueName- the name of the Queue where we will query for Dead letter messagesqueueingSortOrder- the sort order for theQueuedMessage.getId()startIndex- the index of the first message to include in the result (used for pagination)pageSize- how many messages to include in the result (used for pagination)- Returns:
- the dead letter messages matching the criteria
-
getDeadLetterMessages
List<QueuedMessage> getDeadLetterMessages(GetDeadLetterMessages operation)
Query Dead Letter Messages (i.e. not normal Queued Messages) for the given Queue- Parameters:
operation- theGetDeadLetterMessagesoperation- Returns:
- the dead letter messages matching the criteria
-
purgeQueue
default int purgeQueue(QueueName queueName)
Delete all messages (Queued or Dead letter Messages) in the given queue- Parameters:
queueName- the name of the Queue where all the messages will be deleted- Returns:
- the number of deleted messages
-
purgeQueue
int purgeQueue(PurgeQueue operation)
Delete all messages (Queued or Dead letter Messages) in the given queue- Parameters:
operation- thePurgeQueueoperation- Returns:
- the number of deleted messages
-
queryForMessagesSoonReadyForDelivery
default List<NextQueuedMessage> queryForMessagesSoonReadyForDelivery(QueueName queueName, int maxNumberOfMessagesToReturn)
Query for the nextmaxNumberOfMessagesToReturnqueued messages that are soon ready to be delivered usingInstant.now()aswithNextDeliveryTimestampAfter
This is a useful method for a custom queue consumer to know if it's necessary to callgetNextMessageReadyForDelivery(GetNextMessageReadyForDelivery)- Parameters:
queueName- the name of the queue being queriedmaxNumberOfMessagesToReturn- the maximum number of messages to return- Returns:
- the messages soon ready to be delivered
-
queryForMessagesSoonReadyForDelivery
List<NextQueuedMessage> queryForMessagesSoonReadyForDelivery(QueueName queueName, Instant withNextDeliveryTimestampAfter, int maxNumberOfMessagesToReturn)
Query for the nextmaxNumberOfMessagesToReturnqueued messages that are soon ready to be delivered
This is a useful method for a custom queue consumer to know if it's necessary to callgetNextMessageReadyForDelivery(GetNextMessageReadyForDelivery)- Parameters:
queueName- the name of the queue being queriedwithNextDeliveryTimestampAfter- returnNextQueuedMessagewith aNextQueuedMessage.nextDeliveryTimestamp> than this timestampmaxNumberOfMessagesToReturn- the maximum number of messages to return- Returns:
- the messages soon ready to be delivered
-
-