Announcement Announcement Module
Collapse
No announcement yet.
Error with JMsItemReader Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error with JMsItemReader

    Guys......can you please help resolving this issue......i dint find any documentation in the internet regrading the code using JmsItemReader.......
    I am very much new to Spring Batch......

    My Spring batch JOb configuration is

    <bean id="tracker105Job" parent="simpleJob">
    <property name="steps">
    <bean id="step1" parent="simpleStep">
    <property name="commitInterval" value="50" />
    <property name="itemReader" ref="ediJmsItemReader"/>
    <property name="itemWriter">
    <bean class="org.springframework.batch.item.file.EDIFile Writer">
    <property name="dao" ref="ediDao" />
    </bean>
    </property>
    </bean>
    </property>
    </bean>

    <bean id="ediJmsItemReader"
    class="org.springframework.batch.item.jms.JmsItemR eader">
    <property name="itemType" value="java.lang.String"/>
    <property name="jmsTemplate" ref="myJmsTemplate"/>
    </bean>

    <!-- Spring JMS Template -->
    <bean id="myJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory">
    <ref bean="jmsFactory"/>
    </property>
    <property name="defaultDestination" ref="destination"/>
    <property name="receiveTimeout" value="500"/>
    </bean>


    <bean id="jmsFactory" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiTemplate">
    <ref bean="wlsjndiTemplate"/>
    </property>
    <property name="jndiName">
    <value>jms.databroker.JMSConnectionFactory</value>
    </property>
    </bean>

    <bean id="wlsjndiTemplate" class="org.springframework.jndi.JndiTemplate">
    <property name="environment">
    <props>
    <prop key="java.naming.factory.initial">weblogic.jndi.WL InitialContextFactory</prop>
    <prop key="java.naming.provider.url">t3://localhost:7001</prop>
    </props>
    </property>
    </bean>

    <bean id="destination" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiTemplate">
    <ref bean="wlsjndiTemplate"/>
    </property>
    <property name="jndiName">
    <value>jms.databroker.DatabaseEventTopic</value>
    </property>
    </bean>


    JMS Reader class :-

    public class JmsItemReader<T> implements ItemReader<T> {

    protected Log logger = LogFactory.getLog(getClass());

    protected Class<? extends T> itemType;

    protected JmsOperations jmsTemplate;

    /**
    * Setter for jms template.
    *
    * @param jmsTemplate a {@link JmsOperations} instance
    */
    public void setJmsTemplate(JmsOperations jmsTemplate) {
    this.jmsTemplate = jmsTemplate;
    }

    /**
    * Set the expected type of incoming message payloads. Set this to
    * {@link Message} to receive the raw underlying message.
    *
    * @param 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.
    */
    public void setItemType(Class<? extends T> itemType) {
    this.itemType = itemType;
    }

    @SuppressWarnings("unchecked")
    public T read() {
    if (itemType != null && itemType.isAssignableFrom(Message.class)) {
    return (T) jmsTemplate.receive();
    }
    Object result = jmsTemplate.receiveAndConvert();
    if (itemType != null && result != null) {
    Assert.state(itemType.isAssignableFrom(result.getC lass()),
    "Received message payload of wrong type: expected [" + itemType + "]");
    }
    System.out.println("itemType="+itemType.toString() );
    System.out.println("result="+result.toString());

    return (T) result;
    }

    }



    Error:-


    itemType=class java.lang.String
    19:11:33,815 DEBUG main TaskletStep:275 - Applying contribution: [StepContribution: read=0, written=0, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING]
    19:11:33,815 ERROR main AbstractStep:213 - Encountered an error executing the step: class java.lang.NullPointerException: null
    java.lang.NullPointerException
    at org.springframework.batch.item.jms.JmsItemReader.r ead(JmsItemReader.java:81)
    at org.springframework.batch.core.step.item.SimpleChu nkProvider.doRead(SimpleChunkProvider.java:90)
    at org.springframework.batch.core.step.item.SimpleChu nkProvider.read(SimpleChunkProvider.java:127)
    at org.springframework.batch.core.step.item.SimpleChu nkProvider$1.doInIteration(SimpleChunkProvider.jav a:106)
    at org.springframework.batch.repeat.support.RepeatTem plate.getNextResult(RepeatTemplate.java:352)
    at org.springframework.batch.repeat.support.RepeatTem plate.executeInternal(RepeatTemplate.java:212)
    at org.springframework.batch.repeat.support.RepeatTem plate.iterate(RepeatTemplate.java:143)
    at org.springframework.batch.core.step.item.SimpleChu nkProvider.provide(SimpleChunkProvider.java:103)
    at org.springframework.batch.core.step.item.ChunkOrie ntedTasklet.execute(ChunkOrientedTasklet.java:64)
    at org.springframework.batch.core.step.tasklet.Taskle tStep$2.doInChunkContext(TaskletStep.java:264)
    at org.springframework.batch.core.scope.context.StepC ontextRepeatCallback.doInIteration(StepContextRepe atCallback.java:67)
    at org.springframework.batch.repeat.support.RepeatTem plate.getNextResult(RepeatTemplate.java:352)
    at org.springframework.batch.repeat.support.RepeatTem plate.executeInternal(RepeatTemplate.java:212)
    at org.springframework.batch.repeat.support.RepeatTem plate.iterate(RepeatTemplate.java:143)
    at org.springframework.batch.core.step.tasklet.Taskle tStep.doExecute(TaskletStep.java:239)
    at org.springframework.batch.core.step.AbstractStep.e xecute(AbstractStep.java:197)
    at org.springframework.batch.core.job.AbstractJob.han dleStep(AbstractJob.java:348)
    at org.springframework.batch.core.job.SimpleJob.doExe cute(SimpleJob.java:121)

  • #2
    It would appear that your result is null for some reason. I would have to double check the JMSTemplate to make sure of it's behavior, but I believe after a particular timeout it will return null, which indicates that the job is done to Spring Batch. In your case, the println is trying to call toString on a null and causing the exception. (I'm assuming you added the println, since it's not in the official code)

    Trying to read in from JMS in Batch is always kind of tricky, because its difficult to know when the job should be considered 'done'. SB with a JMSItemReader shouldn't be considered a message consumer in a traditional producer/consumer model. It is really meant for reading a stream, which in this case could be a stream of JMS Messages that are written out in batches. You really only have two possibilities to detect the end of the stream though:

    1. timeout - keep trying to read until the queue is empty for some timeout.
    2. 'PoisonPill' - If possible, the sender could send a large amount of messages, after its done send an agreed message type signaling the end of a stream

    Comment


    • #3
      Hi Lucas, Thanks for your reply in the thread created by me.
      But i am still getting the problem.

      I am sening a small text message like "C:\\apps\\Harmony\\data\\EDI832\\US\\process\\AVN ET_2009052917144400.Edi"

      And Secondly, I have increased the timeout 30 times.

      <!-- Spring JMS Template -->
      <bean id="myJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
      <property name="connectionFactory">
      <ref bean="jmsFactory"/>
      </property>
      <property name="defaultDestination" ref="destination"/>
      <property name="receiveTimeout" value="15000"/>
      </bean>

      Can you please look into the matter please . Very much thankfull to your reply.If i get an code example of using JMS in SPRING BATCH , It would be highly appreciable.

      Actually we are buliding an prototype of bulk loading of files for our project.we are trying to use SPRING BATCH with JMS and Quartz.

      i want put jms reader and jmwriter between file raeder and transformer

      ExampleFileReader ->JMSWriter -> JMSQueue -> JMS Reader ->Transformer etc.


      With Regards,
      Chiranjib

      Comment


      • #4
        JmsItemReader is designed to provide items from a queue to a batch step execution. Your input source is a file, so I wouldn't use JmsItemReader if I were you, unless I misunderstood something.

        The null you are seeing in the reader is just telling you that there are no messages to receive. Maybe you wired up the wrong queue, or wrong connection factory, or something? It's impossible to tell from what you posted (and it isn't a Batch problem anyway). You probably need to ask in a middleware vendor forum, or in the Spring JMS or Integration forums.

        You seem to have a step which consists of item processing via a JMS request-response cycle? The MessagingGateway from Spring Integration is a nice way to achieve that (independent of JMS). Or you could write your own with JmsTemplate.

        Comment


        • #5
          Syer,

          thanks for your reply. The message i have sent is not a file..............that is just a text message containing that filename.......thats it..............if use spring integration [Messaging Gateway] ,will i loose the use of Spring batch in the project...i mean is it use spring batch or normal spring......

          you are right that i want to use JMS request-response cycle in the project along with spring batch........

          Comment


          • #6
            I'm even more confused now. What is the item in your Item* components?

            There is no reason you can't use JmsTemplate or MessagingGateway in an ItemProcessor. I can't tell if that's what you need to do or not though.

            Comment

            Working...
            X