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


Java ProducerTemplate.sendBodyAndHeader方法代码示例

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


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

示例1: main

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-file-client.xml");

    // get the camel template for Spring template style sending of messages (= producer)
    final ProducerTemplate producer = context.getBean("camelTemplate", ProducerTemplate.class);

    // now send a lot of messages
    System.out.println("Writing files ...");

    for (int i = 0; i < SIZE; i++) {
        producer.sendBodyAndHeader("file:target//inbox", "File " + i, Exchange.FILE_NAME, i + ".txt");
    }

    System.out.println("... Wrote " + SIZE + " files");

    // we're done so let's properly close the application context
    IOHelper.close(context);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:CamelFileClient.java

示例2: xxxTestForkAndJoin

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public void xxxTestForkAndJoin() throws InterruptedException {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(NUMBER_OF_MESSAGES);

    ProducerTemplate template = context.createProducerTemplate();
    for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
        template.sendBodyAndHeader("seda:fork", "Test Message: " + i,
                "seqnum", new Long(i));
    }

    long expectedTime = NUMBER_OF_MESSAGES
            * (RandomSleepProcessor.MAX_PROCESS_TIME + RandomSleepProcessor.MIN_PROCESS_TIME)
            / 2 / CONCURRENCY + TIMEOUT;
    Thread.sleep(expectedTime);

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

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

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

示例5: testInvokeServers

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

    ProducerTemplate template = camelContext.createProducerTemplate();
    List<String> params = new ArrayList<String>();
    params.add("Willem");
    Object result = template.sendBodyAndHeader("cxf://bean:serviceEndpoint", ExchangePattern.InOut,
                                               params, CxfConstants.OPERATION_NAME, "greetMe");
    assertTrue("Result is a list instance ", result instanceof List);
    assertEquals("Get the wrong response", ((List<?>)result).get(0), "HelloWillem");
    try {
        template.sendBodyAndHeader("cxf://bean:serviceEndpoint", ExchangePattern.InOut,
                                        params, CxfConstants.OPERATION_NAME, "pingMe");
        fail("Expect exception here.");
    } catch (Exception ex) {
        assertTrue("Get a wrong exception.", ex instanceof CamelExecutionException);
        assertTrue("Get a wrong exception cause. ", ex.getCause() instanceof PingMeFault);
    }
    template.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:CamelGreeterConsumerTest.java

示例6: testMocksAreValid

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

    ProducerTemplate template = camelContext.createProducerTemplate();
    template.sendBodyAndHeader(URL, "Hello form Willem", "Operation", "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) {
        Object result = exchange.getIn().getBody();
        assertEquals("Should get the request", "Hello form Willem", result);
        assertEquals("Should get the header", "greetMe", exchange.getIn().getHeader("Operation"));
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:JettyJmsTest.java

示例7: testMulticastEndpoint

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testMulticastEndpoint() throws Exception {
    assertNotNull(resultEndpoint);
    assertNotNull(fileEndpoint);
    
    resultEndpoint.reset();
    fileEndpoint.reset();
    
    ProducerTemplate template = camelContext.createProducerTemplate();
    template.sendBodyAndHeader("direct:start", "Hello form Willem", "Operation", "greetMe");

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

    MockEndpoint.assertIsSatisfied(camelContext);
    List<Exchange> resultExchanges = resultEndpoint.getReceivedExchanges();
    assertEquals("Should get one message for mock endpoint", resultExchanges.size(), 1);
    
    String result = resultExchanges.get(0).getIn().getBody(String.class);
    assertEquals("Should get the request", "<response>Hello form Willem</response>", result);        
    assertEquals("Should get the responise code", 200, resultExchanges.get(0).getIn().getHeader(Exchange.HTTP_RESPONSE_CODE));        
    
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:JettyFileMulticastTest.java

示例8: testPostStatusUpdateRequestResponse

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testPostStatusUpdateRequestResponse() throws Exception {
    Date now = new Date();
    String tweet = "UserProducerInOutTest: This is a tweet posted on " + now.toString();
    LOG.info("Tweet: " + tweet);
    ProducerTemplate producerTemplate = context.createProducerTemplate();
    // send tweet to the twitter endpoint
    producerTemplate.sendBodyAndHeader("direct:tweets", tweet, "customHeader", 12312);


    resultEndpoint.expectedMessageCount(1);
    resultEndpoint.expectedBodyReceived().body(Status.class);
    // Message headers should be preserved
    resultEndpoint.expectedHeaderReceived("customHeader", 12312);
    resultEndpoint.assertIsSatisfied();

    List<Exchange> tweets = resultEndpoint.getExchanges();
    assertNotNull(tweets);
    assertThat(tweets.size(), is(1));
    Status receivedTweet = tweets.get(0).getIn().getBody(Status.class);
    assertNotNull(receivedTweet);
    // The identifier for the published tweet should be there
    assertNotNull(receivedTweet.getId());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:UserProducerInOutTest.java

示例9: testPostStatusUpdateRequestResponse

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testPostStatusUpdateRequestResponse() throws Exception {
    Date now = new Date();
    String tweet = "UserProducerInOnlyTest: This is a tweet posted on " + now.toString();
    LOG.info("Tweet: " + tweet);
    ProducerTemplate producerTemplate = context.createProducerTemplate();
    // send tweet to the twitter endpoint
    producerTemplate.sendBodyAndHeader("direct:tweets", tweet, "customHeader", 12312);


    resultEndpoint.expectedMessageCount(1);
    resultEndpoint.expectedBodyReceived().body(String.class);
    // Message headers should be preserved
    resultEndpoint.expectedHeaderReceived("customHeader", 12312);
    resultEndpoint.assertIsSatisfied();

    List<Exchange> tweets = resultEndpoint.getExchanges();
    assertNotNull(tweets);
    assertThat(tweets.size(), is(1));
    String receivedTweet = tweets.get(0).getIn().getBody(String.class);
    assertThat(receivedTweet, is(tweet));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:UserProducerInOnlyTest.java

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

示例11: testPutAndConsume

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testPutAndConsume() throws InterruptedException {
    ProducerTemplate template = context.createProducerTemplate();
    template.sendBodyAndHeader("direct:put", "TEST1", KratiConstants.KEY, "1");
    template.sendBodyAndHeader("direct:put", "TEST2", KratiConstants.KEY, "2");
    template.sendBodyAndHeader("direct:put", "TEST3", KratiConstants.KEY, "3");
    MockEndpoint endpoint = context.getEndpoint("mock:results", MockEndpoint.class);
    endpoint.expectedMessageCount(3);
    endpoint.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:KratiConsumerSpringTest.java

示例12: runTests

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
private void runTests(CamelContext context) throws Exception {
    MockEndpoint resultEndpoint = context.getEndpoint("mock:result", MockEndpoint.class);
    ProducerTemplate template = context.createProducerTemplate();
    
    String expectedBody = "<matched/>";
    resultEndpoint.expectedBodiesReceived(expectedBody);
    template.sendBodyAndHeader("direct:start", expectedBody, "foo", "bar");
    resultEndpoint.assertIsSatisfied();
    
    resultEndpoint.reset();
    resultEndpoint.expectedMessageCount(0);
    template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo", "notMatchedHeaderValue");
    resultEndpoint.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:15,代码来源:MainTest.java

示例13: sendValue

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
private static void sendValue(final ProducerTemplate producerTemplate, final Variant variant) {
	// we always write synchronously since we do need the message order
	producerTemplate.sendBodyAndHeader(variant, "await", true);
}
 
开发者ID:ctron,项目名称:de.dentrassi.camel.milo,代码行数:5,代码来源:WriteClientTest.java

示例14: sendMessage

import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
void sendMessage(@Observes CamelContextStartedEvent event, @Uri("sjms:sample.queue") ProducerTemplate producer) {
    producer.sendBodyAndHeader("Sample Message", "Sender", getClass().getSimpleName());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:Producer.java


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