Java 类org.apache.camel.impl.DefaultProducerTemplate 实例源码

项目:camel-consul-leader    文件:ConsulLeaderElectorBuilder.java   
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;
}
项目:secure-data-service    文件:TenantProcessor.java   
/**
 * 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);
    }
}
项目:Camel    文件:RouteboxDirectProducerOnlyTest.java   
@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();
}
项目:Camel    文件:RouteboxDispatchMapTest.java   
@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();
}
项目:Camel    文件:RouteboxDefaultContextAndRouteBuilderTest.java   
@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();
}
项目:Camel    文件:RouteboxDirectTest.java   
@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();
}
项目:Camel    文件:RouteboxSedaTest.java   
@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();
}
项目:Camel    文件:CamelContextAwareTest.java   
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");
}
项目:signalk-server-java    文件:SignalkProcessor.java   
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);
    }
}
项目:signalk-server-java    文件:HeartbeatProcessor.java   
public HeartbeatProcessor(){
    producer= new DefaultProducerTemplate(CamelContextFactory.getInstance());
    producer.setDefaultEndpointUri(RouteManager.SEDA_COMMON_OUT );
    try {
        producer.start();
    } catch (Exception e) {
        logger.error(e.getMessage(),e);
    }

}
项目:signalk-server-java    文件:FullExportProcessorTest.java   
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();
        }
    }
项目:signalk-server-java    文件:SignalKGetOutputTest.java   
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);
    }
项目:signalk-server-java    文件:SignalKSubscriptionOutputTest.java   
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);
}
项目:signalk-server-java    文件:SignalKNmeaReceiverTest.java   
public void init() throws Exception{

    declinationProcessor=new DeclinationHandler();
    windProcessor = new TrueWindHandler();
    template= new DefaultProducerTemplate(routeManager.getContext());
    template.setDefaultEndpointUri(DIRECT_INPUT);
    template.start();
}
项目:secure-data-service    文件:JobReportingProcessor.java   
/**
 * 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);
    }
}
项目:Camel    文件:AbstractCamelProducerTemplateFactoryBean.java   
public Class<DefaultProducerTemplate> getObjectType() {
    return DefaultProducerTemplate.class;
}
项目:Camel    文件:ProducerTemplateMixedAutoRegisterTwoCamelContextsTest.java   
@Test
public void testHasTemplateCamel1() {
    DefaultProducerTemplate lookup = context1.getRegistry().lookupByNameAndType("template1", DefaultProducerTemplate.class);
    assertNotNull("Should lookup producer template", lookup);
    assertEquals("camel1", lookup.getCamelContext().getName());
}
项目:Camel    文件:ProducerTemplateMixedAutoRegisterTwoCamelContextsTest.java   
@Test
public void testHasTemplateCamel2() {
    DefaultProducerTemplate lookup = context1.getRegistry().lookupByNameAndType("template2", DefaultProducerTemplate.class);
    assertNotNull("Should lookup producer template", lookup);
    assertEquals("camel2", lookup.getCamelContext().getName());
}
项目:Camel    文件:SdbComponentSpringTest.java   
@Test
public void createDomainOnStartIfNotExists() throws Exception {
    DefaultProducerTemplate.newInstance(context, "aws-sdb://NonExistingDomain?amazonSDBClient=#amazonSDBClient&operation=GetAttributes");

    assertEquals("NonExistingDomain", amazonSDBClient.createDomainRequest.getDomainName());
}
项目:Camel    文件:SdbComponentTest.java   
@Test
public void createDomainOnStartIfNotExists() throws Exception {
    DefaultProducerTemplate.newInstance(context, "aws-sdb://NonExistingDomain?amazonSDBClient=#amazonSDBClient&operation=GetAttributes");

    assertEquals("NonExistingDomain", amazonSDBClient.createDomainRequest.getDomainName());
}
项目:Camel    文件:DdbComponentTest.java   
@Test
public void whenTableIsMissingThenCreateItOnStart() throws Exception {
    DefaultProducerTemplate.newInstance(context,
            "aws-ddb://creatibleTable?amazonDDBClient=#amazonDDBClient");
    assertEquals("creatibleTable", amazonDDBClient.createTableRequest.getTableName());
}
项目:signalk-server-java    文件:CamelUdpNettyHandler.java   
public CamelUdpNettyHandler( String outputType) throws Exception {
    this.outputType=outputType;
    producer= new DefaultProducerTemplate(CamelContextFactory.getInstance());
    producer.setDefaultEndpointUri(RouteManager.SEDA_INPUT );
    producer.start();
}
项目:signalk-server-java    文件:SignalKListOutputTest.java   
public void init() throws Exception{

    template= new DefaultProducerTemplate(routeManager.getContext());
    template.setDefaultEndpointUri(DIRECT_INPUT);
    template.start();
}
项目:boundary-event-sdk    文件:Event.java   
void send() {
    Endpoint endPoint = context.getEndpoint("direct:event-in");
    ProducerTemplate template = new DefaultProducerTemplate(context,endPoint);
    template.sendBody(rawEvent);
}