Poll

Camel supports the Content Enricher from the EIP patterns.

image

In Camel the Content Enricher can be done in several ways:

The Poll EIP is a simplified Poll Enrich which only supports:

  • Static Endpoints

  • No custom aggregation or other advanced features

  • Uses a 20 seconds timeout (default)

Options

The Poll eip supports 0 options, which are listed below.

Name Description Default Type

description

Sets the description of this node.

String

disabled

Whether to disable this EIP from the route during build time. Once an EIP has been disabled then it cannot be enabled later at runtime.

false

Boolean

variableReceive

To use a variable to store the received message body (only body, not headers). This is handy for easy access to the received message body via variables. Important: When using receive variable then the received body is stored only in this variable and not on the current Message .

String

uri

Required Sets the uri of the endpoint to poll from.

String

timeout

Timeout in millis when polling from the external service. The timeout has influence about the poll enrich behavior. It basically operations in three different modes: negative value - Waits until a message is available and then returns it. Warning that this method could block indefinitely if no messages are available. 0 - Attempts to receive a message exchange immediately without waiting and returning null if a message exchange is not available yet. positive value - Attempts to receive a message exchange, waiting up to the given timeout to expire if a message is not yet available. Returns null if timed out The default value is 20000 (20 seconds).

20000

String

Exchange properties

The Poll eip has no exchange properties.

Polling a message using Poll EIP

poll uses a Polling Consumer to obtain the data. It is usually used for Event Message messaging, for instance, to read a file or download a file using FTP.

We have three methods when polling:

  • receive: Waits until a message is available and then returns it. Warning that this method could block indefinitely if no messages are available.

  • receiveNoWait: Attempts to receive a message exchange immediately without waiting and returning null if a message exchange is not available yet.

  • receive(timeout): Attempts to receive a message exchange, waiting up to the given timeout to expire if a message is not yet available. Returns the message or null if the timeout expired.

Timeout

By default, Camel will use the receive(timeout) which has a 20 seconds timeout.

You can pass in a timeout value that determines which method to use:

  • if timeout is -1 or other negative number then receive is selected (Important: the receive method may block if there is no message)

  • if timeout is 0 then receiveNoWait is selected

  • otherwise, receive(timeout) is selected

The timeout values are in milliseconds.

Using Poll

For example to download an FTP file:

<rest path="/report">
    <description>Report REST API</description>
    <get path="/{id}/payload">
        <route id="report-payload-download">
            <poll uri="ftp:myserver.com/myfolder?fileName=report-file.pdf"/>
        </route>
    </get>
</rest>
You can use dynamic values using the simple language in the uri, as shown below:
<rest path="/report">
    <description>Report REST API</description>
    <get path="/{id}/payload">
        <route id="report-payload-download">
            <poll uri="ftp:myserver.com/myfolder?fileName=report-${header.id}.pdf"/>
        </route>
    </get>
</rest>

Using Poll with Rest DSL

You can also use poll with Rest DSL to, for example, download a file from AWS S3 as the response of an API call.

<rest path="/report">
    <description>Report REST API</description>
    <get path="/{id}/payload">
        <route id="report-payload-download">
            <poll uri="aws-s3:xavier-dev?amazonS3Client=#s3client&amp;deleteAfterRead=false&amp;fileName=report-file.pdf"/>
        </route>
    </get>
</rest>

See More