Thursday, December 27, 2012

Schedule Jobs using Mule Studio and Quartz, part II

In the previous blog, we discuss how to use inbound Quartz end point to trigger jobs. In this blog, we discuss how to use outbound Quartz end point to schedule jobs when some external events happen.

Below is the sample Mule flow. When someone accesses the HTTP end point, a message is put on a VM end point, which triggers Quartz Scheduler to run a job that put a message on a different VM end point, which gets picked up by Java transformer that will process it eventually.


 Pay attention to the key difference between this flow and the inbound end point flow. In the inbound end point flow, there is no message following into the inbound end point. For the outbound event, a message (VM or JMS) is necessary to trigger the job.

Double click on the outbound end point and the following window shows up,


Fill in the necessary scheduling information and click on plus sign to add a new job.



Make sure we select "quartz:schedule-dispatch-job".


Make sure "Group Name:", "Job Group Name:", and "Address:" are not filled in at all. If they are filled in, one will get some weird error that can't be made any sense of. I wish Mule Studio can be more helpful but it doesn't. I finally resolved this issue after spending hours searching and googling.

That's it. Now execute the flow and access the HTTP end point. You will see our Java transformer gets executed twice after initial delay of 15 seconds.

8 comments:

  1. screens are useful but at the end if the generated xml was shown that would help.

    ReplyDelete
  2. Hi Lei,

    Thanks very much for the great posting - you're right, the documentation on this is not very good.

    I've set up something very similar to what you've described, but I'm having one problem. When I access the HTTP end point, everything seems to work as expected, i.e. the message doesn't get processed by the final flow until the schedule gets triggered. The problem is that if I then do nothing else, and wait until the schedule gets triggered again, the same message gets processed again! It looks like it will continue to do this forever. It's almost like the message is not being removed from one of the VM queues.

    Any idea what might be causing this? The only difference I can see from your example and mine is that I'm using a Cron expression in the scheduler instead of a repeat interval.

    Thanks

    ReplyDelete
    Replies
    1. Update: I switched to using a repeat interval, and now I get the same behaviour as you - the message gets processed twice.

      Question: Why does the final flow get executed twice instead of just once?

      Question: How can I get this to work with a Cron expression, and execute the final flow only once?

      Delete
    2. Hi Morley,
      I will need to do some research and get back to you this week. Please post any updates or progress.
      Thanks for the feedback.
      -- Lei

      Delete
    3. Hi Morley,

      1. The message is processed exactly twice because repeat count is set to 1.

      2. I got the cron expression 0/5 * * * * ? to work so the messages are repeated every five seconds.

      Good luck.

      Delete
    4. I think you need to specify your cron expression to be a precise date like exactly 2pm, Feb. 23, 2013 and it will be executed once and only once. Of course you need to build the cron expression from some message properties or you need a java component to calculate exactly when the trigger should fire.
      Good luck.

      Delete
    5. Hi Lei,

      I set the repeat count to 0 and set the repeat interval to 1 minute, and everything works as expected.

      However if I remove the 1 minute repeat interval and instead use a Cron expression that triggers once every minute, like e.g. '0 * * * * ?', some strange things happen. I keep getting the same message delivered over and over every minute. I believe this might be an example of this bug: http://www.mulesoft.org/jira/browse/MULE-6386. :-(

      Morley

      Delete
  3. Really cool post, highly informative and professionally written and I am glad to be a visitor of this perfect blog, thank you for this rare info! , Regards, mulesoft training in hyderabad

    ReplyDelete