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


Java ProducerTemplate.start方法代码示例

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


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

示例1: 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

示例2: testCacheProducers

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

    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,代码行数:23,代码来源:DefaultProducerTemplateTest.java

示例3: testRestartSpringIssue

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testRestartSpringIssue() throws Exception {
    context.startRoute("foo");

    ProducerTemplate producer = context.createProducerTemplate();
    producer.start();

    Object out = producer.requestBody("activemq:queue:foo", "Foo");
    assertEquals("Bye Foo", out);

    // on purpose forget to stop the producer and it should still work

    context.stopRoute("foo");
    context.startRoute("foo");

    out = producer.requestBody("activemq:queue:foo", "Bar");
    assertEquals("Bye Bar", out);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:JmsInOutWithSpringRestartIssueTest.java

示例4: testCamel1RecipientList

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public void testCamel1RecipientList() throws Exception {
    String body = "<hello>world!</hello>";

    // seda:foo has no consumer in camel-1 so we should not expect any messages to be routed to result/foo
    MockEndpoint result = camel1.getEndpoint("mock:result", MockEndpoint.class);
    result.expectedMessageCount(0);

    ProducerTemplate template = camel1.createProducerTemplate();
    template.start();
    template.sendBody("seda:foo", body);
    template.stop();

    Thread.sleep(200);
    
    result.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:PojoDualCamelContextConsumerTest.java

示例5: testCamel2RecipientList

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public void testCamel2RecipientList() throws Exception {
    String body = "<bye>world!</bye>";

    MockEndpoint result = camel2.getEndpoint("mock:result", MockEndpoint.class);
    result.expectedBodiesReceived(body);

    MockEndpoint foo = camel2.getEndpoint("mock:foo", MockEndpoint.class);
    foo.expectedBodiesReceived(body);

    ProducerTemplate template = camel2.createProducerTemplate();
    template.start();
    template.sendBody("direct:foo", body);
    template.stop();

    result.assertIsSatisfied();
    foo.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:PojoDualCamelContextConsumerTest.java

示例6: testXMLRouteLoading

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

    SpringCamelContext context = applicationContext.getBean("camel-A", SpringCamelContext.class);
    assertValidContext(context);

    MockEndpoint resultEndpoint = (MockEndpoint) resolveMandatoryEndpoint(context, "mock:result");
    resultEndpoint.expectedBodiesReceived(body);

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

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

示例7: 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

示例8: testTwo

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

    MockEndpoint result = camel2.getEndpoint("mock:result", MockEndpoint.class);
    result.expectedBodiesReceived("Bye World");

    ProducerTemplate template = camel2.createProducerTemplate();
    template.start();
    template.sendBody("direct:two", "Bye World");
    template.stop();

    result.assertIsSatisfied();

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

示例9: 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

示例10: testAutoStartupTrue

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

    SpringCamelContext camel = ac.getBeansOfType(SpringCamelContext.class).values().iterator().next();
    assertNotNull(camel.getName());
    assertEquals(true, camel.isStarted());
    assertEquals(Boolean.TRUE, camel.isAutoStartup());
    assertEquals(1, camel.getRoutes().size());

    // 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,代码行数:21,代码来源:CamelContextAutoStartupTest.java

示例11: testAutoStartupFalse

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

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

    assertEquals(false, camel.getRouteStatus("foo").isStarted());

    // now starting route manually
    camel.startRoute("foo");
    assertEquals(true, camel.getRouteStatus("foo").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,代码行数:23,代码来源:RouteAutoStartupPropertiesTest.java

示例12: 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

示例13: testSendUsingDefaultEndpoint

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

    getMockEndpoint("mock:result").expectedMessageCount(3);

    producer.sendBody("Hello");
    producer.sendBodyAndHeader("Hello", "foo", 123);
    Map<String, Object> headers = new HashMap<String, Object>();
    producer.sendBodyAndHeaders("Hello", headers);

    assertMockEndpointsSatisfied();

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

示例14: sendText

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
protected void sendText(final String fragment, CamelContext context) throws Exception {
    ProducerTemplate template = context.createProducerTemplate();
    template.start();
    template.send("direct:start", new Processor() {
        public void process(Exchange exchange) throws Exception {
            // Set the property of the charset encoding
            exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
            Message in = exchange.getIn();
            in.setBody(fragment);
            log.info("xmlFragment: {}", fragment);
        }
    });
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:14,代码来源:TestHelper.java

示例15: testCamel1

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public void testCamel1() throws Exception {
    String body = "<hello>world!</hello>";

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

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

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


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