本文整理汇总了Java中org.apache.camel.ProducerTemplate.stop方法的典型用法代码示例。如果您正苦于以下问题:Java ProducerTemplate.stop方法的具体用法?Java ProducerTemplate.stop怎么用?Java ProducerTemplate.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.camel.ProducerTemplate
的用法示例。
在下文中一共展示了ProducerTemplate.stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRoutes
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testRoutes() throws Exception {
CamelContext context = getCamelContext();
assertNotNull(context);
assertEquals("MyCamel", context.getName());
assertEquals(2, context.getRoutes().size());
ProducerTemplate template = context.createProducerTemplate();
MockEndpoint mock = context.getEndpoint("mock:foo", MockEndpoint.class);
mock.expectedMessageCount(1);
MockEndpoint mock2 = context.getEndpoint("mock:bar", MockEndpoint.class);
mock2.expectedMessageCount(1);
template.sendBody("direct:foo", "Hello World");
template.sendBody("direct:bar", "Bye World");
mock.assertIsSatisfied();
mock2.assertIsSatisfied();
template.stop();
}
示例2: 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);
}
示例3: doStopTemplates
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
private static void doStopTemplates(ConsumerTemplate consumer,
ProducerTemplate template) throws Exception {
if (consumer != null) {
if (consumer == threadConsumer.get()) {
threadConsumer.remove();
}
consumer.stop();
consumer = null;
}
if (template != null) {
if (template == threadTemplate.get()) {
threadTemplate.remove();
}
template.stop();
template = null;
}
}
示例4: requestBody
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public Object requestBody(String endpointUri, Object body) throws Exception {
ProducerTemplate template = context.createProducerTemplate();
Object answer = null;
try {
answer = template.requestBody(endpointUri, body);
} finally {
template.stop();
}
return answer;
}
示例5: sendExchangesThroughDroppingThrottler
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
private void sendExchangesThroughDroppingThrottler(List<Exchange> sentExchanges, int messages) throws Exception {
ProducerTemplate myTemplate = context.createProducerTemplate();
DirectEndpoint targetEndpoint = resolveMandatoryEndpoint("direct:sample", DirectEndpoint.class);
for (int i = 0; i < messages; i++) {
Exchange e = targetEndpoint.createExchange();
e.getIn().setBody("<message>" + i + "</message>");
// only send if we are still started
if (context.getStatus().isStarted()) {
myTemplate.send(targetEndpoint, e);
sentExchanges.add(e);
Thread.sleep(100);
}
}
myTemplate.stop();
}
示例6: 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();
}
示例7: testCamelContext
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testCamelContext() throws Exception {
CamelContext context = getCamelContext();
assertNotNull(context);
assertEquals("MyCamel", context.getName());
ProducerTemplate template = context.createProducerTemplate();
MockEndpoint mock = context.getEndpoint("mock:foo", MockEndpoint.class);
mock.expectedMessageCount(1);
template.sendBody("seda:foo", "Hello World");
mock.assertIsSatisfied();
template.stop();
}
示例8: testCacheProducersFromContext
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public void testCacheProducersFromContext() throws Exception {
ProducerTemplate template = context.createProducerTemplate(500);
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());
}
示例9: testCamelContext
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testCamelContext() throws Exception {
CamelContext context = getCamelContext();
assertNotNull(context);
assertEquals("MyCamel", context.getName());
ProducerTemplate template = context.createProducerTemplate();
MockEndpoint mock = context.getEndpoint("mock:foo", MockEndpoint.class);
mock.expectedBodiesReceived("Hello World");
template.sendBody("seda:foo", "World");
mock.assertIsSatisfied();
template.stop();
}
示例10: testStandalone
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
public void testStandalone() throws Exception {
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to("mock:result");
}
});
context.start();
MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class);
mock.expectedMessageCount(1);
ProducerTemplate template = context.createProducerTemplate();
template.sendBody("direct:start", "Hello World");
mock.assertIsSatisfied();
template.stop();
context.stop();
}
示例11: 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");
}
}
示例12: 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());
}
示例13: 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());
}
示例14: 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();
}
示例15: testJettyMulticastJmsFile
import org.apache.camel.ProducerTemplate; //导入方法依赖的package包/类
@Test
public void testJettyMulticastJmsFile() throws Exception {
TestSupport.deleteDirectory("target/jetty");
ProducerTemplate template = camelContext.createProducerTemplate();
String out = template.requestBody(URL, "Hello World", String.class);
assertEquals("Bye World", out);
template.stop();
ConsumerTemplate consumer = camelContext.createConsumerTemplate();
String in = consumer.receiveBody("jms:queue:foo", 5000, String.class);
assertEquals("Hello World", in);
String in2 = consumer.receiveBody("file://target/jetty?noop=true&readLock=none", 5000, String.class);
assertEquals("Hello World", in2);
consumer.stop();
}