當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。