Interface Inboxes
-
- All Known Implementing Classes:
Inboxes.DurableQueueBasedInboxes
public interface InboxesTheInboxsupports 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classInboxes.DurableQueueBasedInboxes
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static InboxesdurableQueueBasedInboxes(DurableQueues durableQueues, FencedLockManager fencedLockManager)Create anInboxesinstance that uses aDurableQueuesas its storage and message delivery mechanism.Collection<Inbox>getInboxes()InboxgetOrCreateInbox(InboxConfig inboxConfig)Get an existingInboxinstance or create a new instance.default InboxgetOrCreateInbox(InboxConfig inboxConfig, CommandBus forwardTo)Get an existingInboxinstance or create a new instance.InboxgetOrCreateInbox(InboxConfig inboxConfig, Consumer<Message> messageConsumer)Get an existingInboxinstance or create a new instance.
-
-
-
Method Detail
-
getOrCreateInbox
Inbox getOrCreateInbox(InboxConfig inboxConfig)
Get an existingInboxinstance or create a new instance. If an existingInboxwith a matchingInboxNameis already created then that instance is returned (irrespective of whether the redeliveryPolicy, etc. have the same values)
Remember to callOutbox.consume(Consumer)to start consuming messages- Parameters:
inboxConfig- the inbox configuration- Returns:
- the
Inbox
-
getOrCreateInbox
Inbox getOrCreateInbox(InboxConfig inboxConfig, Consumer<Message> messageConsumer)
Get an existingInboxinstance or create a new instance. If an existingInboxwith a matchingInboxNameis already created then that instance is returned (irrespective of whether the redeliveryPolicy, etc. have the same values)- Parameters:
inboxConfig- the inbox configurationmessageConsumer- the asynchronous message consumer. SeePatternMatchingMessageHandler- Returns:
- the
Inbox
-
getOrCreateInbox
default Inbox getOrCreateInbox(InboxConfig inboxConfig, CommandBus forwardTo)
Get an existingInboxinstance or create a new instance. If an existingInboxwith a matchingInboxNameis already created then that instance is returned (irrespective of whether the redeliveryPolicy, etc. have the same values)- Parameters:
inboxConfig- the inbox configurationforwardTo- forward messages to this command bus usingCommandBus.send(Object)- Returns:
- the
Inbox
-
getInboxes
Collection<Inbox> getInboxes()
-
durableQueueBasedInboxes
static Inboxes durableQueueBasedInboxes(DurableQueues durableQueues, FencedLockManager fencedLockManager)
Create anInboxesinstance that uses aDurableQueuesas its storage and message delivery mechanism.- Parameters:
durableQueues- TheDurableQueuesimplementation used by theInboxesinstance returnedfencedLockManager- theFencedLockManagerused forInbox's that useMessageConsumptionMode.SingleGlobalConsumer- Returns:
- the
Inboxesinstance
-
-