public void configure() throws Exception { errorHandler(deadLetterChannel("seda:errors")); // We pool the atom feeds from the source for further processing in the seda queue // we set the delay to 1 second for each pool. // Using splitEntries=true will during polling only fetch one RSS Entry at any given time. from("rss:" + VERTX_BLOG_ATOM + "?splitEntries=true&consumer.delay=100").to("seda:feeds"); from("seda:feeds") // Filter .filter().method("filterService", "isRelease") // Transform (extract) .transform(simple("${body.entries[0].title}")) // Output .to("seda:announce"); } };
@Override public void configure() throws Exception { final String kafkaUri = kafkaConnectionInformation.kafkaUri(); from("direct:start").process(new Processor() { @Override public void process(Exchange exchange) throws Exception { final INDArray arr = (INDArray) exchange.getIn().getBody(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); Nd4j.write(arr, dos); byte[] bytes = bos.toByteArray(); String base64 = Base64.encodeBase64String(bytes); exchange.getIn().setBody(base64, String.class); String id = UUID.randomUUID().toString(); exchange.getIn().setHeader(KafkaConstants.KEY, id); exchange.getIn().setHeader(KafkaConstants.PARTITION_KEY, id); } }).to(kafkaUri); from(kafkaUri).process(new Processor() { @Override public void process(Exchange exchange) throws Exception { byte[] body2 = (byte[]) exchange.getIn().getBody(); String body = new String(body2); INDArray arr = Nd4jBase64.fromBase64(body); exchange.getIn().setBody(arr); } }).to("direct:receive"); } }
@Override public void configure() throws Exception { // read files from the shared directory from("file:target/inbox" + "?delete=true") // setup route policy to be used .routePolicyRef("myPolicy") .log(name + " - Received file: ${file:name}") .delay(delay) .log(name + " - Done file: ${file:name}") .to("file:target/outbox"); }
@Override public void configure() throws Exception { from("seda:orders").id("legacyRoute") .throttle(5).timePeriodMillis(10000).asyncDelayed().id("orderThrottler") .to("seda:legacy"); } }
context.getShutdownStrategy().setTimeout(getShutdownTimeout()); if (context.getStatus().equals(ServiceStatus.Started)) { log.info("Cannot setting the Debugger to the starting CamelContext, stop the CamelContext now."); context.stop(); context.setDebugger(new DefaultDebugger()); context.getDebugger().addBreakpoint(breakpoint); template = context.createProducerTemplate(); template.start(); fluentTemplate = context.createFluentProducerTemplate(); fluentTemplate.start(); consumer = context.createConsumerTemplate(); consumer.start(); context.addRegisterEndpointCallback(new InterceptSendToMockEndpointStrategy(pattern)); context.addRegisterEndpointCallback(new InterceptSendToMockEndpointStrategy(pattern, true)); PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); Properties extra = useOverridePropertiesWithPropertiesComponent(); if (extra != null && !extra.isEmpty()) { for (RoutesBuilder builder : builders) { log.debug("Using created route builder: " + builder); context.addRoutes(builder);
protected Endpoint getMandatoryEndpoint(String uri) { Endpoint endpoint = context.getEndpoint(uri); assertNotNull("No endpoint found for uri: " + uri, endpoint); return endpoint; }
private void replaceFromEndpoints() throws Exception { for (final Map.Entry<String, String> entry : fromEndpoints.entrySet()) { context.getRouteDefinition(entry.getKey()).adviceWith(context, new AdviceWithRouteBuilder() { @Override public void configure() throws Exception { replaceFromWith(entry.getValue()); } }); } }
protected void startCamelContext() throws Exception { if (camelContextService != null) { camelContextService.start(); } else { if (context instanceof DefaultCamelContext) { DefaultCamelContext defaultCamelContext = (DefaultCamelContext)context; if (!defaultCamelContext.isStarted()) { defaultCamelContext.start(); } } else { context.start(); } } }
routesSummary.append("\tProcessor coverage\n"); MBeanServer server = context.getManagementStrategy().getManagementAgent().getMBeanServer(); for (Route route : context.getRoutes()) { ManagedRouteMBean managedRoute = context.getManagedRoute(route.getId(), ManagedRouteMBean.class); if (managedRoute.getExchangesTotal() == 0) { uncoveredRoutes.add(route.getId());
/** * Asserts that the language name can be resolved */ protected Language assertResolveLanguage(String languageName) { Language language = context.resolveLanguage(languageName); assertNotNull("No language found for name: " + languageName, language); return language; }
/** * Groups all processors from Camel context by route id */ private Map<String, List<ManagedProcessorMBean>> findProcessorsForEachRoute(MBeanServer server) throws MalformedObjectNameException, MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException { String domain = context.getManagementStrategy().getManagementAgent().getMBeanServerDefaultDomain(); Map<String, List<ManagedProcessorMBean>> processorsForRoute = new HashMap<>(); ObjectName processorsObjectName = new ObjectName(domain + ":context=" + context.getManagementName() + ",type=processors,name=*"); Set<ObjectName> objectNames = server.queryNames(processorsObjectName, null); for (ObjectName objectName : objectNames) { String routeId = server.getAttribute(objectName, "RouteId").toString(); String name = objectName.getKeyProperty("name"); name = ObjectName.unquote(name); ManagedProcessorMBean managedProcessor = context.getManagedProcessor(name, ManagedProcessorMBean.class); if (managedProcessor != null) { if (processorsForRoute.get(routeId) == null) { List<ManagedProcessorMBean> processorsList = new ArrayList<>(); processorsList.add(managedProcessor); processorsForRoute.put(routeId, processorsList); } else { processorsForRoute.get(routeId).add(managedProcessor); } } } // sort processors by position in route definition for (Map.Entry<String, List<ManagedProcessorMBean>> entry : processorsForRoute.entrySet()) { Collections.sort(entry.getValue(), Comparator.comparing(ManagedProcessorMBean::getIndex)); } return processorsForRoute; }
ErrorHandlerBuilder builder = (ErrorHandlerBuilder)routeContext.getRoute().getErrorHandlerBuilder(); routeContext.getRoute().setErrorHandlerBuilder(txBuilder);
/** * Resolves the {@link MockEndpoint} using a URI of the form <code>mock:someName</code>, optionally * creating it if it does not exist. * * @param uri the URI which typically starts with "mock:" and has some name * @param create whether or not to allow the endpoint to be created if it doesn't exist * @return the mock endpoint or an {@link NoSuchEndpointException} is thrown if it could not be resolved * @throws NoSuchEndpointException is the mock endpoint does not exists */ protected MockEndpoint getMockEndpoint(String uri, boolean create) throws NoSuchEndpointException { if (create) { return resolveMandatoryEndpoint(uri, MockEndpoint.class); } else { Endpoint endpoint = context.hasEndpoint(uri); if (endpoint instanceof MockEndpoint) { return (MockEndpoint) endpoint; } throw new NoSuchEndpointException(String.format("MockEndpoint %s does not exist.", uri)); } }
String name = className + "-" + getTestMethodName() + ".xml"; ManagedCamelContextMBean managedCamelContext = context != null ? context.getManagedCamelContext() : null; if (managedCamelContext == null) { log.warn("Cannot dump route coverage to file as JMX is not enabled. Override useJmx() method to enable JMX in the unit test classes.");
@Override public void configure() throws Exception { // read files from the shared directory from("file:target/inbox" + "?delete=true") // setup route policy to be used .routePolicyRef("myPolicy") .log(name + " - Received file: ${file:name}") .delay(delay) .log(name + " - Done file: ${file:name}") .to("file:target/outbox"); }
protected <T extends Endpoint> T getMandatoryEndpoint(String uri, Class<T> type) { T endpoint = context.getEndpoint(uri, type); assertNotNull("No endpoint found for uri: " + uri, endpoint); return endpoint; }
private void weaveRoute(String id, Consumer<AdviceWithRouteBuilder> consumer) throws Exception { camelContext.getRouteDefinition(id) .adviceWith(camelContext, new AdviceWithRouteBuilder() { @Override public void configure() { consumer.accept(this); } }); }