public ConsulLeaderElector build() throws Exception { Objects.requireNonNull(camelContext, "No CamelContext provided!"); final ProducerTemplate producerTemplate = DefaultProducerTemplate.newInstance(camelContext, ConsulLeaderElector.CONTROLBUS_ROUTE); final ConsulLeaderElector consulLeaderElector = new ConsulLeaderElector( new ConsulFacadeBean( consulUrl, Optional.ofNullable(username), Optional.ofNullable(password), ttlInSeconds, lockDelayInSeconds, allowIslandMode, createSessionTries, retryPeriod, backOffMultiplier), serviceName, routeId, camelContext, producerTemplate, allowIslandMode); logger.debug("pollInitialDelay={} pollInterval={}", pollInitialDelay, pollInterval); executor.scheduleAtFixedRate(consulLeaderElector, pollInitialDelay, pollInterval, TimeUnit.SECONDS); camelContext.addLifecycleStrategy(consulLeaderElector); producerTemplate.start(); return consulLeaderElector; }
/** * Send a message to the landing zone queue for the given file. * * @param filePathname * the file to be ingested * * @return true if the message was successfully sent to the landing zone queue * * @throws IOException */ private void sendMessageToLzQueue(String filePathname) { // Create a new process to invoke the ruby script to send the message. try { /* * The logic to send this message is also present in following ruby script. Any changes * here should also be made to the script. * sli/opstools/ingestion_trigger/publish_file_uploaded.rb */ ProducerTemplate template = new DefaultProducerTemplate(camelContext); template.start(); template.sendBodyAndHeader(landingZoneQueueUri, "Sample lzfile message", "filePath", filePathname); template.stop(); } catch (Exception e) { LOG.error("Error publishing sample file " + filePathname + " for ingestion", e); } }
@Test public void testRouteboxDirectProducerOnlyRequests() throws Exception { template = new DefaultProducerTemplate(context); template.start(); context.addRoutes(new RouteBuilder() { public void configure() { from("direct:start") .to(routeboxUri) .to("log:Routes operation performed?showAll=true"); } }); context.start(); LOG.debug("Beginning Test ---> testRouteboxDirectSyncRequests()"); Book book = new Book("Sir Arthur Conan Doyle", "The Adventures of Sherlock Holmes"); String response = sendAddToCatalogRequest(template, "direct:start", "addToCatalog", book); assertEquals("Book with Author " + book.getAuthor() + " and title " + book.getTitle() + " added to Catalog", response); //Thread.sleep(2000); book = sendFindBookRequest(template, "direct:start", "findBook", "Sir Arthur Conan Doyle"); LOG.debug("Received book with author {} and title {}", book.getAuthor(), book.getTitle()); assertEquals("The Adventures of Sherlock Holmes", book.getTitle()); LOG.debug("Completed Test ---> testRouteboxDirectSyncRequests()"); context.stop(); }
@Test public void testRouteboxUsingDispatchMap() throws Exception { template = new DefaultProducerTemplate(context); template.start(); context.addRoutes(new RouteBuilder() { public void configure() { from(routeboxUri) .to("log:Routes operation performed?showAll=true"); } }); context.start(); LOG.debug("Beginning Test ---> testRouteboxUsingDispatchMap()"); Book book = new Book("Sir Arthur Conan Doyle", "The Adventures of Sherlock Holmes"); String response = sendAddToCatalogRequest(template, routeboxUri, "addToCatalog", book); assertEquals("Book with Author " + book.getAuthor() + " and title " + book.getTitle() + " added to Catalog", response); book = sendFindBookRequest(template, routeboxUri, "findBook", "Sir Arthur Conan Doyle"); LOG.debug("Received book with author {} and title {}", book.getAuthor(), book.getTitle()); assertEquals("The Adventures of Sherlock Holmes", book.getTitle()); LOG.debug("Completed Test ---> testRouteboxUsingDispatchMap()"); context.stop(); }
@Test public void testRouteboxUsingDefaultContextAndRouteBuilder() throws Exception { template = new DefaultProducerTemplate(context); template.start(); context.addRoutes(new RouteBuilder() { public void configure() { from(routeboxUri) .to("log:Routes operation performed?showAll=true"); } }); context.start(); LOG.debug("Beginning Test ---> testRouteboxUsingDefaultContextAndRouteBuilder()"); Book book = new Book("Sir Arthur Conan Doyle", "The Adventures of Sherlock Holmes"); String response = sendAddToCatalogRequest(template, routeboxUri, "addToCatalog", book); assertEquals("Book with Author " + book.getAuthor() + " and title " + book.getTitle() + " added to Catalog", response); book = sendFindBookRequest(template, routeboxUri, "findBook", "Sir Arthur Conan Doyle"); LOG.debug("Received book with author {} and title {}", book.getAuthor(), book.getTitle()); assertEquals("The Adventures of Sherlock Holmes", book.getTitle()); LOG.debug("Completed Test ---> testRouteboxUsingDefaultContextAndRouteBuilder()"); context.stop(); }
@Test public void testRouteboxDirectAsyncRequests() throws Exception { template = new DefaultProducerTemplate(context); template.start(); context.addRoutes(new RouteBuilder() { public void configure() { from(routeboxUri) .to("log:Routes operation performed?showAll=true"); } }); context.start(); LOG.debug("Beginning Test ---> testRouteboxDirectAsyncRequests()"); Book book = new Book("Sir Arthur Conan Doyle", "The Adventures of Sherlock Holmes"); String response = sendAddToCatalogRequest(template, routeboxUri, "addToCatalog", book); assertEquals("Book with Author " + book.getAuthor() + " and title " + book.getTitle() + " added to Catalog", response); // Wait for 2 seconds before a follow-on request if the requests are sent in async mode // to allow the earlier request to take effect //Thread.sleep(2000); book = sendFindBookRequest(template, routeboxUri, "findBook", "Sir Arthur Conan Doyle"); LOG.debug("Received book with author {} and title {}", book.getAuthor(), book.getTitle()); assertEquals("The Adventures of Sherlock Holmes", book.getTitle()); LOG.debug("Completed Test ---> testRouteboxDirectAsyncRequests()"); context.stop(); }
@Test public void testRouteboxSedaAsyncRequests() throws Exception { template = new DefaultProducerTemplate(context); template.start(); context.addRoutes(new RouteBuilder() { public void configure() { from(routeboxUri) .to("log:Routes operation performed?showAll=true"); } }); context.start(); LOG.debug("Beginning Test ---> testRouteboxSedaAsyncRequests()"); Book book = new Book("Sir Arthur Conan Doyle", "The Adventures of Sherlock Holmes"); String response = sendAddToCatalogRequest(template, routeboxUri, "addToCatalog", book); assertEquals("Book with Author " + book.getAuthor() + " and title " + book.getTitle() + " added to Catalog", response); // Wait for 2 seconds before a follow-on request if the requests are sent in async mode // to allow the earlier request to take effect //Thread.sleep(2000); book = sendFindBookRequest(template, routeboxUri, "findBook", "Sir Arthur Conan Doyle"); LOG.debug("Received book with author {} and title {}", book.getAuthor(), book.getTitle()); assertEquals("The Adventures of Sherlock Holmes", book.getTitle()); LOG.debug("Completed Test ---> testRouteboxSedaAsyncRequests()"); context.stop(); }
public void testCamelTemplates() throws Exception { DefaultProducerTemplate producer1 = getMandatoryBean(DefaultProducerTemplate.class, "producer1"); assertEquals("Inject a wrong camel context", producer1.getCamelContext().getName(), "camel1"); DefaultProducerTemplate producer2 = getMandatoryBean(DefaultProducerTemplate.class, "producer2"); assertEquals("Inject a wrong camel context", producer2.getCamelContext().getName(), "camel2"); DefaultConsumerTemplate consumer = getMandatoryBean(DefaultConsumerTemplate.class, "consumer"); assertEquals("Inject a wrong camel context", consumer.getCamelContext().getName(), "camel2"); }
public SignalkProcessor(){ nmeaProducer= new DefaultProducerTemplate(CamelContextFactory.getInstance()); nmeaProducer.setDefaultEndpointUri(RouteManager.SEDA_NMEA ); outProducer= new DefaultProducerTemplate(CamelContextFactory.getInstance()); outProducer.setDefaultEndpointUri(RouteManager.SEDA_COMMON_OUT ); inProducer= new DefaultProducerTemplate(CamelContextFactory.getInstance()); inProducer.setDefaultEndpointUri(RouteManager.SEDA_INPUT ); try { nmeaProducer.start(); outProducer.start(); inProducer.start(); } catch (Exception e) { logger.error(e.getMessage(),e); } }
public HeartbeatProcessor(){ producer= new DefaultProducerTemplate(CamelContextFactory.getInstance()); producer.setDefaultEndpointUri(RouteManager.SEDA_COMMON_OUT ); try { producer.start(); } catch (Exception e) { logger.error(e.getMessage(),e); } }
private void testScenario(String subKey, String policy, int expectedCount, NavigableSet<String> keys) throws Exception { CamelContext ctx = CamelContextFactory.getInstance(); MockEndpoint resultEndpoint = (MockEndpoint) ctx.getEndpoint("mock:resultEnd"); String session = UUID.randomUUID().toString(); Subscription sub = new Subscription(session, subKey, 10, 1000, FORMAT_DELTA, policy); sub.setRouteId("test"); subscriptionManager.add("ses" + session, session, ConfigConstants.OUTPUT_WS, "127.0.0.1", "127.0.0.1"); subscriptionManager.addSubscription(sub); try { FullExportProcessor processor = new FullExportProcessor(session,"test"); ProducerTemplate exportProducer = new DefaultProducerTemplate(ctx); exportProducer.setDefaultEndpointUri("mock:resultEnd"); exportProducer.start(); processor.outProducer = exportProducer; resultEndpoint.expectedMessageCount(expectedCount); for (String key : keys) { processor.recordEvent(new PathEvent(key, 0, nz.co.fortytwo.signalk.model.event.PathEvent.EventType.ADD)); logger.debug("Posted path event:" + key); } // Sleep to allow for minPeriod. if (POLICY_IDEAL.equals(policy)) { Thread.sleep(100L); } resultEndpoint.assertIsSatisfied(); } finally { subscriptionManager.removeSubscription(sub); subscriptionManager.removeWsSession(session); resultEndpoint.reset(); } }
public void init() throws Exception { template = new DefaultProducerTemplate(routeManager.getContext()); template.setDefaultEndpointUri(DIRECT_INPUT); template.start(); //get model SignalKModel model = SignalKModelFactory.getMotuTestInstance(); model.putAll(TestHelper.getBasicModel().getFullData()); JsonSerializer ser = new JsonSerializer(); jsonString=ser.write(model); }
public void init() throws Exception{ template= new DefaultProducerTemplate(routeManager.getContext()); template.setDefaultEndpointUri(DIRECT_INPUT); template.start(); SignalKModel model = SignalKModelFactory.getCleanInstance(); SignalKModelFactory.loadConfig(signalkModel); logger.debug("SignalKModel at init:"+signalkModel); model.putAll(TestHelper.getBasicModel().getFullData()); JsonSerializer ser = new JsonSerializer(); jsonString=ser.write(model); }
public void init() throws Exception{ declinationProcessor=new DeclinationHandler(); windProcessor = new TrueWindHandler(); template= new DefaultProducerTemplate(routeManager.getContext()); template.setDefaultEndpointUri(DIRECT_INPUT); template.start(); }
/** * broadcast a message to all orchestra nodes to flush their execution stats * * @param exchange * @param workNote */ private void broadcastFlushStats(Exchange exchange, WorkNote workNote) { try { ProducerTemplate template = new DefaultProducerTemplate(exchange.getContext()); template.start(); template.sendBody(this.commandTopicUri, "jobCompleted|" + workNote.getBatchJobId()); template.stop(); } catch (Exception e) { LOG.error("Error sending `that's all folks` message to the orchestra", e); } }
public Class<DefaultProducerTemplate> getObjectType() { return DefaultProducerTemplate.class; }
@Test public void testHasTemplateCamel1() { DefaultProducerTemplate lookup = context1.getRegistry().lookupByNameAndType("template1", DefaultProducerTemplate.class); assertNotNull("Should lookup producer template", lookup); assertEquals("camel1", lookup.getCamelContext().getName()); }
@Test public void testHasTemplateCamel2() { DefaultProducerTemplate lookup = context1.getRegistry().lookupByNameAndType("template2", DefaultProducerTemplate.class); assertNotNull("Should lookup producer template", lookup); assertEquals("camel2", lookup.getCamelContext().getName()); }
@Test public void createDomainOnStartIfNotExists() throws Exception { DefaultProducerTemplate.newInstance(context, "aws-sdb://NonExistingDomain?amazonSDBClient=#amazonSDBClient&operation=GetAttributes"); assertEquals("NonExistingDomain", amazonSDBClient.createDomainRequest.getDomainName()); }
@Test public void whenTableIsMissingThenCreateItOnStart() throws Exception { DefaultProducerTemplate.newInstance(context, "aws-ddb://creatibleTable?amazonDDBClient=#amazonDDBClient"); assertEquals("creatibleTable", amazonDDBClient.createTableRequest.getTableName()); }
public CamelUdpNettyHandler( String outputType) throws Exception { this.outputType=outputType; producer= new DefaultProducerTemplate(CamelContextFactory.getInstance()); producer.setDefaultEndpointUri(RouteManager.SEDA_INPUT ); producer.start(); }
public void init() throws Exception{ template= new DefaultProducerTemplate(routeManager.getContext()); template.setDefaultEndpointUri(DIRECT_INPUT); template.start(); }
void send() { Endpoint endPoint = context.getEndpoint("direct:event-in"); ProducerTemplate template = new DefaultProducerTemplate(context,endPoint); template.sendBody(rawEvent); }