Announcement Announcement Module
Collapse
No announcement yet.
how to stop spring batch job launcher once it completed reading from queue. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to stop spring batch job launcher once it completed reading from queue.

    how to stop spring batch job launcher once it completed reading from queue.

    We are using camel to read our file.After reading .csv file ,it will put the data as batch in the queue.
    Currently in batch_job_execution table the exit_code is coming as "UNKNOWN" after competing the reading.

    What we need to do for getting the exit_code as "COMPLETED".

    current xml entry
    -------------------
    <step id="step1">
    <tasklet>
    <chunk reader="camelReader" writer="itemWriter"
    commit-interval="1" reader-transactional-queue="true">
    </chunk>
    </tasklet>
    <end on="*"/>
    </step>

    I have given <end on="*"/> tag inside the step.But it doesn't give any result.

    ANy help from any body...

  • #2
    What is the camelReader? What does it return once processing is complete?

    Comment


    • #3
      Hi,
      CamelReader reads msg from queue and the itemwriter does commit to db at the interval of 1.
      Say, Queue has 10 items and the job for consuming the msg from queue does not ends even after consuming all 10 msg from queue. How to make the job status completed once all the msg in queue are consumed and is persisted in db.

      Here is the code for camelReader bean.

      <bean id="camelReader" class="org.apache.camel.component.spring.batch.sup port.CamelItemReader">
      <constructor-arg ref="consumer" />
      <constructor-arg value="jms:queue/schedule" />
      </bean>

      Comment


      • #4
        This really isn't a Spring Batch question but a Camel question. In order for an ItemReader to communicate to the job that the input has been exhausted (and can end the step) it must return null. Nothing in the Camel ItemReader does that (unless there is something in the ConsumerTemplate implementation that does that) from what I can see. The Spring Batch JMSItemReader is meant to be a starting point for extension for this very reason. It will take business logic of some kind to determine when all input has been exhausted.

        Comment


        • #5
          Thanks for the reply...
          I have just checked the CamelItemReader Class and found that the read method returns the output of the following code.
          public I read() throws Exception {
          return (I) consumerTemplate.receiveBody(endpointUri);
          }
          I've overridden tat read method and tried the other method in consumerTemplate which has timeout parameter.
          public I read() throws Exception {
          return (I) consumerTemplate.receiveBody(endpointUri,1000);
          }
          But then, the job status is changed to "COMPLETED" when there is no response from queue.

          I thought my problem was solved, but then I realized an issue associated with that approach.
          Say 10 msg in Queue, and 5 is processed, persisted in db and for the 6th msg.. some exeption happens and the processing is halted. Since theconsumerTemplate.receiveBody(URI, TIMEOUT) is invoked.. it waits for some time and updates the job status as "COMPLETED" though some msg were still needs to be consumed from the queue.
          Please assist...

          Comment


          • #6
            In the end, you need to implement the reader to read from the queue and interpret the message. If it's one to be processed, then process it and continue. If it is a message indicating that processing is complete, then return null.

            Comment

            Working...
            X