protected <T extends ProcessorDefinition> T addInterimProc(T route) { if (interimProc != null) { route.process(interimProc); } return route; } }
public static ProcessorDefinition<?> process(ProcessorDefinition<?> self, Closure<?> processorLogic) { return self.process(toProcessor(processorLogic)); }
@Override public void configure() throws Exception { weaveAddFirst() .process(exchange -> { for(Map.Entry<String, Object> entry : properties.entrySet()) { exchange.setProperty(entry.getKey(), entry.getValue()); } exchange.getIn().setBody(body); }); } });
@Override public Optional<ProcessorDefinition<?>> configure(CamelContext context, ProcessorDefinition<?> definition, Map<String, Object> parameters) { ProcessorDefinition<?> processor = definition.process(exchange -> { count++; if( count == 2 ) { throw new IOException("Bean Error"); } }); return Optional.of(processor); } }
@Override public void configure() throws Exception { weaveById(processorId).replace().process(newProcessor); } });
protected <T extends ProcessorDefinition> T addInterimRoute(T route) { if (getInterimProcessor() != null) { route.process(getInterimProcessor()); } return route; }
/** * Replaces calling TO {@link AsynchConstants#URI_ASYNCH_IN_MSG} with processor that creates OK response. * <p> * Useful when you want to test input (IN) route of asynchronous process. * * @param builder the advice builder */ public static void replaceToAsynch(AdviceWithRouteBuilder builder) { // remove AsynchInMessageRoute.URI_ASYNCH_IN_MSG builder.weaveByType(ToDefinition.class).replace().process(new Processor() { @Override public void process(Exchange exchange) throws Exception { // creates OK response CallbackResponse callbackResponse = new CallbackResponse(); callbackResponse.setStatus(ConfirmationTypes.OK); exchange.getIn().setBody(callbackResponse); } }); }
@Override public Optional<ProcessorDefinition> configure(CamelContext context, ProcessorDefinition definition, Map<String, Object> parameters) { ProcessorDefinition processor = definition.process(exchange -> { exchange.getIn().setBody( String.join( "-", exchange.getIn().getBody(String.class), exchange.getIn().getHeader("ExtensionHeader", String.class), message) ); }); return Optional.of(processor); } }
@Override public void configure() throws Exception { LOG.debug("Started REST data stream source at port {}.", port); from("netty4-http:http://0.0.0.0:" + port + "/?matchOnUriPrefix=true&httpMethodRestrict=OPTIONS,GET,POST,PUT,DELETE"). choice(). when(header(HTTP_METHOD).isEqualTo("OPTIONS")).setBody().constant("").endChoice(). otherwise(). setHeader(CONTENT_TYPE).constant(contentType). process( exc -> { String requestUri = exc.getIn().getHeader(HTTP_URI, String.class); LOG.debug("Processing request URI: {}", requestUri); String trimmedUri = removeEnd(requestUri, "/"); LOG.debug("Trimmed request URI: {}", trimmedUri); String busChannel = trimmedUri.substring(1).replaceAll("\\/", "."); exc.setProperty("target", "amqp:" + busChannel); }).toD("${property.target}").endChoice(). end(). process(exc -> { exc.getIn().setHeader("Access-Control-Allow-Origin", "*"); exc.getIn().setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); }); }
public void configure() { from("file:data/inbox?noop=true") .unmarshal() .json(JsonLibrary.Gson) .process(exchange -> { System.out.format(" %s%n", exchange.getIn().getBody()); }) .filter(body().convertToString().contains("uke")) .marshal() .json(JsonLibrary.Gson) .to("file:data/outbox"); } });
@Override public void configure() throws Exception { // 这个线程池用来进行multicast中各个路由线路的并发执行 ExecutorService executorService = Executors.newFixedThreadPool(10); MulticastDefinition multicastDefinition = from("jetty:http://0.0.0.0:8282/multicastCamel").multicast(); // multicast 中的消息路由可以顺序执行也可以并发执行 // 这里我们演示并发执行 multicastDefinition.setParallelProcessing(true); // 为并发执行设置一个独立的线程池 multicastDefinition.setExecutorService(executorService); // 注意,multicast中各路由路径的Excahnge都是基于上一路由元素的excahnge复制而来 // 无论前者Excahnge中的Pattern如何设置,其处理结果都不会反映在最初的Excahnge对象中 multicastDefinition.to("log:helloworld1?showExchangeId=true", "log:helloworld2?showExchangeId=true") // 一定要使用end,否则OtherProcessor会被做为multicast中的一个分支路由 .end() // 所以您在OtherProcessor中看到的Excahnge中的Body、Header等属性内容 // 不会有“复制的Exchange”设置的任何值的痕迹 .process(new OtherProcessor()); }
@Override public void configure() throws Exception { from("xds-iti41:continuaHRNService") .onException(Exception.class) .maximumRedeliveries(0) .end() .process(ContinuaHrnCamelProcessors.continuaHrnRequestTransformerAndValidator()) .process(CHECK_PROCESSOR) .setBody(constant(new Response(Status.SUCCESS))) .process(ContinuaHrnCamelProcessors.continuaHrnResponseValidator()); }
public void configure() { logger.info("configure", null, "Configuring Admin Channel on Endpoint:" + endpoint); onException(Exception.class).handled(true).process(new ErrorProcessor()); from(endpoint).routeId("AdminRoute").unmarshal().xstream() .process(new AdminEventProcessor(delegate)); } });
/** * Creates route definition applicable for actual camel binding model. * * @return Route definition handling given binding. */ protected RouteDefinition createRouteDefinition() { final RouteDefinition route = new RouteDefinition(); route.routeId(getRouteId()).from(getComponentUri().toString()); addTransactionPolicy(route); addNamespacePolicy(route); route.setProperty(ExchangeCompletionEvent.GATEWAY_NAME).simple(getBindingModel().getName(), String.class) .setProperty(CamelConstants.APPLICATION_NAMESPACE).constant(_serviceName.getNamespaceURI()) .process(new MessageComposerProcessor(getBindingModel())) .process(new OperationSelectorProcessor(getServiceName(), getBindingModel())) .to(getSwitchyardEndpointUri()); return route; }
/** * Creates route definition applicable for actual camel binding model. * * @return Route definition handling given binding. */ protected RouteDefinition createRouteDefinition() { final RouteDefinition route = new RouteDefinition(); route.routeId(getRouteId()).from(getComponentUri().toString()); addTransactionPolicy(route); addNamespacePolicy(route); route.setProperty(ExchangeCompletionEvent.GATEWAY_NAME).simple(getBindingModel().getName(), String.class) .setProperty(CamelConstants.APPLICATION_NAMESPACE).constant(_serviceName.getNamespaceURI()) .process(new MessageComposerProcessor(getBindingModel())) .process(new OperationSelectorProcessor(getServiceName(), getBindingModel())) .to(getSwitchyardEndpointUri()); return route; }
.setProperty(ExchangeCompletionEvent.GATEWAY_NAME).simple(getBindingModel().getName(), String.class) .setProperty(CamelConstants.APPLICATION_NAMESPACE).constant(getServiceName().getNamespaceURI()) .process(new MessageComposerProcessor(getBindingModel())) .process(new OperationSelectorProcessor(getServiceName(), getBindingModel())) .to(getSwitchyardEndpointUri())
/** * Let's configure the Camel routing rules using Java code... */ public void configure() { // START SNIPPET: dsl-2 from("jms:queue:loan") // let the credit agency do the first work .process(new CreditAgencyProcessor()) // send the request to the three banks .multicast(new BankResponseAggregationStrategy()).parallelProcessing() .to("jms:queue:bank1", "jms:queue:bank2", "jms:queue:bank3") .end() // and prepare the reply message .process(new ReplyProcessor()); // Each bank processor will process the message and put the response message back from("jms:queue:bank1").process(new BankProcessor("bank1")); from("jms:queue:bank2").process(new BankProcessor("bank2")); from("jms:queue:bank3").process(new BankProcessor("bank3")); // END SNIPPET: dsl-2 }
@Override public void configure() throws Exception { from("direct:input") // Enable the following statement if error handling // has been globally turned off via noErrorHandler(), // otherwise exception() statements have no effect. //.errorHandler(deadLetterChannel()) .onException(Exception1.class).to("mock:error1").end() .onException(Exception2.class).to("mock:error2").end() .onException(Exception.class).to("mock:error3").end() .process(exceptionProcessor()) .to("mock:success"); }
@Override public void configure() { from("direct:start") .id("start") .routePolicy(new ActivityTrackingPolicy(activityTracker)) .split() .body() .process(OutMessageCaptureProcessor.INSTANCE) .pipeline() .id("log") .log(LoggingLevel.INFO, "log", "log", "hi") .process(OutMessageCaptureProcessor.INSTANCE) .end() .pipeline() .id("rnderr") .process().body(String.class, body -> { if ("error".equals(body)) { throw new RuntimeException("Bean Error"); } }) .process(OutMessageCaptureProcessor.INSTANCE) .end() .pipeline() .id("end") .to("mock:end") .process(OutMessageCaptureProcessor.INSTANCE) .end() .end(); } });