Search in sources :

Example 6 with ConsumerTemplate

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

the class ConsumerTemplateAlreadyExistTest method testShouldBeSingleton.

@Test
public void testShouldBeSingleton() {
    ConsumerTemplate lookup = context.getRegistry().lookupByNameAndType("myConsumerTemplate", ConsumerTemplate.class);
    assertNotNull("Should lookup producer template", lookup);
    ConsumerTemplate lookup2 = context.getRegistry().lookupByNameAndType("myConsumerTemplate", ConsumerTemplate.class);
    assertNotNull("Should lookup producer template", lookup);
    assertSame("Should be same instances (singleton)", lookup, lookup2);
}
Also used : ConsumerTemplate(org.apache.camel.ConsumerTemplate) Test(org.junit.Test)

Example 7 with ConsumerTemplate

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

the class ConsumerTemplateMaximumCacheSizeTest method testTemplateMaximumCache.

@Test
public void testTemplateMaximumCache() throws Exception {
    assertNotNull("Should have injected a consumer template", template);
    ConsumerTemplate lookup = context.getRegistry().lookupByNameAndType("template", ConsumerTemplate.class);
    assertNotNull("Should lookup consumer template", lookup);
    assertEquals(50, template.getMaximumCacheSize());
    assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
    // test that we cache at most 50 producers to avoid it eating to much memory
    for (int i = 0; i < 53; i++) {
        Endpoint e = context.getEndpoint("direct:queue:" + i);
        template.receiveNoWait(e);
    }
    // the eviction is async so force cleanup
    template.cleanUp();
    assertEquals("Size should be 50", 50, 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) Test(org.junit.Test)

Example 8 with ConsumerTemplate

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

the class ProducerTemplateMixedAutoRegisterTwoCamelContextsTest method testHasNoConsumerTemplateCamel1.

@Test
public void testHasNoConsumerTemplateCamel1() {
    ConsumerTemplate lookup = context1.getRegistry().lookupByNameAndType("consumerTemplate", ConsumerTemplate.class);
    assertNull("Should NOT lookup consumer template", lookup);
}
Also used : ConsumerTemplate(org.apache.camel.ConsumerTemplate) Test(org.junit.Test)

Example 9 with ConsumerTemplate

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

the class JettyMulticastJmsFileTest method testJettyMulticastJmsFile.

@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();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) ConsumerTemplate(org.apache.camel.ConsumerTemplate) Test(org.junit.Test)

Example 10 with ConsumerTemplate

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

the class ConsumerTemplateAutoRegisterTest method testHasTemplate.

@Test
public void testHasTemplate() {
    assertNotNull("Should have injected a consumer template", template);
    assertNotNull("The template context should not be null", ((DefaultConsumerTemplate) template).getCamelContext());
    ConsumerTemplate lookup = context.getRegistry().lookupByNameAndType("consumerTemplate", ConsumerTemplate.class);
    assertNotNull("Should lookup consumer template", lookup);
}
Also used : ConsumerTemplate(org.apache.camel.ConsumerTemplate) DefaultConsumerTemplate(org.apache.camel.impl.DefaultConsumerTemplate) 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