All Known Implementing Classes:
Outboxes.DurableQueueBasedOutboxes

public interface Outboxes
The Outbox supports the transactional Store and Forward pattern from Enterprise Integration Patterns supporting At-Least-Once delivery guarantee.
The Outbox pattern 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 an Outbox that can join in the same UnitOfWork/transactional-resource that the database is using.
The message is added to the Outbox in a transaction/UnitOfWork and afterwards the UnitOfWork is committed.
If the transaction fails then both the entity and the message will be rolled back when then UnitOfWork rolls back.
After the UnitOfWork has been committed, the messages will be asynchronously delivered to the message consumer in a new UnitOfWork.
The Outbox itself supports Message Redelivery in case the Message consumer experiences failures.
This means that the Message consumer, registered with the Outbox, 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 Outbox consumer must be configured with OutboxConfig.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 OutboxConfig.numberOfParallelMessageConsumers as you wish to use.

  • Method Details

    • getOrCreateOutbox

      Outbox getOrCreateOutbox(OutboxConfig outboxConfig, Consumer<Message> messageConsumer)
      Get an existing Outbox instance or create a new instance. If an existing Outbox with a matching OutboxName is already created then that instance is returned (irrespective of whether the redeliveryPolicy, etc. have the same values)
      Parameters:
      outboxConfig - the outbox configuration
      messageConsumer - the asynchronous message consumer. See PatternMatchingMessageHandler
      Returns:
      the Outbox
    • getOrCreateOutbox

      Outbox getOrCreateOutbox(OutboxConfig outboxConfig)
      Get an existing Outbox instance or create a new instance. If an existing Outbox with a matching OutboxName is already created then that instance is returned (irrespective of whether the redeliveryPolicy, etc. have the same values)
      Remember to call Outbox.consume(Consumer) to start consuming messages
      Parameters:
      outboxConfig - the outbox configuration
      Returns:
      the Outbox
    • getOrCreateForwardingOutbox

      default Outbox getOrCreateForwardingOutbox(OutboxConfig outboxConfig, dk.cloudcreate.essentials.reactive.EventHandler eventHandler)
      Get an existing Outbox instance or create a new instance that forwards to an EventHandler.
      If an existing Outbox with a matching OutboxName is already created then that instance is returned (irrespective of whether the redeliveryPolicy, etc. have the same values)
      Parameters:
      outboxConfig - the outbox configuration
      eventHandler - the asynchronous event handler
      Returns:
      the Outbox
    • getOutboxes

      Collection<Outbox> getOutboxes()
      Get all the Outbox instances managed by this Outboxes instance
      Returns:
      all the Outbox instances managed by this Outboxes instance
    • durableQueueBasedOutboxes

      static Outboxes durableQueueBasedOutboxes(DurableQueues durableQueues, FencedLockManager fencedLockManager)
      Create an Outboxes instance that uses a DurableQueues as its storage and message delivery mechanism.
      Parameters:
      durableQueues - The DurableQueues implementation used by the Outboxes instance returned
      fencedLockManager - the FencedLockManager used for Outbox's that use MessageConsumptionMode.SingleGlobalConsumer
      Returns:
      the Outboxes instance