camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hans Orbaan <hans.orb...@docdata.eu>
Subject RE: Manually trigger a scheduled route for testing
Date Fri, 20 May 2016 11:44:30 GMT
HI,

Using a direct and not a quartz schedule just for testing is your best option.
You could however use this to kick of a route that uses a quartz schedule: ftp://bla?cron.scheduler=quartz2
I could however not configure a triggerId on a quartz2:// route (did also not look too thoroughly
I must admit), so that might not work, and I do not know if it works during testing.
But this is how you would kick off a scheduler:

{code}

import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.Trigger;
import org.quartz.TriggerKey;

    private String trigger(Exchange exchange, String triggerId) {
        try {
            TriggerKey triggerKey = new TriggerKey(triggerId, "QuartzScheduledPollConsumerScheduler");
            Trigger trigger = this.getTrigger(exchange, triggerKey);
            JobKey jobKey = trigger.getJobKey();
            this.scheduler.triggerJob(jobKey);
            LOGGER.warn("Manually executed trigger: " + triggerId);
        } catch (Exception e) {
            LOGGER.error("Could not manually executed trigger: " + triggerId);
            return "FAIL";
        }
        return "OK";
    }

    private Trigger getTrigger(Exchange exchange, TriggerKey triggerKey) throws Exception
{
        try {
            Trigger result = this.getScheduler(exchange).getTrigger(triggerKey);
            if (null != result) {
                return result;
            }
        } catch (Exception e) {
            throw new ConfigurationException("Could not find trigger: " + triggerKey.getName(),
e);
        }
        throw new ConfigurationException("Could not find trigger: " + triggerKey.getName());
    }

    private Scheduler getScheduler(Exchange exchange) {
        if (null == this.scheduler) {
            QuartzComponent quartz = exchange.getContext().getComponent("quartz2", QuartzComponent.class);
            this.scheduler = quartz.getScheduler();
        }
        return this.scheduler;
    }
{code}



Met vriendelijke groet,
Docdata Commerce B.V.
Hans Orbaan
Developer
Docdata Commerce
Energieweg 2
5145 NW Waalwijk
t
+31 (0)416 - 674 169
m
+31 (0)6 - 469 543 23
 
 
e
hans.orbaan@docdata.eu
i
www.docdata.nl
Docdata Commerce B.V. is part of DOCDATA N.V., listed at the NYSE Euronext Amsterdam (ticker
symbol DOCD).
All information contained within this e-mail, including any attachments, is confidential.
If you have received this e-mail in error, please delete it immediately and remove the attachments
from your system. Do not use, disclose or spread the information in any way and notify the
sender immediately. Any views and opinions expressed in this e-mail may not represent those
of Docdata.

-----Oorspronkelijk bericht-----
Van: henricao [mailto:henrique.limao@outlook.com] 
Verzonden: Friday 20 May 2016 12:11
Aan: users@camel.apache.org
Onderwerp: Re: Manually trigger a scheduled route for testing

Hi Claus,

  First of all, thanks for the response.

  I'm afraid the advice option won't work for me, since the original from part is part of
the scope of my test.  And to clarify, it is not really a unit test, but more of a integration
test.

  The property place holder however works for me and I started using a similar approach before
your answer (concatenating the cron expression instead of a proper placeholder, but the same
principle).

  Ideally, my idea was to have something like this:

  from("direct: realroute").from("fille...").to("sftp:...") 

  from("quartz2:...").to("direct: realroute") //the real scheduled route used in production

  from("http:...").to("direct: realroute") // a http entrypoint that you could trigger from
the test or manually runs

  I googled about this and couldn't find any evidence that this could work.
It seems that: 
  - the file component has a internal scheduler than can be disabled
  - I can't have a route with two from parts (like the real route above)

  Are these assumptions correct?

  I will use the property placeholder solution if I can't implement this idea, but I can see
this last approach providing some extra benefits that I really would like to have.

Thanks again for the support,
Henrique

  



--
View this message in context: http://camel.465427.n5.nabble.com/Manually-trigger-a-scheduled-route-for-testing-tp5782791p5782822.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message