@Test public void testScheduledResumeRoutePolicy() throws Exception { MockEndpoint success = context.getEndpoint("mock:success", MockEndpoint.class); success.expectedMessageCount(1); context .getComponent("quartz2", QuartzComponent.class) .setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties"); context.addRoutes( new RouteBuilder() { public void configure() { CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy(); policy.setRouteResumeTime("*/3 * * * * ?"); from("direct:start").routeId("test").routePolicy(policy).to("mock:success"); } }); context.start(); ServiceHelper.suspendService(context.getRoute("test").getConsumer()); Thread.sleep(5000); assertTrue(context.getRouteStatus("test") == ServiceStatus.Started); template.sendBody("direct:start", "Ready or not, Here, I come"); success.assertIsSatisfied(); }
@Override public void afterPoll() throws Exception { LOG.trace("After poll {}", getEndpoint()); // suspend or stop our self if (!ServiceHelper.suspendService(this)) { ServiceHelper.stopService(this); } }
/** * The consumer is to be suspended because it exceeded the limit * * @param consumer the consumer * @param endpoint the endpoint * @throws Exception is thrown if error suspending the consumer */ protected void onSuspend(Consumer consumer, Endpoint endpoint) throws Exception { log.warn( "Suspending consumer " + consumer + " after " + limit + " attempts to consume from " + endpoint + ". You have to manually resume the consumer!"); ServiceHelper.suspendService(consumer); }
@Test public void testScheduledResumeRoutePolicy() throws Exception { MockEndpoint success = (MockEndpoint) context.getEndpoint("mock:success"); success.expectedMessageCount(1); context .getComponent("quartz", QuartzComponent.class) .setPropertiesFile("org/apache/camel/routepolicy/quartz/myquartz.properties"); context.getComponent("quartz", QuartzComponent.class).start(); context.addRoutes( new RouteBuilder() { public void configure() { SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy(); long startTime = System.currentTimeMillis() + 3000L; policy.setRouteResumeDate(new Date(startTime)); policy.setRouteResumeRepeatCount(1); policy.setRouteResumeRepeatInterval(3000); from("direct:start").routeId("test").routePolicy(policy).to("mock:success"); } }); context.start(); ServiceHelper.suspendService(context.getRoute("test").getConsumer()); try { template.sendBody("direct:start", "Ready or not, Here, I come"); } catch (CamelExecutionException e) { LOG.debug("Consumer successfully suspended"); } Thread.sleep(4000); template.sendBody("direct:start", "Ready or not, Here, I come"); context.getComponent("quartz", QuartzComponent.class).stop(); success.assertIsSatisfied(); }