Class MessageChannelItemReader<T>

java.lang.Object
org.springframework.batch.integration.support.MessageChannelItemReader<T>
Type Parameters:
T - the type of items to be read
All Implemented Interfaces:
ItemReader<T>

public class MessageChannelItemReader<T> extends Object implements ItemReader<T>
An ItemReader implementation that receives items as messages from a message channel using a MessagingTemplate. This item reader enables SEDA (Staged Event-Driven Architecture) patterns in Spring Batch jobs by decoupling item production from item consumption through messaging.
Since:
6.0.0
Author:
Mahmoud Ben Hassine
  • Constructor Details

    • MessageChannelItemReader

      public MessageChannelItemReader(org.springframework.integration.core.MessagingTemplate messagingTemplate, Class<T> targetType)
      Create a new MessageChannelItemReader instance. Messages will be read from the default destination of the provided MessagingTemplate which must not be null.
      Parameters:
      messagingTemplate - the messaging template to use for reading messages
      targetType - the target type of items to convert messages to
    • MessageChannelItemReader

      public MessageChannelItemReader(org.springframework.integration.core.MessagingTemplate messagingTemplate, org.springframework.messaging.MessageChannel messageChannel, Class<T> targetType)
      Create a new MessageChannelItemReader instance. Messages will be read from the provided target message channel.
      Parameters:
      messagingTemplate - the messaging template to use for receiving messages
      messageChannel - the message channel to read messages from
      targetType - the target type of items to convert messages to
  • Method Details

    • setMessageChannel

      public void setMessageChannel(org.springframework.messaging.MessageChannel messageChannel)
      Set the source message channel.
      Parameters:
      messageChannel - the message channel to read messages from
    • read

      public @Nullable T read() throws Exception
      Description copied from interface: ItemReader
      Reads a piece of input data and advance to the next one. Implementations must return null at the end of the input data set. In a transactional setting, caller might get the same item twice from successive calls (or otherwise), if the first call was in a transaction that rolled back.
      Specified by:
      read in interface ItemReader<T>
      Returns:
      T the item to be processed or null if the data source is exhausted
      Throws:
      Exception - if an error occurs.