Search in sources :

Example 16 with ConsumerTemplate

use of org.apache.camel.ConsumerTemplate in project camel by apache.

the class DefaultConsumerTemplateWithCustomCacheMaxSizeTest method testCacheConsumers.

public void testCacheConsumers() throws Exception {
    ConsumerTemplate template = context.createConsumerTemplate();
    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 < 203; i++) {
        Endpoint e = context.getEndpoint("direct:queue:" + i);
        template.receiveNoWait(e);
    }
    // the eviction is async so force cleanup
    template.cleanUp();
    assertEquals("Size should be 200", 200, template.getCurrentCacheSize());
    template.stop();
    // should be 0
    assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
}
Also used : ConsumerTemplate(org.apache.camel.ConsumerTemplate) Endpoint(org.apache.camel.Endpoint) Endpoint(org.apache.camel.Endpoint)

Example 17 with ConsumerTemplate

use of org.apache.camel.ConsumerTemplate in project camel by apache.

the class RedeliveryErrorHandlerAsyncDelayedTwoCamelContextIssueTest method shouldNotBreakRedeliveriesOfSecondContextAfterFirstBeingStopped.

@Test
public void shouldNotBreakRedeliveriesOfSecondContextAfterFirstBeingStopped() throws Exception {
    DefaultCamelContext context1 = createContext();
    ProducerTemplate producer1 = context1.createProducerTemplate();
    ConsumerTemplate consumer1 = context1.createConsumerTemplate();
    context1.start();
    producer1.sendBody("seda://input", "Hey1");
    Exchange ex1 = consumer1.receive("seda://output", 5000);
    DefaultCamelContext context2 = createContext();
    ProducerTemplate producer2 = context2.createProducerTemplate();
    ConsumerTemplate consumer2 = context2.createConsumerTemplate();
    context2.start();
    // now stop 1, and see that 2 is still working
    consumer1.stop();
    producer1.stop();
    context1.stop();
    producer2.sendBody("seda://input", "Hey2");
    Exchange ex2 = consumer2.receive("seda://output", 5000);
    Assert.assertNotNull(ex1);
    Assert.assertEquals("Hey1", ex1.getIn().getBody());
    Assert.assertNotNull(ex2);
    Assert.assertEquals("Hey2", ex2.getIn().getBody());
    consumer2.stop();
    producer2.stop();
    context2.stop();
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) ConsumerTemplate(org.apache.camel.ConsumerTemplate) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Aggregations

ConsumerTemplate (org.apache.camel.ConsumerTemplate)17 Test (org.junit.Test)11 Endpoint (org.apache.camel.Endpoint)4 ProducerTemplate (org.apache.camel.ProducerTemplate)3 Exchange (org.apache.camel.Exchange)2 CamelContext (org.apache.camel.CamelContext)1 CamelExchangeException (org.apache.camel.CamelExchangeException)1 Processor (org.apache.camel.Processor)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 DefaultConsumerTemplate (org.apache.camel.impl.DefaultConsumerTemplate)1 Before (org.junit.Before)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1