Announcement Announcement Module
Collapse
No announcement yet.
Integrate Spring Batch Steps from MDB Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Integrate Spring Batch Steps from MDB

    I want to lunch spring batch steps from the spring enabled MDB rather the using JmsItemReader. Can somebody give suggestion how to accomplish this?

  • #2
    Did you mean to say that you want to launch a Spring Batch job from an MDB? If so I suggest you look at the quartz and JMX samples (the latter is called TaskExecutorLauncher) for some code that you could use in your listener. Does that make sense (your post is pretty thin on details)?

    I am also working on some message-driven use cases with Spring Integration -not quite ready for public use yet (Spring Integration is only at m3), and those implementations are directly usable with JMS, by virtue of the JMS features of that project.

    Comment


    • #3
      Is that what Dave means is to use Spring Integration to act as an listener to wait for job launch requests? Then launch the job as a stand-alone process?

      Comment


      • #4
        hello dave,

        Here is my use case in detail so that you get a clear insight. We are working on the claim processing system. There are spring batch steps which reads the claims.txt file and store a data into the database and push as message in the message queues called claim queue. There is ClaimProcessingMDB attached to the claim queue, which picks message and perform the claim processing, which are also composed of spring batch steps

        Now what I want to achieve is seamless integration of spring batch with ClaimProcessingMDB (which extends AbstractJmsMessageDrivenBean) so that it passes the message received in onMessage method to claim processing steps.

        public class CPMessageDrivenEJBBean
        extends AbstractJmsMessageDrivenBean


        {
        //ClaimProcessing claimProcessingService;
        public void onMessage(Message message) {
        System.out.println("inside MDB: "+message);
        TextMessage textMessage = (TextMessage)message;
        try {
        String messageString = textMessage.getText();
        System.out.println("Eating the message:n"+messageString);
        JAXBMarshalUnMarshalUtility jaxbUtility = new JAXBMarshalUnMarshalUtility();
        JAXBContext jc = JAXBContext.newInstance("com.mycompany.healthinsur ance.cp.message");
        ClaimMessage claimMessage = (ClaimMessage)jaxbUtility.unmarshalFromString(jc,m essageString);
        System.out.println("object after unmarshalling in the MDB is: "+claimMessage);
        //boolean status = claimProcessingService.processClaimLinesPerMember( claimMessage);
        // Trigger the Spring Batch Claim Processing steps

        } catch (Exception e) {
        System.out.println("Exception is Gaurav : "+e);
        e.printStackTrace();
        }
        }

        protected void onEjbCreate() {
        //claimProcessingService = (ClaimProcessing)getBeanFactory().getBean("claimPr ocessing");
        // Create the spring batch job launcher
        }
        }

        Comment


        • #5
          Right, I get it. That's a bit more complicated than my use case (which is the same as other people seem to be implementing http://forum.springframework.org/showthread.php?t=52617).

          What you have is a Job with a Step that has processing split over multiple processes connected by JMS. In that case you need to get the message back from the processing thread to the dispatcher to say that it succeeded or failed. If you can't do that asynchronously there is no benefit at all to splitting the processing. But if it is asynchronous you also need some special logic in the dispatcher to accept the responses and make sure that failures are detected and all the statistics for the job as a whole are accurate.

          These problems are not difficult to overcome, but currently you will have to do some work in the dispatcher and the processor. I am working on a simliar use case with Spring Integration,and when the features of Spring Integration catch up to what we need here that will probably appear as a sub-project in Spring Batch (we haven't decided exactly yet).

          Comment


          • #6
            Is there some way we can pass the parameter as Object (in my case ClaimMessage) to the spring steps?

            Comment


            • #7
              You can stuff it in the ExecutionContext. I'm not sure how that helps you though. If you have an object to be processed it is not naturally an input to a Step, rather it is an item, which is processed by an ItemWriter. Couldn't you re-engineer your job to make this object an item?

              Comment

              Working...
              X