当前位置: 首页>>代码示例>>Java>>正文


Java ProducerTemplate.stop方法代码示例

本文整理汇总了Java中org.apache.camel.ProducerTemplate.stop方法的典型用法代码示例。如果您正苦于以下问题:Java ProducerTemplate.stop方法的具体用法?Java ProducerTemplate.stop怎么用?Java ProducerTemplate.stop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.camel.ProducerTemplate的用法示例。


在下文中一共展示了ProducerTemplate.stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRoutes

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testRoutes() throws Exception {
    CamelContext context = getCamelContext();
    assertNotNull(context);

    assertEquals("MyCamel", context.getName());
    assertEquals(2, context.getRoutes().size());

    ProducerTemplate template = context.createProducerTemplate();

    MockEndpoint mock = context.getEndpoint("mock:foo", MockEndpoint.class);
    mock.expectedMessageCount(1);
    MockEndpoint mock2 = context.getEndpoint("mock:bar", MockEndpoint.class);
    mock2.expectedMessageCount(1);

    template.sendBody("direct:foo", "Hello World");
    template.sendBody("direct:bar", "Bye World");

    mock.assertIsSatisfied();
    mock2.assertIsSatisfied();

    template.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:RoutesFromXmlTest.java

示例2: testOne

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public void testOne() throws Exception {
    int start = myInterceptor.getCount();

    MockEndpoint result = camel1.getEndpoint("mock:result", MockEndpoint.class);
    result.expectedBodiesReceived("Hello World");

    ProducerTemplate template = camel1.createProducerTemplate();
    template.start();
    template.sendBody("direct:one", "Hello World");
    template.stop();

    result.assertIsSatisfied();

    // lets see if the counter is +1 since last (has 1 step in the route)
    int delta = myInterceptor.getCount() - start;
    assertEquals("Should have been counted +1", 1, delta);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:ContainerWideInterceptorTest.java

示例3: doStopTemplates

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
private static void doStopTemplates(ConsumerTemplate consumer,
                                    ProducerTemplate template) throws Exception {
    if (consumer != null) {
        if (consumer == threadConsumer.get()) {
            threadConsumer.remove();
        }
        consumer.stop();
        consumer = null;
    }
    if (template != null) {
        if (template == threadTemplate.get()) {
            threadTemplate.remove();
        }
        template.stop();
        template = null;
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:CamelTestSupport.java

示例4: requestBody

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public Object requestBody(String endpointUri, Object body) throws Exception {
    ProducerTemplate template = context.createProducerTemplate();
    Object answer = null;
    try {
        answer = template.requestBody(endpointUri, body);
    } finally {
        template.stop();
    }
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:ManagedCamelContext.java

示例5: sendExchangesThroughDroppingThrottler

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
private void sendExchangesThroughDroppingThrottler(List<Exchange> sentExchanges, int messages) throws Exception {
    ProducerTemplate myTemplate = context.createProducerTemplate();

    DirectEndpoint targetEndpoint = resolveMandatoryEndpoint("direct:sample", DirectEndpoint.class);
    for (int i = 0; i < messages; i++) {
        Exchange e = targetEndpoint.createExchange();
        e.getIn().setBody("<message>" + i + "</message>");
        // only send if we are still started
        if (context.getStatus().isStarted()) {
            myTemplate.send(targetEndpoint, e);
            sentExchanges.add(e);
            Thread.sleep(100);
        }
    }
    myTemplate.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:SamplingThrottlerTest.java

示例6: testRequestUsingDefaultEndpoint

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public void testRequestUsingDefaultEndpoint() throws Exception {
    ProducerTemplate producer = new DefaultProducerTemplate(context, context.getEndpoint("direct:out"));
    producer.start();

    Object out = producer.requestBody("Hello");
    assertEquals("Bye Bye World", out);

    out = producer.requestBodyAndHeader("Hello", "foo", 123);
    assertEquals("Bye Bye World", out);

    Map<String, Object> headers = new HashMap<String, Object>();
    out = producer.requestBodyAndHeaders("Hello", headers);
    assertEquals("Bye Bye World", out);

    out = producer.requestBodyAndHeaders("Hello", null);
    assertEquals("Bye Bye World", out);

    producer.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:DefaultProducerTemplateTest.java

示例7: testCamelContext

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testCamelContext() throws Exception {
    CamelContext context = getCamelContext();
    assertNotNull(context);

    assertEquals("MyCamel", context.getName());

    ProducerTemplate template = context.createProducerTemplate();

    MockEndpoint mock = context.getEndpoint("mock:foo", MockEndpoint.class);
    mock.expectedMessageCount(1);

    template.sendBody("seda:foo", "Hello World");

    mock.assertIsSatisfied();
    template.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:SingleRouteTest.java

示例8: testCacheProducersFromContext

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public void testCacheProducersFromContext() throws Exception {
    ProducerTemplate template = context.createProducerTemplate(500);

    assertEquals("Size should be 0", 0, template.getCurrentCacheSize());

    // test that we cache at most 500 producers to avoid it eating to much memory
    for (int i = 0; i < 503; i++) {
        Endpoint e = context.getEndpoint("seda:queue:" + i);
        template.sendBody(e, "Hello");
    }

    // the eviction is async so force cleanup
    template.cleanUp();

    assertEquals("Size should be 500", 500, template.getCurrentCacheSize());
    template.stop();

    // should be 0
    assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:DefaultProducerTemplateTest.java

示例9: testCamelContext

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testCamelContext() throws Exception {
    CamelContext context = getCamelContext();
    assertNotNull(context);

    assertEquals("MyCamel", context.getName());

    ProducerTemplate template = context.createProducerTemplate();

    MockEndpoint mock = context.getEndpoint("mock:foo", MockEndpoint.class);
    mock.expectedBodiesReceived("Hello World");

    template.sendBody("seda:foo", "World");

    mock.assertIsSatisfied();
    template.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:LifecycleTest.java

示例10: testStandalone

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public void testStandalone() throws Exception {
    CamelContext context = new DefaultCamelContext();
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").to("mock:result");
        }
    });
    context.start();

    MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMessageCount(1);

    ProducerTemplate template = context.createProducerTemplate();
    template.sendBody("direct:start", "Hello World");

    mock.assertIsSatisfied();

    template.stop();
    context.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:CamelContextStandaloneTest.java

示例11: testMocksAreValid

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testMocksAreValid() throws Exception {
    assertNotNull(camelContext);
    assertNotNull(resultEndpoint);

    ProducerTemplate template = camelContext.createProducerTemplate();
    template.sendBodyAndHeader("jms:requestQueue", "Willem", CxfConstants.OPERATION_NAME, "greetMe");

    // Sleep a while and wait for the message whole processing
    Thread.sleep(4000);
    template.stop();

    MockEndpoint.assertIsSatisfied(camelContext);
    List<Exchange> list = resultEndpoint.getReceivedExchanges();
    assertEquals("Should get one message", list.size(), 1);
    for (Exchange exchange : list) {
        String result = (String) exchange.getIn().getBody();
        assertEquals("Get the wrong result ", result, "Hello Willem");
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:CamelGreeterTest.java

示例12: testFileWithOnewayOperation

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testFileWithOnewayOperation() throws Exception {
    deleteDirectory("target/messages/input/");
    greeterImpl.resetOneWayCounter();
    ProducerTemplate template = context.createProducerTemplate();
    template.sendBodyAndHeader("file://target/messages/input/", "Hello World", Exchange.FILE_NAME, "hello.txt");

    // Sleep a while and wait for the message whole processing
    Thread.sleep(4000);
    template.stop();
    
    // make sure the greeter is called
    assertEquals("The oneway operation of greeter should be called", 1, greeterImpl.getOneWayCounter());

    File file = new File("target/messages/input/hello.txt");
    assertFalse("File " + file + " should be deleted", file.exists());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:CamelFileGreeterOneWayTest.java

示例13: testXMLRouteLoading

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public void testXMLRouteLoading() throws Exception {
    applicationContext = createApplicationContext();

    SpringCamelContext context = applicationContext.getBeansOfType(SpringCamelContext.class).values().iterator().next();
    assertValidContext(context);

    // now lets send a message
    ProducerTemplate template = context.createProducerTemplate();
    template.start();
    template.send("direct:start", new Processor() {
        public void process(Exchange exchange) {
            Message in = exchange.getIn();
            in.setHeader("name", "James");
            in.setBody(body);
        }
    });
    template.stop();

    MyProcessor myProcessor = applicationContext.getBean("myProcessor", MyProcessor.class);
    List<Exchange> list = myProcessor.getExchanges();
    assertEquals("Should have received a single exchange: " + list, 1, list.size());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:CustomProcessorWithNamespacesTest.java

示例14: testAutoStartupTrue

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public void testAutoStartupTrue() throws Exception {
    ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/RouteAutoStartupTrueTest.xml");

    SpringCamelContext camel = ac.getBeansOfType(SpringCamelContext.class).values().iterator().next();

    assertEquals(true, camel.getRouteStatus("bar").isStarted());

    // and now we can send a message to the route and see that it works
    MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMessageCount(1);

    ProducerTemplate template = camel.createProducerTemplate();
    template.start();
    template.sendBody("direct:start", "Hello World");
    template.stop();

    mock.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:RouteAutoStartupPropertiesTest.java

示例15: testJettyMulticastJmsFile

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testJettyMulticastJmsFile() throws Exception {
    TestSupport.deleteDirectory("target/jetty");

    ProducerTemplate template = camelContext.createProducerTemplate();

    String out = template.requestBody(URL, "Hello World", String.class);
    assertEquals("Bye World", out);

    template.stop();

    ConsumerTemplate consumer = camelContext.createConsumerTemplate();
    String in = consumer.receiveBody("jms:queue:foo", 5000, String.class);
    assertEquals("Hello World", in);

    String in2 = consumer.receiveBody("file://target/jetty?noop=true&readLock=none", 5000, String.class);
    assertEquals("Hello World", in2);

    consumer.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:JettyMulticastJmsFileTest.java


注:本文中的org.apache.camel.ProducerTemplate.stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。