JMS
Java Messaging Service (JMS) is a message-oriented method of communicating between two or more endpoints by using either point-to-point communication via JMS queue or a publish-subscribe model via JMS topic.
Spring Batch provides two classes org.springframework.batch.item.jms.JmsItemReader and org.springframework.batch.item.jms.JmsItemWriter for reading and writing respectively.
JmsItemReader is an ItemReader for JMS using a JmsTemplate. The template should have a default destination, which will be used to provide items in read(). JmsItemwriter is an ItemWriter for JMS using a JmsTemplate. The template should have a default destination, which will be used to send items in write(List). Listing 23-19 below shows configuring JMS reader ad writer in the Spring configuration file.
Listing 23-19. Configuring JMS item reader and writer in Spring configuration file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
... <bean id="destination" class="org.apache.activemq.command.ActiveMQQueue"> <constructor-arg value="sampleQueue"/> </bean> <bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="vm://localhost"/> </bean> <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"> <property name="connectionFactory" ref="jmsConnectionFactory"/> <property name="defaultDestination" ref="destination"/> <property name="receiveTimeout" value="5000"/> </bean> <bean id="jmsReader" class="org.springframework.batch.item.jms.JmsItemReader"> <property name="jmsTemplate" ref="jmsTemplate"/> </bean> <bean id="jmsWriter" class="org.springframework.batch.item.jms.JmsItemWriter"> <property name="jmsTemplate" ref="jmsTemplate"/> </bean> … |
All the available ItemReader’s in Spring Batch can be summarized as shown in Table 23-1 below.
Table 23-1. Available ItemReader’s in Spring Batch (Spring Batch Documentation)
Item Readers | Description | ||
AbstractItemCountingItemStreamItemReader | Abstract base class that provides basic restart capabilities by counting the number of items returned from an
|
||
ListItemReader | Provides the items from a list, one at a time. | ||
ItemReaderAdapter | Adapts any class to the
|
||
AggregateItemReader | An ItemReader that delivers a list as its item, storing up objects from the injected ItemReader until they are ready to be packed out as a collection. | ||
FlatFileItemReader | Reads from a flat file. Includes ItemStream and Skippable functionality. | ||
StaxEventItemReader | Reads via StAX. | ||
JdbcCursorItemReader | Reads from a database cursor via JDBC. | ||
HibernateCursorItemReader | Reads from a cursor based on an HQL query. | ||
IbatisPagingItemReader | Reads via iBATIS based on a query. Pages through the rows so that large datasets can be read without running out of memory. | ||
JmsItemReader | Given a Spring JmsOperations object and a JMS Destination or destination name to send errors, provides items received through the injected JmsOperations receive() method | ||
JpaPagingItemReader | Given a JPQL statement, pages through the rows, such that large datasets can be read without running out of memory. | ||
JdbcPagingItemReader | Given a SQL statement, pages through the rows, such that large datasets can be read without running out of memory. |
All the available ItemWriter’s in Spring Batch can be summarized as shown in Table 23-2 below.
Table 23-2. Available Itemwriter’s in Spring Batch (Spring Batch Documentation)
Item Writer | Description |
AbstractItemStreamItemWriter | Abstract base class that combines the ItemStream and ItemWriter interfaces. |
CompositeItemWriter | Passes an item to the process method of each in an injected List of ItemWriter objects |
ItemWriterAdapter | Adapts any class to the ItemWriter interface. |
PropertyExtractingDelegatingItemWriter | Extends AbstractMethodInvokingDelegator creating arguments on the fly. Arguments are created by retrieving the values from the fields in the item to be processed (via a SpringBeanWrapper) based on an injected array of field name |
FlatFileItemWriter | Writes to a flat file. Includes ItemStream and Skippable functionality. See section on Writing to a File |
HibernateItemWriter | This item writer is hibernate session aware and handles some transaction-related work that a non-“hibernate aware” item writer would not need to know about and then delegates to another item writer to do the actual writing. |
JdbcBatchItemWriter | Uses batching features from a PreparedStatement, if available, and can take rudimentary steps to locate a failure during a flush. |
JpaItemWriter | This item writer is JPA EntityManager aware and handles some transaction-related work that a non-“jpa aware”ItemWriter would not need to know about and then delegates to another writer to do the actual writing. |
StaxEventItemWriter | Uses an ObjectToXmlSerializer implementation to convert each item to XML and then writes it to an XML file using StAX. |
Page Visitors: 25708

Tomcy John

Latest posts by Tomcy John (see all)
- A Guide to Continuous Improvement for Architects - February 2, 2023
- Cloud-first Architecture Strategy - January 26, 2023
- Architecture Strategy and how to create One - January 24, 2023
Thanks for sharing the information but what’s the difference between CursorItemReader’s setFetchSize() and PagingItemReader’s setPageSize()? isn’t it the same?
Please provide an example for StoredProcedureItem Reader – which returns cursor and how to process cursor in processor – I am new to Spring Batch as part of my work I need to invoke Oracle Stored proc which takes one param as input and returns result set which I need to process in Spring Batch Processor.
Thanks
Laxmi