@Override public Object call() throws Exception { context.startRoute(routeId); return null; } }, getClassLoader(context));
/** * Start the route by id */ public static void gracefullyStartRoute(CamelContext camelContext, String id) throws Exception { //NOSONAR if (camelContext.getRoute(id) != null) { LOGGER.info("Gracefully starting route " + id); try { camelContext.startRoute(id); } catch (Exception e) { LOGGER.error("Failed to start route: " + id, e); } } }
@Override public void doExecute(TestContext context) { for (String routeId : routeIds) { String route = context.replaceDynamicContentInString(routeId); try { camelContext.startRoute(route); log.info(String.format("Started Camel route '%s' on context '%s'", route, camelContext.getName())); } catch (Exception e) { throw new CitrusRuntimeException("Failed to start Camel route: " + route, e); } } } }
@Override public void process(Exchange exchange) throws Exception { InputStream bodyStream = exchange.getIn().getBody(InputStream.class); String bodyStr = IOUtils.toString(bodyStream, "UTF-8"); LOGGER.info("bodyStr : {}", new Object[]{bodyStr}); PersonDTO personDTO = CommonUtils.toJavaObject(bodyStr, PersonDTO.class); if ("0".equals(personDTO.getSlaveFlag())) { //停止'test-route-control-03'路由 camelContext.stopRoute("test-route-control-03"); LOGGER.info("===== 停止 routeID:test-route-control-03 ====="); } else if ("1".equals(personDTO.getSlaveFlag())) { //启动'test-route-control-03'路由 camelContext.startRoute("test-route-control-03"); LOGGER.info("===== 启动 routeID:test-route-control-03 ====="); } else if ("2".equals(personDTO.getSlaveFlag())) { //暂停'test-route-control-03'路由 camelContext.suspendRoute("test-route-control-03"); LOGGER.info("===== 暂停 routeID:test-route-control-03 ====="); //设置暂停时间 //camelContext.suspendRoute("",3600, TimeUnit.SECONDS); } if (exchange.getPattern() == ExchangePattern.InOut) { Message outMessage = exchange.getOut(); outMessage.setBody("消息收到" + "-已处理-00"); } } });
@Handler public void orderSomeBooks() throws Exception { log.info("-------------------------------------------------------------------------------------------------------------------------"); log.info("Make sure to have Postgres database up and running, as configured in the src/test/resources/META-INF/persistence.xml file"); log.info("-------------------------------------------------------------------------------------------------------------------------"); BookOrder order = new BookOrder(); order.setAmount(1); order.setTitle("Camel in Action 2nd ed"); template.sendBody("jpa:camelinaction.BookOrder", order); Thread.sleep(5000); log.info("... sleeping for 5 seconds and then stopping the route"); // now stop the route context.stopRoute("books"); // insert a new order which will sit in the database BookOrder order2 = new BookOrder(); order2.setAmount(3); order2.setTitle("ActiveMQ in Action"); template.sendBody("jpa:camelinaction.BookOrder", order2); log.info("-------------------------------------------------------------------------------------------------------------------------"); log.info("Now we want to provoke a connection error, so stop the postgres database - and then press ENTER to continue!"); log.info("-------------------------------------------------------------------------------------------------------------------------"); System.console().readLine(); context.startRoute("books"); log.info("... starting route which should indicate some errors, which the bridge error handler should catch and handle"); log.info("Notice that the consumer will backoff and not poll so fast, instead of every second, it now runs x10 sec."); log.info("Press CTRL+C to exit this application!"); }
public String startRoute(@PathVariable String routeId) { try { camelContext.startRoute(routeId); if (LOG.isDebugEnabled()) { LOG.debug("camel context is starting route [" + routeId + "]");
context.startRoute(route.getId()); logger.info("start",null, "---OR Route in Camel Context-"+route.getEndpoint().getEndpointUri()+" Route State:"+context.getRouteStatus(route.getId()));