@Override protected CamelContext createCamelContext() throws Exception { SimpleRegistry registry = new SimpleRegistry(); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://embedded?broker.persistent=false"); registry.put("connectionFactory", connectionFactory); JmsTransactionManager jmsTransactionManager = new JmsTransactionManager(); jmsTransactionManager.setConnectionFactory(connectionFactory); registry.put("jmsTransactionManager", jmsTransactionManager); SpringTransactionPolicy propagationRequired = new SpringTransactionPolicy(); propagationRequired.setTransactionManager(jmsTransactionManager); propagationRequired.setPropagationBehaviorName("PROPAGATION_REQUIRED"); registry.put("PROPAGATION_REQUIRED", propagationRequired); SpringTransactionPolicy propagationNotSupported = new SpringTransactionPolicy(); propagationNotSupported.setTransactionManager(jmsTransactionManager); propagationNotSupported.setPropagationBehaviorName("PROPAGATION_NOT_SUPPORTED"); registry.put("PROPAGATION_NOT_SUPPORTED", propagationNotSupported); CamelContext camelContext = new DefaultCamelContext(registry); ActiveMQComponent activeMQComponent = new ActiveMQComponent(); activeMQComponent.setConnectionFactory(connectionFactory); activeMQComponent.setTransactionManager(jmsTransactionManager); camelContext.addComponent("jms", activeMQComponent); return camelContext; }
@SuppressWarnings("Convert2streamapi") private void unregisterExecutorComponent(Executor... executors) { for (Executor executor : executors) { //unregister beans Registry registry = context.getRegistry(); if (registry instanceof PropertyPlaceholderDelegateRegistry) { registry = ((PropertyPlaceholderDelegateRegistry) registry).getRegistry(); } SimpleRegistry openexRegistry = (SimpleRegistry) registry; Set<Map.Entry<String, Object>> beansEntries = executor.beans().entrySet(); for (Map.Entry<String, Object> beansEntry : beansEntries) { if (openexRegistry.containsKey(beansEntry.getKey())) { openexRegistry.remove(beansEntry.getKey()); } } //unregister components Set<String> keys = executor.components().keySet(); for (String key : keys) { if (context.getComponentNames().contains(key)) { context.removeComponent(key); } } } }
@SuppressWarnings("Convert2streamapi") private void registerExecutorComponent(Executor... executors) { for (Executor executor : executors) { //register beans Registry registry = context.getRegistry(); if (registry instanceof PropertyPlaceholderDelegateRegistry) { registry = ((PropertyPlaceholderDelegateRegistry) registry).getRegistry(); } SimpleRegistry openexRegistry = (SimpleRegistry) registry; Set<Map.Entry<String, Object>> beansEntries = executor.beans().entrySet(); for (Map.Entry<String, Object> beansEntry : beansEntries) { if (!openexRegistry.containsKey(beansEntry.getKey())) { openexRegistry.put(beansEntry.getKey(), beansEntry.getValue()); } } //register components Set<Map.Entry<String, org.apache.camel.Component>> components = executor.components().entrySet(); for (Map.Entry<String, org.apache.camel.Component> entry : components) { if (!context.getComponentNames().contains(entry.getKey())) { context.addComponent(entry.getKey(), entry.getValue()); } } } }
public void testLoadRegistry() throws Exception { SimpleRegistry registry = new SimpleRegistry(); registry.put("myBean", "This is a log4j logging configuation file"); CamelContext context = new DefaultCamelContext(registry); context.start(); InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(context, "ref:myBean"); assertNotNull(is); String text = context.getTypeConverter().convertTo(String.class, is); assertNotNull(text); assertTrue(text.contains("log4j")); is.close(); context.stop(); }
public void testErrorListener() throws Exception { try { SimpleRegistry registry = new SimpleRegistry(); registry.put("myListener", listener); RouteBuilder builder = createRouteBuilder(); CamelContext context = new DefaultCamelContext(registry); context.addRoutes(builder); context.start(); fail("Should have thrown an exception due XSLT file not found"); } catch (FailedToCreateRouteException e) { // expected } assertFalse(listener.isWarning()); assertTrue("My error listener should been invoked", listener.isError()); assertTrue("My error listener should been invoked", listener.isFatalError()); }
@Override protected CamelContext createCamelContext() throws Exception { final PropertiesComponent pc = new PropertiesComponent("classpath:org/apache/camel/component/properties/myproperties.properties"); pc.setPropertiesResolver(new PropertiesResolver() { public Properties resolveProperties(CamelContext context, boolean ignoreMissingLocation, String... uri) throws Exception { resolvedCount++; return new DefaultPropertiesResolver(pc).resolveProperties(context, ignoreMissingLocation, uri); } }); // put the properties component into the registry so that it survives restarts SimpleRegistry registry = new SimpleRegistry(); registry.put("properties", pc); return new DefaultCamelContext(registry); }
@Test(expected = FailedToCreateRouteException.class) public void shouldFailWhenThereIsNoJobLauncher() throws Exception { // Given SimpleRegistry registry = new SimpleRegistry(); registry.put("mockJob", job); CamelContext camelContext = new DefaultCamelContext(registry); camelContext.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("spring-batch:mockJob"); } }); // When camelContext.start(); }
@Test(expected = FailedToCreateRouteException.class) public void shouldFailWhenThereIsMoreThanOneJobLauncher() throws Exception { // Given SimpleRegistry registry = new SimpleRegistry(); registry.put("mockJob", job); registry.put("launcher1", jobLauncher); registry.put("launcher2", jobLauncher); CamelContext camelContext = new DefaultCamelContext(registry); camelContext.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("spring-batch:mockJob"); } }); // When camelContext.start(); }
@Test public void shouldResolveAnyJobLauncher() throws Exception { // Given SimpleRegistry registry = new SimpleRegistry(); registry.put("mockJob", job); registry.put("someRandomName", jobLauncher); CamelContext camelContext = new DefaultCamelContext(registry); camelContext.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("spring-batch:mockJob"); } }); // When camelContext.start(); // Then SpringBatchEndpoint batchEndpoint = camelContext.getEndpoint("spring-batch:mockJob", SpringBatchEndpoint.class); JobLauncher batchEndpointJobLauncher = (JobLauncher) FieldUtils.readField(batchEndpoint, "jobLauncher", true); assertSame(jobLauncher, batchEndpointJobLauncher); }
@Before public void setUp() throws Exception { camelContext = new DefaultCamelContext(); SimpleRegistry registry = new SimpleRegistry(); Map<String, Object> params = new HashMap<String, Object>(); params.put("custName", "Willem"); // bind the params registry.put("params", params); camelContext.setRegistry(registry); template = camelContext.createProducerTemplate(); ServiceHelper.startServices(template, camelContext); Endpoint value = camelContext.getEndpoint(getEndpointUri()); assertNotNull("Could not find endpoint!", value); assertTrue("Should be a JPA endpoint but was: " + value, value instanceof JpaEndpoint); endpoint = (JpaEndpoint)value; transactionTemplate = endpoint.createTransactionTemplate(); entityManager = endpoint.createEntityManager(); }
@Override public CamelContext createCamelContext() throws Exception { SimpleRegistry registry = new SimpleRegistry(); registry.put("testStrategy", new ListAggregationStrategy()); ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(broker.getTcpConnectorUri()); SjmsComponent sjmsComponent = new SjmsComponent(); sjmsComponent.setConnectionFactory(connectionFactory); SjmsBatchComponent sjmsBatchComponent = new SjmsBatchComponent(); sjmsBatchComponent.setConnectionFactory(connectionFactory); CamelContext context = new DefaultCamelContext(registry); context.addComponent("sjms", sjmsComponent); context.addComponent("sjms-batch", sjmsBatchComponent); return context; }
@Override protected CamelContext createCamelContext() throws Exception { SimpleRegistry registry = new SimpleRegistry(); registry.put("aggStrategy", AggregationStrategies.groupedExchange()); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(); connectionFactory.setBrokerURL(broker.getTcpConnectorUri()); SjmsComponent sjmsComponent = new SjmsComponent(); sjmsComponent.setConnectionFactory(connectionFactory); SjmsBatchComponent sjmsBatchComponent = new SjmsBatchComponent(); sjmsBatchComponent.setConnectionFactory(connectionFactory); CamelContext context = new DefaultCamelContext(registry); context.addComponent("sjms-batch", sjmsBatchComponent); context.addComponent("sjms", sjmsComponent); return context; }
@Test public void invalidConfiguration() throws Exception { // Given SimpleRegistry registry = new SimpleRegistry(); registry.put("eventBus", new EventBus()); CamelContext context = new DefaultCamelContext(registry); context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("guava-eventbus:eventBus?listenerInterface=org.apache.camel.component.guava.eventbus.CustomListener&eventClass=org.apache.camel.component.guava.eventbus.MessageWrapper"). to("mock:customListenerEvents"); } }); try { context.start(); fail("Should throw exception"); } catch (FailedToCreateRouteException e) { IllegalStateException ise = assertIsInstanceOf(IllegalStateException.class, e.getCause()); assertEquals("You cannot set both 'eventClass' and 'listenerInterface' parameters.", ise.getMessage()); } }
@Override protected void setUp() throws Exception { // create the registry to be the SimpleRegistry which is just a Map based implementation SimpleRegistry registry = new SimpleRegistry(); // register our HelloBean under the name helloBean registry.put("helloBean", new HelloBean()); // tell Camel to use our SimpleRegistry context = new DefaultCamelContext(registry); // create a producer template to use for testing template = context.createProducerTemplate(); // add the route using an inlined RouteBuilder context.addRoutes(new RouteBuilder() { public void configure() throws Exception { from("direct:hello").bean("helloBean", "hello"); } }); // star Camel context.start(); }
protected void createContextWithGivenRoute(RouteBuilder route, int timeWork) throws Exception, InterruptedException { SimpleRegistry registry = new SimpleRegistry(); ModelCamelContext context = new DefaultCamelContext(registry); Tracer tracer = new Tracer(); tracer.setLogName("MyTracerLog"); tracer.getDefaultTraceFormatter().setShowProperties(false); tracer.getDefaultTraceFormatter().setShowHeaders(false); tracer.getDefaultTraceFormatter().setShowBody(true); context.addInterceptStrategy(tracer); context.addRoutes(route); context.addComponent("activeMq", activeMq); this.camelContext = context; this.ct = context.createConsumerTemplate(); this.pt = context.createProducerTemplate(); context.start(); context.setTracing(false); Thread.sleep(timeWork); context.stop(); }
public void testSendA19() throws Exception { SimpleRegistry registry = new SimpleRegistry(); HL7MLLPCodec codec = new HL7MLLPCodec(); codec.setCharset("iso-8859-1"); codec.setConvertLFtoCR(true); registry.put("hl7codec", codec); CamelContext camelContext = new DefaultCamelContext(registry); camelContext.start(); ProducerTemplate template = camelContext.createProducerTemplate(); String line1 = "MSH|^~\\&|MYSENDER|MYRECEIVER|MYAPPLICATION||200612211200||QRY^A19|1234|P|2.4"; String line2 = "QRD|200612211200|R|I|GetPatient|||1^RD|0101701234|DEM||"; StringBuilder in = new StringBuilder(); in.append(line1); in.append("\r"); in.append(line2); template.requestBody("mina2:tcp://127.0.0.1:" + MINA2_PORT + "?sync=true&codec=#hl7codec", in.toString()); template.stop(); camelContext.stop(); }
@Override public void init(ServiceDomain domain) { if (_logger.isDebugEnabled()) { _logger.debug("Initialization of CamelExchangeBus for domain " + domain.getName()); } SimpleRegistry registry = _camelContext.getWritebleRegistry(); for (Processors processor : Processors.values()) { registry.put(processor.name(), processor.create(domain)); } // CAMEL-7728 introduces an issue on finding BeanManager due to the fact that default // applicationContextClassLoader in the CamelContext is not a bundle deployment class loader. // We need to ensure the applicationContextClassLoader is the bundle deployment class loader // for now. This will be unnecessary once CAMEL-7759 is merged. _camelContext.setApplicationContextClassLoader(Thread.currentThread().getContextClassLoader()); }
@Override protected void setUp() throws Exception { // create the registry to be the SimpleRegistry which is just a Map based implementation SimpleRegistry registry = new SimpleRegistry(); // register our HelloBean under the name helloBean registry.put("helloBean", new HelloBean()); // tell Camel to use our SimpleRegistry context = new DefaultCamelContext(registry); // create a producer template to use for testing template = context.createProducerTemplate(); // add the route using an inlined RouteBuilder context.addRoutes(new RouteBuilder() { public void configure() throws Exception { from("direct:hello").beanRef("helloBean"); } }); // star Camel context.start(); }
@Inject JdbiExample(ReceiveCommandsAsJsonRoute receiveCommandsRoute, JdbiConsumeCommandsRoute consumeCommandsRoute, JdbiConsumeEventsRoute consumeEventsRoute) throws Exception { main = new Main() ; main.enableHangupSupport(); registry = new SimpleRegistry(); context = new DefaultCamelContext(registry); context.addRoutes(receiveCommandsRoute); context.addRoutes(consumeCommandsRoute); context.addRoutes(consumeEventsRoute); main.getCamelContexts().clear(); main.getCamelContexts().add(context); main.setDuration(-1); main.start(); }
@Inject CmdProducer(CommandsDataSetsRoute datasetRoute) throws Exception { main = new Main() ; main.enableHangupSupport(); registry = new SimpleRegistry(); context = new DefaultCamelContext(registry); populate(); registry.put("createCommandDataset", new CreateCommandDataSet(ids, dataSetSize)); registry.put("increaseCommandDataset", new IncreaseCommandDataSet(ids, dataSetSize)); registry.put("decreaseCommandDataset", new DecreaseCommandDataSet(ids, dataSetSize)); context.addRoutes(datasetRoute); main.getCamelContexts().clear(); main.getCamelContexts().add(context); main.setDuration(-1); main.start(); }
/** Prepares Db and data source, which must be added to Camel registry. */ @BeforeClass public static void setup() throws Exception { DeleteDbFiles.execute("~", "jbpm-db-test", true); h2Server = Server.createTcpServer(new String[0]); h2Server.start(); setupDb(); DataSource ds = setupDataSource(); SimpleRegistry simpleRegistry = new SimpleRegistry(); simpleRegistry.put("myDs", ds); handler = new CamelHandler(new SQLURIMapper(), new RequestPayloadMapper("payload"), new ResponsePayloadMapper("queryResult"), new DefaultCamelContext(simpleRegistry)); }
@Override protected CamelContext createCamelContext() throws Exception { final int testBatchSize = 1000; InputDataSet inputDataSet = new InputDataSet(); inputDataSet.setSize(testBatchSize); ExpectedOutputDataSet expectedOutputDataSet = new ExpectedOutputDataSet(); expectedOutputDataSet.setSize(testBatchSize); SimpleRegistry registry = new SimpleRegistry(); registry.put("input", inputDataSet); registry.put("expectedOutput", expectedOutputDataSet); return new DefaultCamelContext(registry); }
@Override protected CamelContext createCamelContext() throws Exception { SimpleRegistry registry = new SimpleRegistry(); dataSource = EmbeddedDataSourceFactory.getDataSource("sql/schema.sql"); DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(dataSource); registry.put("transactionManager", transactionManager); SpringTransactionPolicy propagationRequired = new SpringTransactionPolicy(); propagationRequired.setTransactionManager(transactionManager); propagationRequired.setPropagationBehaviorName("PROPAGATION_REQUIRED"); registry.put("PROPAGATION_REQUIRED", propagationRequired); auditLogDao = new AuditLogDao(dataSource); messageDao = new MessageDao(dataSource); CamelContext camelContext = new DefaultCamelContext(registry); SqlComponent sqlComponent = new SqlComponent(); sqlComponent.setDataSource(dataSource); camelContext.addComponent("sql", sqlComponent); return camelContext; }
@Override protected CamelContext createCamelContext() throws Exception { SimpleRegistry registry = new SimpleRegistry(); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(); connectionFactory.setBrokerURL(broker.getTcpConnectorUri()); registry.put("connectionFactory", connectionFactory); JmsTransactionManager jmsTransactionManager = new JmsTransactionManager(); jmsTransactionManager.setConnectionFactory(connectionFactory); registry.put("jmsTransactionManager", jmsTransactionManager); SpringTransactionPolicy policy = new SpringTransactionPolicy(); policy.setTransactionManager(jmsTransactionManager); policy.setPropagationBehaviorName("PROPAGATION_REQUIRED"); registry.put("PROPAGATION_REQUIRED", policy); CamelContext camelContext = new DefaultCamelContext(registry); ActiveMQComponent activeMQComponent = new ActiveMQComponent(); activeMQComponent.setConnectionFactory(connectionFactory); activeMQComponent.setTransactionManager(jmsTransactionManager); camelContext.addComponent("jms", activeMQComponent); return camelContext; }
@Override protected CamelContext createCamelContext() throws Exception { SimpleRegistry registry = new SimpleRegistry(); DataSource auditDataSource = EmbeddedDataSourceFactory.getDataSource("sql/schema.sql"); DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(auditDataSource); registry.put("transactionManager", transactionManager); SpringTransactionPolicy propagationRequired = new SpringTransactionPolicy(); propagationRequired.setTransactionManager(transactionManager); propagationRequired.setPropagationBehaviorName("PROPAGATION_REQUIRED"); registry.put("PROPAGATION_REQUIRED", propagationRequired); auditLogDao = new AuditLogDao(auditDataSource); CamelContext camelContext = new DefaultCamelContext(registry); SqlComponent sqlComponent = new SqlComponent(); sqlComponent.setDataSource(auditDataSource); camelContext.addComponent("sql", sqlComponent); return camelContext; }
@Override protected CamelContext createCamelContext() throws Exception { SimpleRegistry registry = new SimpleRegistry(); auditDataSource = EmbeddedDataSourceFactory.getDataSource("sql/schema.sql"); //registry.put("auditDataSource", auditDataSource); DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(auditDataSource); registry.put("transactionManager", transactionManager); SpringTransactionPolicy propagationRequired = new SpringTransactionPolicy(); propagationRequired.setTransactionManager(transactionManager); propagationRequired.setPropagationBehaviorName("PROPAGATION_REQUIRED"); registry.put("PROPAGATION_REQUIRED", propagationRequired); auditLogDao = new AuditLogDao(auditDataSource); CamelContext camelContext = new DefaultCamelContext(registry); SqlComponent sqlComponent = new SqlComponent(); sqlComponent.setDataSource(auditDataSource); camelContext.addComponent("sql", sqlComponent); return camelContext; }
public static void main(String[] args) throws Exception { SimpleRegistry registry = new SimpleRegistry(); // add POJOs to the registry here using registry.put("name", <object reference>) CamelContext context = new DefaultCamelContext(registry); context.addComponent("mylogger", new LogComponent()); context.addRoutes(new LogMessageOnTimerEventRoute()); context.start(); // let the Camel runtime do its job for 5 seconds Thread.sleep(5000); // shutdown context.stop(); }
@Override protected CamelContext createCamelContext() throws Exception { final String keyStorePassword = "keystorePassword"; final String trustStorePassword = "truststorePassword"; SimpleRegistry registry = new SimpleRegistry(); KeyStore keyStore = KeyStore.getInstance("JKS"); // Java keystore ClassLoader classLoader = getClass().getClassLoader(); log.info("Loading keystore from [{}]", classLoader.getResource("keystore.jks").toString()); keyStore.load(classLoader.getResourceAsStream("keystore.jks"), keyStorePassword.toCharArray()); registry.put("keyStore", keyStore); KeyStore trustStore = KeyStore.getInstance("JKS"); // Java keystore trustStore.load(classLoader.getResourceAsStream("truststore.jks"), trustStorePassword.toCharArray()); registry.put("trustStore", trustStore); return new DefaultCamelContext(registry); }
public static void registerBean(Registry registry, String beanName, Object bean) { if (registry instanceof SimpleRegistry) { ((SimpleRegistry) registry).put(beanName, bean); } else if (registry instanceof PropertyPlaceholderDelegateRegistry) { Registry wrappedRegistry = ((PropertyPlaceholderDelegateRegistry) registry).getRegistry(); registerBean(wrappedRegistry, beanName, bean); } else if (registry instanceof JndiRegistry) { ((JndiRegistry) registry).bind(beanName, bean); } else { throw new RuntimeException("could not identify the registry type while registering core beans"); } }
@Test public void camelConnectorTest() throws Exception { BasicDataSource ds = new BasicDataSource(); ds.setUsername(properties.getProperty("sql-stored-start-connector.user")); ds.setPassword(properties.getProperty("sql-stored-start-connector.password")); ds.setUrl( properties.getProperty("sql-stored-start-connector.url")); SimpleRegistry registry = new SimpleRegistry(); registry.put("dataSource", ds); CamelContext context = new DefaultCamelContext(registry); CountDownLatch latch = new CountDownLatch(1); final Result result = new Result(); try { context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("sql-stored-start-connector:DEMO_OUT( OUT INTEGER c)") .process(new Processor() { @Override public void process(Exchange exchange) throws Exception { String jsonBean = (String) exchange.getIn().getBody(); result.setResult(jsonBean); latch.countDown(); } }).to("stream:out"); } }); context.start(); latch.await(5l,TimeUnit.SECONDS); Assert.assertEquals("{\"c\":60}", result.getJsonBean()); } finally { context.stop(); } }
@Test public void testCamelProducerOverridenAction() throws Exception { SimpleRegistry registry = new SimpleRegistry(); Engine engine = DefaultEngine.builder().knowledgeBase("camelkb", "examples/camel/camel_producer_overridden_action.py").build(); registry.put("spongeEngine", engine); CamelContext camel = new DefaultCamelContext(registry); camel.addRoutes(new RouteBuilder() { @Override public void configure() { // @formatter:off from("direct:start").routeId("spongeProducer") .to("sponge:spongeEngine"); // @formatter:on } }); camel.start(); try { ProducerTemplate producerTemplate = camel.createProducerTemplate(); producerTemplate.sendBody("direct:start", "Send me to the Sponge"); await().pollDelay(2, TimeUnit.SECONDS).atMost(60, TimeUnit.SECONDS) .until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "sentCamelMessage_camelEvent").get()); assertFalse(engine.getOperations().getVariable(AtomicBoolean.class, "sentCamelMessage_spongeProducer").get()); assertFalse(engine.isError()); } finally { camel.stop(); } }
@Test public void testCamelProducer() throws Exception { SimpleRegistry registry = new SimpleRegistry(); Engine engine = DefaultEngine.builder().knowledgeBase("camelkb", "examples/camel/camel_producer.py").build(); registry.put("spongeEngine", engine); CamelContext camel = new DefaultCamelContext(registry); camel.addRoutes(new RouteBuilder() { @Override public void configure() { // @formatter:off from("direct:start").routeId("spongeProducer") .to("sponge:spongeEngine"); // @formatter:on } }); camel.start(); try { ProducerTemplate producerTemplate = camel.createProducerTemplate(); producerTemplate.sendBody("direct:start", "Send me to the Sponge"); await().atMost(10, TimeUnit.SECONDS) .until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "sentCamelMessage").get()); } finally { camel.stop(); } }
@Test public void testCamelConsumer() throws Exception { SimpleRegistry registry = new SimpleRegistry(); Engine engine = DefaultEngine.builder().knowledgeBase("camelkb", "examples/camel/camel_consumer.py").build(); registry.put("spongeEngine", engine); CamelContext camel = new DefaultCamelContext(registry); camel.addRoutes(new RouteBuilder() { @Override public void configure() { // @formatter:off from("sponge:spongeEngine").routeId("spongeConsumer") .log("${body}") .process(exchange -> engine.getOperations().getVariable(AtomicBoolean.class, "receivedCamelMessage").set(true)) .to("stream:out"); // @formatter:on } }); camel.start(); try { engine.getOperations().event("spongeEvent").set("message", "Send me to Camel").send(); await().atMost(60, TimeUnit.SECONDS) .until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "receivedCamelMessage").get()); assertFalse(engine.isError()); } finally { camel.stop(); } }
private void createContext() throws Exception { SimpleRegistry registry = new SimpleRegistry(); registry.put("openexRouter", new OpenexRouter()); registry.put("openexStrategy", new OpenexAggregationStrategy()); registry.put("openexCallback", new OpenexCallbackBuilder()); context.setRegistry(registry); context.addComponent("properties", buildPropertiesComponent()); context.getExecutorServiceManager().registerThreadPoolProfile(threadPoolProfileRemote()); context.getExecutorServiceManager().registerThreadPoolProfile(threadPoolProfileExecutor()); context.setTracing(true); //Populate data formats JsonDataFormat jsonDataFormat = new JsonDataFormat(JsonLibrary.Gson); jsonDataFormat.setUseList(true); context.setDataFormats(Collections.singletonMap("json", jsonDataFormat)); //Rest direct call routes InputStream defaultRoutesStream = getClass().getResourceAsStream("routes.xml"); context.addRouteDefinitions(context.loadRoutesDefinition(defaultRoutesStream).getRoutes()); //Dynamic routes building for (Executor executor : workerRegistry.workers().values()) { registerCamelModule(executor); } //Starting context context.start(); }
public void initialize() { LOGGER.info("Initializing Camel Standalone"); this.registry = new SimpleRegistry(); this.contextMap = new HashMap<>(); try { addCamelContext(MAIN_CONTEXT_NAME, true, true); } catch (Exception e) { throw new RuntimeException("Could not initialize the main Camel Context", e); } this.duration = 0; this.timeUnit = TimeUnit.SECONDS; }
@Override protected CamelContext createCamelContext() throws Exception { SimpleRegistry registry = new SimpleRegistry(); registry.put("mylogger1", LoggerFactory.getLogger("org.apache.camel.customlogger")); CamelContext context = new DefaultCamelContext(registry); return context; }