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>
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 Summary
ConstructorsConstructorDescriptionMessageChannelItemReader(org.springframework.integration.core.MessagingTemplate messagingTemplate, Class<T> targetType) Create a newMessageChannelItemReaderinstance.MessageChannelItemReader(org.springframework.integration.core.MessagingTemplate messagingTemplate, org.springframework.messaging.MessageChannel messageChannel, Class<T> targetType) Create a newMessageChannelItemReaderinstance. -
Method Summary
Modifier and TypeMethodDescription@Nullable Tread()Reads a piece of input data and advance to the next one.voidsetMessageChannel(org.springframework.messaging.MessageChannel messageChannel) Set the source message channel.
-
Constructor Details
-
MessageChannelItemReader
public MessageChannelItemReader(org.springframework.integration.core.MessagingTemplate messagingTemplate, Class<T> targetType) Create a newMessageChannelItemReaderinstance. Messages will be read from the default destination of the providedMessagingTemplatewhich must not be null.- Parameters:
messagingTemplate- the messaging template to use for reading messagestargetType- 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 newMessageChannelItemReaderinstance. Messages will be read from the provided target message channel.- Parameters:
messagingTemplate- the messaging template to use for receiving messagesmessageChannel- the message channel to read messages fromtargetType- 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
Description copied from interface:ItemReaderReads a piece of input data and advance to the next one. Implementations must returnnullat 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:
readin interfaceItemReader<T>- Returns:
- T the item to be processed or
nullif the data source is exhausted - Throws:
Exception- if an error occurs.
-