Class JmsItemReader<T>

java.lang.Object
org.springframework.batch.infrastructure.item.jms.JmsItemReader<T>
All Implemented Interfaces:
ItemReader<T>

public class JmsItemReader<T> extends Object implements ItemReader<T>
An ItemReader for JMS using a JmsTemplate. The template should have a default destination, which will be used to provide items in read().

The implementation is thread-safe after its properties are set (normal singleton behavior).
Author:
Dave Syer, Mahmoud Ben Hassine
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected @Nullable Class<? extends T>
     
    protected org.springframework.jms.core.JmsOperations
     
    protected org.apache.commons.logging.Log
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    JmsItemReader(org.springframework.jms.core.JmsOperations jmsTemplate)
    Create a new JmsItemReader with the provided JmsOperations.
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable T
    Reads a piece of input data and advance to the next one.
    void
    setItemType(Class<? extends T> itemType)
    Set the expected type of incoming message payloads.
    void
    setJmsTemplate(org.springframework.jms.core.JmsOperations jmsTemplate)
    Setter for JMS template.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • logger

      protected org.apache.commons.logging.Log logger
    • itemType

      protected @Nullable Class<? extends T> itemType
    • jmsTemplate

      protected org.springframework.jms.core.JmsOperations jmsTemplate
  • Constructor Details

    • JmsItemReader

      public JmsItemReader(org.springframework.jms.core.JmsOperations jmsTemplate)
      Create a new JmsItemReader with the provided JmsOperations.
      Parameters:
      jmsTemplate - a JmsOperations instance
      Since:
      6.0
  • Method Details

    • setJmsTemplate

      public void setJmsTemplate(org.springframework.jms.core.JmsOperations jmsTemplate)
      Setter for JMS template.
      Parameters:
      jmsTemplate - a JmsOperations instance
    • setItemType

      public void setItemType(Class<? extends T> itemType)
      Set the expected type of incoming message payloads. Set this to Message to receive the raw underlying message.
      Parameters:
      itemType - the java class of the items to be delivered. Typically the same as the class parameter
      Throws:
      IllegalStateException - if the message payload is of the wrong type.
    • read

      public @Nullable T read()
      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