Interface Inbox
- All Known Implementing Classes:
Inboxes.DurableQueueBasedInboxes.DurableQueueBasedInbox
public interface Inbox
The
The
The message is added to the
If the ACK fails then the message infrastructure will attempt to redeliver the message even if the
After the
The
This means that the Message consumer, registered with the
Inbox supports the transactional Store and Forward pattern from Enterprise Integration Patterns supporting At-Least-Once delivery guarantee.The
Inbox pattern is used to handle incoming messages from a message infrastructure (such as a Queue, Kafka, EventBus, etc). The message is added to the
Inbox in a transaction/UnitOfWork and afterwards the message is Acknowledged (ACK) with the message infrastructure the UnitOfWork is committed.If the ACK fails then the message infrastructure will attempt to redeliver the message even if the
UnitOfWork has been committed, since the message infrastructure and the Inbox
don't share the same transactional resource. This means that messages received from the message infrastructure
can be added more than once to the Inbox.After the
UnitOfWork has been committed, the messages will be asynchronously delivered to the message consumer in a new UnitOfWork.The
Inbox itself supports Message Redelivery in case the Message consumer experiences failures.This means that the Message consumer, registered with the
Inbox, can and will receive Messages more than once and therefore its message handling has to be idempotent.
If you're working with OrderedMessage's then the Inbox consumer must be configured
with InboxConfig.getMessageConsumptionMode() having value MessageConsumptionMode.SingleGlobalConsumer
in order to be able to guarantee that OrderedMessage's are delivered in OrderedMessage.getOrder() per OrderedMessage.getKey()
across as many InboxConfig.numberOfParallelMessageConsumers as you wish to use.
-
Method Summary
Modifier and TypeMethodDescriptiondefault InboxaddMessageListReceived(List<? extends Object> payloads) Register or add a list of message payloads that have been received.default InboxaddMessageListReceived(List<? extends Object> payloads, Duration deliveryDelay) Register or add a list of message payloads that have been received and where the messages should be delivered later.addMessageReceived(Message message) Register or add a message that has been received
This message will be stored durably (without any duplication check) in connection with the currently activeUnitOfWork(or a newUnitOfWorkwill be created in case there isn't an activeUnitOfWork).
The message will be delivered asynchronously to the message consumeraddMessageReceived(Message message, Duration deliveryDelay) Register or add a message that has been received and where the message should be delivered later
This message will be stored durably (without any duplication check) in connection with the currently activeUnitOfWork(or a newUnitOfWorkwill be created in case there isn't an activeUnitOfWork).
The message will be delivered asynchronously to the message consumerdefault InboxaddMessageReceived(Object payload) Register or add a message (without meta-data) that has been received
This message will be stored durably (without any duplication check) in connection with the currently activeUnitOfWork(or a newUnitOfWorkwill be created in case there isn't an activeUnitOfWork).
The message will be delivered asynchronously to the message consumerdefault InboxaddMessageReceived(Object payload, MessageMetaData metaData) Register or add a message (with meta-data) that has been received
This message will be stored durably (without any duplication check) in connection with the currently activeUnitOfWork(or a newUnitOfWorkwill be created in case there isn't an activeUnitOfWork).
The message will be delivered asynchronously to the message consumerdefault InboxaddMessageReceived(Object payload, MessageMetaData metaData, Duration deliveryDelay) Register or add a message (with meta-data) that has been received and where the message should be delivered later
This message will be stored durably (without any duplication check) in connection with the currently activeUnitOfWork(or a newUnitOfWorkwill be created in case there isn't an activeUnitOfWork).
The message will be delivered asynchronously to the message consumerdefault InboxaddMessageReceived(Object payload, Duration deliveryDelay) Register or add a message (without meta-data) that has been received and where the message should be delivered later
This message will be stored durably (without any duplication check) in connection with the currently activeUnitOfWork(or a newUnitOfWorkwill be created in case there isn't an activeUnitOfWork).
The message will be delivered asynchronously to the message consumeraddMessagesReceived(List<Message> messages) Register or add a list of messages that has been received
These messages will be stored durably (without any duplication check) in connection with the currently activeUnitOfWork(or a newUnitOfWorkwill be created in case there isn't an activeUnitOfWork).
The messages will be delivered asynchronously to the message consumeraddMessagesReceived(List<Message> messages, Duration deliveryDelay) Register or add a list of messages that has been received and where the message should be delivered later
These messages will be stored durably (without any duplication check) in connection with the currently activeUnitOfWork(or a newUnitOfWorkwill be created in case there isn't an activeUnitOfWork).
The messages will be delivered asynchronously to the message consumerStart consuming messages from the Inbox using the provided message consumer.
This is the same as callingsetMessageConsumer(Consumer)followed bystartConsuming()
Only needs to be called if the instance was created without a message consumer such as viaInboxes.getOrCreateInbox(InboxConfig)voidDelete all messages (Queued or Dead letter Messages) in the underlying storage (such as a Queue)longGet the number of message received that haven't been processed yet (or successfully processed) by the message consumerbooleanHas the instance been created with a Message consumer or hasconsume(Consumer)been calledbooleanIs the provided Message consumer consuming messages from theInboxname()The name of the inboxsetMessageConsumer(Consumer<Message> messageConsumer) Set the message consumer.Start consuming messages from theInbox.Stop consuming messages from theInbox.
-
Method Details
-
consume
Start consuming messages from the Inbox using the provided message consumer.
This is the same as callingsetMessageConsumer(Consumer)followed bystartConsuming()
Only needs to be called if the instance was created without a message consumer such as viaInboxes.getOrCreateInbox(InboxConfig)If an
OrderedMessageis delivered via anInboxusing aFencedLock(such asInboxes.durableQueueBasedInboxes(DurableQueues, FencedLockManager)) to coordinate message consumption, then you can find theFencedLock.getCurrentToken()of the consumer in theMessage.getMetaData()under keyMessageMetaData.FENCED_LOCK_TOKEN- Parameters:
messageConsumer- the message consumer. SeePatternMatchingMessageHandler- Returns:
- this inbox instance
-
setMessageConsumer
Set the message consumer. To start consuming callstartConsuming()- Parameters:
messageConsumer- the message consumer. SeePatternMatchingMessageHandler- Returns:
- this inbox instance
-
startConsuming
Inbox startConsuming()Start consuming messages from theInbox. Requires callingsetMessageConsumer(Consumer)first
If anOrderedMessageis delivered via anInboxusing aFencedLock(such asInboxes.durableQueueBasedInboxes(DurableQueues, FencedLockManager)) to coordinate message consumption, then you can find theFencedLock.getCurrentToken()of the consumer in theMessage.getMetaData()under keyMessageMetaData.FENCED_LOCK_TOKEN- Returns:
- this inbox instance
-
stopConsuming
Inbox stopConsuming()Stop consuming messages from theInbox. Calling this method will remove the message consumer and to resume message consumption you need to callconsume(Consumer)- Returns:
- this inbox instance
-
hasAMessageConsumer
boolean hasAMessageConsumer()Has the instance been created with a Message consumer or hasconsume(Consumer)been called- Returns:
- Has the instance been created with a Message consumer or has
consume(Consumer)been called
-
isConsumingMessages
boolean isConsumingMessages()Is the provided Message consumer consuming messages from theInbox- Returns:
- Is the provided Message consumer consuming messages from the
Inbox
-
name
InboxName name()The name of the inbox- Returns:
- the name of the inbox
-
deleteAllMessages
void deleteAllMessages()Delete all messages (Queued or Dead letter Messages) in the underlying storage (such as a Queue) -
addMessageReceived
Register or add a message (with meta-data) that has been received
This message will be stored durably (without any duplication check) in connection with the currently activeUnitOfWork(or a newUnitOfWorkwill be created in case there isn't an activeUnitOfWork).
The message will be delivered asynchronously to the message consumer- Parameters:
payload- the message payloadmetaData- the message meta-data- Returns:
- this inbox instance
-
addMessageReceived
Register or add a message (with meta-data) that has been received and where the message should be delivered later
This message will be stored durably (without any duplication check) in connection with the currently activeUnitOfWork(or a newUnitOfWorkwill be created in case there isn't an activeUnitOfWork).
The message will be delivered asynchronously to the message consumer- Parameters:
payload- the message payloadmetaData- the message meta-datadeliveryDelay- duration before the message should be delivered- Returns:
- this inbox instance
-
addMessageReceived
Register or add a message (without meta-data) that has been received
This message will be stored durably (without any duplication check) in connection with the currently activeUnitOfWork(or a newUnitOfWorkwill be created in case there isn't an activeUnitOfWork).
The message will be delivered asynchronously to the message consumer- Parameters:
payload- the message payload
-
addMessageReceived
Register or add a message (without meta-data) that has been received and where the message should be delivered later
This message will be stored durably (without any duplication check) in connection with the currently activeUnitOfWork(or a newUnitOfWorkwill be created in case there isn't an activeUnitOfWork).
The message will be delivered asynchronously to the message consumer- Parameters:
payload- the message payloaddeliveryDelay- duration before the message should be delivered
-
addMessageListReceived
Register or add a list of message payloads that have been received. The payloads will be converted toMessage's
These messages will be stored durably (without any duplication check) in connection with the currently activeUnitOfWork(or a newUnitOfWorkwill be created in case there isn't an activeUnitOfWork).
The messages will be delivered asynchronously to the message consumer- Parameters:
payloads- the list of message payloads- Returns:
- this inbox instance
-
addMessageListReceived
Register or add a list of message payloads that have been received and where the messages should be delivered later. The payloads will be converted toMessage's
These messages will be stored durably (without any duplication check) in connection with the currently activeUnitOfWork(or a newUnitOfWorkwill be created in case there isn't an activeUnitOfWork).
The messages will be delivered asynchronously to the message consumer- Parameters:
payloads- the list of message payloads- Returns:
- this inbox instance
-
addMessageReceived
Register or add a message that has been received
This message will be stored durably (without any duplication check) in connection with the currently activeUnitOfWork(or a newUnitOfWorkwill be created in case there isn't an activeUnitOfWork).
The message will be delivered asynchronously to the message consumer- Parameters:
message- the message- Returns:
- this inbox instance
- See Also:
-
addMessageReceived
Register or add a message that has been received and where the message should be delivered later
This message will be stored durably (without any duplication check) in connection with the currently activeUnitOfWork(or a newUnitOfWorkwill be created in case there isn't an activeUnitOfWork).
The message will be delivered asynchronously to the message consumer- Parameters:
message- the messagedeliveryDelay- duration before the message should be delivered- Returns:
- this inbox instance
- See Also:
-
addMessagesReceived
Register or add a list of messages that has been received
These messages will be stored durably (without any duplication check) in connection with the currently activeUnitOfWork(or a newUnitOfWorkwill be created in case there isn't an activeUnitOfWork).
The messages will be delivered asynchronously to the message consumer- Parameters:
messages- the list of messages- Returns:
- this inbox instance
- See Also:
-
addMessagesReceived
Register or add a list of messages that has been received and where the message should be delivered later
These messages will be stored durably (without any duplication check) in connection with the currently activeUnitOfWork(or a newUnitOfWorkwill be created in case there isn't an activeUnitOfWork).
The messages will be delivered asynchronously to the message consumer- Parameters:
messages- the list of messagesdeliveryDelay- duration before the messages should be delivered- Returns:
- this inbox instance
- See Also:
-
getNumberOfUndeliveredMessages
long getNumberOfUndeliveredMessages()Get the number of message received that haven't been processed yet (or successfully processed) by the message consumer- Returns:
- the number of message received that haven't been processed yet (or successfully processed) by the message consumer
-