Package org.apache.camel

Examples of org.apache.camel.PollingConsumer


    }

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

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


    }

    public Exchange receiveNoWait(Endpoint endpoint) {
        LOG.debug("<<<< {}", endpoint);

        PollingConsumer consumer = getConsumer(endpoint);
        return consumer.receiveNoWait();
    }
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, Object bean, String beanName) {
        try {
            PollingConsumer pollingConsumer = endpoint.createPollingConsumer();
            startService(pollingConsumer, bean, beanName);
            return pollingConsumer;
        } catch (Exception e) {
            throw ObjectHelper.wrapRuntimeCamelException(e);
        }
View Full Code Here

        };
    }

    @Override
    public PollingConsumer createPollingConsumer() throws Exception {
        PollingConsumer answer = new ProcessorPollingConsumer(this, getProcessor());
        configurePollingConsumer(answer);
        return answer;
    }
View Full Code Here

     * Creates a {@link PollingConsumer} and polls all pending messages on the endpoint
     * and invokes the given {@link Processor} to process each {@link Exchange} and then closes
     * down the consumer and throws any exceptions thrown.
     */
    public static void pollEndpoint(Endpoint endpoint, Processor processor, long timeout) throws Exception {
        PollingConsumer consumer = endpoint.createPollingConsumer();
        try {
            consumer.start();

            while (true) {
                Exchange exchange = consumer.receive(timeout);
                if (exchange == null) {
                    break;
                } else {
                    processor.process(exchange);
                }
            }
        } finally {
            try {
                consumer.stop();
            } catch (Exception e) {
                LOG.warn("Failed to stop PollingConsumer: " + e, e);
            }
        }
    }
View Full Code Here

    @Test
    public void testPollingConsumer() throws Exception {
        template.sendBodyAndHeader(getFtpUrl(), "Hello World", Exchange.FILE_NAME, "hello.txt");

        PollingConsumer consumer = context.getEndpoint(getFtpUrl()).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(1000);

        // drop a new file which should not be picked up by the consumer
        template.sendBodyAndHeader(getFtpUrl(), "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(FTP_ROOT_DIR + "/polling/bye.txt");
        assertTrue("File should exist " + file, file.exists());

        consumer.stop();
    }
View Full Code Here

        Jt400DataQueueEndpoint endpoint = resolveMandatoryEndpoint(
                "jt400://user:" + PASSWORD + "@host/qsys.lib/library.lib/queue.dtaq?connectionPool=#mockPool&pollStrategy=#jt400PollStrategy",
                Jt400DataQueueEndpoint.class);
        assertNotNull(endpoint);

        PollingConsumer consumer = endpoint.createPollingConsumer();
        assertNotNull(consumer);
    }
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");
        assertTrue("File should exist " + file, file.exists());

        consumer.stop();
    }
View Full Code Here

     * Creates a {@link PollingConsumer} and polls all pending messages on the endpoint
     * and invokes the given {@link Processor} to process each {@link Exchange} and then closes
     * down the consumer and throws any exceptions thrown.
     */
    public static void pollEndpoint(Endpoint endpoint, Processor processor, long timeout) throws Exception {
        PollingConsumer consumer = endpoint.createPollingConsumer();
        try {
            consumer.start();

            while (true) {
                Exchange exchange = consumer.receive(timeout);
                if (exchange == null) {
                    break;
                } else {
                    processor.process(exchange);
                }
            }
        } finally {
            try {
                consumer.stop();
            } catch (Exception e) {
                LOG.warn("Failed to stop PollingConsumer: " + e, e);
            }
        }
    }
View Full Code Here

        super.setUp();
        context.addComponent("my", new MyQueueComponent());
    }

    public void testQueueSize() throws Exception {
        PollingConsumer consumer = context.getEndpoint(uri).createPollingConsumer();
        consumer.start();

        assertNotNull(consumer);
        EventDrivenPollingConsumer edpc = assertIsInstanceOf(EventDrivenPollingConsumer.class, consumer);
        assertEquals(0, edpc.getQueueSize());
        assertEquals(10, edpc.getQueueCapacity());
        assertFalse(edpc.isBlockWhenFull());

        for (int i = 0; i < 10; i++) {
            template.sendBody(uri, "Message " + i);
        }

        assertEquals(10, edpc.getQueueSize());

        try {
            template.sendBody(uri, "Message 10");
            fail("Should have thrown exception");
        } catch (CamelExecutionException e) {
            // queue should be full
            assertIsInstanceOf(IllegalStateException.class, e.getCause());
        }

        Exchange out = consumer.receive(5000);
        assertNotNull(out);
        assertEquals("Message 0", out.getIn().getBody());

        assertEquals(9, edpc.getQueueSize());
        assertEquals(10, edpc.getQueueCapacity());
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.