All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.camel.PollingConsumer Maven / Gradle / Ivy

The newest version!
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.camel;

/**
 * Represents a Polling Consumer where the caller polls for
 * messages when it is ready.
 * 

* When you are done with the returned {@link Exchange} you must ensure to invoke * {@link org.apache.camel.spi.UnitOfWork#done(Exchange)} to signal to Camel that the {@link Exchange} is done. *

* This is needed to ensure any {@link org.apache.camel.spi.Synchronization} works is being executed. For example if you * consumed from a file endpoint, then the consumed file is only moved/delete when you done the {@link Exchange}. *

* Important: Do not do any initialization in the constructor. Instead use * {@link org.apache.camel.support.service.ServiceSupport#doInit()} or * {@link org.apache.camel.support.service.ServiceSupport#doStart()}. */ public interface PollingConsumer extends Consumer { /** * Waits until a message is available and then returns it. Warning that this method could block indefinitely if no * messages are available. *

* Will return null if the consumer is not started *

* Important: See the class javadoc about the need for done the {@link org.apache.camel.spi.UnitOfWork} on * the returned {@link Exchange} * * @return the message exchange received. */ Exchange receive(); /** * Attempts to receive a message exchange immediately without waiting and returning null if a message * exchange is not available yet. *

* Important: See the class javadoc about the need for done the {@link org.apache.camel.spi.UnitOfWork} on * the returned {@link Exchange} * * @return the message exchange if one is immediately available otherwise null */ Exchange receiveNoWait(); /** * Attempts to receive a message exchange, waiting up to the given timeout to expire if a message is not yet * available. *

* Important: See the class javadoc about the need for done the {@link org.apache.camel.spi.UnitOfWork} on * the returned {@link Exchange} * * @param timeout the amount of time in milliseconds to wait for a message before timing out and returning * null * * @return the message exchange if one was available within the timeout period, or null if the * timeout expired */ Exchange receive(long timeout); }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy