public class DefaultFluentProducerTemplate extends ServiceSupport implements FluentProducerTemplate
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending
Constructor and Description |
---|
DefaultFluentProducerTemplate(CamelContext context) |
Modifier and Type | Method and Description |
---|---|
Future<Object> |
asyncRequest()
Sends asynchronously to the given endpoint (InOut).
|
<T> Future<T> |
asyncRequest(Class<T> type)
Sends asynchronously to the given endpoint (InOut).
|
Future<Exchange> |
asyncSend()
Sends asynchronously to the given endpoint (InOnly).
|
void |
cleanUp()
Cleanup the cache (purging stale entries)
|
FluentProducerTemplate |
clearBody()
Remove the body.
|
FluentProducerTemplate |
clearHeaders()
Remove the headers.
|
protected void |
doStart()
Implementations override this method to support customized start/stop.
|
protected void |
doStop()
Implementations override this method to support customized start/stop.
|
CamelContext |
getCamelContext()
Get the
CamelContext |
int |
getCurrentCacheSize()
Gets an approximated size of the current cached resources in the backing cache pools.
|
Endpoint |
getDefaultEndpoint()
Get the default endpoint to use if none is specified
|
int |
getMaximumCacheSize()
Gets the maximum cache size used in the backing cache pools.
|
boolean |
isEventNotifierEnabled()
Whether the
EventNotifier should be
used by this ProducerTemplate to send events about the Exchange
being sent. |
static FluentProducerTemplate |
on(CamelContext context)
Create the FluentProducerTemplate by setting the camel context
|
Object |
request()
Send to an endpoint (InOut) returning any result output body.
|
<T> T |
request(Class<T> type)
Send to an endpoint (InOut).
|
Exchange |
send()
Send to an endpoint (InOnly)
|
void |
setDefaultEndpoint(Endpoint defaultEndpoint)
Sets the default endpoint to use if none is specified
|
void |
setDefaultEndpointUri(String endpointUri)
Sets the default endpoint uri to use if none is specified
|
void |
setEventNotifierEnabled(boolean eventNotifierEnabled)
Sets whether the
EventNotifier should be
used by this ProducerTemplate to send events about the Exchange
being sent. |
void |
setMaximumCacheSize(int maximumCacheSize)
Sets a custom maximum cache size to use in the backing cache pools.
|
FluentProducerTemplate |
to(Endpoint endpoint)
Endpoint to send to
|
FluentProducerTemplate |
to(String endpointUri)
Endpoint to send to
|
FluentProducerTemplate |
withBody(Object body)
Set the message body
|
FluentProducerTemplate |
withBodyAs(Object body,
Class<?> type)
Set the message body after converting it to the given type
|
FluentProducerTemplate |
withExchange(Exchange exchange)
Set the exchange to use for send.
|
FluentProducerTemplate |
withExchange(Supplier<Exchange> exchangeSupplier)
Set the exchangeSupplier which will be invoke to get the exchange to be
used for send.
|
FluentProducerTemplate |
withHeader(String key,
Object value)
Set the header
|
FluentProducerTemplate |
withProcessor(Processor processor)
Set the processor to use for send/request.
|
FluentProducerTemplate |
withProcessor(Supplier<Processor> processorSupplier)
Set the processorSupplier which will be invoke to get the processor to be
used for send/request.
|
FluentProducerTemplate |
withTemplateCustomizer(Consumer<ProducerTemplate> templateCustomizer)
To customize the producer template for advanced usage like to set the
executor service to use.
|
doResume, doShutdown, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
public DefaultFluentProducerTemplate(CamelContext context)
public CamelContext getCamelContext()
FluentProducerTemplate
CamelContext
getCamelContext
in interface FluentProducerTemplate
public int getCurrentCacheSize()
FluentProducerTemplate
getCurrentCacheSize
in interface FluentProducerTemplate
public void cleanUp()
FluentProducerTemplate
cleanUp
in interface FluentProducerTemplate
public void setDefaultEndpointUri(String endpointUri)
FluentProducerTemplate
setDefaultEndpointUri
in interface FluentProducerTemplate
endpointUri
- the default endpoint uripublic Endpoint getDefaultEndpoint()
FluentProducerTemplate
getDefaultEndpoint
in interface FluentProducerTemplate
public void setDefaultEndpoint(Endpoint defaultEndpoint)
FluentProducerTemplate
setDefaultEndpoint
in interface FluentProducerTemplate
defaultEndpoint
- the default endpoint instancepublic int getMaximumCacheSize()
FluentProducerTemplate
getMaximumCacheSize
in interface FluentProducerTemplate
public void setMaximumCacheSize(int maximumCacheSize)
FluentProducerTemplate
setMaximumCacheSize
in interface FluentProducerTemplate
maximumCacheSize
- the custom maximum cache sizepublic boolean isEventNotifierEnabled()
FluentProducerTemplate
EventNotifier
should be
used by this ProducerTemplate
to send events about the Exchange
being sent.isEventNotifierEnabled
in interface FluentProducerTemplate
public void setEventNotifierEnabled(boolean eventNotifierEnabled)
FluentProducerTemplate
EventNotifier
should be
used by this ProducerTemplate
to send events about the Exchange
being sent.
By default this is enabled.setEventNotifierEnabled
in interface FluentProducerTemplate
eventNotifierEnabled
- true to enable, false to disable.public FluentProducerTemplate withHeader(String key, Object value)
FluentProducerTemplate
withHeader
in interface FluentProducerTemplate
key
- the key of the headervalue
- the value of the headerpublic FluentProducerTemplate clearHeaders()
FluentProducerTemplate
clearHeaders
in interface FluentProducerTemplate
public FluentProducerTemplate withBody(Object body)
FluentProducerTemplate
withBody
in interface FluentProducerTemplate
body
- the bodypublic FluentProducerTemplate withBodyAs(Object body, Class<?> type)
FluentProducerTemplate
withBodyAs
in interface FluentProducerTemplate
body
- the bodytype
- the type which the body should be converted topublic FluentProducerTemplate clearBody()
FluentProducerTemplate
clearBody
in interface FluentProducerTemplate
public FluentProducerTemplate withTemplateCustomizer(Consumer<ProducerTemplate> templateCustomizer)
FluentProducerTemplate
FluentProducerTemplate.on(context) .withTemplateCustomizer( template -> { template.setExecutorService(myExecutor); template.setMaximumCacheSize(10); } ) .withBody("the body") .to("direct:start") .request()Note that it is invoked only once.
withTemplateCustomizer
in interface FluentProducerTemplate
templateCustomizer
- the customizerpublic FluentProducerTemplate withExchange(Exchange exchange)
FluentProducerTemplate
withExchange
in interface FluentProducerTemplate
exchange
- the exchangepublic FluentProducerTemplate withExchange(Supplier<Exchange> exchangeSupplier)
FluentProducerTemplate
withExchange
in interface FluentProducerTemplate
exchangeSupplier
- the supplierpublic FluentProducerTemplate withProcessor(Processor processor)
FluentProducerTemplate
FluentProducerTemplate.on(context) .withProcessor( exchange -> { exchange.getIn().setHeader("Key1", "Val1") exchange.getIn().setHeader("Key2", "Val2") exchange.getIn().setBody("the body") } ) .to("direct:start") .request()
withProcessor
in interface FluentProducerTemplate
public FluentProducerTemplate withProcessor(Supplier<Processor> processorSupplier)
FluentProducerTemplate
withProcessor
in interface FluentProducerTemplate
processorSupplier
- the supplierpublic FluentProducerTemplate to(String endpointUri)
FluentProducerTemplate
to
in interface FluentProducerTemplate
endpointUri
- the endpoint URI to send topublic FluentProducerTemplate to(Endpoint endpoint)
FluentProducerTemplate
to
in interface FluentProducerTemplate
endpoint
- the endpoint to send topublic Object request() throws CamelExecutionException
FluentProducerTemplate
request
in interface FluentProducerTemplate
CamelExecutionException
- is thrown if error occurredpublic <T> T request(Class<T> type) throws CamelExecutionException
FluentProducerTemplate
request
in interface FluentProducerTemplate
type
- the expected response typeCamelExecutionException
- is thrown if error occurredpublic Future<Object> asyncRequest()
FluentProducerTemplate
asyncRequest
in interface FluentProducerTemplate
public <T> Future<T> asyncRequest(Class<T> type)
FluentProducerTemplate
asyncRequest
in interface FluentProducerTemplate
type
- the expected response typepublic Exchange send() throws CamelExecutionException
FluentProducerTemplate
send
in interface FluentProducerTemplate
CamelExecutionException
- is thrown if error occurredpublic Future<Exchange> asyncSend()
FluentProducerTemplate
asyncSend
in interface FluentProducerTemplate
public static FluentProducerTemplate on(CamelContext context)
context
- the camel contextprotected void doStart() throws Exception
ServiceSupport
ServiceSupport.doStop()
for more details.doStart
in class ServiceSupport
Exception
ServiceSupport.doStop()
protected void doStop() throws Exception
ServiceSupport
ServiceSupport.doStop()
method when
the service is being stopped. This method will also be invoked
if the service is still in uninitialized state (eg has not
been started). The method is always called to allow the service
to do custom logic when the service is being stopped, such as when
CamelContext
is shutting down.doStop
in class ServiceSupport
Exception
ServiceSupport.doStart()
Apache Camel