Package org.apache.camel

Examples of org.apache.camel.PollingConsumer


    public Exchange receive(Endpoint endpoint, long timeout) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("<<<< " + endpoint);
        }

        PollingConsumer consumer = getConsumer(endpoint);
        return consumer.receive(timeout);
    }
View Full Code Here


    public Exchange receiveNoWait(Endpoint endpoint) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("<<<< " + endpoint);
        }

        PollingConsumer consumer = getConsumer(endpoint);
        return consumer.receiveNoWait();
    }
View Full Code Here

        assertEquals("Size should be 0", 0, cache.size());

        // test that we cache at most 1000 producers to avoid it eating to much memory
        for (int i = 0; i < 1003; i++) {
            Endpoint e = context.getEndpoint("direct:queue:" + i);
            PollingConsumer p = cache.getConsumer(e);
        }

        assertEquals("Size should be 1000", 1000, cache.size());
        cache.stop();
    }
View Full Code Here

        assertEquals("Size should be 0", 0, cache.size());

        // test that we cache at most 1000 consumers to avoid it eating to much memory
        for (int i = 0; i < 1003; i++) {
            Endpoint e = context.getEndpoint("direct:queue:" + i);
            PollingConsumer p = cache.getConsumer(e);
            assertNotNull("the polling consumer should not be null", p);
        }

        assertEquals("Size should be 1000", 1000, cache.size());
        cache.stop();
View Full Code Here

        prepareFtpServer();
    }

    @Test
    public void testConsumerDeleteNoWritePermission() throws Exception {
        PollingConsumer consumer = context.getEndpoint(getFtpUrl()).createPollingConsumer();
        consumer.start();
        Exchange out = consumer.receive(3000);
        assertNotNull("Should get the file", out);

        try {
            // give consumer time to try to delete the file
            Thread.sleep(1000);
            consumer.stop();
        } catch (GenericFileOperationFailedException fofe) {
            // expected, ignore
        }
    }
View Full Code Here

public class InvalidConfigurationTest extends CamelTestSupport {

    @Test
    public void testSMTPCanNotBeUsedForConsumingMails() throws Exception {
        Endpoint endpoint = this.context.getEndpoint("smtp://localhost?username=james");
        PollingConsumer consumer = endpoint.createPollingConsumer();
        try {
            consumer.start();
            fail("Should have thrown NoSuchProviderException as stmp protocol cannot be used for consuming mails");
        } catch (IllegalArgumentException e) {
            // expected
        }
    }
View Full Code Here

    }

    @Test
    public void testSMTPSCanNotBeUsedForConsumingMails() throws Exception {
        Endpoint endpoint = this.context.getEndpoint("smtps://localhost?username=james");
        PollingConsumer consumer = endpoint.createPollingConsumer();
        try {
            consumer.start();
            fail("Should have thrown NoSuchProviderException as stmp protocol cannot be used for consuming mails");
        } catch (IllegalArgumentException e) {
            // expected
        }
    }
View Full Code Here

                        // create a ftp endpoint
                        Endpoint ftp = context.getEndpoint(url);

                        // create a polling consumer where we can poll the myfile from the ftp server
                        PollingConsumer consumer = ftp.createPollingConsumer();

                        // must start the consumer before we can receive
                        consumer.start();

                        // poll the file from the ftp server
                        Exchange result = consumer.receive();

                        // the result is the response from the FTP consumer (the downloaded file)
                        // replace the outher exchange with the content from the downloaded file
                        exchange.getIn().setBody(result.getIn().getBody());

                        // stop the consumer
                        consumer.stop();
                    }
                }).to("mock:result");
                // END SNIPPET: e2
            }
        };
View Full Code Here

    }

    public void testPollingConsumer() throws Exception {
        template.sendBodyAndHeader("file:target/enrich", "Hello World", Exchange.FILE_NAME, "hello.txt");

        PollingConsumer consumer = context.getEndpoint("file:target/enrich").createPollingConsumer();
        consumer.start();
        Exchange exchange = consumer.receive(5000);
        assertNotNull(exchange);
        assertEquals("Hello World", exchange.getIn().getBody(String.class));

        // sleep a bit to ensure polling consumer would be suspended after we have used it
        Thread.sleep(500);

        // drop a new file which should not be picked up by the consumer
        template.sendBodyAndHeader("file:target/enrich", "Bye World", Exchange.FILE_NAME, "bye.txt");

        // sleep a bit to ensure polling consumer would not have picked up that file
        Thread.sleep(1000);

        File file = new File("target/enrich/bye.txt").getAbsoluteFile();
        assertTrue("File should exist " + file, file.exists());

        consumer.stop();
    }
View Full Code Here

    /**
     * Factory method to create a started {@link org.apache.camel.PollingConsumer} to be injected into a POJO
     */
    protected PollingConsumer createInjectionPollingConsumer(Endpoint endpoint) {
        try {
            PollingConsumer pollingConsumer = endpoint.createPollingConsumer();
            startService(pollingConsumer);
            return pollingConsumer;
        } catch (Exception e) {
            throw ObjectHelper.wrapRuntimeCamelException(e);
        }
View Full Code Here

TOP

Related Classes of org.apache.camel.PollingConsumer

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.