Package org.apache.camel
Interface ConsumerTemplate
-
- All Superinterfaces:
AutoCloseable
,Service
public interface ConsumerTemplate extends Service
Template for working with Camel and consumingMessage
instances in anExchange
from anEndpoint
.
This template is an implementation of the Polling Consumer EIP. This is not the Event Driven Consumer EIP.
TheConsumerTemplate
is thread safe.
All methods throwsRuntimeCamelException
if consuming of theExchange
failed and an Exception occurred. The getCause method onRuntimeCamelException
returns the wrapper original caused exception. Before using the template it must be started. And when you are done using the template, make sure toService.stop()
the template. Important note on usage: See this FAQ entry before using, it applies to thisConsumerTemplate
as well.- See Also:
ProducerTemplate
,FluentProducerTemplate
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
cleanUp()
Cleanup the cache (purging stale entries)void
doneUoW(Exchange exchange)
CamelContext
getCamelContext()
Get theCamelContext
int
getCurrentCacheSize()
Gets an approximated size of the current cached resources in the backing cache pools.int
getMaximumCacheSize()
Gets the maximum cache size used.Exchange
receive(String endpointUri)
Receives from the endpoint, waiting until there is a responseExchange
receive(String endpointUri, long timeout)
Receives from the endpoint, waiting until there is a response or the timeout occursExchange
receive(Endpoint endpoint)
Receives from the endpoint, waiting until there is a response.Exchange
receive(Endpoint endpoint, long timeout)
Receives from the endpoint, waiting until there is a response or the timeout occursObject
receiveBody(String endpointUri)
Receives from the endpoint, waiting until there is a responseObject
receiveBody(String endpointUri, long timeout)
Receives from the endpoint, waiting until there is a response or the timeout occurs<T> T
receiveBody(String endpointUri, long timeout, Class<T> type)
Receives from the endpoint, waiting until there is a response or the timeout occurs<T> T
receiveBody(String endpointUri, Class<T> type)
Receives from the endpoint, waiting until there is a responseObject
receiveBody(Endpoint endpoint)
Receives from the endpoint, waiting until there is a responseObject
receiveBody(Endpoint endpoint, long timeout)
Receives from the endpoint, waiting until there is a response or the timeout occurs<T> T
receiveBody(Endpoint endpoint, long timeout, Class<T> type)
Receives from the endpoint, waiting until there is a response or the timeout occurs<T> T
receiveBody(Endpoint endpoint, Class<T> type)
Receives from the endpoint, waiting until there is a responseObject
receiveBodyNoWait(String endpointUri)
Receives from the endpoint, not waiting for a response if non exists.<T> T
receiveBodyNoWait(String endpointUri, Class<T> type)
Receives from the endpoint, not waiting for a response if non exists.Object
receiveBodyNoWait(Endpoint endpoint)
Receives from the endpoint, not waiting for a response if non exists.<T> T
receiveBodyNoWait(Endpoint endpoint, Class<T> type)
Receives from the endpoint, not waiting for a response if non exists.Exchange
receiveNoWait(String endpointUri)
Receives from the endpoint, not waiting for a response if non exists.Exchange
receiveNoWait(Endpoint endpoint)
Receives from the endpoint, not waiting for a response if non exists.void
setMaximumCacheSize(int maximumCacheSize)
Sets a custom maximum cache size.
-
-
-
Method Detail
-
getCamelContext
CamelContext getCamelContext()
Get theCamelContext
- Returns:
- camelContext the Camel context
-
getMaximumCacheSize
int getMaximumCacheSize()
Gets the maximum cache size used.- Returns:
- the maximum cache size
-
setMaximumCacheSize
void setMaximumCacheSize(int maximumCacheSize)
Sets a custom maximum cache size.- Parameters:
maximumCacheSize
- the custom maximum cache size
-
getCurrentCacheSize
int getCurrentCacheSize()
Gets an approximated size of the current cached resources in the backing cache pools.- Returns:
- the size of current cached resources
-
cleanUp
void cleanUp()
Cleanup the cache (purging stale entries)
-
receive
Exchange receive(String endpointUri)
Receives from the endpoint, waiting until there is a response Important: SeedoneUoW(Exchange)
- Parameters:
endpointUri
- the endpoint to receive from- Returns:
- the returned exchange
-
receive
Exchange receive(Endpoint endpoint)
Receives from the endpoint, waiting until there is a response. Important: SeedoneUoW(Exchange)
- Parameters:
endpoint
- the endpoint to receive from- Returns:
- the returned exchange
- See Also:
doneUoW(Exchange)
-
receive
Exchange receive(String endpointUri, long timeout)
Receives from the endpoint, waiting until there is a response or the timeout occurs Important: SeedoneUoW(Exchange)
- Parameters:
endpointUri
- the endpoint to receive fromtimeout
- timeout in millis to wait for a response- Returns:
- the returned exchange, or null if no response
- See Also:
doneUoW(Exchange)
-
receive
Exchange receive(Endpoint endpoint, long timeout)
Receives from the endpoint, waiting until there is a response or the timeout occurs Important: SeedoneUoW(Exchange)
- Parameters:
endpoint
- the endpoint to receive fromtimeout
- timeout in millis to wait for a response- Returns:
- the returned exchange, or null if no response
- See Also:
doneUoW(Exchange)
-
receiveNoWait
Exchange receiveNoWait(String endpointUri)
Receives from the endpoint, not waiting for a response if non exists. Important: SeedoneUoW(Exchange)
- Parameters:
endpointUri
- the endpoint to receive from- Returns:
- the returned exchange, or null if no response
-
receiveNoWait
Exchange receiveNoWait(Endpoint endpoint)
Receives from the endpoint, not waiting for a response if non exists. Important: SeedoneUoW(Exchange)
- Parameters:
endpoint
- the endpoint to receive from- Returns:
- the returned exchange, or null if no response
-
receiveBody
Object receiveBody(String endpointUri)
Receives from the endpoint, waiting until there is a response- Parameters:
endpointUri
- the endpoint to receive from- Returns:
- the returned response body
-
receiveBody
Object receiveBody(Endpoint endpoint)
Receives from the endpoint, waiting until there is a response- Parameters:
endpoint
- the endpoint to receive from- Returns:
- the returned response body
-
receiveBody
Object receiveBody(String endpointUri, long timeout)
Receives from the endpoint, waiting until there is a response or the timeout occurs- Parameters:
endpointUri
- the endpoint to receive fromtimeout
- timeout in millis to wait for a response- Returns:
- the returned response body, or null if no response
-
receiveBody
Object receiveBody(Endpoint endpoint, long timeout)
Receives from the endpoint, waiting until there is a response or the timeout occurs- Parameters:
endpoint
- the endpoint to receive fromtimeout
- timeout in millis to wait for a response- Returns:
- the returned response body, or null if no response
-
receiveBodyNoWait
Object receiveBodyNoWait(String endpointUri)
Receives from the endpoint, not waiting for a response if non exists.- Parameters:
endpointUri
- the endpoint to receive from- Returns:
- the returned response body, or null if no response
-
receiveBodyNoWait
Object receiveBodyNoWait(Endpoint endpoint)
Receives from the endpoint, not waiting for a response if non exists.- Parameters:
endpoint
- the endpoint to receive from- Returns:
- the returned response body, or null if no response
-
receiveBody
<T> T receiveBody(String endpointUri, Class<T> type)
Receives from the endpoint, waiting until there is a response- Parameters:
endpointUri
- the endpoint to receive fromtype
- the expected response type- Returns:
- the returned response body
-
receiveBody
<T> T receiveBody(Endpoint endpoint, Class<T> type)
Receives from the endpoint, waiting until there is a response- Parameters:
endpoint
- the endpoint to receive fromtype
- the expected response type- Returns:
- the returned response body
-
receiveBody
<T> T receiveBody(String endpointUri, long timeout, Class<T> type)
Receives from the endpoint, waiting until there is a response or the timeout occurs- Parameters:
endpointUri
- the endpoint to receive fromtimeout
- timeout in millis to wait for a responsetype
- the expected response type- Returns:
- the returned response body, or null if no response
-
receiveBody
<T> T receiveBody(Endpoint endpoint, long timeout, Class<T> type)
Receives from the endpoint, waiting until there is a response or the timeout occurs- Parameters:
endpoint
- the endpoint to receive fromtimeout
- timeout in millis to wait for a responsetype
- the expected response type- Returns:
- the returned response body, or null if no response
-
receiveBodyNoWait
<T> T receiveBodyNoWait(String endpointUri, Class<T> type)
Receives from the endpoint, not waiting for a response if non exists.- Parameters:
endpointUri
- the endpoint to receive fromtype
- the expected response type- Returns:
- the returned response body, or null if no response
-
receiveBodyNoWait
<T> T receiveBodyNoWait(Endpoint endpoint, Class<T> type)
Receives from the endpoint, not waiting for a response if non exists.- Parameters:
endpoint
- the endpoint to receive fromtype
- the expected response type- Returns:
- the returned response body, or null if no response
-
doneUoW
void doneUoW(Exchange exchange)
If you have used any of the receive methods which returns aExchange
type then you need to invoke this method when you are done using the returnedExchange
. This is needed to ensure anySynchronization
works is being executed. For example if you consumed from a file endpoint, then the consumed file is only moved/delete when you done theExchange
. Note for all the other receive methods which does not return aExchange
type, the done has been executed automatic by Camel itself.- Parameters:
exchange
- the exchange
-
-