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