Interface Inbox
-
- All Known Implementing Classes:
Inboxes.DurableQueueBasedInboxes.DurableQueueBasedInbox
public interface InboxTheInboxsupports the transactional Store and Forward pattern from Enterprise Integration Patterns supporting At-Least-Once delivery guarantee.
TheInboxpattern is used to handle incoming messages from a message infrastructure (such as a Queue, Kafka, EventBus, etc).
The message is added to theInboxin a transaction/UnitOfWorkand afterwards the message is Acknowledged (ACK) with the message infrastructure theUnitOfWorkis committed.
If the ACK fails then the message infrastructure will attempt to redeliver the message even if theUnitOfWorkhas been committed, since the message infrastructure and theInboxdon't share the same transactional resource. This means that messages received from the message infrastructure can be added more than once to theInbox.
After theUnitOfWorkhas been committed, the messages will be asynchronously delivered to the message consumer in a newUnitOfWork.
TheInboxitself supports Message Redelivery in case the Message consumer experiences failures.
This means that the Message consumer, registered with theInbox, 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 theInboxconsumer must be configured withInboxConfig.getMessageConsumptionMode()having valueMessageConsumptionMode.SingleGlobalConsumerin order to be able to guarantee thatOrderedMessage's are delivered inOrderedMessage.getOrder()perOrderedMessage.getKey()across as manyInboxConfig.numberOfParallelMessageConsumersas you wish to use.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description InboxaddMessageReceived(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 no 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 no 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 no there isn't an activeUnitOfWork).
The message will be delivered asynchronously to the message consumerInboxconsume(Consumer<Message> messageConsumer)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)longgetNumberOfUndeliveredMessages()Get the number of message received that haven't been processed yet (or successfully processed) by the message consumerbooleanhasAMessageConsumer()Has the instance been created with a Message consumer or hasconsume(Consumer)been calledbooleanisConsumingMessages()Is the provided Message consumer consuming messages from theInboxInboxNamename()The name of the inboxInboxsetMessageConsumer(Consumer<Message> messageConsumer)Set the message consumer.InboxstartConsuming()Start consuming messages from theInbox.InboxstopConsuming()Stop consuming messages from theInbox.
-
-
-
Method Detail
-
consume
Inbox consume(Consumer<Message> messageConsumer)
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
Inbox setMessageConsumer(Consumer<Message> messageConsumer)
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
-
addMessageReceived
default Inbox addMessageReceived(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 no 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
default Inbox addMessageReceived(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 no there isn't an activeUnitOfWork).
The message will be delivered asynchronously to the message consumer- Parameters:
payload- the message payload
-
addMessageReceived
Inbox 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 no 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:
OrderedMessage
-
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
-
-