Package org.apache.camel

Examples of org.apache.camel.PollingConsumer


        template.sendBodyAndHeaders("activemq:queue:bar?preserveMessageQos=true", "Hello World", headers);

        // sleep just a little
        Thread.sleep(50);

        PollingConsumer consumer = context.getEndpoint("activemq:queue:bar").createPollingConsumer();
        consumer.start();

        Exchange bar = consumer.receive(5000);
        assertNotNull("Should be a message on queue", bar);

        consumer.stop();

        template.send("activemq:queue:foo?preserveMessageQos=true", bar);

        Thread.sleep(1000);
View Full Code Here


        template.sendBodyAndHeaders("activemq:queue:bar?preserveMessageQos=true", "Hello World", headers);

        // sleep more so the message is expired
        Thread.sleep(5000);

        PollingConsumer consumer = context.getEndpoint("activemq:queue:bar").createPollingConsumer();
        consumer.start();

        Exchange bar = consumer.receiveNoWait();
        assertNull("Should NOT be a message on queue", bar);

        consumer.stop();

        template.sendBody("activemq:queue:foo", "Hello World");

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

     * 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

        this.consumers = cache;
    }

    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) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("<<<< " + endpoint);
        }

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

    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

        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

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.