org.apache.camel.main.Main Java Examples
The following examples show how to use
org.apache.camel.main.Main.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: camel.java From jbang with MIT License | 6 votes |
@Override public Integer call() throws Exception { // your business logic goes here... Main main = new Main(); main.addRoutesBuilder(new RouteBuilder() { @Override public void configure() throws Exception { from("timer:test?period=1000") .process(e -> out.println("Hello " + greeting)); } }); main.run(); return 0; }
Example #2
Source File: ServerFoo.java From camelinaction2 with Apache License 2.0 | 6 votes |
public void boot(String[] args) throws Exception { // create and embed the hazelcast server // (you can use the hazelcast client if you want to connect to external hazelcast server) HazelcastInstance hz = Hazelcast.newHazelcastInstance(); main = new Main(); main.bind("hz", hz); if (args.length == 0) { // route which uses get/put operations main.addRouteBuilder(new CounterRoute("Foo", 8080)); } else { // route which uses atomic counter main.addRouteBuilder(new AtomicCounterRoute("Foo", 8080)); } main.run(); }
Example #3
Source File: ServerBar.java From camelinaction2 with Apache License 2.0 | 6 votes |
public void boot(String[] args) throws Exception { // create and embed the hazelcast server // (you can use the hazelcast client if you want to connect to external hazelcast server) HazelcastInstance hz = Hazelcast.newHazelcastInstance(); main = new Main(); main.bind("hz", hz); if (args.length == 0) { // route which uses get/put operations main.addRouteBuilder(new CounterRoute("Bar", 9090)); } else { // route which uses atomic counter main.addRouteBuilder(new AtomicCounterRoute("Bar", 9090)); } main.run(); }
Example #4
Source File: ServerBar.java From camelinaction2 with Apache License 2.0 | 6 votes |
public void boot() throws Exception { // create and embed the hazelcast server // (you can use the hazelcast client if you want to connect to external hazelcast server) HazelcastInstance hz = Hazelcast.newHazelcastInstance(); // setup the hazelcast route policy HazelcastRoutePolicy routePolicy = new HazelcastRoutePolicy(hz); // the lock names must be same in the foo and bar server routePolicy.setLockMapName("myLock"); routePolicy.setLockKey("myLockKey"); routePolicy.setLockValue("myLockValue"); // attempt to grab lock every 5th second routePolicy.setTryLockTimeout(5, TimeUnit.SECONDS); main = new Main(); // bind the hazelcast route policy to the name myPolicy which we refer to from the route main.bind("myPolicy", routePolicy); // add the route and and let the route be named Bar and use a little delay when processing the files main.addRouteBuilder(new FileConsumerRoute("Bar", 100)); main.run(); }
Example #5
Source File: ServerFoo.java From camelinaction2 with Apache License 2.0 | 6 votes |
public void boot() throws Exception { // create and embed the hazelcast server // (you can use the hazelcast client if you want to connect to external hazelcast server) HazelcastInstance hz = Hazelcast.newHazelcastInstance(); // setup the hazelcast route policy HazelcastRoutePolicy routePolicy = new HazelcastRoutePolicy(hz); // the lock names must be same in the foo and bar server routePolicy.setLockMapName("myLock"); routePolicy.setLockKey("myLockKey"); routePolicy.setLockValue("myLockValue"); // attempt to grab lock every 5th second routePolicy.setTryLockTimeout(5, TimeUnit.SECONDS); main = new Main(); // bind the hazelcast route policy to the name myPolicy which we refer to from the route main.bind("myPolicy", routePolicy); // add the route and and let the route be named Bar and use a little delay when processing the files main.addRouteBuilder(new FileConsumerRoute("Foo", 100)); main.run(); }
Example #6
Source File: ServerBar.java From camelinaction2 with Apache License 2.0 | 6 votes |
public void boot() throws Exception { main = new Main(); // create jcache component and configure it JCacheComponent jcache = new JCacheComponent(); // use infinispan jcache.setCachingProvider(JCachingProvider.class.getName()); // load infinispan client (hotrod) configuration from the classpath jcache.setConfigurationUri("hotrod-client.properties"); // register the component to Camel with the name jcache main.bind("jcache", jcache); // route which uses get/put operations main.addRouteBuilder(new CounterRoute("Bar", 8889)); main.run(); }
Example #7
Source File: ServerFoo.java From camelinaction2 with Apache License 2.0 | 6 votes |
public void boot() throws Exception { main = new Main(); // create jcache component and configure it JCacheComponent jcache = new JCacheComponent(); // use infinispan jcache.setCachingProvider(JCachingProvider.class.getName()); // load infinispan client (hotrod) configuration from the classpath jcache.setConfigurationUri("hotrod-client.properties"); // register the component to Camel with the name jcache main.bind("jcache", jcache); main.addRouteBuilder(new CounterRoute("Foo", 8888)); main.run(); }
Example #8
Source File: ServerBar.java From camelinaction2 with Apache License 2.0 | 5 votes |
public void boot() throws Exception { main = new Main(); // setup quartz component QuartzComponent quartz = new QuartzComponent(); quartz.setPropertiesFile("quartz.properties"); // add the component to Camel main.bind("quartz2", quartz); // route which uses get/put operations main.addRouteBuilder(new QuartzRoute("Bar")); main.run(); }
Example #9
Source File: ServerBar.java From camelinaction2 with Apache License 2.0 | 5 votes |
public void boot() throws Exception { // create and embed the hazelcast server // (you can use the hazelcast client if you want to connect to external hazelcast server) HazelcastInstance hz = Hazelcast.newHazelcastInstance(); // setup the hazelcast idempotent repository which we will use in the route HazelcastIdempotentRepository repo = new HazelcastIdempotentRepository(hz, "camel"); main = new Main(); // bind the hazelcast repository to the name myRepo which we refer to from the route main.bind("myRepo", repo); // add the route and and let the route be named BAR and use a little delay when processing the files main.addRouteBuilder(new FileConsumerRoute("BAR", 100)); main.run(); }
Example #10
Source File: ServerFoo.java From camelinaction2 with Apache License 2.0 | 5 votes |
public void boot() throws Exception { // create and embed the hazelcast server // (you can use the hazelcast client if you want to connect to external hazelcast server) HazelcastInstance hz = Hazelcast.newHazelcastInstance(); // setup the hazelcast idempotent repository which we will use in the route HazelcastIdempotentRepository repo = new HazelcastIdempotentRepository(hz, "camel"); main = new Main(); // bind the hazelcast repository to the name myRepo which we refer to from the route main.bind("myRepo", repo); // add the route and and let the route be named BAR and use a little delay when processing the files main.addRouteBuilder(new FileConsumerRoute("FOO", 100)); main.run(); }
Example #11
Source File: ServerBar.java From camelinaction2 with Apache License 2.0 | 5 votes |
public void boot() throws Exception { main = new Main(); // the default zookeeper url is localhost:2181 MasterComponent master = new MasterComponent(); master.setZooKeeperUrl("localhost:2181"); main.bind("zookeeper-master", master); // add the route and and let the route be named Bar and use a little delay when processing the files main.addRouteBuilder(new FileConsumerRoute("Bar", 200)); main.run(); }
Example #12
Source File: ServerFoo.java From camelinaction2 with Apache License 2.0 | 5 votes |
public void boot() throws Exception { main = new Main(); // the default zookeeper url is localhost:2181 MasterComponent master = new MasterComponent(); master.setZooKeeperUrl("localhost:2181"); main.bind("zookeeper-master", master); // add the route and and let the route be named Bar and use a little delay when processing the files main.addRouteBuilder(new FileConsumerRoute("Foo", 200)); main.run(); }
Example #13
Source File: ServerBar.java From camelinaction2 with Apache License 2.0 | 5 votes |
public void boot() throws Exception { main = new Main(); // the default zookeeper url is localhost:2181 MasterRoutePolicy master = new MasterRoutePolicy(); master.setZooKeeperUrl("localhost:2181"); master.setGroupName("myGroup"); main.bind("zookeeper-master-policy", master); // add the route and and let the route be named Bar and use a little delay when processing the files main.addRouteBuilder(new FileConsumerRoute("Bar", 200)); main.run(); }
Example #14
Source File: ServerFoo.java From camelinaction2 with Apache License 2.0 | 5 votes |
public void boot() throws Exception { main = new Main(); // the default zookeeper url is localhost:2181 MasterRoutePolicy master = new MasterRoutePolicy(); master.setZooKeeperUrl("localhost:2181"); master.setGroupName("myGroup"); main.bind("zookeeper-master-policy", master); // add the route and and let the route be named Bar and use a little delay when processing the files main.addRouteBuilder(new FileConsumerRoute("Foo", 200)); main.run(); }
Example #15
Source File: ServerFoo.java From camelinaction2 with Apache License 2.0 | 5 votes |
public void boot() throws Exception { main = new Main(); // setup quartz component QuartzComponent quartz = new QuartzComponent(); quartz.setPropertiesFile("quartz.properties"); // add the component to Camel main.bind("quartz2", quartz); main.addRouteBuilder(new QuartzRoute("Foo")); main.run(); }
Example #16
Source File: ServerBar.java From camelinaction2 with Apache License 2.0 | 5 votes |
public void boot() throws Exception { Properties props = new Properties(); // list of urls for the infinispan server // as we run in domain node we have two servers out of the box, and can therefore include both // that the client can load balance/failover to be highly available props.setProperty("infinispan.client.hotrod.server_list", "localhost:11222;localhost:11372"); // by default, previously existing values for java.util.Map operations // are not returned for remote caches but they are required for the route // policy to work. props.setProperty("infinispan.client.hotrod.force_return_values", "true"); // create remote infinispan cache manager and start it RemoteCacheManager remote = new RemoteCacheManager( new ConfigurationBuilder().withProperties(props).build(), true ); // setup Camel infinispan configuration to use the remote cache manager InfinispanConfiguration ic = new InfinispanConfiguration(); ic.setCacheContainer(remote); // setup the hazelcast route policy InfinispanRoutePolicy routePolicy = new InfinispanRoutePolicy(ic); // the lock names must be same in the foo and bar server routePolicy.setLockMapName("myLock"); routePolicy.setLockKey("myLockKey"); // the lock value identifies the node routePolicy.setLockValue("bar"); main = new Main(); // bind the hazelcast route policy to the name myPolicy which we refer to from the route main.bind("myPolicy", routePolicy); // add the route and and let the route be named Bar and use a little delay when processing the files main.addRouteBuilder(new FileConsumerRoute("Bar", 100)); main.run(); }
Example #17
Source File: ServerFoo.java From camelinaction2 with Apache License 2.0 | 5 votes |
public void boot() throws Exception { Properties props = new Properties(); // list of urls for the infinispan server // as we run in domain node we have two servers out of the box, and can therefore include both // that the client can load balance/failover to be highly available props.setProperty("infinispan.client.hotrod.server_list", "localhost:11222;localhost:11372"); // by default, previously existing values for java.util.Map operations // are not returned for remote caches but they are required for the route // policy to work. props.setProperty("infinispan.client.hotrod.force_return_values", "true"); // create remote infinispan cache manager and start it RemoteCacheManager remote = new RemoteCacheManager( new ConfigurationBuilder().withProperties(props).build(), true ); // setup Camel infinispan configuration to use the remote cache manager InfinispanConfiguration ic = new InfinispanConfiguration(); ic.setCacheContainer(remote); // setup the hazelcast route policy InfinispanRoutePolicy routePolicy = new InfinispanRoutePolicy(ic); // the lock names must be same in the foo and bar server routePolicy.setLockMapName("myLock"); routePolicy.setLockKey("myLockKey"); // the lock value identifies the node routePolicy.setLockValue("foo"); main = new Main(); // bind the hazelcast route policy to the name myPolicy which we refer to from the route main.bind("myPolicy", routePolicy); // add the route and and let the route be named Bar and use a little delay when processing the files main.addRouteBuilder(new FileConsumerRoute("Foo", 100)); main.run(); }
Example #18
Source File: ServerBar.java From camelinaction2 with Apache License 2.0 | 5 votes |
public void boot() throws Exception { // setup the hazelcast route policy ConsulRoutePolicy routePolicy = new ConsulRoutePolicy(); // the service names must be same in the foo and bar server routePolicy.setServiceName("myLock"); routePolicy.setTtl(5); main = new Main(); // bind the hazelcast route policy to the name myPolicy which we refer to from the route main.bind("myPolicy", routePolicy); // add the route and and let the route be named Bar and use a little delay when processing the files main.addRouteBuilder(new FileConsumerRoute("Bar", 100)); main.run(); }
Example #19
Source File: ServerFoo.java From camelinaction2 with Apache License 2.0 | 5 votes |
public void boot() throws Exception { // setup the hazelcast route policy ConsulRoutePolicy routePolicy = new ConsulRoutePolicy(); // the service names must be same in the foo and bar server routePolicy.setServiceName("myLock"); routePolicy.setTtl(5); main = new Main(); // bind the hazelcast route policy to the name myPolicy which we refer to from the route main.bind("myPolicy", routePolicy); // add the route and and let the route be named Bar and use a little delay when processing the files main.addRouteBuilder(new FileConsumerRoute("Foo", 100)); main.run(); }
Example #20
Source File: ArdulinkMailOnCamelIntegrationTest.java From Ardulink-2 with Apache License 2.0 | 5 votes |
private void runInBackground(Main main) { newSingleThreadExecutor().execute(() -> { try { main.run(); } catch (Exception e) { Throwables.propagate(e); } }); }
Example #21
Source File: ArdulinkMailOnCamelIntegrationTest.java From Ardulink-2 with Apache License 2.0 | 5 votes |
@Test public void writesResultToSender_ConfiguredViaProperties() throws Exception { String receiver = "[email protected]"; String username = "loginIdReceiver"; String password = "secretOfReceiver"; createMailUser(receiver, username, password); String validSender = "[email protected]"; createMailUser(validSender, "loginIdSender", "secretOfSender"); String commandName = "usedScenario"; String command1 = alpProtocolMessage(DIGITAL_PIN_READ).forPin(1).withState(true); String command2 = alpProtocolMessage(ANALOG_PIN_READ).forPin(2).withValue(123); String command = command1 + "," + command2; send(mailFrom(validSender).to(receiver).withSubject(anySubject()).withText(commandName)); Main main = new Main(); main.addProperty("from", imapUri(username, password)); main.addProperty("to", smtpUri(username, password)); // main.addProperty("commandName", commandName); // main.addProperty("command", command); String smtpRouteStart = "direct:smtp-" + UUID.randomUUID(); main.addRoutesBuilder(setToAndFromHeaderAndSendTo(smtpRouteStart, "{{to}}")); main.addRoutesBuilder(ardulinkProcessing("{{from}}", validSender, commandName, Arrays.asList(command.split("\\,")), makeURI(mockURI, emptyMap()), smtpRouteStart)); runInBackground(main); try { assertThat(((String) fetchMail("loginIdSender", "secretOfSender").getContent()), is(command1 + "=OK\r\n" + command2 + "=OK")); } finally { main.stop(); } }
Example #22
Source File: CamelMainSupport.java From camel-kafka-connector with Apache License 2.0 | 4 votes |
public CamelMainSupport(Map<String, String> props, String fromUrl, String toUrl, String marshal, String unmarshal, int aggregationSize, long aggregationTimeout, CamelContext camelContext) throws Exception { camel = camelContext; camelMain = new Main() { @Override protected ProducerTemplate findOrCreateCamelTemplate() { return camel.createProducerTemplate(); } @Override protected CamelContext createCamelContext() { return camel; } }; camelMain.addMainListener(new CamelMainFinishedListener()); camelMain.configure().setAutoConfigurationLogSummary(false); // reordering properties to place the one starting with "#class:" first LinkedHashMap<String, String> orderedProps = new LinkedHashMap<>(); props.keySet().stream() .filter(k -> props.get(k).startsWith("#class:")) .forEach(k -> orderedProps.put(k, props.get(k))); props.keySet().stream() .filter(k -> !props.get(k).startsWith("#class:")) .forEach(k -> orderedProps.put(k, props.get(k))); Properties camelProperties = new OrderedProperties(); camelProperties.putAll(orderedProps); LOG.info("Setting initial properties in Camel context: [{}]", camelProperties); this.camel.getPropertiesComponent().setInitialProperties(camelProperties); camelMain.init(); //creating the actual route this.camel.addRoutes(new RouteBuilder() { public void configure() { RouteDefinition rd = from(fromUrl); if (marshal != null && unmarshal != null) { throw new UnsupportedOperationException("Uses of both marshal (i.e. " + marshal + ") and unmarshal (i.e. " + unmarshal + ") is not supported"); } else if (marshal != null) { LOG.info("Creating Camel route from({}).marshal().custom({}).to({})", fromUrl, marshal, toUrl); camel.getRegistry().bind(marshal, lookupAndInstantiateDataformat(marshal)); rd.marshal().custom(marshal); } else if (unmarshal != null) { LOG.info("Creating Camel route from({}).unmarshal().custom({}).to({})", fromUrl, unmarshal, toUrl); camel.getRegistry().bind(unmarshal, lookupAndInstantiateDataformat(unmarshal)); rd.unmarshal().custom(unmarshal); } else { LOG.info("Creating Camel route from({}).to({})", fromUrl, toUrl); } if (camel.getRegistry().lookupByName("aggregate") != null) { AggregationStrategy s = (AggregationStrategy) camel.getRegistry().lookupByName("aggregate"); rd.aggregate(s).constant(true).completionSize(aggregationSize).completionTimeout(aggregationTimeout).toD(toUrl); } else { rd.toD(toUrl); } } }); }
Example #23
Source File: RestMain.java From Ardulink-2 with Apache License 2.0 | 4 votes |
public RestMain(Properties properties) { main = new Main(); main.setInitialProperties(properties); main.addRoutesBuilder(new RestRouteBuilder()); main.start(); }
Example #24
Source File: Application.java From camel-cookbook-examples with Apache License 2.0 | 4 votes |
public void boot() throws Exception { this.main = new Main(); this.main.addRouteBuilder(new CamelRoutes()); main.run(); }