public interface FluentProducerTemplate extends Service
Message
instances in an
Exchange
to an Endpoint
using a fluent build style.
CamelExecutionException
while others stores any thrown exception on the returned
Exchange
.
FluentProducerTemplate
is thread safe.
FailedToCreateProducerException
in
case the Producer
could not be created. Or a NoSuchEndpointException
if the endpoint could
not be resolved. There may be other related exceptions being thrown which occurs before the Producer
has started sending the message.
CamelExecutionException
if processing failed during routing
with the caused exception wrappedService.stop()
the template.
ProducerTemplate
,
ConsumerTemplate
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 |
clearAll()
Remove the body and headers.
|
FluentProducerTemplate |
clearBody()
Remove the body.
|
FluentProducerTemplate |
clearHeaders()
Remove the headers.
|
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. |
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 enabled)
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.
|
CamelContext getCamelContext()
CamelContext
int getMaximumCacheSize()
void setMaximumCacheSize(int maximumCacheSize)
maximumCacheSize
- the custom maximum cache sizeint getCurrentCacheSize()
Endpoint getDefaultEndpoint()
void setDefaultEndpoint(Endpoint defaultEndpoint)
defaultEndpoint
- the default endpoint instancevoid setDefaultEndpointUri(String endpointUri)
endpointUri
- the default endpoint urivoid setEventNotifierEnabled(boolean enabled)
EventNotifier
should be
used by this ProducerTemplate
to send events about the Exchange
being sent.
By default this is enabled.enabled
- true to enable, false to disable.boolean isEventNotifierEnabled()
EventNotifier
should be
used by this ProducerTemplate
to send events about the Exchange
being sent.void cleanUp()
FluentProducerTemplate clearAll()
FluentProducerTemplate withHeader(String key, Object value)
key
- the key of the headervalue
- the value of the headerFluentProducerTemplate clearHeaders()
FluentProducerTemplate withBody(Object body)
body
- the bodyFluentProducerTemplate withBodyAs(Object body, Class<?> type)
body
- the bodytype
- the type which the body should be converted toFluentProducerTemplate clearBody()
FluentProducerTemplate withTemplateCustomizer(Consumer<ProducerTemplate> templateCustomizer)
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.templateCustomizer
- the customizerFluentProducerTemplate withExchange(Exchange exchange)
exchange
- the exchangeFluentProducerTemplate withExchange(Supplier<Exchange> exchangeSupplier)
exchangeSupplier
- the supplierFluentProducerTemplate withProcessor(Processor processor)
FluentProducerTemplate.on(context)
.withProcessor(
exchange -> {
exchange.getIn().setHeader("Key1", "Val1");
exchange.getIn().setHeader("Key2", "Val2");
exchange.getIn().setBody("the body");
}
)
.to("direct:start")
.request()
processor
- FluentProducerTemplate withProcessor(Supplier<Processor> processorSupplier)
processorSupplier
- the supplierFluentProducerTemplate to(String endpointUri)
endpointUri
- the endpoint URI to send toFluentProducerTemplate to(Endpoint endpoint)
endpoint
- the endpoint to send toObject request() throws CamelExecutionException
CamelExecutionException
- is thrown if error occurred<T> T request(Class<T> type) throws CamelExecutionException
type
- the expected response typeCamelExecutionException
- is thrown if error occurredFuture<Object> asyncRequest()
<T> Future<T> asyncRequest(Class<T> type)
type
- the expected response typeExchange send() throws CamelExecutionException
CamelExecutionException
- is thrown if error occurredApache Camel