Class MessageChannelItemWriter<T>

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

public class MessageChannelItemWriter<T> extends Object implements ItemWriter<T>
An ItemWriter implementation that sends items as messages to a message channel using a MessagingTemplate. This item writer 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

    • MessageChannelItemWriter

      public MessageChannelItemWriter(org.springframework.integration.core.MessagingTemplate messagingGateway)
      Create a new MessageChannelItemWriter instance. Messages will be sent to the default destination of the provided MessagingTemplate which must not be null.
      Parameters:
      messagingGateway - the messaging template to use for sending messages
    • MessageChannelItemWriter

      public MessageChannelItemWriter(org.springframework.integration.core.MessagingTemplate messagingTemplate, org.springframework.messaging.MessageChannel messageChannel)
      Create a new MessageChannelItemWriter instance. Messages will be sent to the provided message channel.
      Parameters:
      messagingTemplate - the messaging template to use for sending messages
      messageChannel - the message channel to send messages to
  • Method Details

    • setMessageChannel

      public void setMessageChannel(org.springframework.messaging.MessageChannel messageChannel)
      Set the target message channel.
      Parameters:
      messageChannel - the message channel to send messages to
    • write

      public void write(Chunk<? extends T> items) throws Exception
      Description copied from interface: ItemWriter
      Process the supplied data element. Will not be called with any null items in normal operation but might be called with an empty chunk, for example when all items have been filtered by an ItemProcessor or skipped by the fault-tolerant step processing. Implementations are expected to handle empty chunks gracefully.
      Specified by:
      write in interface ItemWriter<T>
      Parameters:
      items - of items to be written. Never null but may be empty.
      Throws:
      Exception - if there are errors. The framework will catch the exception and convert or rethrow it as appropriate.