Package org.apache.camel
Interface PollingConsumer
- All Superinterfaces:
AutoCloseable
,Consumer
,EndpointAware
,Service
Represents a Polling Consumer where the caller polls for
messages when it is ready.
When you are done with the returned
Exchange
you must ensure to invoke
UnitOfWork.done(Exchange)
to signal to Camel that the Exchange
is done.
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
.
Important: Do not do any initialization in the constructor. Instead use
BaseService.doInit()
or
BaseService.doStart()
.-
Method Summary
Modifier and TypeMethodDescriptionreceive()
Waits until a message is available and then returns it.receive
(long timeout) Attempts to receive a message exchange, waiting up to the given timeout to expire if a message is not yet available.Attempts to receive a message exchange immediately without waiting and returning null if a message exchange is not available yet.Methods inherited from interface org.apache.camel.Consumer
createExchange, defaultConsumerCallback, getProcessor, releaseExchange
Methods inherited from interface org.apache.camel.EndpointAware
getEndpoint
-
Method Details
-
receive
Exchange receive()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 theUnitOfWork
on the returnedExchange
- Returns:
- the message exchange received.
-
receiveNoWait
Exchange receiveNoWait()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 theUnitOfWork
on the returnedExchange
- Returns:
- the message exchange if one is immediately available otherwise null
-
receive
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 theUnitOfWork
on the returnedExchange
- Parameters:
timeout
- the amount of time in milliseconds to wait for a message before timing out and returning null- Returns:
- the message exchange if one was available within the timeout period, or null if the timeout expired
-