info@yenlo.com
eng
Menu
Enterprise Integration 7 min

Working with Tasks on the Enterprise Integrator 6.6.0

Rob Blaauboer
Rob Blaauboer
Integration Consultant & WSO2 Trainer
enterprise integrator

WSO2 Enterprise Integrator has a task implementation that allows you to schedule repetitive or regular CRON based tasks. But how does this work? Especially with CRON, because for many, these combinations of question marks and dashes can be a little daunting to comprehend.

As part of this exercise, I’ve created a very simple sequence that we can use with a number of sample task setups. This will help showcase to you, the versatility of tasks in Enterprise Integrator 6.6.0.

Custom Task Implementations

Integrator provides a mechanism to introduce your own custom task implementations. That means you’re extending the WSO2 Enterprise Integrator’s task implementation with a custom Java program. This allows you even more flexibility beyond the realm of sequences and proxy-based tasks.

One example would be that in the Netherlands, every first Monday of the month at noon, we test the sirens that are used in case of emergency.

That could be possible with a custom Java extension allowing you to define what needs to be done in this case, sending signals to other systems. However, we will not go into that since that is a very specific use case.

Repetitive tasks

But let’s start with the two possibilities that we have with regards to scheduling tasks. The first one is the simplest: a repetitive task with an interval. Such a task will simply execute an action the number of times you specify, with the interval which you can also define, in seconds.

How to set this up in Integration Studio is as follows;

sheduled task artifect

Once set-up, the task will look like below;

sheduled task

So, if you want to send a message to a system or run a routine query, you can do so by simply specifying the number of iterations and the interval. There is one exception. However, if you schedule something to be executed only once, this means that it is actually done at startup. So a scheduled task with count as one will only be executed at system startup/restarts.

DadJokeAPI

So let’s take a look at how that works for the sequence. I’m using a very nice API. That will give you a so called Dad joke. These jokes can sometimes be very funny, and are not at all offensive in any way. It’s mostly wordplay. I’ve created the DadJokeSequence to call the API. The joke is contained in the field labelled joke, in the incoming JSON response payload.

The sequence is as below:

sequence

And the source code:

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="DadJokeSequence" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <header name="Accept" scope="transport" value="application/json"/>
    <call>
        <endpoint>
            <http method="get" uri-template="https://icanhazdadjoke.com/">
                <suspendOnFailure>
                    <initialDuration>-1</initialDuration>
                    <progressionFactor>-1</progressionFactor>
                    <maximumDuration>0</maximumDuration>
                </suspendOnFailure>
                <markForSuspension>
                    <retriesBeforeSuspension>0</retriesBeforeSuspension>
                </markForSuspension>
            </http>
        </endpoint>
    </call>
    <log level="custom">
        <property expression="json-eval($.joke)" name="Today's Super Funny Dad Joke brought to you by Yenlo"/>
    </log>
</sequence>

So let’s use that. And try to see if we can get 5 of these Dad jokes with an interval of five seconds on our console.

[2021-09-27 13:30:44,070]  INFO {org.apache.synapse.mediators.builtin.LogMediator} - Today's Super Funny Dad Joke brought to you by Yenlo = Why was Pavlov's beard so soft?  Because he conditioned it.
[2021-09-27 13:30:49,032]  INFO {org.apache.synapse.mediators.builtin.LogMediator} - Today's Super Funny Dad Joke brought to you by Yenlo = Ever wondered why bees hum? It's because they don't know the words.
[2021-09-27 13:30:54,037]  INFO {org.apache.synapse.mediators.builtin.LogMediator} - Today's Super Funny Dad Joke brought to you by Yenlo = Every machine in the coin factory broke down all of a sudden without explanation. It just doesn’t make any cents.
[2021-09-27 13:30:59,032]  INFO {org.apache.synapse.mediators.builtin.LogMediator} - Today's Super Funny Dad Joke brought to you by Yenlo = Cosmetic surgery used to be such a taboo subject.
Now you can talk about Botox and nobody raises an eyebrow.
[2021-09-27 13:31:04,032]  INFO {org.apache.synapse.mediators.builtin.LogMediator} - Today's Super Funny Dad Joke brought to you by Yenlo = Chances are if you' ve seen one shopping center, you've seen a mall.

As you can see, that was kind of easy. In the next example, I’ve made it that it schedules only once at startup.

trigger informatiion

And as you can see, from the below snippets that was copied from the console at startup, the dad joke is displayed. You can, you can manually schedule a task like that as well. You can open up the task implementation using your management UI, and manually schedule it. The strange thing is that it shows interval 0 in Integration Studio but 1 in Management UI.

triggertask
[2021-09-27 13:43:56,114]  INFO {org.apache.synapse.mediators.builtin.LogMediator} - Today's Super Funny Dad Joke brought to you by Yenlo = Why did the cookie cry?
Because his mother was a wafer so long

CRON

The EI Schedule Task implementation are based on Quartz Scheduler. A cron expression in Quartz is a string comprising of 6 or 7 fields separated by white space. There is a nice tutorial, online.

triggertype

This task will be executed every two minutes of every hour of day and year.

[2021-09-27 14:44:00,248]  INFO {org.apache.synapse.mediators.builtin.LogMediator} - Today's Super Funny Dad Joke brought to you by Yenlo = I gave all my dead batteries away today, free of charge.
[2021-09-27 14:46:00,177]  INFO {org.apache.synapse.mediators.builtin.LogMediator} - Today's Super Funny Dad Joke brought to you by Yenlo = What is a centipedes's favorite Beatle song?  I want to hold your hand, hand, hand, hand...

Each field can contain any of the allowed values, along with various combinations of the allowed special characters for said field. The fields are as follows:

Field NameMandatoryAllowed ValuesAllowed Special Characters
SecondsYES0-59, – * /
MinutesYES0-59, – * /
HoursYES0-23, – * /
Day of monthYES1-31, – * ? / L W
MonthYES1-12 of JAN-DEC, – * /
Day of weekYES1-7 of SUN-SAT, – * ? / L #
YEARNOleeg, 1970-2099, – * /

What does these special Characters allow us to do? Well, according to the documentation:

  • (“all values”) – used to select all values within a field.
  • “?” (“no specific value”) – useful when you need to specify something in one of the two fields in which the character is allowed, but not the other.
  • “-“ used to specify ranges.
  • “,” used to specify additional values.
  • / – used to specify increments.
  • L (“last”) – has different meaning in each of the two fields in which it is allowed. For example, the value “L” in the day-of-month field means “the last day of the month” – day 31 for January, day 28 for February on non-leap years.
  • W (“weekday”) – used to specify the weekday (Monday-Friday) nearest the given day.
  • The ‘L’ and ‘W’ characters can also be combined in the day-of-month field to yield ‘LW’, which translates to *”last weekday of the month”*.
  • # – used to specify “the nth” XXX day of the month. For example, the value of “6#3” in the day-of-week field means “the third Friday of the month” (day 6 = Friday and “#3” = the 3rd one in the month).

As you can see (and I’ve shortened this above piece) there are very nice combinations that can be tried out. Reminds a bit of the idea behind RegEx. In some cases, you can actually achieve the same result with different combinations.

Some examples

This example schedules tasks for every minute.

Afbeelding1

Whereas this schedules every 10 seconds

Afbeelding2

And this one between the 10th and 12th minute of the hour. Up to 12:50.

Afbeelding3

Finally: every 10 seconds between the 33rd and 35st minute of the hour 2PM and 3PM (14-15) in September (the ninth month) of every year.

Afbeelding4

Tricky stuff

Working with Quartz Cron statements can be a bit tricky. It took me a while to figure out some of the configurations and I have not even touched the complex combinations. There are many possibilities but not all of them are easy to figure out. Trying out the configurations yourselves and deploying them will show which scenario works, and which does not (an error message will be shown on the console).

I hope I have a been able to provide a better insight into the Quartz Implementation in WSO2 Enterprise Integrator 6.6.0.

Are you Interested in Learning more about WSO2 Enterprise Integrator? Take a look at one of our trainings.

eng
Close