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

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

There is a newer version: 4.6.0
Show 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;

/**
 * Template for working with Camel and consuming {@link Message} instances in an
 * {@link Exchange} from an {@link Endpoint}.
 * 
*

This template is an implementation of the * Polling Consumer EIP. * This is not the Event Driven Consumer EIP. *
*

The {@link ConsumerTemplate} is thread safe. *
*

All methods throws {@link RuntimeCamelException} if consuming of * the {@link Exchange} failed and an Exception occurred. The getCause * method on {@link RuntimeCamelException} returns the wrapper original caused * exception. *
*

All the receiveBody methods will return the content according to this strategy *

    *
  • throws {@link RuntimeCamelException} as stated above
  • *
  • The fault.body if there is a fault message set and its not null
  • *
  • The out.body if there is a out message set and its not null
  • *
  • The in.body
  • *
*
*

Before using the template it must be started. * And when you are done using the template, make sure to {@link #stop()} the template. *
*

Important note on usage: See this * FAQ entry * before using, it applies to this {@link ConsumerTemplate} as well. * * @see ProducerTemplate * @see FluentProducerTemplate */ public interface ConsumerTemplate extends Service { /** * Get the {@link CamelContext} * * @return camelContext the Camel context */ CamelContext getCamelContext(); // Configuration methods // ----------------------------------------------------------------------- /** * Gets the maximum cache size used. * * @return the maximum cache size */ int getMaximumCacheSize(); /** * Sets a custom maximum cache size. * * @param maximumCacheSize the custom maximum cache size */ void setMaximumCacheSize(int maximumCacheSize); /** * Gets an approximated size of the current cached resources in the backing cache pools. * * @return the size of current cached resources */ int getCurrentCacheSize(); /** * Cleanup the cache (purging stale entries) */ void cleanUp(); // Synchronous methods // ----------------------------------------------------------------------- /** * Receives from the endpoint, waiting until there is a response *

* Important: See {@link #doneUoW(Exchange)} * * @param endpointUri the endpoint to receive from * @return the returned exchange */ Exchange receive(String endpointUri); /** * Receives from the endpoint, waiting until there is a response. *

* Important: See {@link #doneUoW(Exchange)} * * @param endpoint the endpoint to receive from * @return the returned exchange * @see #doneUoW(Exchange) */ Exchange receive(Endpoint endpoint); /** * Receives from the endpoint, waiting until there is a response * or the timeout occurs *

* Important: See {@link #doneUoW(Exchange)} * * @param endpointUri the endpoint to receive from * @param timeout timeout in millis to wait for a response * @return the returned exchange, or null if no response * @see #doneUoW(Exchange) */ Exchange receive(String endpointUri, long timeout); /** * Receives from the endpoint, waiting until there is a response * or the timeout occurs *

* Important: See {@link #doneUoW(Exchange)} * * @param endpoint the endpoint to receive from * @param timeout timeout in millis to wait for a response * @return the returned exchange, or null if no response * @see #doneUoW(Exchange) */ Exchange receive(Endpoint endpoint, long timeout); /** * Receives from the endpoint, not waiting for a response if non exists. *

* Important: See {@link #doneUoW(Exchange)} * * @param endpointUri the endpoint to receive from * @return the returned exchange, or null if no response */ Exchange receiveNoWait(String endpointUri); /** * Receives from the endpoint, not waiting for a response if non exists. *

* Important: See {@link #doneUoW(Exchange)} * * @param endpoint the endpoint to receive from * @return the returned exchange, or null if no response */ Exchange receiveNoWait(Endpoint endpoint); /** * Receives from the endpoint, waiting until there is a response * * @param endpointUri the endpoint to receive from * @return the returned response body */ Object receiveBody(String endpointUri); /** * Receives from the endpoint, waiting until there is a response * * @param endpoint the endpoint to receive from * @return the returned response body */ Object receiveBody(Endpoint endpoint); /** * Receives from the endpoint, waiting until there is a response * or the timeout occurs * * @param endpointUri the endpoint to receive from * @param timeout timeout in millis to wait for a response * @return the returned response body, or null if no response */ Object receiveBody(String endpointUri, long timeout); /** * Receives from the endpoint, waiting until there is a response * or the timeout occurs * * @param endpoint the endpoint to receive from * @param timeout timeout in millis to wait for a response * @return the returned response body, or null if no response */ Object receiveBody(Endpoint endpoint, long timeout); /** * Receives from the endpoint, not waiting for a response if non exists. * * @param endpointUri the endpoint to receive from * @return the returned response body, or null if no response */ Object receiveBodyNoWait(String endpointUri); /** * Receives from the endpoint, not waiting for a response if non exists. * * @param endpoint the endpoint to receive from * @return the returned response body, or null if no response */ Object receiveBodyNoWait(Endpoint endpoint); /** * Receives from the endpoint, waiting until there is a response * * @param endpointUri the endpoint to receive from * @param type the expected response type * @return the returned response body */ T receiveBody(String endpointUri, Class type); /** * Receives from the endpoint, waiting until there is a response * * @param endpoint the endpoint to receive from * @param type the expected response type * @return the returned response body */ T receiveBody(Endpoint endpoint, Class type); /** * Receives from the endpoint, waiting until there is a response * or the timeout occurs * * @param endpointUri the endpoint to receive from * @param timeout timeout in millis to wait for a response * @param type the expected response type * @return the returned response body, or null if no response */ T receiveBody(String endpointUri, long timeout, Class type); /** * Receives from the endpoint, waiting until there is a response * or the timeout occurs * * @param endpoint the endpoint to receive from * @param timeout timeout in millis to wait for a response * @param type the expected response type * @return the returned response body, or null if no response */ T receiveBody(Endpoint endpoint, long timeout, Class type); /** * Receives from the endpoint, not waiting for a response if non exists. * * @param endpointUri the endpoint to receive from * @param type the expected response type * @return the returned response body, or null if no response */ T receiveBodyNoWait(String endpointUri, Class type); /** * Receives from the endpoint, not waiting for a response if non exists. * * @param endpoint the endpoint to receive from * @param type the expected response type * @return the returned response body, or null if no response */ T receiveBodyNoWait(Endpoint endpoint, Class type); /** * If you have used any of the receive methods which returns a {@link Exchange} type * then you need to invoke this method when you are done using the returned {@link Exchange}. *

* 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}. *

* Note for all the other receive methods which does not return a {@link Exchange} type, * the done has been executed automatic by Camel itself. * * @param exchange the exchange */ void doneUoW(Exchange exchange); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy