Interface Outboxes
-
- All Known Implementing Classes:
Outboxes.DurableQueueBasedOutboxes
public interface OutboxesTheOutboxsupports the transactional Store and Forward pattern from Enterprise Integration Patterns supporting At-Least-Once delivery guarantee.
TheOutboxpattern is used to handle outgoing messages, that are created as a side effect of adding/updating an entity in a database, but where the message infrastructure (such as a Queue, Kafka, EventBus, etc.) that doesn't share the same underlying transactional resource as the database.
Instead, you need to use anOutboxthat can join in the sameUnitOfWork/transactional-resource that the database is using.
The message is added to theOutboxin a transaction/UnitOfWorkand afterwards theUnitOfWorkis committed.
If the transaction fails then both the entity and the message will be rolled back when thenUnitOfWorkrolls back.
After theUnitOfWorkhas been committed, the messages will be asynchronously delivered to the message consumer in a newUnitOfWork.
TheOutboxitself supports Message Redelivery in case the Message consumer experiences failures.
This means that the Message consumer, registered with theOutbox, 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 theOutboxconsumer must be configured withOutboxConfig.getMessageConsumptionMode()having valueMessageConsumptionMode.SingleGlobalConsumerin order to be able to guarantee thatOrderedMessage's are delivered inOrderedMessage.getOrder()perOrderedMessage.getKey()across as manyOutboxConfig.numberOfParallelMessageConsumersas you wish to use.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classOutboxes.DurableQueueBasedOutboxes
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static OutboxesdurableQueueBasedOutboxes(DurableQueues durableQueues, FencedLockManager fencedLockManager)Create anOutboxesinstance that uses aDurableQueuesas its storage and message delivery mechanism.default OutboxgetOrCreateForwardingOutbox(OutboxConfig outboxConfig, EventHandler eventHandler)Get an existingOutboxinstance or create a new instance that forwards to anEventHandler.
If an existingOutboxwith a matchingOutboxNameis already created then that instance is returned (irrespective of whether the redeliveryPolicy, etc.OutboxgetOrCreateOutbox(OutboxConfig outboxConfig)Get an existingOutboxinstance or create a new instance.OutboxgetOrCreateOutbox(OutboxConfig outboxConfig, Consumer<Message> messageConsumer)Get an existingOutboxinstance or create a new instance.Collection<Outbox>getOutboxes()
-
-
-
Method Detail
-
getOrCreateOutbox
Outbox getOrCreateOutbox(OutboxConfig outboxConfig, Consumer<Message> messageConsumer)
Get an existingOutboxinstance or create a new instance. If an existingOutboxwith a matchingOutboxNameis already created then that instance is returned (irrespective of whether the redeliveryPolicy, etc. have the same values)- Parameters:
outboxConfig- the outbox configurationmessageConsumer- the asynchronous message consumer. SeePatternMatchingMessageHandler- Returns:
- the
Outbox
-
getOrCreateOutbox
Outbox getOrCreateOutbox(OutboxConfig outboxConfig)
Get an existingOutboxinstance or create a new instance. If an existingOutboxwith a matchingOutboxNameis 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:
outboxConfig- the outbox configuration- Returns:
- the
Outbox
-
getOrCreateForwardingOutbox
default Outbox getOrCreateForwardingOutbox(OutboxConfig outboxConfig, EventHandler eventHandler)
Get an existingOutboxinstance or create a new instance that forwards to anEventHandler.
If an existingOutboxwith a matchingOutboxNameis already created then that instance is returned (irrespective of whether the redeliveryPolicy, etc. have the same values)- Parameters:
outboxConfig- the outbox configurationeventHandler- the asynchronous event handler- Returns:
- the
Outbox
-
getOutboxes
Collection<Outbox> getOutboxes()
-
durableQueueBasedOutboxes
static Outboxes durableQueueBasedOutboxes(DurableQueues durableQueues, FencedLockManager fencedLockManager)
Create anOutboxesinstance that uses aDurableQueuesas its storage and message delivery mechanism.- Parameters:
durableQueues- TheDurableQueuesimplementation used by theOutboxesinstance returnedfencedLockManager- theFencedLockManagerused forOutbox's that useMessageConsumptionMode.SingleGlobalConsumer- Returns:
- the
Outboxesinstance
-
-