private static void routes(final Configurer<RouteBuilder> callback, final DefaultCamelContext ctx, final Config config) throws Exception { ctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { callback.configure(this, config); } }); }
@Inject public CamelFinalizer(final GuiceInjector injector, final DefaultCamelContext ctx, final @Named("camel.routes") Set<Object> routes, final RouteBuilder rb, final ProducerTemplate producer, final ConsumerTemplate consumer) throws Exception { this.ctx = ctx; this.producer = producer; this.consumer = consumer; this.ctx.setInjector(injector); for (Object route : routes) { if (route instanceof RoutesBuilder) { this.ctx.addRoutes((RoutesBuilder) route); } } this.ctx.addRoutes(rb); }
/** * Program entry point */ public static void main(String[] args) throws Exception { CamelContext context = new DefaultCamelContext(); context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("stream:in").to("direct:greetings"); from("direct:greetings").to("stream:out"); } }); context.start(); context.getRoutes().forEach(r -> LOGGER.info(r.toString())); context.stop(); } }
@Override public void start() throws Exception { vertx.eventBus().consumer("announce", message -> { System.out.println("ANNOUNCE >> " + message.body()); }); vertx.eventBus().consumer("errors", message -> { System.out.println("ERROR >> " + message.body()); }); SimpleRegistry registry = new SimpleRegistry(); registry.put("filterService", new ReleasePostFilter()); CamelContext camelContext = new DefaultCamelContext(registry); camelContext.addRoutes(createMyRoutes()); camelContext.start(); CamelBridge.create(vertx, new CamelBridgeOptions(camelContext) .addInboundMapping(fromCamel("seda:announce").toVertx("announce")) .addInboundMapping(fromCamel("seda:errors").toVertx("errors"))) .start(); }
@Override public void configure(final Env env, final Config config, final Binder binder) throws Throwable { Config $camel = config.getConfig("camel"); DefaultCamelContext ctx = configure(new DefaultCamelContext(), $camel .withoutPath("shutdown") .withoutPath("threads") ctx.disableJMX(); ctx.getExecutorServiceManager().setDefaultThreadPoolProfile(threadPool); configure(ctx.getShutdownStrategy(), $camel.getConfig("shutdown")); ctx.setStreamCaching(true); configure(ctx.getStreamCachingStrategy(), $camel.getConfig("streamCaching")); } else { ctx.setStreamCaching(false); properties.setPrefixToken("${"); properties.setSuffixToken("}"); ctx.addComponent("properties", properties); binder.bind(ProducerTemplate.class).toInstance(ctx.createProducerTemplate()); binder.bind(FluentProducerTemplate.class).toInstance(ctx.createFluentProducerTemplate()); binder.bind(ConsumerTemplate.class).toInstance(ctx.createConsumerTemplate());
@Override protected void doStart() throws Exception { super.doStart(); endpoint.consumerStarted(this); }
@Override protected void doStop() throws Exception { endpoint.consumerStopped(this); super.doStop(); } }
/** * A factory method to create an Exchange implementation */ protected Exchange createExchange() { return new DefaultExchange(context); }
@Override public EventComponent getComponent() { return (EventComponent) super.getComponent(); }
@Override protected void doStop() throws Exception { endpoints.clear(); super.doStop(); } }
@PostConstruct public void start() throws Exception { this.ctx.start(); this.producer.start(); this.consumer.start(); }
@PreDestroy public void stop() throws Exception { try { this.consumer.stop(); } catch (Exception ex) { log.error("Can't stop consumer template", ex); } try { this.producer.stop(); } catch (Exception ex) { log.error("Can't stop producer template", ex); } try { this.ctx.stop(); } catch (Exception ex) { log.error("Can't stop camel context template", ex); } }
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { try { return delegate.postProcessBeforeInitialization(bean, beanName); } catch (Exception e) { // do not wrap already beans exceptions if (e instanceof BeansException) { throw (BeansException) e; } throw new GenericBeansException("Error post processing bean: " + beanName, e); } }
protected JndiRegistry createRegistry() throws Exception { return new JndiRegistry(createJndiContext()); }
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { try { return delegate.postProcessAfterInitialization(bean, beanName); } catch (Exception e) { // do not wrap already beans exceptions if (e instanceof BeansException) { throw (BeansException) e; } throw new GenericBeansException("Error post processing bean: " + beanName, e); } }
@Override public boolean canPostProcessBean(Object bean, String beanName) { // the JMXAgent is a bit strange and causes Spring issues if we let it being // post processed by this one. It does not need it anyway so we are good to go. // We should also avoid to process the null object bean (in Spring 2.5.x) if (bean == null || bean instanceof CamelJMXAgentDefinition) { return false; } return super.canPostProcessBean(bean, beanName); }
protected String getPackages() { return super.getPackages() + ADDITIONAL_JAXB_CONTEXT_PACKAGES; } }
camelCtx = new DefaultCamelContext();
/** * A helper method to create a list of Route objects for a given route builder */ public static List<Route> getRouteList(RouteBuilder builder) throws Exception { CamelContext context = new DefaultCamelContext(); context.addRoutes(builder); context.start(); List<Route> answer = context.getRoutes(); context.stop(); return answer; }
/** * A helper method to create a list of Route objects for a given route builder */ public static List<Route> getRouteList(RouteBuilder builder) throws Exception { CamelContext context = new DefaultCamelContext(); context.addRoutes(builder); context.start(); List<Route> answer = context.getRoutes(); context.stop(); return answer; }