All Known Implementing Classes:
Inboxes.DurableQueueBasedInboxes.DurableQueueBasedInbox

public interface Inbox
The Inbox supports the transactional Store and Forward pattern from Enterprise Integration Patterns supporting At-Least-Once delivery guarantee.
The Inbox pattern is used to handle incoming messages from a message infrastructure (such as a Queue, Kafka, EventBus, etc).
The message is added to the Inbox in a transaction/UnitOfWork and afterwards the message is Acknowledged (ACK) with the message infrastructure the UnitOfWork is committed.
If the ACK fails then the message infrastructure will attempt to redeliver the message even if the UnitOfWork has been committed, since the message infrastructure and the Inbox don't share the same transactional resource. This means that messages received from the message infrastructure can be added more than once to the Inbox.
After the UnitOfWork has been committed, the messages will be asynchronously delivered to the message consumer in a new UnitOfWork.
The Inbox itself supports Message Redelivery in case the Message consumer experiences failures.
This means that the Message consumer, registered with the Inbox, 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 Inbox consumer must be configured with InboxConfig.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 InboxConfig.numberOfParallelMessageConsumers as you wish to use.

  • Method Summary

    Modifier and Type
    Method
    Description
    Register or add a message that has been received
    This message will be stored durably (without any duplication check) in connection with the currently active UnitOfWork (or a new UnitOfWork will be created in case no there isn't an active UnitOfWork).
    The message will be delivered asynchronously to the message consumer
    addMessageReceived(Message message, Duration deliveryDelay)
    Register or add a message that has been received and where the message should be delivered later
    This message will be stored durably (without any duplication check) in connection with the currently active UnitOfWork (or a new UnitOfWork will be created in case no there isn't an active UnitOfWork).
    The message will be delivered asynchronously to the message consumer
    default Inbox
    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 active UnitOfWork (or a new UnitOfWork will be created in case no there isn't an active UnitOfWork).
    The message will be delivered asynchronously to the message consumer
    default Inbox
    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 active UnitOfWork (or a new UnitOfWork will be created in case no there isn't an active UnitOfWork).
    The message will be delivered asynchronously to the message consumer
    default Inbox
    addMessageReceived(Object payload, MessageMetaData metaData, Duration deliveryDelay)
    Register or add a message (with meta-data) that has been received and where the message should be delivered later
    This message will be stored durably (without any duplication check) in connection with the currently active UnitOfWork (or a new UnitOfWork will be created in case no there isn't an active UnitOfWork).
    The message will be delivered asynchronously to the message consumer
    default Inbox
    addMessageReceived(Object payload, Duration deliveryDelay)
    Register or add a message (without meta-data) that has been received and where the message should be delivered later
    This message will be stored durably (without any duplication check) in connection with the currently active UnitOfWork (or a new UnitOfWork will be created in case no there isn't an active UnitOfWork).
    The message will be delivered asynchronously to the message consumer
    consume(Consumer<Message> messageConsumer)
    Start consuming messages from the Inbox using the provided message consumer.
    This is the same as calling setMessageConsumer(Consumer) followed by startConsuming()
    Only needs to be called if the instance was created without a message consumer such as via Inboxes.getOrCreateInbox(InboxConfig)
    long
    Get the number of message received that haven't been processed yet (or successfully processed) by the message consumer
    boolean
    Has the instance been created with a Message consumer or has consume(Consumer) been called
    boolean
    Is the provided Message consumer consuming messages from the Inbox
    The name of the inbox
    Set the message consumer.
    Start consuming messages from the Inbox.
    Stop consuming messages from the Inbox.
  • Method Details

    • consume

      Inbox consume(Consumer<Message> messageConsumer)
      Start consuming messages from the Inbox using the provided message consumer.
      This is the same as calling setMessageConsumer(Consumer) followed by startConsuming()
      Only needs to be called if the instance was created without a message consumer such as via Inboxes.getOrCreateInbox(InboxConfig)

      If an OrderedMessage is delivered via an Inbox using a FencedLock (such as Inboxes.durableQueueBasedInboxes(DurableQueues, FencedLockManager)) to coordinate message consumption, then you can find the FencedLock.getCurrentToken() of the consumer in the Message.getMetaData() under key MessageMetaData.FENCED_LOCK_TOKEN

      Parameters:
      messageConsumer - the message consumer. See PatternMatchingMessageHandler
      Returns:
      this inbox instance
    • setMessageConsumer

      Inbox setMessageConsumer(Consumer<Message> messageConsumer)
      Set the message consumer. To start consuming call startConsuming()
      Parameters:
      messageConsumer - the message consumer. See PatternMatchingMessageHandler
      Returns:
      this inbox instance
    • startConsuming

      Inbox startConsuming()
      Start consuming messages from the Inbox. Requires calling setMessageConsumer(Consumer) first
      If an OrderedMessage is delivered via an Inbox using a FencedLock (such as Inboxes.durableQueueBasedInboxes(DurableQueues, FencedLockManager)) to coordinate message consumption, then you can find the FencedLock.getCurrentToken() of the consumer in the Message.getMetaData() under key MessageMetaData.FENCED_LOCK_TOKEN
      Returns:
      this inbox instance
    • stopConsuming

      Inbox stopConsuming()
      Stop consuming messages from the Inbox. Calling this method will remove the message consumer and to resume message consumption you need to call consume(Consumer)
      Returns:
      this inbox instance
    • hasAMessageConsumer

      boolean hasAMessageConsumer()
      Has the instance been created with a Message consumer or has consume(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 the Inbox
      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 active UnitOfWork (or a new UnitOfWork will be created in case no there isn't an active UnitOfWork).
      The message will be delivered asynchronously to the message consumer
      Parameters:
      payload - the message payload
      metaData - the message meta-data
      Returns:
      this inbox instance
    • addMessageReceived

      default Inbox addMessageReceived(Object payload, MessageMetaData metaData, Duration deliveryDelay)
      Register or add a message (with meta-data) that has been received and where the message should be delivered later
      This message will be stored durably (without any duplication check) in connection with the currently active UnitOfWork (or a new UnitOfWork will be created in case no there isn't an active UnitOfWork).
      The message will be delivered asynchronously to the message consumer
      Parameters:
      payload - the message payload
      metaData - the message meta-data
      deliveryDelay - duration before the message should be delivered
      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 active UnitOfWork (or a new UnitOfWork will be created in case no there isn't an active UnitOfWork).
      The message will be delivered asynchronously to the message consumer
      Parameters:
      payload - the message payload
    • addMessageReceived

      default Inbox addMessageReceived(Object payload, Duration deliveryDelay)
      Register or add a message (without meta-data) that has been received and where the message should be delivered later
      This message will be stored durably (without any duplication check) in connection with the currently active UnitOfWork (or a new UnitOfWork will be created in case no there isn't an active UnitOfWork).
      The message will be delivered asynchronously to the message consumer
      Parameters:
      payload - the message payload
      deliveryDelay - duration before the message should be delivered
    • 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 active UnitOfWork (or a new UnitOfWork will be created in case no there isn't an active UnitOfWork).
      The message will be delivered asynchronously to the message consumer
      Parameters:
      message - the message
      Returns:
      this inbox instance
      See Also:
    • addMessageReceived

      Inbox addMessageReceived(Message message, Duration deliveryDelay)
      Register or add a message that has been received and where the message should be delivered later
      This message will be stored durably (without any duplication check) in connection with the currently active UnitOfWork (or a new UnitOfWork will be created in case no there isn't an active UnitOfWork).
      The message will be delivered asynchronously to the message consumer
      Parameters:
      message - the message
      deliveryDelay - duration before the message should be delivered
      Returns:
      this inbox instance
      See Also:
    • 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