Interface ConsumerTemplate

All Superinterfaces:
AutoCloseable, Service

public interface ConsumerTemplate extends Service
Template for working with Camel and consuming Message instances in an Exchange from an Endpoint.

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

The ConsumerTemplate is thread safe.

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

Before using the template it must be started. And when you are done using the template, make sure to Service.stop() the template.

Important note on usage: See this FAQ entry before using, it applies to this ConsumerTemplate as well.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Cleanup the cache (purging stale entries)
    void
    doneUoW(Exchange exchange)
    If you have used any of the receive methods which returns a Exchange type then you need to invoke this method when you are done using the returned Exchange.
    Get the CamelContext
    int
    Gets an approximated size of the current cached resources in the backing cache pools.
    int
    Gets the maximum cache size used.
    receive(String endpointUri)
    Receives from the endpoint, waiting until there is a response
    @Nullable Exchange
    receive(String endpointUri, long timeout)
    Receives from the endpoint, waiting until there is a response or the timeout occurs
    receive(Endpoint endpoint)
    Receives from the endpoint, waiting until there is a response.
    @Nullable Exchange
    receive(Endpoint endpoint, long timeout)
    Receives from the endpoint, waiting until there is a response or the timeout occurs
    @Nullable Object
    receiveBody(String endpointUri)
    Receives from the endpoint, waiting until there is a response
    @Nullable Object
    receiveBody(String endpointUri, long timeout)
    Receives from the endpoint, waiting until there is a response or the timeout occurs
    <T> @Nullable T
    receiveBody(String endpointUri, long timeout, Class<T> type)
    Receives from the endpoint, waiting until there is a response or the timeout occurs
    <T> @Nullable T
    receiveBody(String endpointUri, Class<T> type)
    Receives from the endpoint, waiting until there is a response
    @Nullable Object
    Receives from the endpoint, waiting until there is a response
    @Nullable Object
    receiveBody(Endpoint endpoint, long timeout)
    Receives from the endpoint, waiting until there is a response or the timeout occurs
    <T> @Nullable T
    receiveBody(Endpoint endpoint, long timeout, Class<T> type)
    Receives from the endpoint, waiting until there is a response or the timeout occurs
    <T> @Nullable T
    receiveBody(Endpoint endpoint, Class<T> type)
    Receives from the endpoint, waiting until there is a response
    @Nullable Object
    Receives from the endpoint, not waiting for a response if none exists.
    <T> @Nullable T
    receiveBodyNoWait(String endpointUri, Class<T> type)
    Receives from the endpoint, not waiting for a response if none exists.
    @Nullable Object
    Receives from the endpoint, not waiting for a response if none exists.
    <T> @Nullable T
    receiveBodyNoWait(Endpoint endpoint, Class<T> type)
    Receives from the endpoint, not waiting for a response if none exists.
    @Nullable Exchange
    receiveNoWait(String endpointUri)
    Receives from the endpoint, not waiting for a response if none exists.
    @Nullable Exchange
    Receives from the endpoint, not waiting for a response if none exists.
    void
    setMaximumCacheSize(int maximumCacheSize)
    Sets a custom maximum cache size.

    Methods inherited from interface Service

    build, close, init, start, stop
  • Method Details

    • getCamelContext

      CamelContext getCamelContext()
      Get the CamelContext
      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: See doneUoW(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: See doneUoW(Exchange)

      Parameters:
      endpoint - the endpoint to receive from
      Returns:
      the returned exchange
      See Also:
    • receive

      @Nullable Exchange receive(String endpointUri, long timeout)
      Receives from the endpoint, waiting until there is a response or the timeout occurs

      Important: See doneUoW(Exchange)

      Parameters:
      endpointUri - the endpoint to receive from
      timeout - timeout in millis to wait for a response
      Returns:
      the returned exchange, or null if no response
      See Also:
    • receive

      @Nullable Exchange receive(Endpoint endpoint, long timeout)
      Receives from the endpoint, waiting until there is a response or the timeout occurs

      Important: See doneUoW(Exchange)

      Parameters:
      endpoint - the endpoint to receive from
      timeout - timeout in millis to wait for a response
      Returns:
      the returned exchange, or null if no response
      See Also:
    • receiveNoWait

      @Nullable Exchange receiveNoWait(String endpointUri)
      Receives from the endpoint, not waiting for a response if none exists.

      Important: See doneUoW(Exchange)

      Parameters:
      endpointUri - the endpoint to receive from
      Returns:
      the returned exchange, or null if no response
    • receiveNoWait

      @Nullable Exchange receiveNoWait(Endpoint endpoint)
      Receives from the endpoint, not waiting for a response if none exists.

      Important: See doneUoW(Exchange)

      Parameters:
      endpoint - the endpoint to receive from
      Returns:
      the returned exchange, or null if no response
    • receiveBody

      @Nullable 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, or null if no body
    • receiveBody

      @Nullable 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, or null if no body
    • receiveBody

      @Nullable 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 from
      timeout - timeout in millis to wait for a response
      Returns:
      the returned response body, or null if no response
    • receiveBody

      @Nullable 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 from
      timeout - timeout in millis to wait for a response
      Returns:
      the returned response body, or null if no response
    • receiveBodyNoWait

      @Nullable Object receiveBodyNoWait(String endpointUri)
      Receives from the endpoint, not waiting for a response if none exists.
      Parameters:
      endpointUri - the endpoint to receive from
      Returns:
      the returned response body, or null if no response
    • receiveBodyNoWait

      @Nullable Object receiveBodyNoWait(Endpoint endpoint)
      Receives from the endpoint, not waiting for a response if none exists.
      Parameters:
      endpoint - the endpoint to receive from
      Returns:
      the returned response body, or null if no response
    • receiveBody

      <T> @Nullable T receiveBody(String endpointUri, Class<T> type)
      Receives from the endpoint, waiting until there is a response
      Parameters:
      endpointUri - the endpoint to receive from
      type - the expected response type
      Returns:
      the returned response body, or null if no body
    • receiveBody

      <T> @Nullable T receiveBody(Endpoint endpoint, Class<T> type)
      Receives from the endpoint, waiting until there is a response
      Parameters:
      endpoint - the endpoint to receive from
      type - the expected response type
      Returns:
      the returned response body, or null if no body
    • receiveBody

      <T> @Nullable 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 from
      timeout - timeout in millis to wait for a response
      type - the expected response type
      Returns:
      the returned response body, or null if no response
    • receiveBody

      <T> @Nullable 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 from
      timeout - timeout in millis to wait for a response
      type - the expected response type
      Returns:
      the returned response body, or null if no response
    • receiveBodyNoWait

      <T> @Nullable T receiveBodyNoWait(String endpointUri, Class<T> type)
      Receives from the endpoint, not waiting for a response if none exists.
      Parameters:
      endpointUri - the endpoint to receive from
      type - the expected response type
      Returns:
      the returned response body, or null if no response
    • receiveBodyNoWait

      <T> @Nullable T receiveBodyNoWait(Endpoint endpoint, Class<T> type)
      Receives from the endpoint, not waiting for a response if none exists.
      Parameters:
      endpoint - the endpoint to receive from
      type - 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 a Exchange type then you need to invoke this method when you are done using the returned Exchange.

      This is needed to ensure any 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 Exchange.

      Note for all the other receive methods which does not return a Exchange type, the done has been executed automatic by Camel itself.

      Parameters:
      exchange - the exchange