Package org.apache.camel

Examples of org.apache.camel.PollingConsumer


        return new LRUSoftCache<String, PollingConsumer>(cacheSize);
    }

    public synchronized PollingConsumer getConsumer(Endpoint endpoint) {
        String key = endpoint.getEndpointUri();
        PollingConsumer answer = consumers.get(key);
        if (answer == null) {
            try {
                answer = endpoint.createPollingConsumer();
                answer.start();
            } catch (Exception e) {
                throw new FailedToCreateConsumerException(endpoint, e);
            }

            boolean singleton = true;
View Full Code Here


    }

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

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

    }

    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

     * 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

    /**
     * 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

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

        Endpoint endpoint = context.getEndpoint("file://target/fpc?fileName=hello.txt");
        PollingConsumer consumer = endpoint.createPollingConsumer();
        consumer.start();
        Exchange exchange = consumer.receive(5000);
        assertNotNull(exchange);

        assertEquals("hello.txt", exchange.getIn().getHeader(Exchange.FILE_NAME, String.class));
        assertEquals("Hello World", exchange.getIn().getBody(String.class));

        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

        return new LRUSoftCache<String, PollingConsumer>(cacheSize);
    }

    public synchronized PollingConsumer getConsumer(Endpoint endpoint) {
        String key = endpoint.getEndpointUri();
        PollingConsumer answer = consumers.get(key);
        if (answer == null) {
            try {
                answer = endpoint.createPollingConsumer();
                answer.start();
            } catch (Exception e) {
                throw new FailedToCreateConsumerException(endpoint, e);
            }

            boolean singleton = true;
View Full Code Here

    }

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

        PollingConsumer consumer = getConsumer(endpoint);
        return consumer.receive();
    }
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.