本文整理汇总了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);
}
示例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();
}
示例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");
}
}
示例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());
}
示例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();
}
示例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"));
}
}
示例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));
}
示例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());
}
示例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));
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
示例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());
}