Package org.apache.camel

Examples of org.apache.camel.ConsumerTemplate


    @Autowired
    private CamelContext context;

    public void testHasTwoTemplates() {
        ConsumerTemplate lookup = context.getRegistry().lookup("myTemplate", ConsumerTemplate.class);
        assertNotNull("Should lookup producer template", lookup);

        ConsumerTemplate lookup2 = context.getRegistry().lookup("myOtherTemplate", ConsumerTemplate.class);
        assertNotNull("Should lookup producer template", lookup2);

        assertNotSame("Should not be same", lookup, lookup2);
    }
View Full Code Here


    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().lookup("consumerTemplate", ConsumerTemplate.class);
        assertNotNull("Should lookup consumer template", lookup);
    }
View Full Code Here

    /**
     * Factory method to create a {@link org.apache.camel.ConsumerTemplate} to be injected into a POJO
     */
    protected ConsumerTemplate createInjectionConsumerTemplate(String endpointUri, String endpointRef, String injectionPointName) {
        ConsumerTemplate answer = new DefaultConsumerTemplate(getCamelContext());
        // start the template so its ready to use
        try {
            answer.start();
        } catch (Exception e) {
            throw ObjectHelper.wrapRuntimeCamelException(e);
        }
        return answer;
    }
View Full Code Here

        context.getProperties().put(Exchange.MAXIMUM_CACHE_POOL_SIZE, "200");
        return context;
    }

    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);
        }

        assertEquals("Size should be 200", 200, template.getCurrentCacheSize());
        template.stop();

        // should be 0
        assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
    }
View Full Code Here

        String out = consumer.receiveBody("seda:foo", String.class);
        assertEquals("Bye World", out);
    }

    public void testCacheConsumers() throws Exception {
        ConsumerTemplate template = new DefaultConsumerTemplate(context);
        template.setMaximumCacheSize(500);
        template.start();

        assertEquals("Size should be 0", 0, template.getCurrentCacheSize());

        // test that we cache at most 500 consumers to avoid it eating to much memory
        for (int i = 0; i < 503; i++) {
            Endpoint e = context.getEndpoint("direct:queue:" + i);
            template.receiveNoWait(e);
        }

        assertEquals("Size should be 500", 500, template.getCurrentCacheSize());
        template.stop();

        // should be 0
        assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
    }
View Full Code Here

        // should be 0
        assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
    }

    public void testCacheConsumersFromContext() throws Exception {
        ConsumerTemplate template = context.createConsumerTemplate(500);

        assertEquals("Size should be 0", 0, template.getCurrentCacheSize());

        // test that we cache at most 500 consumers to avoid it eating to much memory
        for (int i = 0; i < 503; i++) {
            Endpoint e = context.getEndpoint("direct:queue:" + i);
            template.receiveNoWait(e);
        }

        assertEquals("Size should be 500", 500, template.getCurrentCacheSize());
        template.stop();

        // should be 0
        assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
    }
View Full Code Here

        // should be 0
        assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
    }

    public void testCacheConsumersFromContext() throws Exception {
        ConsumerTemplate template = context.createConsumerTemplate(500);

        assertEquals("Size should be 0", 0, template.getCurrentCacheSize());

        // test that we cache at most 500 consumers to avoid it eating to much memory
        for (int i = 0; i < 503; i++) {
            Endpoint e = context.getEndpoint("direct:queue:" + i);
            template.receiveNoWait(e);
        }

        assertEquals("Size should be 500", 500, template.getCurrentCacheSize());
        template.stop();

        // should be 0
        assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
    }
View Full Code Here

        String out = consumer.receiveBody("seda:foo", String.class);
        assertEquals("Bye World", out);
    }

    public void testCacheConsumers() throws Exception {
        ConsumerTemplate template = new DefaultConsumerTemplate(context);
        template.setMaximumCacheSize(500);
        template.start();

        assertEquals("Size should be 0", 0, template.getCurrentCacheSize());

        // test that we cache at most 500 consumers to avoid it eating to much memory
        for (int i = 0; i < 503; i++) {
            Endpoint e = context.getEndpoint("direct:queue:" + i);
            template.receiveNoWait(e);
        }

        assertEquals("Size should be 500", 500, template.getCurrentCacheSize());
        template.stop();

        // should be 0
        assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
    }
View Full Code Here

    /**
     * Factory method to create a {@link org.apache.camel.ConsumerTemplate} to be injected into a POJO
     */
    protected ConsumerTemplate createInjectionConsumerTemplate(String endpointUri, String endpointRef, String injectionPointName) {
        ConsumerTemplate answer = new DefaultConsumerTemplate(getCamelContext());
        // start the template so its ready to use
        try {
            answer.start();
        } catch (Exception e) {
            throw ObjectHelper.wrapRuntimeCamelException(e);
        }
        return answer;
    }
View Full Code Here

                            String name = exchange.getIn().getHeader(Exchange.FILE_NAME_ONLY, String.class);
                            name = FileUtil.stripExt(name) + ".dat";

                            // use a consumer template to get the data file
                            Exchange data = null;
                            ConsumerTemplate con = exchange.getContext().createConsumerTemplate();
                            try {
                                // try to get the data file
                                data = con.receive("file://target/enrichdata?move=.done&fileName=" + name, 5000);
                            } finally {
                                // stop the consumer as it does not need to poll for files anymore
                                con.stop();
                            }

                            // if we found the data file then process it by sending it to the direct:data endpoint
                            if (data != null) {
                                template.send("direct:data", data);
View Full Code Here

TOP

Related Classes of org.apache.camel.ConsumerTemplate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.