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 voidaddMessageReceived(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 voidaddMessageReceived(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 voidaddMessageReceived(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 Outbox using the provided message consumer.
Only needs to be called if the instance was created without a message consumerlonggetNumberOfUndeliveredMessages()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 theOutboxInboxNamename()The name of the inboxvoidstopConsuming()Stop consuming messages from theOutbox.
-
-
-
Method Detail
-
consume
Inbox consume(Consumer<Message> messageConsumer)
Start consuming messages from the Outbox using the provided message consumer.
Only needs to be called if the instance was created without a message consumerIf 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
-
stopConsuming
void stopConsuming()
Stop consuming messages from theOutbox. Calling this method will remove the message consumer and to resume message consumption you need to callconsume(Consumer)
-
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 theOutbox- Returns:
- Is the provided Message consumer consuming messages from the
Outbox
-
name
InboxName name()
The name of the inbox- Returns:
- the name of the inbox
-
addMessageReceived
default void 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
-
addMessageReceived
default void 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
void 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- 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
-
-