Red Hat build of Apache Camel for Spring Boot Reference


Red Hat build of Apache Camel 4.4

Red Hat build of Apache Camel for Spring Boot Reference

Red Hat build of Apache Camel Documentation Team Red Hat build of Apache Camel Support Team http://access.redhat.com/support

Abstract

This guide describes the settings for Red Hat build of Apache Camel components.

Preface

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. We are beginning with these four terms: master, slave, blacklist, and whitelist. Because of the enormity of this endeavor, these changes will be implemented gradually over several upcoming releases. For more details, see our CTO Chris Wright’s message.

Chapter 1. Component Starters

Camel Spring Boot supports the following Camel artifacts as Spring Boot Starters:

Note

The BOM for Red Hat build of Apache Camel for Camel Spring Boot lists both supported and unsupported components. See Component Starters for the latest list of supported components.

Table 1.1. Camel Components
ComponentArtifactDescriptionSupport on IBM Power and IBM Z

AMQP

camel-amqp-starter

Messaging with AMQP protocol using Apache QPid Client.

Yes

AWS Cloudwatch

camel-aws2-cw-starter

Sending metrics to AWS CloudWatch using AWS SDK version 2.x.

Yes

AWS DynamoDB

camel-aws2-ddb-starter

Store and retrieve data from AWS DynamoDB service using AWS SDK version 2.x.

Yes

AWS Kinesis

camel-aws2-kinesis-starter

Consume and produce records from and to AWS Kinesis Streams using AWS SDK version 2.x.

Yes

AWS Lambda

camel-aws2-lambda-starter

Manage and invoke AWS Lambda functions using AWS SDK version 2.x.

Yes

AWS S3 Storage Service

camel-aws2-s3-starter

Store and retrieve objects from AWS S3 Storage Service using AWS SDK version 2.x.

Yes

AWS Simple Notification System (SNS)

camel-aws2-sns-starter

Send messages to an AWS Simple Notification Topic using AWS SDK version 2.x.

Yes

AWS Simple Queue Service (SQS)

camel-aws2-sqs-starter

Send and receive messages to/from AWS SQS service using AWS SDK version 2.x.

Yes

Azure ServiceBus

camel-azure-servicebus-starter

Send and receive messages to/from Azure Event Bus.

Yes

Azure Storage Blob Service

camel-azure-storage-blob-starter

Store and retrieve blobs from Azure Storage Blob Service using SDK v12.

Yes

Azure Storage Queue Service

camel-azure-storage-queue-starter

The azure-storage-queue component is used for storing and retrieving the messages to/from Azure Storage Queue using Azure SDK v12.

Yes

Bean

camel-bean-starter

Invoke methods of Java beans stored in Camel registry.

Yes

Bean Validator

camel-bean-validator-starter

Validate the message body using the Java Bean Validation API.

Yes

Browse

camel-browse-starter

Inspect the messages received on endpoints supporting BrowsableEndpoint.

Yes

Cassandra CQL

camel-cassandraql-starter

Integrate with Cassandra 2.0 using the CQL3 API (not the Thrift API). Based on Cassandra Java Driver provided by DataStax.

Yes

CICS

camel-cics-starter

Interact with CICS® general-purpose transaction processing subsystem.

No

Control Bus

camel-controlbus-starter

Manage and monitor Camel routes.

Yes

Cron

camel-cron-starter

A generic interface for triggering events at times specified through the Unix cron syntax.

Yes

Crypto (JCE)

camel-crypto-starter

Sign and verify exchanges using the Signature Service of the Java Cryptographic Extension (JCE).

Yes

CXF

camel-cxf-soap-starter

Expose SOAP WebServices using Apache CXF or connect to external WebServices using CXF WS client.

Yes

CXF-RS

camel-cxf-rest-starter

Expose JAX-RS REST services using Apache CXF or connect to external REST services using CXF REST client.

Yes

Data Format

camel-dataformat-starter

Use a Camel Data Format as a regular Camel Component.

Yes

Dataset

camel-dataset-starter

Provide data for load and soak testing of your Camel application.

Yes

Direct

camel-direct-starter

Call another endpoint from the same Camel Context synchronously.

Yes

Elastic Search

camel-elasticsearch-starter

Send requests to ElasticSearch via Java Client API.

No

FHIR

camel-fhir-starter

Exchange information in the healthcare domain using the FHIR (Fast Healthcare Interoperability Resources) standard.

No

File

camel-file-starter

Read and write files.

Yes

Flink

camel-flink-starter

Send DataSet jobs to an Apache Flink cluster.

Yes

FTP

camel-ftp-starter

Upload and download files to/from FTP servers.

Yes

Google BigQuery

camel-google-bigquery-starter

Google BigQuery data warehouse for analytics.

Yes

Google Pubsub

camel-google-pubsub-starter

Send and receive messages to/from Google Cloud Platform PubSub Service.

Yes

gRPC

camel-grpc-starter

Expose gRPC endpoints and access external gRPC endpoints.

Yes

HTTP

camel-http-starter

Send requests to external HTTP servers using Apache HTTP Client 4.x.

Yes

Infinispan

camel-infinispan-starter

Read and write from/to Infinispan distributed key/value store and data grid.

No

Infinispan Embedded

camel-infinispan-embedded-starter

Read and write from/to Infinispan distributed key/value store and data grid.

Yes

JDBC

camel-jdbc-starter

Access databases through SQL and JDBC.

Yes

Jira

camel-jira-starter

Interact with JIRA issue tracker.

Yes

JMS

camel-jms-starter

Sent and receive messages to/from a JMS Queue or Topic.

Yes

JPA

camel-jpa-starter

Store and retrieve Java objects from databases using Java Persistence API (JPA).

Yes

JSLT

camel-jslt-starter

Query or transform JSON payloads using an JSLT.

Yes

Kafka

camel-kafka-starter

Sent and receive messages to/from an Apache Kafka broker.

Yes

Kamelet

camel-kamelet-starter

To call Kamelets

Yes

Kubernetes ConfigMap

camel-kubernetes-starter

Perform operations on Kubernetes ConfigMaps and get notified on ConfigMaps changes.

Yes

Kubernetes Custom Resources

camel-kubernetes-starter

Perform operations on Kubernetes Custom Resources and get notified on Deployment changes.

Yes

Kubernetes Deployments

camel-kubernetes-starter

Perform operations on Kubernetes Deployments and get notified on Deployment changes.

Yes

Kubernetes Event

camel-kubernetes-starter

Perform operations on Kubernetes Events and get notified on Events changes.

Yes

Kubernetes HPA

camel-kubernetes-starter

Perform operations on Kubernetes Horizontal Pod Autoscalers (HPA) and get notified on HPA changes.

Yes

Kubernetes Job

camel-kubernetes-starter

Perform operations on Kubernetes Jobs.

Yes

Kubernetes Namespaces

camel-kubernetes-starter

Perform operations on Kubernetes Namespaces and get notified on Namespace changes.

Yes

Kubernetes Nodes

camel-kubernetes-starter

Perform operations on Kubernetes Nodes and get notified on Node changes.

Yes

Kubernetes Persistent Volume

camel-kubernetes-starter

Perform operations on Kubernetes Persistent Volumes and get notified on Persistent Volume changes.

Yes

Kubernetes Persistent Volume Claim

camel-kubernetes-starter

Perform operations on Kubernetes Persistent Volumes Claims and get notified on Persistent Volumes Claim changes.

Yes

Kubernetes Pods

camel-kubernetes-starter

Perform operations on Kubernetes Pods and get notified on Pod changes.

Yes

Kubernetes Replication Controller

camel-kubernetes-starter

Yes Perform operations on Kubernetes Replication Controllers and get notified on Replication Controllers changes.

Yes

Kubernetes Resources Quota

camel-kubernetes-starter

Perform operations on Kubernetes Resources Quotas.

Yes

Kubernetes Secrets

camel-kubernetes-starter

Perform operations on Kubernetes Secrets.

Yes

Kubernetes Service Account

camel-kubernetes-starter

Perform operations on Kubernetes Service Accounts.

Yes

Kubernetes Services

camel-kubernetes-starter

Perform operations on Kubernetes Services and get notified on Service changes.

Yes

Kudu

camel-kudu-starter

Interact with Apache Kudu, a free and open source column-oriented data store of the Apache Hadoop ecosystem.

No

Language

camel-language-starter

Execute scripts in any of the languages supported by Camel.

Yes

LDAP

camel-ldap-starter

Perform searches on LDAP servers.

Yes

Log

camel-log-starter

Log messages to the underlying logging mechanism.

Yes

LRA

camel-lra-starter

Camel saga binding for Long-Running-Action framework.

Yes

Mail

camel-mail-starter

Send and receive emails using imap, pop3 and smtp protocols.

Yes

Mail Microsoft OAuth

camel-mail-microsoft-oauth-starter

Camel Mail OAuth2 Authenticator for Microsoft Exchange Online.

Yes

MapStruct

camel-mapstruct-starter

Type Conversion using Mapstruct.

Yes

Master

camel-master-starter

Have only a single consumer in a cluster consuming from a given endpoint; with automatic failover if the JVM dies.

Yes

Micrometer

camel-micrometer-starter

Collect various metrics directly from Camel routes using the Micrometer library.

Yes

Minio

camel-minio-starter

Store and retrieve objects from Minio Storage Service using Minio SDK.

Yes

MLLP

camel-mllp-starter

Communicate with external systems using the MLLP protocol.

Yes

Mock

camel-mock-starter

Test routes and mediation rules using mocks.

Yes

MongoDB

camel-mongodb-starter

Perform operations on MongoDB documents and collections.

Yes

MyBatis

camel-mybatis-starter

Performs a query, poll, insert, update or delete in a relational database using MyBatis.

Yes

Netty

camel-netty-starter

Socket level networking using TCP or UDP with Netty 4.x.

Yes

Olingo4

camel-olingo4-starter

Communicate with OData 4.0 services using Apache Olingo OData API.

Yes

Openshift Build Config

camel-kubernetes-starter

Perform operations on OpenShift Build Configs.

Yes

Openshift Builds

camel-kubernetes-starter

Perform operations on OpenShift Builds.

Yes

Openshift Deployment Configs

camel-kubernetes-starter

Perform operations on Openshift Deployment Configs and get notified on Deployment Config changes.

Yes

Netty HTTP

camel-netty-http-starter

Netty HTTP server and client using the Netty 4.x.

Yes

Paho

camel-paho-starter

Communicate with MQTT message brokers using Eclipse Paho MQTT Client.

Yes

Paho MQTT 5

camel-paho-mqtt5-starter

Communicate with MQTT message brokers using Eclipse Paho MQTT v5 Client.

Yes

Platform HTTP

camel-platform-http-starter

Expose HTTP endpoints using the HTTP server available in the current platform.

Yes

Quartz

camel-quartz-starter

Schedule sending of messages using the Quartz 2.x scheduler.

Yes

Ref

camel-ref-starter

Route messages to an endpoint looked up dynamically by name in the Camel Registry.

Yes

REST

camel-rest-starter

Expose REST services or call external REST services.

Yes

Saga

camel-saga-starter

Execute custom actions within a route using the Saga EIP.

Yes

Salesforce

camel-salesforce-starter

Communicate with Salesforce using Java DTOs.

Yes

SAP

camel-sap-starter

Uses the SAP Java Connector (SAP JCo) library to facilitate bidirectional communication with SAP and the SAP IDoc library to facilitate the transmission of documents in the Intermediate Document (IDoc) format.

Yes

Scheduler

camel-scheduler-starter

Generate messages in specified intervals using java.util.concurrent.ScheduledExecutorService.

Yes

SEDA

camel-seda-starter

Asynchronously call another endpoint from any Camel Context in the same JVM.

Yes

Servlet

camel-servlet-starter

Serve HTTP requests by a Servlet.

Yes

Slack

camel-slack-starter

Send and receive messages to/from Slack.

Yes

SMB

camel-smb-starter

Receive files from SMB (Server Message Block) shares.

Yes

SNMP

camel-snmp-starter

Receive traps and poll SNMP (Simple Network Management Protocol) capable devices.

Yes

Splunk

camel-splunk-starter

Publish or search for events in Splunk.

No

Spring Batch

camel-spring-batch-starter

Send messages to Spring Batch for further processing.

Yes

Spring JDBC

camel-spring-jdbc-starter

Access databases through SQL and JDBC with Spring Transaction support.

Yes

Spring LDAP

camel-spring-ldap-starter

Perform searches in LDAP servers using filters as the message payload.

Yes

Spring RabbitMQ

camel-spring-rabbitmq-starter

Send and receive messages from RabbitMQ using Spring RabbitMQ client.

Yes

Spring Redis

camel-spring-redis-starter

Send and receive messages from Redis.

Yes

Spring Webservice

camel-spring-ws-starter

You can use this component to integrate with Spring Web Services. It offers client-side support for accessing web services and server-side support for creating your contract-first web services.

Yes

SQL

camel-sql-starter

Perform SQL queries using Spring JDBC.

Yes

SQL Stored Procedure

camel-sql-starter

Perform SQL queries as a JDBC Stored Procedures using Spring JDBC.

Yes

SSH

camel-ssh-starter

Execute commands on remote hosts using SSH.

Yes

Stub

camel-stub-starter

Stub out any physical endpoints while in development or testing.

Yes

Telegram

camel-telegram-starter

Send and receive messages acting as a Telegram Bot Telegram Bot API.

Yes

Timer

camel-timer-starter

Generate messages in specified intervals using java.util.Timer.

Yes

Validator

camel-validator-starter

Validate the payload using XML Schema and JAXP Validation.

Yes

Velocity

camel-velocity-starter

Transform messages using a Velocity template.

Yes

Vert.x HTTP Client

camel-vertx-http-starter

Send requests to external HTTP servers using Vert.x.

Yes

Vert.x WebSocket

camel-vertx-websocket-starter

Expose WebSocket endpoints and connect to remote WebSocket servers using Vert.x.

Yes

Webhook

camel-webhook-starter

Expose webhook endpoints to receive push notifications for other Camel components.

Yes

XJ

camel-xj-starter

Transform JSON and XML message using a XSLT.

Yes

XSLT

camel-xslt-starter

Transforms XML payload using an XSLT template.

Yes

XSLT Saxon

camel-xslt-saxon-starter

Transform XML payloads using an XSLT template using Saxon.

Yes

Table 1.2. Camel Data Formats
ComponentArtifactDescriptionSupport on IBM Power and IBM Z

Avro

camel-avro-starter

Serialize and deserialize messages using Apache Avro binary data format.

Yes

Avro Jackson

camel-jackson-avro-starter

Marshal POJOs to Avro and back using Jackson.

Yes

Bindy

camel-bindy-starter

Marshal and unmarshal between POJOs and key-value pair (KVP) format using Camel Bindy.

Yes

HL7

camel-hl7-starter

Marshal and unmarshal HL7 (Health Care) model objects using the HL7 MLLP codec.

Yes

JacksonXML

camel-jacksonxml-starter

Unmarshal a XML payloads to POJOs and back using XMLMapper extension of Jackson.

Yes

JAXB

camel-jaxb-starter

Unmarshal XML payloads to POJOs and back using JAXB2 XML marshalling standard.

Yes

JSON Gson

camel-gson-starter

Marshal POJOs to JSON and back using Gson

Yes

JSON Jackson

camel-jackson-starter

Marshal POJOs to JSON and back using Jackson

Yes

Protobuf Jackson

camel-jackson-protobuf-starter

Marshal POJOs to Protobuf and back using Jackson.

Yes

SOAP

camel-soap-starter

Marshal Java objects to SOAP messages and back.

Yes

Zip File

camel-zipfile-starter

Compression and decompress streams using java.util.zip.ZipStream.

Yes

Table 1.3. Camel Languages
LanguageArtifactDescriptionSupport on IBM Power and IBM Z

Constant

camel-core-starter

A fixed value set only once during the route startup.

Yes

CSimple

camel-core-starter

Evaluate a compiled simple expression.

Yes

ExchangeProperty

camel-core-starter

Gets a property from the Exchange.

Yes

File

camel-core-starter

File related capabilities for the Simple language.

Yes

Groovy

camel-groovy-starter

Evaluates a Groovy script.

Yes

Header

camel-core-starter

Gets a header from the Exchange.

Yes

JQ

camel-jq-starter

Evaluates a JQ expression against a JSON message body.

Yes

JSONPath

camel-jsonpath-starter

Evaluates a JSONPath expression against a JSON message body.

Yes

Ref

camel-core-starter

Uses an existing expression from the registry.

Yes

Simple

camel-core-starter

Evaluates a Camel simple expression.

Yes

Tokenize

camel-core-starter

Tokenize text payloads using delimiter patterns.

Yes

XML Tokenize

camel-xml-jaxp-starter

Tokenize XML payloads.

Yes

XPath

camel-xpath-starter

Evaluates an XPath expression against an XML payload.

Yes

XQuery

camel-saxon-starter

Query and/or transform XML payloads using XQuery and Saxon.

Yes

Table 1.4. Miscellaneous Extensions
ExtensionsArtifactDescriptionSupport on IBM Power and IBM Z

Jasypt

camel-jasypt-starter

Security using Jasypt

Yes

Kamelet Main

camel-kamelet-main-starter

Main to run Kamelet standalone

Yes

Openapi Java

camel-openapi-java-starter

Rest-dsl support for using openapi doc

Yes

OpenTelemetry

camel-opentelemetry-starter

Distributed tracing using OpenTelemetry

Yes

Spring Security

camel-spring-security-starter

Security using Spring Security

Yes

YAML DSL

camel-yaml-dsl-starter

Camel DSL with YAML

Yes

Chapter 2. AMQP

Since Camel 1.2

Both producer and consumer are supported

The AMQP component supports the AMQP 1.0 protocol using the JMS Client API of the Qpid project.

2.1. Dependencies

When using camel-amqp with Red Hat build of Camel Spring Boot, add the following Maven dependency to your pom.xml to have support for auto configuration:

<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-amqp-starter</artifactId>
</dependency>

2.2. URI format

amqp:[queue:|topic:]destinationName[?options]

2.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

2.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

2.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

2.4. Component Options

The AMQP component supports 100 options, which are listed below.

NameDescriptionDefaultType

clientId (common)

Sets the JMS client ID to use. Note that this value, if specified, must be unique and can only be used by a single JMS connection instance. The clientId option is compulsory with JMS 1.1 durable topic subscriptions, because the client ID is used to control which client messages have to be stored for. With JMS 2.0 clients, clientId may be omitted, which creates a 'global' subscription.

 

String

connectionFactory (common)

The connection factory to be use. A connection factory must be configured either on the component or endpoint.

 

ConnectionFactory

disableReplyTo (common)

Specifies whether Camel ignores the JMSReplyTo header in messages. If true, Camel does not send a reply back to the destination specified in the JMSReplyTo header. You can use this option if you want Camel to consume from a route and you do not want Camel to automatically send back a reply message because another component in your code handles the reply message. You can also use this option if you want to use Camel as a proxy between different message brokers and you want to route message from one system to another.

false

boolean

durableSubscriptionName (common)

The durable subscriber name for specifying durable topic subscriptions. The clientId option must be configured for a JMS 1.1 durable subscription, and may be configured for JMS 2.0, to create a private durable subscription.

 

String

includeAmqpAnnotations (common)

Whether to include AMQP annotations when mapping from AMQP to Camel Message. Setting this to true maps AMQP message annotations that contain a JMS_AMQP_MA_ prefix to message headers. Due to limitations in Apache Qpid JMS API, currently delivery annotations are ignored.

false

boolean

jmsMessageType (common)

Allows you to force the use of a specific javax.jms.Message implementation for sending JMS messages. Possible values are: Bytes, Map, Object, Stream, Text. By default, Camel would determine which JMS message type to use from the In body type. This option allows you to specify it.

Enum values:

  • Bytes
  • Map
  • Object
  • Stream
  • Text
 

JmsMessageType

replyTo (common)

Provides an explicit ReplyTo destination (overrides any incoming value of Message.getJMSReplyTo() in consumer).

 

String

testConnectionOnStartup (common)

Specifies whether to test the connection on startup. This ensures that when Camel starts that all the JMS consumers have a valid connection to the JMS broker. If a connection cannot be granted then Camel throws an exception on startup. This ensures that Camel is not started with failed connections. The JMS producers is tested as well.

false

boolean

acknowledgementModeName (consumer)

The JMS acknowledgement name, which is one of: SESSION_TRANSACTED, CLIENT_ACKNOWLEDGE, AUTO_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE.

Enum values:

  • SESSION_TRANSACTED
  • CLIENT_ACKNOWLEDGE
  • AUTO_ACKNOWLEDGE
  • DUPS_OK_ACKNOWLEDGE

AUTO_ACKNOWLEDGE

String

artemisConsumerPriority (consumer)

Consumer priorities allow you to ensure that high priority consumers receive messages while they are active. Normally, active consumers connected to a queue receive messages from it in a round-robin fashion. When consumer priorities are in use, messages are delivered round-robin if multiple active consumers exist with the same high priority. Messages will only going to lower priority consumers when the high priority consumers do not have credit available to consume the message, or those high priority consumers have declined to accept the message (for instance because it does not meet the criteria of any selectors associated with the consumer).

 

int

asyncConsumer (consumer)

Whether the JmsConsumer processes the Exchange asynchronously. If enabled then the JmsConsumer may pickup the next message from the JMS queue, while the previous message is being processed asynchronously (by the Asynchronous Routing Engine). This means that messages may be processed not 100% strictly in order. If disabled (as default) then the Exchange is fully processed before the JmsConsumer picks up the next message from the JMS queue. Note if transacted has been enabled, then asyncConsumer=true does not run asynchronously, as transaction must be executed synchronously (Camel 3.0 may support async transactions).

false

boolean

autoStartup (consumer)

Specifies whether the consumer container should auto-startup.

true

boolean

cacheLevel (consumer)

Sets the cache level by ID for the underlying JMS resources. See cacheLevelName option for more details.

 

int

cacheLevelName (consumer)

Sets the cache level by name for the underlying JMS resources. Possible values are: CACHE_AUTO, CACHE_CONNECTION, CACHE_CONSUMER, CACHE_NONE, and CACHE_SESSION. The default setting is CACHE_AUTO. See the Spring documentation and Transactions Cache Levels for more information.

Enum values:

  • CACHE_AUTO
  • CACHE_CONNECTION
  • CACHE_CONSUMER
  • CACHE_NONE
  • CACHE_SESSION

CACHE_AUTO

String

concurrentConsumers (consumer)

Specifies the default number of concurrent consumers when consuming from JMS (not for request/reply over JMS). See also the maxMessagesPerTask option to control dynamic scaling up/down of threads. When doing request/reply over JMS then the option replyToConcurrentConsumers is used to control number of concurrent consumers on the reply message listener.

1

int

maxConcurrentConsumers (consumer)

Specifies the maximum number of concurrent consumers when consuming from JMS (not for request/reply over JMS). See also the maxMessagesPerTask option to control dynamic scaling up/down of threads. When doing request/reply over JMS then the option replyToMaxConcurrentConsumers is used to control number of concurrent consumers on the reply message listener.

 

int

replyToDeliveryPersistent (consumer)

Specifies whether to use persistent delivery by default for replies.

true

boolean

selector (consumer)

Sets the JMS selector to use.

 

String

subscriptionDurable (consumer)

Set whether to make the subscription durable. The durable subscription name to be used can be specified through the subscriptionName property. Default is false. Set this to true to register a durable subscription, typically in combination with a subscriptionName value (unless your message listener class name is good enough as subscription name). Only makes sense when listening to a topic (pub-sub domain), therefore this method switches the pubSubDomain flag as well.

false

boolean

subscriptionName (consumer)

Set the name of a subscription to create. To be applied in case of a topic (pub-sub domain) with a shared or durable subscription. The subscription name needs to be unique within this client’s JMS client id, if the client ID is configured. Default is the class name of the specified message listener. Note: Only 1 concurrent consumer (which is the default of this message listener container) is allowed for each subscription, except for a shared subscription (which requires JMS 2.0).

 

String

subscriptionShared (consumer)

Set whether to make the subscription shared. The shared subscription name to be used can be specified through the subscriptionName property. Default is false. Set this to true to register a shared subscription, typically in combination with a subscriptionName value (unless your message listener class name is good enough as subscription name). Note that shared subscriptions may also be durable, so this flag can (and often will) be combined with subscriptionDurable as well. Only makes sense when listening to a topic (pub-sub domain), therefore this method switches the pubSubDomain flag as well. Requires a JMS 2.0 compatible message broker.

false

boolean

acceptMessagesWhileStopping (consumer (advanced))

Specifies whether the consumer accept messages while it is stopping. You may consider enabling this option, if you start and stop JMS routes at runtime, while there are still messages enqueued on the queue. If this option is false, and you stop the JMS route, then messages may be rejected, and the JMS broker would have to attempt redeliveries, which yet again may be rejected, and eventually the message may be moved at a dead letter queue on the JMS broker. To avoid this its recommended to enable this option.

false

boolean

allowReplyManagerQuickStop (consumer (advanced))

Whether the DefaultMessageListenerContainer used in the reply managers for request-reply messaging allow the DefaultMessageListenerContainer.runningAllowed flag to quick stop in case JmsConfiguration#isAcceptMessagesWhileStopping is enabled, and org.apache.camel.CamelContext is currently being stopped. This quick stop ability is enabled by default in the regular JMS consumers but to enable for reply managers you must enable this flag.

false

boolean

consumerType (consumer (advanced))

The consumer type to use, which can be one of: Simple, Default, or Custom. The consumer type determines which Spring JMS listener to use. Default will use org.springframework.jms.listener.DefaultMessageListenerContainer, Simple will use org.springframework.jms.listener.SimpleMessageListenerContainer. When Custom is specified, the MessageListenerContainerFactory defined by the messageListenerContainerFactory option will determine what org.springframework.jms.listener.AbstractMessageListenerContainer to use.

Enum values:

  • Simple
  • Default
  • Custom

Default

ConsumerType

defaultTaskExecutorType (consumer (advanced))

Specifies what default TaskExecutor type to use in the DefaultMessageListenerContainer, for both consumer endpoints and the ReplyTo consumer of producer endpoints. Possible values: SimpleAsync (uses Spring’s SimpleAsyncTaskExecutor) or ThreadPool (uses Spring’s ThreadPoolTaskExecutor with optimal values - cached threadpool-like). If not set, it defaults to the previous behaviour, which uses a cached thread pool for consumer endpoints and SimpleAsync for reply consumers. The use of ThreadPool is recommended to reduce thread trash in elastic configurations with dynamically increasing and decreasing concurrent consumers.

Enum values:

  • ThreadPool
  • SimpleAsync
 

DefaultTaskExecutorType

eagerLoadingOfProperties (consumer (advanced))

Enables eager loading of JMS properties and payload as soon as a message is loaded which generally is inefficient as the JMS properties may not be required but sometimes can catch early any issues with the underlying JMS provider and the use of JMS properties. See also the option eagerPoisonBody.

false

boolean

eagerPoisonBody (consumer (advanced))

If eagerLoadingOfProperties is enabled and the JMS message payload (JMS body or JMS properties) is poison (cannot be read/mapped), then set this text as the message body instead so the message can be processed (the cause of the poison are already stored as exception on the Exchange). This can be turned off by setting eagerPoisonBody=false. See also the option eagerLoadingOfProperties.

Poison JMS message due to $\{exception.message}

String

exposeListenerSession (consumer (advanced))

Specifies whether the listener session should be exposed when consuming messages.

false

boolean

replyToConsumerType (consumer (advanced))

The consumer type of the reply consumer (when doing request/reply), which can be one of: Simple, Default, or Custom. The consumer type determines which Spring JMS listener to use. Default will use org.springframework.jms.listener.DefaultMessageListenerContainer, Simple will use org.springframework.jms.listener.SimpleMessageListenerContainer. When Custom is specified, the MessageListenerContainerFactory defined by the messageListenerContainerFactory option will determine what org.springframework.jms.listener.AbstractMessageListenerContainer to use.

Enum values:

  • Simple
  • Default
  • Custom

Default

ConsumerType

replyToSameDestinationAllowed (consumer (advanced))

Whether a JMS consumer is allowed to send a reply message to the same destination that the consumer is using to consume from. This prevents an endless loop by consuming and sending back the same message to itself.

false

boolean

taskExecutor (consumer (advanced))

Allows you to specify a custom task executor for consuming messages.

 

TaskExecutor

deliveryDelay (producer)

Sets delivery delay to use for send calls for JMS. This option requires JMS 2.0 compliant broker.

-1

long

deliveryMode (producer)

Specifies the delivery mode to be used. Possible values are those defined by javax.jms.DeliveryMode. NON_PERSISTENT = 1 and PERSISTENT = 2.

Enum values:

  • 1
  • 2
 

Integer

deliveryPersistent (producer)

Specifies whether persistent delivery is used by default.

true

boolean

explicitQosEnabled (producer)

Set if the deliveryMode, priority or timeToLive qualities of service should be used when sending messages. This option is based on Spring’s JmsTemplate. The deliveryMode, priority and timeToLive options are applied to the current endpoint. This contrasts with the preserveMessageQos option, which operates at message granularity, reading QoS properties exclusively from the Camel In message headers.

false

Boolean

formatDateHeadersToIso8601 (producer)

Sets whether JMS date properties should be formatted according to the ISO 8601 standard.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

preserveMessageQos (producer)

Set to true, if you want to send message using the QoS settings specified on the message, instead of the QoS settings on the JMS endpoint. The following three headers are considered JMSPriority, JMSDeliveryMode, and JMSExpiration. You can provide all or only some of them. If not provided, Camel will fall back to use the values from the endpoint instead. So, when using this option, the headers override the values from the endpoint. The explicitQosEnabled option, by contrast, will only use options set on the endpoint, and not values from the message header.

false

boolean

priority (producer)

Values greater than 1 specify the message priority when sending (where 1 is the lowest priority and 9 is the highest). The explicitQosEnabled option must also be enabled in order for this option to have any effect.

Enum values:

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

4

int

replyToConcurrentConsumers (producer)

Specifies the default number of concurrent consumers when doing request/reply over JMS. See also the maxMessagesPerTask option to control dynamic scaling up/down of threads.

1

int

replyToMaxConcurrentConsumers (producer)

Specifies the maximum number of concurrent consumers when using request/reply over JMS. See also the maxMessagesPerTask option to control dynamic scaling up/down of threads.

 

int

replyToOnTimeoutMaxConcurrentConsumers (producer)

Specifies the maximum number of concurrent consumers for continue routing when timeout occurred when using request/reply over JMS.

1

int

replyToOverride (producer)

Provides an explicit ReplyTo destination in the JMS message, which overrides the setting of replyTo. It is useful if you want to forward the message to a remote Queue and receive the reply message from the ReplyTo destination.

 

String

replyToType (producer)

Allows for explicitly specifying which kind of strategy to use for replyTo queues when doing request/reply over JMS. Possible values are: Temporary, Shared, or Exclusive. By default Camel will use temporary queues. However if replyTo has been configured, then Shared is used by default. This option allows you to use exclusive queues instead of shared ones. See Camel JMS documentation for more details, and especially the notes about the implications if running in a clustered environment, and the fact that Shared reply queues has lower performance than its alternatives Temporary and Exclusive.

Enum values:

  • Temporary
  • Shared
  • Exclusive
 

ReplyToType

requestTimeout (producer)

The timeout for waiting for a reply when using the InOut Exchange Pattern (in milliseconds). The default is 20 seconds. You can include the header CamelJmsRequestTimeout to override this endpoint configured timeout value, and thus have per message individual timeout values. See also the requestTimeoutCheckerInterval option.

20000

long

timeToLive (producer)

When sending messages, specifies the time-to-live of the message (in milliseconds).

-1

long

allowAdditionalHeaders (producer (advanced))

This option is used to allow additional headers which may have values that are invalid according to JMS specification. For example some message systems such as WMQ do this with header names using prefix JMS_IBM_MQMD_ containing values with byte array or other invalid types. You can specify multiple header names separated by comma, and use as suffix for wildcard matching.

 

String

allowNullBody (producer (advanced))

Whether to allow sending messages with no body. If this option is false and the message body is null, then an JMSException is thrown.

true

boolean

alwaysCopyMessage (producer (advanced))

If true, Camel will always make a JMS message copy of the message when it is passed to the producer for sending. Copying the message is needed in some situations, such as when a replyToDestinationSelectorName is set (incidentally, Camel will set the alwaysCopyMessage option to true, if a replyToDestinationSelectorName is set).

false

boolean

correlationProperty (producer (advanced))

When using InOut exchange pattern use this JMS property instead of JMSCorrelationID JMS property to correlate messages. If set messages will be correlated solely on the value of this property JMSCorrelationID property will be ignored and not set by Camel.

 

String

disableTimeToLive (producer (advanced))

Use this option to force disabling time to live. For example when you do request/reply over JMS, then Camel will by default use the requestTimeout value as time to live on the message being sent. The problem is that the sender and receiver systems have to have their clocks synchronized, so they are in sync. This is not always so easy to archive. So you can use disableTimeToLive=true to not set a time to live value on the sent message. Then the message will not expire on the receiver system. See below in section About time to live for more details.

false

boolean

forceSendOriginalMessage (producer (advanced))

When using mapJmsMessage=false Camel will create a new JMS message to send to a new JMS destination if you touch the headers (get or set) during the route. Set this option to true to force Camel to send the original JMS message that was received.

false

boolean

includeSentJMSMessageID (producer (advanced))

Only applicable when sending to JMS destination using InOnly (eg fire and forget). Enabling this option will enrich the Camel Exchange with the actual JMSMessageID that was used by the JMS client when the message was sent to the JMS destination.

false

boolean

replyToCacheLevelName (producer (advanced))

Sets the cache level by name for the reply consumer when doing request/reply over JMS. This option only applies when using fixed reply queues (not temporary). Camel will by default use: CACHE_CONSUMER for exclusive or shared w/ replyToSelectorName. And CACHE_SESSION for shared without replyToSelectorName. Some JMS brokers such as IBM WebSphere may require to set the replyToCacheLevelName=CACHE_NONE to work. Note: If using temporary queues then CACHE_NONE is not allowed, and you must use a higher value such as CACHE_CONSUMER or CACHE_SESSION.

Enum values:

  • CACHE_AUTO
  • CACHE_CONNECTION
  • CACHE_CONSUMER
  • CACHE_NONE
  • CACHE_SESSION
 

String

replyToDestinationSelectorName (producer (advanced))

Sets the JMS Selector using the fixed name to be used so you can filter out your own replies from the others when using a shared queue (that is, if you are not using a temporary reply queue).

 

String

streamMessageTypeEnabled (producer (advanced))

Sets whether StreamMessage type is enabled or not. Message payloads of streaming kind such as files, InputStream, etc will either by sent as BytesMessage or StreamMessage. This option controls which kind will be used. By default BytesMessage is used which enforces the entire message payload to be read into memory. By enabling this option the message payload is read into memory in chunks and each chunk is then written to the StreamMessage until no more data.

false

boolean

allowAutoWiredConnectionFactory (advanced)

Whether to auto-discover ConnectionFactory from the registry, if no connection factory has been configured. If only one instance of ConnectionFactory is found then it will be used. This is enabled by default.

true

boolean

allowAutoWiredDestinationResolver (advanced)

Whether to auto-discover DestinationResolver from the registry, if no destination resolver has been configured. If only one instance of DestinationResolver is found then it will be used. This is enabled by default.

true

boolean

allowSerializedHeaders (advanced)

Controls whether or not to include serialized headers. Applies only when transferExchange is true. This requires that the objects are serializable. Camel will exclude any non-serializable objects and log it at WARN level.

false

boolean

artemisStreamingEnabled (advanced)

Whether optimizing for Apache Artemis streaming mode. This can reduce memory overhead when using Artemis with JMS StreamMessage types. This option must only be enabled if Apache Artemis is being used.

false

boolean

asyncStartListener (advanced)

Whether to startup the JmsConsumer message listener asynchronously, when starting a route. For example if a JmsConsumer cannot get a connection to a remote JMS broker, then it may block while retrying and/or failover. This will cause Camel to block while starting routes. By setting this option to true, you will let routes startup, while the JmsConsumer connects to the JMS broker using a dedicated thread in asynchronous mode. If this option is used, then beware that if the connection could not be established, then an exception is logged at WARN level, and the consumer will not be able to receive messages; You can then restart the route to retry.

false

boolean

asyncStopListener (advanced)

Whether to stop the JmsConsumer message listener asynchronously, when stopping a route.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

configuration (advanced)

To use a shared JMS configuration.

 

JmsConfiguration

destinationResolver (advanced)

A pluggable org.springframework.jms.support.destination.DestinationResolver that allows you to use your own resolver (for example, to lookup the real destination in a JNDI registry).

 

DestinationResolver

errorHandler (advanced)

Specifies a org.springframework.util.ErrorHandler to be invoked in case of any uncaught exceptions thrown while processing a Message. By default these exceptions will be logged at the WARN level, if no errorHandler has been configured. You can configure logging level and whether stack traces should be logged using errorHandlerLoggingLevel and errorHandlerLogStackTrace options. This makes it much easier to configure, than having to code a custom errorHandler.

 

ErrorHandler

exceptionListener (advanced)

Specifies the JMS Exception Listener that is to be notified of any underlying JMS exceptions.

 

ExceptionListener

idleConsumerLimit (advanced)

Specify the limit for the number of consumers that are allowed to be idle at any given time.

1

int

idleTaskExecutionLimit (advanced)

Specifies the limit for idle executions of a receive task, not having received any message within its execution. If this limit is reached, the task will shut down and leave receiving to other executing tasks (in the case of dynamic scheduling; see the maxConcurrentConsumers setting). There is additional doc available from Spring.

1

int

includeAllJMSXProperties (advanced)

Whether to include all JMSXxxx properties when mapping from JMS to Camel Message. Setting this to true will include properties such as JMSXAppID, and JMSXUserID etc. Note: If you are using a custom headerFilterStrategy then this option does not apply.

false

boolean

jmsKeyFormatStrategy (advanced)

Pluggable strategy for encoding and decoding JMS keys so they can be compliant with the JMS specification. Camel provides two implementations out of the box: default and passthrough. The default strategy will safely marshal dots and hyphens (. and -). The passthrough strategy leaves the key as is. Can be used for JMS brokers which do not care whether JMS header keys contain illegal characters. You can provide your own implementation of the org.apache.camel.component.jms.JmsKeyFormatStrategy and refer to it using the # notation.

Enum values:

  • default
  • passthrough
 

JmsKeyFormatStrategy

mapJmsMessage (advanced)

Specifies whether Camel should auto map the received JMS message to a suited payload type, such as javax.jms.TextMessage to a String etc.

true

boolean

maxMessagesPerTask (advanced)

The number of messages per task. -1 is unlimited. If you use a range for concurrent consumers (eg min max), then this option can be used to set a value to eg 100 to control how fast the consumers will shrink when less work is required.

-1

int

messageConverter (advanced)

To use a custom Spring org.springframework.jms.support.converter.MessageConverter so you can be in control how to map to/from a javax.jms.Message.

 

MessageConverter

messageCreatedStrategy (advanced)

To use the given MessageCreatedStrategy which are invoked when Camel creates new instances of javax.jms.Message objects when Camel is sending a JMS message.

 

MessageCreatedStrategy

messageIdEnabled (advanced)

When sending, specifies whether message IDs should be added. This is just an hint to the JMS broker. If the JMS provider accepts this hint, these messages must have the message ID set to null; if the provider ignores the hint, the message ID must be set to its normal unique value.

true

boolean

messageListenerContainerFactory (advanced)

Registry ID of the MessageListenerContainerFactory used to determine what org.springframework.jms.listener.AbstractMessageListenerContainer to use to consume messages. Setting this will automatically set consumerType to Custom.

 

MessageListenerContainerFactory

messageTimestampEnabled (advanced)

Specifies whether timestamps should be enabled by default on sending messages. This is just an hint to the JMS broker. If the JMS provider accepts this hint, these messages must have the timestamp set to zero; if the provider ignores the hint the timestamp must be set to its normal value.

true

boolean

pubSubNoLocal (advanced)

Specifies whether to inhibit the delivery of messages published by its own connection.

false

boolean

queueBrowseStrategy (advanced)

To use a custom QueueBrowseStrategy when browsing queues.

 

QueueBrowseStrategy

receiveTimeout (advanced)

The timeout for receiving messages (in milliseconds).

1000

long

recoveryInterval (advanced)

Specifies the interval between recovery attempts, i.e. when a connection is being refreshed, in milliseconds. The default is 5000 ms, that is, 5 seconds.

5000

long

requestTimeoutCheckerInterval (advanced)

Configures how often Camel should check for timed out Exchanges when doing request/reply over JMS. By default Camel checks once per second. But if you must react faster when a timeout occurs, then you can lower this interval, to check more frequently. The timeout is determined by the option requestTimeout.

1000

long

synchronous (advanced)

Sets whether synchronous processing should be strictly used.

false

boolean

transferException (advanced)

If enabled and you are using Request Reply messaging (InOut) and an Exchange failed on the consumer side, then the caused Exception will be send back in response as a javax.jms.ObjectMessage. If the client is Camel, the returned Exception is rethrown. This allows you to use Camel JMS as a bridge in your routing - for example, using persistent queues to enable robust routing. Notice that if you also have transferExchange enabled, this option takes precedence. The caught exception is required to be serializable. The original Exception on the consumer side can be wrapped in an outer exception such as org.apache.camel.RuntimeCamelException when returned to the producer. Use this with caution as the data is using Java Object serialization and requires the received to be able to deserialize the data at Class level, which forces a strong coupling between the producers and consumer!.

false

boolean

transferExchange (advanced)

You can transfer the exchange over the wire instead of just the body and headers. The following fields are transferred: In body, Out body, Fault body, In headers, Out headers, Fault headers, exchange properties, exchange exception. This requires that the objects are serializable. Camel will exclude any non-serializable objects and log it at WARN level. You must enable this option on both the producer and consumer side, so Camel knows the payloads is an Exchange and not a regular payload. Use this with caution as the data is using Java Object serialization and requires the receiver to be able to deserialize the data at Class level, which forces a strong coupling between the producers and consumers having to use compatible Camel versions!.

false

boolean

useMessageIDAsCorrelationID (advanced)

Specifies whether JMSMessageID should always be used as JMSCorrelationID for InOut messages.

false

boolean

waitForProvisionCorrelationToBeUpdatedCounter (advanced)

Number of times to wait for provisional correlation id to be updated to the actual correlation id when doing request/reply over JMS and when the option useMessageIDAsCorrelationID is enabled.

50

int

waitForProvisionCorrelationToBeUpdatedThreadSleepingTime (advanced)

Interval in millis to sleep each time while waiting for provisional correlation id to be updated.

100

long

headerFilterStrategy (filter)

To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message.

 

HeaderFilterStrategy

errorHandlerLoggingLevel (logging)

Allows to configure the default errorHandler logging level for logging uncaught exceptions.

Enum values:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • OFF

WARN

LoggingLevel

errorHandlerLogStackTrace (logging)

Allows to control whether stacktraces should be logged or not, by the default errorHandler.

true

boolean

password (security)

Password to use with the ConnectionFactory. You can also configure username/password directly on the ConnectionFactory.

 

String

username (security)

Username to use with the ConnectionFactory. You can also configure username/password directly on the ConnectionFactory.

 

String

transacted (transaction)

Specifies whether to use transacted mode.

false

boolean

transactedInOut (transaction)

Specifies whether InOut operations (request reply) default to using transacted mode If this flag is set to true, then Spring JmsTemplate will have sessionTransacted set to true, and the acknowledgeMode as transacted on the JmsTemplate used for InOut operations. Note from Spring JMS: that within a JTA transaction, the parameters passed to createQueue, createTopic methods are not taken into account. Depending on the Java EE transaction context, the container makes its own decisions on these values. Analogously, these parameters are not taken into account within a locally managed transaction either, since Spring JMS operates on an existing JMS Session in this case. Setting this flag to true will use a short local JMS transaction when running outside of a managed transaction, and a synchronized local JMS transaction in case of a managed transaction (other than an XA transaction) being present. This has the effect of a local JMS transaction being managed alongside the main transaction (which might be a native JDBC transaction), with the JMS transaction committing right after the main transaction.

false

boolean

lazyCreateTransactionManager (transaction (advanced))

If true, Camel will create a JmsTransactionManager, if there is no transactionManager injected when option transacted=true.

true

boolean

transactionManager (transaction (advanced))

The Spring transaction manager to use.

 

PlatformTransactionManager

transactionName (transaction (advanced))

The name of the transaction to use.

 

String

transactionTimeout (transaction (advanced))

The timeout value of the transaction (in seconds), if using transacted mode.

-1

int

2.5. Endpoint Options

The AMQP endpoint is configured using URI syntax:

amqp:destinationType:destinationName

with the following path and query parameters:

2.5.1. Path Parameters (2 parameters)

NameDescriptionDefaultType

destinationType (common)

The kind of destination to use.

Enum values:

  • queue
  • topic
  • temp-queue
  • temp-topic

queue

String

destinationName (common)

Required Name of the queue or topic to use as destination.

 

String

2.5.2. Query Parameters (96 parameters)

NameDescriptionDefaultType

clientId (common)

Sets the JMS client ID to use. Note that this value, if specified, must be unique and can only be used by a single JMS connection instance. It is typically only required for durable topic subscriptions with JMS 1.1. The clientId option is compulsory with JMS 1.1 durable topic subscriptions, because the client ID is used to control which client messages have to be stored for. With JMS 2.0 clients, clientId may be omitted, which creates a 'global' subscription.

 

String

connectionFactory (common)

The connection factory to be use. A connection factory must be configured either on the component or endpoint.

 

ConnectionFactory

disableReplyTo (common)

Specifies whether Camel ignores the JMSReplyTo header in messages. If true, Camel does not send a reply back to the destination specified in the JMSReplyTo header. You can use this option if you want Camel to consume from a route and you do not want Camel to automatically send back a reply message because another component in your code handles the reply message. You can also use this option if you want to use Camel as a proxy between different message brokers and you want to route message from one system to another.

false

boolean

durableSubscriptionName (common)

The durable subscriber name for specifying durable topic subscriptions. The clientId option must be configured for a JMS 1.1 durable subscription, and may be configured for JMS 2.0, to create a private durable subscription.

 

String

jmsMessageType (common)

Allows you to force the use of a specific javax.jms.Message implementation for sending JMS messages. Possible values are: Bytes, Map, Object, Stream, Text. By default, Camel would determine which JMS message type to use from the In body type. This option allows you to specify it.

Enum values:

  • Bytes
  • Map
  • Object
  • Stream
  • Text
 

JmsMessageType

replyTo (common)

Provides an explicit ReplyTo destination (overrides any incoming value of Message.getJMSReplyTo() in consumer).

 

String

testConnectionOnStartup (common)

Specifies whether to test the connection on startup. This ensures that when Camel starts that all the JMS consumers have a valid connection to the JMS broker. If a connection cannot be granted then Camel throws an exception on startup. This ensures that Camel is not started with failed connections. The JMS producers is tested as well.

false

boolean

acknowledgementModeName (consumer)

The JMS acknowledgement name, which is one of: SESSION_TRANSACTED, CLIENT_ACKNOWLEDGE, AUTO_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE.

Enum values:

  • SESSION_TRANSACTED
  • CLIENT_ACKNOWLEDGE
  • AUTO_ACKNOWLEDGE
  • DUPS_OK_ACKNOWLEDGE

AUTO_ACKNOWLEDGE

String

artemisConsumerPriority (consumer)

Consumer priorities allow you to ensure that high priority consumers receive messages while they are active. Normally, active consumers connected to a queue receive messages from it in a round-robin fashion. When consumer priorities are in use, messages are delivered round-robin if multiple active consumers exist with the same high priority. Messages will only going to lower priority consumers when the high priority consumers do not have credit available to consume the message, or those high priority consumers have declined to accept the message (for instance because it does not meet the criteria of any selectors associated with the consumer).

 

int

asyncConsumer (consumer)

Whether the JmsConsumer processes the Exchange asynchronously. If enabled then the JmsConsumer may pickup the next message from the JMS queue, while the previous message is being processed asynchronously (by the Asynchronous Routing Engine). This means that messages may be processed not 100% strictly in order. If disabled (as default) then the Exchange is fully processed before the JmsConsumer picks up the next message from the JMS queue. Note if transacted has been enabled, then asyncConsumer=true does not run asynchronously, as transaction must be executed synchronously (Camel 3.0 may support async transactions).

false

boolean

autoStartup (consumer)

Specifies whether the consumer container should auto-startup.

true

boolean

cacheLevel (consumer)

Sets the cache level by ID for the underlying JMS resources. See cacheLevelName option for more details.

 

int

cacheLevelName (consumer)

Sets the cache level by name for the underlying JMS resources. Possible values are: CACHE_AUTO, CACHE_CONNECTION, CACHE_CONSUMER, CACHE_NONE, and CACHE_SESSION. The default setting is CACHE_AUTO. See the Spring documentation and Transactions Cache Levels for more information.

Enum values:

  • CACHE_AUTO
  • CACHE_CONNECTION
  • CACHE_CONSUMER
  • CACHE_NONE
  • CACHE_SESSION

CACHE_AUTO

String

concurrentConsumers (consumer)

Specifies the default number of concurrent consumers when consuming from JMS (not for request/reply over JMS). See also the maxMessagesPerTask option to control dynamic scaling up/down of threads. When doing request/reply over JMS then the option replyToConcurrentConsumers is used to control number of concurrent consumers on the reply message listener.

1

int

maxConcurrentConsumers (consumer)

Specifies the maximum number of concurrent consumers when consuming from JMS (not for request/reply over JMS). See also the maxMessagesPerTask option to control dynamic scaling up/down of threads. When doing request/reply over JMS then the option replyToMaxConcurrentConsumers is used to control number of concurrent consumers on the reply message listener.

 

int

replyToDeliveryPersistent (consumer)

Specifies whether to use persistent delivery by default for replies.

true

boolean

selector (consumer)

Sets the JMS selector to use.

 

String

subscriptionDurable (consumer)

Set whether to make the subscription durable. The durable subscription name to be used can be specified through the subscriptionName property. Default is false. Set this to true to register a durable subscription, typically in combination with a subscriptionName value (unless your message listener class name is good enough as subscription name). Only makes sense when listening to a topic (pub-sub domain), therefore this method switches the pubSubDomain flag as well.

false

boolean

subscriptionName (consumer)

Set the name of a subscription to create. To be applied in case of a topic (pub-sub domain) with a shared or durable subscription. The subscription name needs to be unique within this client’s JMS client id, if the client ID is configured. Default is the class name of the specified message listener. Note: Only 1 concurrent consumer (which is the default of this message listener container) is allowed for each subscription, except for a shared subscription (which requires JMS 2.0).

 

String

subscriptionShared (consumer)

Set whether to make the subscription shared. The shared subscription name to be used can be specified through the subscriptionName property. Default is false. Set this to true to register a shared subscription, typically in combination with a subscriptionName value (unless your message listener class name is good enough as subscription name). Note that shared subscriptions may also be durable, so this flag can (and often will) be combined with subscriptionDurable as well. Only makes sense when listening to a topic (pub-sub domain), therefore this method switches the pubSubDomain flag as well. Requires a JMS 2.0 compatible message broker.

false

boolean

acceptMessagesWhileStopping (consumer (advanced))

Specifies whether the consumer accept messages while it is stopping. You may consider enabling this option, if you start and stop JMS routes at runtime, while there are still messages enqueued on the queue. If this option is false, and you stop the JMS route, then messages may be rejected, and the JMS broker would have to attempt redeliveries, which yet again may be rejected, and eventually the message may be moved at a dead letter queue on the JMS broker. To avoid this its recommended to enable this option.

false

boolean

allowReplyManagerQuickStop (consumer (advanced))

Whether the DefaultMessageListenerContainer used in the reply managers for request-reply messaging allow the DefaultMessageListenerContainer.runningAllowed flag to quick stop in case JmsConfiguration#isAcceptMessagesWhileStopping is enabled, and org.apache.camel.CamelContext is currently being stopped. This quick stop ability is enabled by default in the regular JMS consumers but to enable for reply managers you must enable this flag.

false

boolean

consumerType (consumer (advanced))

The consumer type to use, which can be one of: Simple, Default, or Custom. The consumer type determines which Spring JMS listener to use. Default will use org.springframework.jms.listener.DefaultMessageListenerContainer, Simple will use org.springframework.jms.listener.SimpleMessageListenerContainer. When Custom is specified, the MessageListenerContainerFactory defined by the messageListenerContainerFactory option will determine what org.springframework.jms.listener.AbstractMessageListenerContainer to use.

Enum values:

  • Simple
  • Default
  • Custom

Default

ConsumerType

defaultTaskExecutorType (consumer (advanced))

Specifies what default TaskExecutor type to use in the DefaultMessageListenerContainer, for both consumer endpoints and the ReplyTo consumer of producer endpoints. Possible values: SimpleAsync (uses Spring’s SimpleAsyncTaskExecutor) or ThreadPool (uses Spring’s ThreadPoolTaskExecutor with optimal values - cached threadpool-like). If not set, it defaults to the previous behaviour, which uses a cached thread pool for consumer endpoints and SimpleAsync for reply consumers. The use of ThreadPool is recommended to reduce thread trash in elastic configurations with dynamically increasing and decreasing concurrent consumers.

Enum values:

  • ThreadPool
  • SimpleAsync
 

DefaultTaskExecutorType

eagerLoadingOfProperties (consumer (advanced))

Enables eager loading of JMS properties and payload as soon as a message is loaded which generally is inefficient as the JMS properties may not be required but sometimes can catch early any issues with the underlying JMS provider and the use of JMS properties. See also the option eagerPoisonBody.

false

boolean

eagerPoisonBody (consumer (advanced))

If eagerLoadingOfProperties is enabled and the JMS message payload (JMS body or JMS properties) is poison (cannot be read/mapped), then set this text as the message body instead so the message can be processed (the cause of the poison are already stored as exception on the Exchange). This can be turned off by setting eagerPoisonBody=false. See also the option eagerLoadingOfProperties.

Poison JMS message due to $\{exception.message}

String

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

exposeListenerSession (consumer (advanced))

Specifies whether the listener session should be exposed when consuming messages.

false

boolean

replyToConsumerType (consumer (advanced))

The consumer type of the reply consumer (when doing request/reply), which can be one of: Simple, Default, or Custom. The consumer type determines which Spring JMS listener to use. Default will use org.springframework.jms.listener.DefaultMessageListenerContainer, Simple will use org.springframework.jms.listener.SimpleMessageListenerContainer. When Custom is specified, the MessageListenerContainerFactory defined by the messageListenerContainerFactory option will determine what org.springframework.jms.listener.AbstractMessageListenerContainer to use.

Enum values:

  • Simple
  • Default
  • Custom

Default

ConsumerType

replyToSameDestinationAllowed (consumer (advanced))

Whether a JMS consumer is allowed to send a reply message to the same destination that the consumer is using to consume from. This prevents an endless loop by consuming and sending back the same message to itself.

false

boolean

taskExecutor (consumer (advanced))

Allows you to specify a custom task executor for consuming messages.

 

TaskExecutor

deliveryDelay (producer)

Sets delivery delay to use for send calls for JMS. This option requires JMS 2.0 compliant broker.

-1

long

deliveryMode (producer)

Specifies the delivery mode to be used. Possible values are those defined by javax.jms.DeliveryMode. NON_PERSISTENT = 1 and PERSISTENT = 2.

Enum values:

  • 1
  • 2
 

Integer

deliveryPersistent (producer)

Specifies whether persistent delivery is used by default.

true

boolean

explicitQosEnabled (producer)

Set if the deliveryMode, priority or timeToLive qualities of service should be used when sending messages. This option is based on Spring’s JmsTemplate. The deliveryMode, priority and timeToLive options are applied to the current endpoint. This contrasts with the preserveMessageQos option, which operates at message granularity, reading QoS properties exclusively from the Camel In message headers.

false

Boolean

formatDateHeadersToIso8601 (producer)

Sets whether JMS date properties should be formatted according to the ISO 8601 standard.

false

boolean

preserveMessageQos (producer)

Set to true, if you want to send message using the QoS settings specified on the message, instead of the QoS settings on the JMS endpoint. The following three headers are considered JMSPriority, JMSDeliveryMode, and JMSExpiration. You can provide all or only some of them. If not provided, Camel will fall back to use the values from the endpoint instead. So, when using this option, the headers override the values from the endpoint. The explicitQosEnabled option, by contrast, will only use options set on the endpoint, and not values from the message header.

false

boolean

priority (producer)

Values greater than 1 specify the message priority when sending (where 1 is the lowest priority and 9 is the highest). The explicitQosEnabled option must also be enabled in order for this option to have any effect.

Enum values:

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

4

int

replyToConcurrentConsumers (producer)

Specifies the default number of concurrent consumers when doing request/reply over JMS. See also the maxMessagesPerTask option to control dynamic scaling up/down of threads.

1

int

replyToMaxConcurrentConsumers (producer)

Specifies the maximum number of concurrent consumers when using request/reply over JMS. See also the maxMessagesPerTask option to control dynamic scaling up/down of threads.

 

int

replyToOnTimeoutMaxConcurrentConsumers (producer)

Specifies the maximum number of concurrent consumers for continue routing when timeout occurred when using request/reply over JMS.

1

int

replyToOverride (producer)

Provides an explicit ReplyTo destination in the JMS message, which overrides the setting of replyTo. It is useful if you want to forward the message to a remote Queue and receive the reply message from the ReplyTo destination.

 

String

replyToType (producer)

Allows for explicitly specifying which kind of strategy to use for replyTo queues when doing request/reply over JMS. Possible values are: Temporary, Shared, or Exclusive. By default Camel will use temporary queues. However if replyTo has been configured, then Shared is used by default. This option allows you to use exclusive queues instead of shared ones. See Camel JMS documentation for more details, and especially the notes about the implications if running in a clustered environment, and the fact that Shared reply queues has lower performance than its alternatives Temporary and Exclusive.

Enum values:

  • Temporary
  • Shared
  • Exclusive
 

ReplyToType

requestTimeout (producer)

The timeout for waiting for a reply when using the InOut Exchange Pattern (in milliseconds). The default is 20 seconds. You can include the header CamelJmsRequestTimeout to override this endpoint configured timeout value, and thus have per message individual timeout values. See also the requestTimeoutCheckerInterval option.

20000

long

timeToLive (producer)

When sending messages, specifies the time-to-live of the message (in milliseconds).

-1

long

allowAdditionalHeaders (producer (advanced))

This option is used to allow additional headers which may have values that are invalid according to JMS specification. For example some message systems such as WMQ do this with header names using prefix JMS_IBM_MQMD_ containing values with byte array or other invalid types. You can specify multiple header names separated by comma, and use as suffix for wildcard matching.

 

String

allowNullBody (producer (advanced))

Whether to allow sending messages with no body. If this option is false and the message body is null, then an JMSException is thrown.

true

boolean

alwaysCopyMessage (producer (advanced))

If true, Camel will always make a JMS message copy of the message when it is passed to the producer for sending. Copying the message is needed in some situations, such as when a replyToDestinationSelectorName is set (incidentally, Camel will set the alwaysCopyMessage option to true, if a replyToDestinationSelectorName is set).

false

boolean

correlationProperty (producer (advanced))

When using InOut exchange pattern use this JMS property instead of JMSCorrelationID JMS property to correlate messages. If set messages will be correlated solely on the value of this property JMSCorrelationID property will be ignored and not set by Camel.

 

String

disableTimeToLive (producer (advanced))

Use this option to force disabling time to live. For example when you do request/reply over JMS, then Camel will by default use the requestTimeout value as time to live on the message being sent. The problem is that the sender and receiver systems have to have their clocks synchronized, so they are in sync. This is not always so easy to archive. So you can use disableTimeToLive=true to not set a time to live value on the sent message. Then the message will not expire on the receiver system. See below in section About time to live for more details.

false

boolean

forceSendOriginalMessage (producer (advanced))

When using mapJmsMessage=false Camel will create a new JMS message to send to a new JMS destination if you touch the headers (get or set) during the route. Set this option to true to force Camel to send the original JMS message that was received.

false

boolean

includeSentJMSMessageID (producer (advanced))

Only applicable when sending to JMS destination using InOnly (eg fire and forget). Enabling this option will enrich the Camel Exchange with the actual JMSMessageID that was used by the JMS client when the message was sent to the JMS destination.

false

boolean

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

replyToCacheLevelName (producer (advanced))

Sets the cache level by name for the reply consumer when doing request/reply over JMS. This option only applies when using fixed reply queues (not temporary). Camel will by default use: CACHE_CONSUMER for exclusive or shared w/ replyToSelectorName. And CACHE_SESSION for shared without replyToSelectorName. Some JMS brokers such as IBM WebSphere may require to set the replyToCacheLevelName=CACHE_NONE to work. Note: If using temporary queues then CACHE_NONE is not allowed, and you must use a higher value such as CACHE_CONSUMER or CACHE_SESSION.

Enum values:

  • CACHE_AUTO
  • CACHE_CONNECTION
  • CACHE_CONSUMER
  • CACHE_NONE
  • CACHE_SESSION
 

String

replyToDestinationSelectorName (producer (advanced))

Sets the JMS Selector using the fixed name to be used so you can filter out your own replies from the others when using a shared queue (that is, if you are not using a temporary reply queue).

 

String

streamMessageTypeEnabled (producer (advanced))

Sets whether StreamMessage type is enabled or not. Message payloads of streaming kind such as files, InputStream, etc will either by sent as BytesMessage or StreamMessage. This option controls which kind will be used. By default BytesMessage is used which enforces the entire message payload to be read into memory. By enabling this option the message payload is read into memory in chunks and each chunk is then written to the StreamMessage until no more data.

false

boolean

allowSerializedHeaders (advanced)

Controls whether or not to include serialized headers. Applies only when transferExchange is true. This requires that the objects are serializable. Camel will exclude any non-serializable objects and log it at WARN level.

false

boolean

artemisStreamingEnabled (advanced)

Whether optimizing for Apache Artemis streaming mode. This can reduce memory overhead when using Artemis with JMS StreamMessage types. This option must only be enabled if Apache Artemis is being used.

false

boolean

asyncStartListener (advanced)

Whether to startup the JmsConsumer message listener asynchronously, when starting a route. For example if a JmsConsumer cannot get a connection to a remote JMS broker, then it may block while retrying and/or failover. This will cause Camel to block while starting routes. By setting this option to true, you will let routes startup, while the JmsConsumer connects to the JMS broker using a dedicated thread in asynchronous mode. If this option is used, then beware that if the connection could not be established, then an exception is logged at WARN level, and the consumer will not be able to receive messages; You can then restart the route to retry.

false

boolean

asyncStopListener (advanced)

Whether to stop the JmsConsumer message listener asynchronously, when stopping a route.

false

boolean

destinationResolver (advanced)

A pluggable org.springframework.jms.support.destination.DestinationResolver that allows you to use your own resolver (for example, to lookup the real destination in a JNDI registry).

 

DestinationResolver

errorHandler (advanced)

Specifies a org.springframework.util.ErrorHandler to be invoked in case of any uncaught exceptions thrown while processing a Message. By default these exceptions will be logged at the WARN level, if no errorHandler has been configured. You can configure logging level and whether stack traces should be logged using errorHandlerLoggingLevel and errorHandlerLogStackTrace options. This makes it much easier to configure, than having to code a custom errorHandler.

 

ErrorHandler

exceptionListener (advanced)

Specifies the JMS Exception Listener that is to be notified of any underlying JMS exceptions.

 

ExceptionListener

headerFilterStrategy (advanced)

To use a custom HeaderFilterStrategy to filter header to and from Camel message.

 

HeaderFilterStrategy

idleConsumerLimit (advanced)

Specify the limit for the number of consumers that are allowed to be idle at any given time.

1

int

idleTaskExecutionLimit (advanced)

Specifies the limit for idle executions of a receive task, not having received any message within its execution. If this limit is reached, the task will shut down and leave receiving to other executing tasks (in the case of dynamic scheduling; see the maxConcurrentConsumers setting). There is additional doc available from Spring.

1

int

includeAllJMSXProperties (advanced)

Whether to include all JMSXxxx properties when mapping from JMS to Camel Message. Setting this to true will include properties such as JMSXAppID, and JMSXUserID etc. Note: If you are using a custom headerFilterStrategy then this option does not apply.

false

boolean

jmsKeyFormatStrategy (advanced)

Pluggable strategy for encoding and decoding JMS keys so they can be compliant with the JMS specification. Camel provides two implementations out of the box: default and passthrough. The default strategy will safely marshal dots and hyphens (. and -). The passthrough strategy leaves the key as is. Can be used for JMS brokers which do not care whether JMS header keys contain illegal characters. You can provide your own implementation of the org.apache.camel.component.jms.JmsKeyFormatStrategy and refer to it using the # notation.

Enum values:

  • default
  • passthrough
 

JmsKeyFormatStrategy

mapJmsMessage (advanced)

Specifies whether Camel should auto map the received JMS message to a suited payload type, such as javax.jms.TextMessage to a String etc.

true

boolean

maxMessagesPerTask (advanced)

The number of messages per task. -1 is unlimited. If you use a range for concurrent consumers (eg min max), then this option can be used to set a value to eg 100 to control how fast the consumers will shrink when less work is required.

-1

int

messageConverter (advanced)

To use a custom Spring org.springframework.jms.support.converter.MessageConverter so you can be in control how to map to/from a javax.jms.Message.

 

MessageConverter

messageCreatedStrategy (advanced)

To use the given MessageCreatedStrategy which are invoked when Camel creates new instances of javax.jms.Message objects when Camel is sending a JMS message.

 

MessageCreatedStrategy

messageIdEnabled (advanced)

When sending, specifies whether message IDs should be added. This is just an hint to the JMS broker. If the JMS provider accepts this hint, these messages must have the message ID set to null; if the provider ignores the hint, the message ID must be set to its normal unique value.

true

boolean

messageListenerContainerFactory (advanced)

Registry ID of the MessageListenerContainerFactory used to determine what org.springframework.jms.listener.AbstractMessageListenerContainer to use to consume messages. Setting this will automatically set consumerType to Custom.

 

MessageListenerContainerFactory

messageTimestampEnabled (advanced)

Specifies whether timestamps should be enabled by default on sending messages. This is just an hint to the JMS broker. If the JMS provider accepts this hint, these messages must have the timestamp set to zero; if the provider ignores the hint the timestamp must be set to its normal value.

true

boolean

pubSubNoLocal (advanced)

Specifies whether to inhibit the delivery of messages published by its own connection.

false

boolean

receiveTimeout (advanced)

The timeout for receiving messages (in milliseconds).

1000

long

recoveryInterval (advanced)

Specifies the interval between recovery attempts, i.e. when a connection is being refreshed, in milliseconds. The default is 5000 ms, that is, 5 seconds.

5000

long

requestTimeoutCheckerInterval (advanced)

Configures how often Camel should check for timed out Exchanges when doing request/reply over JMS. By default Camel checks once per second. But if you must react faster when a timeout occurs, then you can lower this interval, to check more frequently. The timeout is determined by the option requestTimeout.

1000

long

synchronous (advanced)

Sets whether synchronous processing should be strictly used.

false

boolean

transferException (advanced)

If enabled and you are using Request Reply messaging (InOut) and an Exchange failed on the consumer side, then the caused Exception will be send back in response as a javax.jms.ObjectMessage. If the client is Camel, the returned Exception is rethrown. This allows you to use Camel JMS as a bridge in your routing - for example, using persistent queues to enable robust routing. Notice that if you also have transferExchange enabled, this option takes precedence. The caught exception is required to be serializable. The original Exception on the consumer side can be wrapped in an outer exception such as org.apache.camel.RuntimeCamelException when returned to the producer. Use this with caution as the data is using Java Object serialization and requires the received to be able to deserialize the data at Class level, which forces a strong coupling between the producers and consumer!.

false

boolean

transferExchange (advanced)

You can transfer the exchange over the wire instead of just the body and headers. The following fields are transferred: In body, Out body, Fault body, In headers, Out headers, Fault headers, exchange properties, exchange exception. This requires that the objects are serializable. Camel will exclude any non-serializable objects and log it at WARN level. You must enable this option on both the producer and consumer side, so Camel knows the payloads is an Exchange and not a regular payload. Use this with caution as the data is using Java Object serialization and requires the receiver to be able to deserialize the data at Class level, which forces a strong coupling between the producers and consumers having to use compatible Camel versions!.

false

boolean

useMessageIDAsCorrelationID (advanced)

Specifies whether JMSMessageID should always be used as JMSCorrelationID for InOut messages.

false

boolean

waitForProvisionCorrelationToBeUpdatedCounter (advanced)

Number of times to wait for provisional correlation id to be updated to the actual correlation id when doing request/reply over JMS and when the option useMessageIDAsCorrelationID is enabled.

50

int

waitForProvisionCorrelationToBeUpdatedThreadSleepingTime (advanced)

Interval in millis to sleep each time while waiting for provisional correlation id to be updated.

100

long

errorHandlerLoggingLevel (logging)

Allows to configure the default errorHandler logging level for logging uncaught exceptions.

Enum values:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • OFF

WARN

LoggingLevel

errorHandlerLogStackTrace (logging)

Allows to control whether stacktraces should be logged or not, by the default errorHandler.

true

boolean

password (security)

Password to use with the ConnectionFactory. You can also configure username/password directly on the ConnectionFactory.

 

String

username (security)

Username to use with the ConnectionFactory. You can also configure username/password directly on the ConnectionFactory.

 

String

transacted (transaction)

Specifies whether to use transacted mode.

false

boolean

transactedInOut (transaction)

Specifies whether InOut operations (request reply) default to using transacted mode If this flag is set to true, then Spring JmsTemplate will have sessionTransacted set to true, and the acknowledgeMode as transacted on the JmsTemplate used for InOut operations. Note from Spring JMS: that within a JTA transaction, the parameters passed to createQueue, createTopic methods are not taken into account. Depending on the Java EE transaction context, the container makes its own decisions on these values. Analogously, these parameters are not taken into account within a locally managed transaction either, since Spring JMS operates on an existing JMS Session in this case. Setting this flag to true will use a short local JMS transaction when running outside of a managed transaction, and a synchronized local JMS transaction in case of a managed transaction (other than an XA transaction) being present. This has the effect of a local JMS transaction being managed alongside the main transaction (which might be a native JDBC transaction), with the JMS transaction committing right after the main transaction.

false

boolean

lazyCreateTransactionManager (transaction (advanced))

If true, Camel will create a JmsTransactionManager, if there is no transactionManager injected when option transacted=true.

true

boolean

transactionManager (transaction (advanced))

The Spring transaction manager to use.

 

PlatformTransactionManager

transactionName (transaction (advanced))

The name of the transaction to use.

 

String

transactionTimeout (transaction (advanced))

The timeout value of the transaction (in seconds), if using transacted mode.

-1

int

2.6. Usage

As AMQP component is inherited from JMS component, the usage of the former is almost identical to the latter:

Using AMQP component

// Consuming from AMQP queue
from("amqp:queue:incoming").
  to(...);

// Sending message to the AMQP topic
from(...).
  to("amqp:topic:notify");

2.7. Configuring AMQP component

Creating AMQP 1.0 component

AMQPComponent amqp = AMQPComponent.amqpComponent("amqp://localhost:5672");

AMQPComponent authorizedAmqp = AMQPComponent.amqpComponent("amqp://localhost:5672", "user", "password");

You can also add an instance of org.apache.camel.component.amqp.AMQPConnectionDetails to the registry in order to automatically configure the AMQP component. For example for Spring Boot you just have to define bean:

AMQP connection details auto-configuration

@Bean
AMQPConnectionDetails amqpConnection() {
  return new AMQPConnectionDetails("amqp://localhost:5672");
}

@Bean
AMQPConnectionDetails securedAmqpConnection() {
  return new AMQPConnectionDetails("amqp://localhost:5672", "username", "password");
}

Likewise, you can also use CDI producer methods when using Camel-CDI

AMQP connection details auto-configuration for CDI

@Produces
AMQPConnectionDetails amqpConnection() {
  return new AMQPConnectionDetails("amqp://localhost:5672");
}

You can also rely on the to read the AMQP connection details. Factory method AMQPConnectionDetails.discoverAMQP() attempts to read Camel properties in a Kubernetes-like convention, just as demonstrated on the snippet below:

AMQP connection details auto-configuration

export AMQP_SERVICE_HOST = "mybroker.com"
export AMQP_SERVICE_PORT = "6666"
export AMQP_SERVICE_USERNAME = "username"
export AMQP_SERVICE_PASSWORD = "password"

...

@Bean
AMQPConnectionDetails amqpConnection() {
  return AMQPConnectionDetails.discoverAMQP();
}

Enabling AMQP specific options

If you, for example, need to enable amqp.traceFrames you can do that by appending the option to your URI, like the following example:

AMQPComponent amqp = AMQPComponent.amqpComponent("amqp://localhost:5672?amqp.traceFrames=true");

For reference refer QPID JMS client configuration.

2.8. Using topics

To have using topics working with camel-amqp you need to configure the component to use topic:// as topic prefix, as shown below:

 <bean id="amqp" class="org.apache.camel.component.amqp.AmqpComponent">
   <property name="connectionFactory">
     <bean class="org.apache.qpid.jms.JmsConnectionFactory" factory-method="createFromURL">
       <property name="remoteURI" value="amqp://localhost:5672" />
       <property name="topicPrefix" value="topic://" />  <!-- only necessary when connecting to ActiveMQ over AMQP 1.0 -->
     </bean>
   </property>
 </bean>

Keep in mind that both AMQPComponent#amqpComponent() methods and AMQPConnectionDetails pre-configure the component with the topic prefix, so you don’t have to configure it explicitly.

2.9. Spring Boot Auto-Configuration

The component supports 101 options, which are listed below.

NameDescriptionDefaultType

camel.component.amqp.accept-messages-while-stopping

Specifies whether the consumer accept messages while it is stopping. You may consider enabling this option, if you start and stop JMS routes at runtime, while there are still messages enqueued on the queue. If this option is false, and you stop the JMS route, then messages may be rejected, and the JMS broker would have to attempt redeliveries, which yet again may be rejected, and eventually the message may be moved at a dead letter queue on the JMS broker. To avoid this its recommended to enable this option.

false

Boolean

camel.component.amqp.acknowledgement-mode-name

The JMS acknowledgement name, which is one of: SESSION_TRANSACTED, CLIENT_ACKNOWLEDGE, AUTO_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE.

AUTO_ACKNOWLEDGE

String

camel.component.amqp.allow-additional-headers

This option is used to allow additional headers which may have values that are invalid according to JMS specification. For example some message systems such as WMQ do this with header names using prefix JMS_IBM_MQMD_ containing values with byte array or other invalid types. You can specify multiple header names separated by comma, and use as suffix for wildcard matching.

 

String

camel.component.amqp.allow-auto-wired-connection-factory

Whether to auto-discover ConnectionFactory from the registry, if no connection factory has been configured. If only one instance of ConnectionFactory is found then it will be used. This is enabled by default.

true

Boolean

camel.component.amqp.allow-auto-wired-destination-resolver

Whether to auto-discover DestinationResolver from the registry, if no destination resolver has been configured. If only one instance of DestinationResolver is found then it will be used. This is enabled by default.

true

Boolean

camel.component.amqp.allow-null-body

Whether to allow sending messages with no body. If this option is false and the message body is null, then an JMSException is thrown.

true

Boolean

camel.component.amqp.allow-reply-manager-quick-stop

Whether the DefaultMessageListenerContainer used in the reply managers for request-reply messaging allow the DefaultMessageListenerContainer.runningAllowed flag to quick stop in case JmsConfiguration#isAcceptMessagesWhileStopping is enabled, and org.apache.camel.CamelContext is currently being stopped. This quick stop ability is enabled by default in the regular JMS consumers but to enable for reply managers you must enable this flag.

false

Boolean

camel.component.amqp.allow-serialized-headers

Controls whether or not to include serialized headers. Applies only when transferExchange is true. This requires that the objects are serializable. Camel will exclude any non-serializable objects and log it at WARN level.

false

Boolean

camel.component.amqp.always-copy-message

If true, Camel will always make a JMS message copy of the message when it is passed to the producer for sending. Copying the message is needed in some situations, such as when a replyToDestinationSelectorName is set (incidentally, Camel will set the alwaysCopyMessage option to true, if a replyToDestinationSelectorName is set).

false

Boolean

camel.component.amqp.artemis-consumer-priority

Consumer priorities allow you to ensure that high priority consumers receive messages while they are active. Normally, active consumers connected to a queue receive messages from it in a round-robin fashion. When consumer priorities are in use, messages are delivered round-robin if multiple active consumers exist with the same high priority. Messages will only going to lower priority consumers when the high priority consumers do not have credit available to consume the message, or those high priority consumers have declined to accept the message (for instance because it does not meet the criteria of any selectors associated with the consumer).

 

Integer

camel.component.amqp.artemis-streaming-enabled

Whether optimizing for Apache Artemis streaming mode. This can reduce memory overhead when using Artemis with JMS StreamMessage types. This option must only be enabled if Apache Artemis is being used.

false

Boolean

camel.component.amqp.async-consumer

Whether the JmsConsumer processes the Exchange asynchronously. If enabled then the JmsConsumer may pickup the next message from the JMS queue, while the previous message is being processed asynchronously (by the Asynchronous Routing Engine). This means that messages may be processed not 100% strictly in order. If disabled (as default) then the Exchange is fully processed before the JmsConsumer picks up the next message from the JMS queue. Note if transacted has been enabled, then asyncConsumer=true does not run asynchronously, as transaction must be executed synchronously (Camel 3.0 may support async transactions).

false

Boolean

camel.component.amqp.async-start-listener

Whether to startup the JmsConsumer message listener asynchronously, when starting a route. For example if a JmsConsumer cannot get a connection to a remote JMS broker, then it may block while retrying and/or failover. This will cause Camel to block while starting routes. By setting this option to true, you will let routes startup, while the JmsConsumer connects to the JMS broker using a dedicated thread in asynchronous mode. If this option is used, then beware that if the connection could not be established, then an exception is logged at WARN level, and the consumer will not be able to receive messages; You can then restart the route to retry.

false

Boolean

camel.component.amqp.async-stop-listener

Whether to stop the JmsConsumer message listener asynchronously, when stopping a route.

false

Boolean

camel.component.amqp.auto-startup

Specifies whether the consumer container should auto-startup.

true

Boolean

camel.component.amqp.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.amqp.cache-level

Sets the cache level by ID for the underlying JMS resources. See cacheLevelName option for more details.

 

Integer

camel.component.amqp.cache-level-name

Sets the cache level by name for the underlying JMS resources. Possible values are: CACHE_AUTO, CACHE_CONNECTION, CACHE_CONSUMER, CACHE_NONE, and CACHE_SESSION. The default setting is CACHE_AUTO. See the Spring documentation and Transactions Cache Levels for more information.

CACHE_AUTO

String

camel.component.amqp.client-id

Sets the JMS client ID to use. Note that this value, if specified, must be unique and can only be used by a single JMS connection instance. It is typically only required for durable topic subscriptions with JMS 1.1.

 

String

camel.component.amqp.concurrent-consumers

Specifies the default number of concurrent consumers when consuming from JMS (not for request/reply over JMS). See also the maxMessagesPerTask option to control dynamic scaling up/down of threads. When doing request/reply over JMS then the option replyToConcurrentConsumers is used to control number of concurrent consumers on the reply message listener.

1

Integer

camel.component.amqp.configuration

To use a shared JMS configuration. The option is a org.apache.camel.component.jms.JmsConfiguration type.

 

JmsConfiguration

camel.component.amqp.connection-factory

The connection factory to be use. A connection factory must be configured either on the component or endpoint. The option is a javax.jms.ConnectionFactory type.

 

ConnectionFactory

camel.component.amqp.consumer-type

The consumer type to use, which can be one of: Simple, Default, or Custom. The consumer type determines which Spring JMS listener to use. Default will use org.springframework.jms.listener.DefaultMessageListenerContainer, Simple will use org.springframework.jms.listener.SimpleMessageListenerContainer. When Custom is specified, the MessageListenerContainerFactory defined by the messageListenerContainerFactory option will determine what org.springframework.jms.listener.AbstractMessageListenerContainer to use.

 

ConsumerType

camel.component.amqp.correlation-property

When using InOut exchange pattern use this JMS property instead of JMSCorrelationID JMS property to correlate messages. If set messages will be correlated solely on the value of this property JMSCorrelationID property will be ignored and not set by Camel.

 

String

camel.component.amqp.default-task-executor-type

Specifies what default TaskExecutor type to use in the DefaultMessageListenerContainer, for both consumer endpoints and the ReplyTo consumer of producer endpoints. Possible values: SimpleAsync (uses Spring’s SimpleAsyncTaskExecutor) or ThreadPool (uses Spring’s ThreadPoolTaskExecutor with optimal values - cached threadpool-like). If not set, it defaults to the previous behaviour, which uses a cached thread pool for consumer endpoints and SimpleAsync for reply consumers. The use of ThreadPool is recommended to reduce thread trash in elastic configurations with dynamically increasing and decreasing concurrent consumers.

 

DefaultTaskExecutorType

camel.component.amqp.delivery-delay

Sets delivery delay to use for send calls for JMS. This option requires JMS 2.0 compliant broker.

-1

Long

camel.component.amqp.delivery-mode

Specifies the delivery mode to be used. Possible values are those defined by javax.jms.DeliveryMode. NON_PERSISTENT = 1 and PERSISTENT = 2.

 

Integer

camel.component.amqp.delivery-persistent

Specifies whether persistent delivery is used by default.

true

Boolean

camel.component.amqp.destination-resolver

A pluggable org.springframework.jms.support.destination.DestinationResolver that allows you to use your own resolver (for example, to lookup the real destination in a JNDI registry). The option is a org.springframework.jms.support.destination.DestinationResolver type.

 

DestinationResolver

camel.component.amqp.disable-reply-to

Specifies whether Camel ignores the JMSReplyTo header in messages. If true, Camel does not send a reply back to the destination specified in the JMSReplyTo header. You can use this option if you want Camel to consume from a route and you do not want Camel to automatically send back a reply message because another component in your code handles the reply message. You can also use this option if you want to use Camel as a proxy between different message brokers and you want to route message from one system to another.

false

Boolean

camel.component.amqp.disable-time-to-live

Use this option to force disabling time to live. For example when you do request/reply over JMS, then Camel will by default use the requestTimeout value as time to live on the message being sent. The problem is that the sender and receiver systems have to have their clocks synchronized, so they are in sync. This is not always so easy to archive. So you can use disableTimeToLive=true to not set a time to live value on the sent message. Then the message will not expire on the receiver system. See below in section About time to live for more details.

false

Boolean

camel.component.amqp.durable-subscription-name

The durable subscriber name for specifying durable topic subscriptions. The clientId option must be configured as well.

 

String

camel.component.amqp.eager-loading-of-properties

Enables eager loading of JMS properties and payload as soon as a message is loaded which generally is inefficient as the JMS properties may not be required but sometimes can catch early any issues with the underlying JMS provider and the use of JMS properties. See also the option eagerPoisonBody.

false

Boolean

camel.component.amqp.eager-poison-body

If eagerLoadingOfProperties is enabled and the JMS message payload (JMS body or JMS properties) is poison (cannot be read/mapped), then set this text as the message body instead so the message can be processed (the cause of the poison are already stored as exception on the Exchange). This can be turned off by setting eagerPoisonBody=false. See also the option eagerLoadingOfProperties.

Poison JMS message due to $\{exception.message}

String

camel.component.amqp.enabled

Whether to enable auto configuration of the amqp component. This is enabled by default.

 

Boolean

camel.component.amqp.error-handler

Specifies a org.springframework.util.ErrorHandler to be invoked in case of any uncaught exceptions thrown while processing a Message. By default these exceptions will be logged at the WARN level, if no errorHandler has been configured. You can configure logging level and whether stack traces should be logged using errorHandlerLoggingLevel and errorHandlerLogStackTrace options. This makes it much easier to configure, than having to code a custom errorHandler. The option is a org.springframework.util.ErrorHandler type.

 

ErrorHandler

camel.component.amqp.error-handler-log-stack-trace

Allows to control whether stacktraces should be logged or not, by the default errorHandler.

true

Boolean

camel.component.amqp.error-handler-logging-level

Allows to configure the default errorHandler logging level for logging uncaught exceptions.

 

LoggingLevel

camel.component.amqp.exception-listener

Specifies the JMS Exception Listener that is to be notified of any underlying JMS exceptions. The option is a javax.jms.ExceptionListener type.

 

ExceptionListener

camel.component.amqp.explicit-qos-enabled

Set if the deliveryMode, priority or timeToLive qualities of service should be used when sending messages. This option is based on Spring’s JmsTemplate. The deliveryMode, priority and timeToLive options are applied to the current endpoint. This contrasts with the preserveMessageQos option, which operates at message granularity, reading QoS properties exclusively from the Camel In message headers.

false

Boolean

camel.component.amqp.expose-listener-session

Specifies whether the listener session should be exposed when consuming messages.

false

Boolean

camel.component.amqp.force-send-original-message

When using mapJmsMessage=false Camel will create a new JMS message to send to a new JMS destination if you touch the headers (get or set) during the route. Set this option to true to force Camel to send the original JMS message that was received.

false

Boolean

camel.component.amqp.format-date-headers-to-iso8601

Sets whether JMS date properties should be formatted according to the ISO 8601 standard.

false

Boolean

camel.component.amqp.header-filter-strategy

To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message. The option is a org.apache.camel.spi.HeaderFilterStrategy type.

 

HeaderFilterStrategy

camel.component.amqp.idle-consumer-limit

Specify the limit for the number of consumers that are allowed to be idle at any given time.

1

Integer

camel.component.amqp.idle-task-execution-limit

Specifies the limit for idle executions of a receive task, not having received any message within its execution. If this limit is reached, the task will shut down and leave receiving to other executing tasks (in the case of dynamic scheduling; see the maxConcurrentConsumers setting). There is additional doc available from Spring.

1

Integer

camel.component.amqp.include-all-jmsx-properties

Whether to include all JMSXxxx properties when mapping from JMS to Camel Message. Setting this to true will include properties such as JMSXAppID, and JMSXUserID etc. Note: If you are using a custom headerFilterStrategy then this option does not apply.

false

Boolean

camel.component.amqp.include-amqp-annotations

Whether to include AMQP annotations when mapping from AMQP to Camel Message. Setting this to true maps AMQP message annotations that contain a JMS_AMQP_MA_ prefix to message headers. Due to limitations in Apache Qpid JMS API, currently delivery annotations are ignored.

false

Boolean

camel.component.amqp.include-sent-jms-message-id

Only applicable when sending to JMS destination using InOnly (eg fire and forget). Enabling this option will enrich the Camel Exchange with the actual JMSMessageID that was used by the JMS client when the message was sent to the JMS destination.

false

Boolean

camel.component.amqp.jms-key-format-strategy

Pluggable strategy for encoding and decoding JMS keys so they can be compliant with the JMS specification. Camel provides two implementations out of the box: default and passthrough. The default strategy will safely marshal dots and hyphens (. and -). The passthrough strategy leaves the key as is. Can be used for JMS brokers which do not care whether JMS header keys contain illegal characters. You can provide your own implementation of the org.apache.camel.component.jms.JmsKeyFormatStrategy and refer to it using the # notation.

 

JmsKeyFormatStrategy

camel.component.amqp.jms-message-type

Allows you to force the use of a specific javax.jms.Message implementation for sending JMS messages. Possible values are: Bytes, Map, Object, Stream, Text. By default, Camel would determine which JMS message type to use from the In body type. This option allows you to specify it.

 

JmsMessageType

camel.component.amqp.lazy-create-transaction-manager

If true, Camel will create a JmsTransactionManager, if there is no transactionManager injected when option transacted=true.

true

Boolean

camel.component.amqp.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.amqp.map-jms-message

Specifies whether Camel should auto map the received JMS message to a suited payload type, such as javax.jms.TextMessage to a String etc.

true

Boolean

camel.component.amqp.max-concurrent-consumers

Specifies the maximum number of concurrent consumers when consuming from JMS (not for request/reply over JMS). See also the maxMessagesPerTask option to control dynamic scaling up/down of threads. When doing request/reply over JMS then the option replyToMaxConcurrentConsumers is used to control number of concurrent consumers on the reply message listener.

 

Integer

camel.component.amqp.max-messages-per-task

The number of messages per task. -1 is unlimited. If you use a range for concurrent consumers (eg min max), then this option can be used to set a value to eg 100 to control how fast the consumers will shrink when less work is required.

-1

Integer

camel.component.amqp.message-converter

To use a custom Spring org.springframework.jms.support.converter.MessageConverter so you can be in control how to map to/from a javax.jms.Message. The option is a org.springframework.jms.support.converter.MessageConverter type.

 

MessageConverter

camel.component.amqp.message-created-strategy

To use the given MessageCreatedStrategy which are invoked when Camel creates new instances of javax.jms.Message objects when Camel is sending a JMS message. The option is a org.apache.camel.component.jms.MessageCreatedStrategy type.

 

MessageCreatedStrategy

camel.component.amqp.message-id-enabled

When sending, specifies whether message IDs should be added. This is just an hint to the JMS broker. If the JMS provider accepts this hint, these messages must have the message ID set to null; if the provider ignores the hint, the message ID must be set to its normal unique value.

true

Boolean

camel.component.amqp.message-listener-container-factory

Registry ID of the MessageListenerContainerFactory used to determine what org.springframework.jms.listener.AbstractMessageListenerContainer to use to consume messages. Setting this will automatically set consumerType to Custom. The option is a org.apache.camel.component.jms.MessageListenerContainerFactory type.

 

MessageListenerContainerFactory

camel.component.amqp.message-timestamp-enabled

Specifies whether timestamps should be enabled by default on sending messages. This is just an hint to the JMS broker. If the JMS provider accepts this hint, these messages must have the timestamp set to zero; if the provider ignores the hint the timestamp must be set to its normal value.

true

Boolean

camel.component.amqp.password

Password to use with the ConnectionFactory. You can also configure username/password directly on the ConnectionFactory.

 

String

camel.component.amqp.preserve-message-qos

Set to true, if you want to send message using the QoS settings specified on the message, instead of the QoS settings on the JMS endpoint. The following three headers are considered JMSPriority, JMSDeliveryMode, and JMSExpiration. You can provide all or only some of them. If not provided, Camel will fall back to use the values from the endpoint instead. So, when using this option, the headers override the values from the endpoint. The explicitQosEnabled option, by contrast, will only use options set on the endpoint, and not values from the message header.

false

Boolean

camel.component.amqp.priority

Values greater than 1 specify the message priority when sending (where 1 is the lowest priority and 9 is the highest). The explicitQosEnabled option must also be enabled in order for this option to have any effect.

4

Integer

camel.component.amqp.pub-sub-no-local

Specifies whether to inhibit the delivery of messages published by its own connection.

false

Boolean

camel.component.amqp.queue-browse-strategy

To use a custom QueueBrowseStrategy when browsing queues. The option is a org.apache.camel.component.jms.QueueBrowseStrategy type.

 

QueueBrowseStrategy

camel.component.amqp.receive-timeout

The timeout for receiving messages (in milliseconds). The option is a long type.

1000

Long

camel.component.amqp.recovery-interval

Specifies the interval between recovery attempts, i.e. when a connection is being refreshed, in milliseconds. The default is 5000 ms, that is, 5 seconds. The option is a long type.

5000

Long

camel.component.amqp.reply-to

Provides an explicit ReplyTo destination (overrides any incoming value of Message.getJMSReplyTo() in consumer).

 

String

camel.component.amqp.reply-to-cache-level-name

Sets the cache level by name for the reply consumer when doing request/reply over JMS. This option only applies when using fixed reply queues (not temporary). Camel will by default use: CACHE_CONSUMER for exclusive or shared w/ replyToSelectorName. And CACHE_SESSION for shared without replyToSelectorName. Some JMS brokers such as IBM WebSphere may require to set the replyToCacheLevelName=CACHE_NONE to work. Note: If using temporary queues then CACHE_NONE is not allowed, and you must use a higher value such as CACHE_CONSUMER or CACHE_SESSION.

 

String

camel.component.amqp.reply-to-concurrent-consumers

Specifies the default number of concurrent consumers when doing request/reply over JMS. See also the maxMessagesPerTask option to control dynamic scaling up/down of threads.

1

Integer

camel.component.amqp.reply-to-consumer-type

The consumer type of the reply consumer (when doing request/reply), which can be one of: Simple, Default, or Custom. The consumer type determines which Spring JMS listener to use. Default will use org.springframework.jms.listener.DefaultMessageListenerContainer, Simple will use org.springframework.jms.listener.SimpleMessageListenerContainer. When Custom is specified, the MessageListenerContainerFactory defined by the messageListenerContainerFactory option will determine what org.springframework.jms.listener.AbstractMessageListenerContainer to use.

 

ConsumerType

camel.component.amqp.reply-to-delivery-persistent

Specifies whether to use persistent delivery by default for replies.

true

Boolean

camel.component.amqp.reply-to-destination-selector-name

Sets the JMS Selector using the fixed name to be used so you can filter out your own replies from the others when using a shared queue (that is, if you are not using a temporary reply queue).

 

String

camel.component.amqp.reply-to-max-concurrent-consumers

Specifies the maximum number of concurrent consumers when using request/reply over JMS. See also the maxMessagesPerTask option to control dynamic scaling up/down of threads.

 

Integer

camel.component.amqp.reply-to-on-timeout-max-concurrent-consumers

Specifies the maximum number of concurrent consumers for continue routing when timeout occurred when using request/reply over JMS.

1

Integer

camel.component.amqp.reply-to-override

Provides an explicit ReplyTo destination in the JMS message, which overrides the setting of replyTo. It is useful if you want to forward the message to a remote Queue and receive the reply message from the ReplyTo destination.

 

String

camel.component.amqp.reply-to-same-destination-allowed

Whether a JMS consumer is allowed to send a reply message to the same destination that the consumer is using to consume from. This prevents an endless loop by consuming and sending back the same message to itself.

false

Boolean

camel.component.amqp.reply-to-type

Allows for explicitly specifying which kind of strategy to use for replyTo queues when doing request/reply over JMS. Possible values are: Temporary, Shared, or Exclusive. By default Camel will use temporary queues. However if replyTo has been configured, then Shared is used by default. This option allows you to use exclusive queues instead of shared ones. See Camel JMS documentation for more details, and especially the notes about the implications if running in a clustered environment, and the fact that Shared reply queues has lower performance than its alternatives Temporary and Exclusive.

 

ReplyToType

camel.component.amqp.request-timeout

The timeout for waiting for a reply when using the InOut Exchange Pattern (in milliseconds). The default is 20 seconds. You can include the header CamelJmsRequestTimeout to override this endpoint configured timeout value, and thus have per message individual timeout values. See also the requestTimeoutCheckerInterval option. The option is a long type.

20000

Long

camel.component.amqp.request-timeout-checker-interval

Configures how often Camel should check for timed out Exchanges when doing request/reply over JMS. By default Camel checks once per second. But if you must react faster when a timeout occurs, then you can lower this interval, to check more frequently. The timeout is determined by the option requestTimeout. The option is a long type.

1000

Long

camel.component.amqp.selector

Sets the JMS selector to use.

 

String

camel.component.amqp.stream-message-type-enabled

Sets whether StreamMessage type is enabled or not. Message payloads of streaming kind such as files, InputStream, etc will either by sent as BytesMessage or StreamMessage. This option controls which kind will be used. By default BytesMessage is used which enforces the entire message payload to be read into memory. By enabling this option the message payload is read into memory in chunks and each chunk is then written to the StreamMessage until no more data.

false

Boolean

camel.component.amqp.subscription-durable

Set whether to make the subscription durable. The durable subscription name to be used can be specified through the subscriptionName property. Default is false. Set this to true to register a durable subscription, typically in combination with a subscriptionName value (unless your message listener class name is good enough as subscription name). Only makes sense when listening to a topic (pub-sub domain), therefore this method switches the pubSubDomain flag as well.

false

Boolean

camel.component.amqp.subscription-name

Set the name of a subscription to create. To be applied in case of a topic (pub-sub domain) with a shared or durable subscription. The subscription name needs to be unique within this client’s JMS client id. Default is the class name of the specified message listener. Note: Only 1 concurrent consumer (which is the default of this message listener container) is allowed for each subscription, except for a shared subscription (which requires JMS 2.0).

 

String

camel.component.amqp.subscription-shared

Set whether to make the subscription shared. The shared subscription name to be used can be specified through the subscriptionName property. Default is false. Set this to true to register a shared subscription, typically in combination with a subscriptionName value (unless your message listener class name is good enough as subscription name). Note that shared subscriptions may also be durable, so this flag can (and often will) be combined with subscriptionDurable as well. Only makes sense when listening to a topic (pub-sub domain), therefore this method switches the pubSubDomain flag as well. Requires a JMS 2.0 compatible message broker.

false

Boolean

camel.component.amqp.synchronous

Sets whether synchronous processing should be strictly used.

false

Boolean

camel.component.amqp.task-executor

Allows you to specify a custom task executor for consuming messages. The option is a org.springframework.core.task.TaskExecutor type.

 

TaskExecutor

camel.component.amqp.test-connection-on-startup

Specifies whether to test the connection on startup. This ensures that when Camel starts that all the JMS consumers have a valid connection to the JMS broker. If a connection cannot be granted then Camel throws an exception on startup. This ensures that Camel is not started with failed connections. The JMS producers is tested as well.

false

Boolean

camel.component.amqp.time-to-live

When sending messages, specifies the time-to-live of the message (in milliseconds).

-1

Long

camel.component.amqp.transacted

Specifies whether to use transacted mode.

false

Boolean

camel.component.amqp.transacted-in-out

Specifies whether InOut operations (request reply) default to using transacted mode If this flag is set to true, then Spring JmsTemplate will have sessionTransacted set to true, and the acknowledgeMode as transacted on the JmsTemplate used for InOut operations. Note from Spring JMS: that within a JTA transaction, the parameters passed to createQueue, createTopic methods are not taken into account. Depending on the Java EE transaction context, the container makes its own decisions on these values. Analogously, these parameters are not taken into account within a locally managed transaction either, since Spring JMS operates on an existing JMS Session in this case. Setting this flag to true will use a short local JMS transaction when running outside of a managed transaction, and a synchronized local JMS transaction in case of a managed transaction (other than an XA transaction) being present. This has the effect of a local JMS transaction being managed alongside the main transaction (which might be a native JDBC transaction), with the JMS transaction committing right after the main transaction.

false

Boolean

camel.component.amqp.transaction-manager

The Spring transaction manager to use. The option is a org.springframework.transaction.PlatformTransactionManager type.

 

PlatformTransactionManager

camel.component.amqp.transaction-name

The name of the transaction to use.

 

String

camel.component.amqp.transaction-timeout

The timeout value of the transaction (in seconds), if using transacted mode.

-1

Integer

camel.component.amqp.transfer-exception

If enabled and you are using Request Reply messaging (InOut) and an Exchange failed on the consumer side, then the caused Exception will be send back in response as a javax.jms.ObjectMessage. If the client is Camel, the returned Exception is rethrown. This allows you to use Camel JMS as a bridge in your routing - for example, using persistent queues to enable robust routing. Notice that if you also have transferExchange enabled, this option takes precedence. The caught exception is required to be serializable. The original Exception on the consumer side can be wrapped in an outer exception such as org.apache.camel.RuntimeCamelException when returned to the producer. Use this with caution as the data is using Java Object serialization and requires the received to be able to deserialize the data at Class level, which forces a strong coupling between the producers and consumer!.

false

Boolean

camel.component.amqp.transfer-exchange

You can transfer the exchange over the wire instead of just the body and headers. The following fields are transferred: In body, Out body, Fault body, In headers, Out headers, Fault headers, exchange properties, exchange exception. This requires that the objects are serializable. Camel will exclude any non-serializable objects and log it at WARN level. You must enable this option on both the producer and consumer side, so Camel knows the payloads is an Exchange and not a regular payload. Use this with caution as the data is using Java Object serialization and requires the receiver to be able to deserialize the data at Class level, which forces a strong coupling between the producers and consumers having to use compatible Camel versions!.

false

Boolean

camel.component.amqp.use-message-id-as-correlation-id

Specifies whether JMSMessageID should always be used as JMSCorrelationID for InOut messages.

false

Boolean

camel.component.amqp.username

Username to use with the ConnectionFactory. You can also configure username/password directly on the ConnectionFactory.

 

String

camel.component.amqp.wait-for-provision-correlation-to-be-updated-counter

Number of times to wait for provisional correlation id to be updated to the actual correlation id when doing request/reply over JMS and when the option useMessageIDAsCorrelationID is enabled.

50

Integer

camel.component.amqp.wait-for-provision-correlation-to-be-updated-thread-sleeping-time

Interval in millis to sleep each time while waiting for provisional correlation id to be updated. The option is a long type.

100

Long

Chapter 3. Avro

This component provides a dataformat for avro, which allows serialization and deserialization of messages using Apache Avro’s binary dataformat. Since Camel 3.2 rpc functionality was moved into separate camel-avro-rpc component.

You can easily generate classes from a schema, using maven, ant etc. More details can be found at the Apache Avro documentation.

3.1. Dependencies

When using camel-avro with Red Hat build of Camel Spring Boot, add the following Maven dependency to have support for auto configuration:

<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-avro-starter</artifactId>
</dependency>

3.2. Avro Dataformat Options

The Avro dataformat supports 1 options, which are listed below.

NameDefaultJava TypeDescription

instanceClassName

 

String

Class name to use for marshal and unmarshalling.

3.3. Avro Data Format usage

Using the avro data format is as easy as specifying that the class that you want to marshal or unmarshal in your route.

AvroDataFormat format = new AvroDataFormat(Value.SCHEMA$);

from("direct:in").marshal(format).to("direct:marshal");
from("direct:back").unmarshal(format).to("direct:unmarshal");

Where Value is an Avro Maven Plugin Generated class.

or in XML

    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="direct:in"/>
            <marshal>
                <avro instanceClass="org.apache.camel.dataformat.avro.Message"/>
            </marshal>
            <to uri="log:out"/>
        </route>
    </camelContext>

An alternative can be to specify the dataformat inside the context and reference it from your route.

    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
         <dataFormats>
            <avro id="avro" instanceClass="org.apache.camel.dataformat.avro.Message"/>
        </dataFormats>
        <route>
            <from uri="direct:in"/>
            <marshal><custom ref="avro"/></marshal>
            <to uri="log:out"/>
        </route>
    </camelContext>

In the same manner you can umarshal using the avro data format.

3.4. Spring Boot Auto-Configuration

When using avro with Spring Boot make sure to add the Maven dependency to have support for auto configuration. The component supports 2 options, which are listed below.

NameDescriptionDefaultType

camel.dataformat.avro.enabled

Whether to enable auto configuration of the avro data format. This is enabled by default.

 

Boolean

camel.dataformat.avro.instance-class-name

Class name to use for marshal and unmarshalling.

 

String

Chapter 4. Avro Jackson

Jackson Avro is a Data Format which uses the Jackson library with the Avro extension to unmarshal an Avro payload into Java objects or to marshal Java objects into an Avro payload.

Note

If you are familiar with Jackson, this Avro data format behaves in the same way as its JSON counterpart, and thus can be used with classes annotated for JSON serialization/deserialization.

from("kafka:topic").
  unmarshal().avro(AvroLibrary.Jackson, JsonNode.class).
  to("log:info");

4.1. Dependencies

When using avro-jackson with Red Hat build of Camel Spring Boot make sure to add the Maven dependency to have support for auto configuration.

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-jackson-avro-starter</artifactId>
</dependency>

4.2. Configuring the SchemaResolver

Since Avro serialization is schema-based, this data format requires that you provide a SchemaResolver object that is able to lookup the schema for each exchange that is going to be marshalled/unmarshalled.

You can add a single SchemaResolver to the registry and it will be looked up automatically. Or you can explicitly specify the reference to a custom SchemaResolver.

4.3. Avro Jackson Options

The Avro Jackson dataformat supports 18 options, which are listed below.

NameDefaultJava TypeDescription

objectMapper

 

String

Lookup and use the existing ObjectMapper with the given id when using Jackson.

useDefaultObjectMapper

 

Boolean

Whether to lookup and use default Jackson ObjectMapper from the registry.

unmarshalType

 

String

Class name of the java type to use when unmarshalling.

jsonView

 

String

When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations.

include

 

String

If you want to marshal a pojo to JSON, and the pojo has some fields with null values. And you want to skip these null values, you can set this option to NON_NULL.

allowJmsType

 

Boolean

Used for JMS users to allow the JMSType header from the JMS spec to specify a FQN classname to use to unmarshal to.

collectionType

 

String

Refers to a custom collection type to lookup in the registry to use. This option should rarely be used, but allows to use different collection types than java.util.Collection based as default.

useList

 

Boolean

To unmarshal to a List of Map or a List of Pojo.

moduleClassNames

 

String

To use custom Jackson modules com.fasterxml.jackson.databind.Module specified as a String with FQN class names. Multiple classes can be separated by comma.

moduleRefs

 

String

To use custom Jackson modules referred from the Camel registry. Multiple modules can be separated by comma.

enableFeatures

 

String

Set of features to enable on the Jackson com.fasterxml.jackson.databind.ObjectMapper. The features should be a name that matches a enum from com.fasterxml.jackson.databind.SerializationFeature, com.fasterxml.jackson.databind.DeserializationFeature, or com.fasterxml.jackson.databind.MapperFeature Multiple features can be separated by comma.

disableFeatures

 

String

Set of features to disable on the Jackson com.fasterxml.jackson.databind.ObjectMapper. The features should be a name that matches a enum from com.fasterxml.jackson.databind.SerializationFeature, com.fasterxml.jackson.databind.DeserializationFeature, or com.fasterxml.jackson.databind.MapperFeature Multiple features can be separated by comma.

allowUnmarshallType

 

Boolean

If enabled then Jackson is allowed to attempt to use the CamelJacksonUnmarshalType header during the unmarshalling. This should only be enabled when desired to be used.

timezone

 

String

If set then Jackson will use the Timezone when marshalling/unmarshalling.

autoDiscoverObjectMapper

 

Boolean

If set to true then Jackson will lookup for an objectMapper into the registry.

contentTypeHeader

 

Boolean

Whether the data format should set the Content-Type header with the type from the data format. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON.

schemaResolver

 

String

Optional schema resolver used to lookup schemas for the data in transit.

autoDiscoverSchemaResolver

 

Boolean

When not disabled, the SchemaResolver will be looked up into the registry.

4.4. Using custom AvroMapper

You can configure JacksonAvroDataFormat to use a custom AvroMapper in case you need more control of the mapping configuration.

If you setup a single AvroMapper in the registry, then Camel will automatic lookup and use this AvroMapper.

4.5. Spring Boot Auto-Configuration

The component supports 19 options, which are listed below.

NameDescriptionDefaultType

camel.dataformat.avro-jackson.allow-jms-type

Used for JMS users to allow the JMSType header from the JMS spec to specify a FQN classname to use to unmarshal to.

false

Boolean

camel.dataformat.avro-jackson.allow-unmarshall-type

If enabled then Jackson is allowed to attempt to use the CamelJacksonUnmarshalType header during the unmarshalling. This should only be enabled when desired to be used.

false

Boolean

camel.dataformat.avro-jackson.auto-discover-object-mapper

If set to true then Jackson will lookup for an objectMapper into the registry.

false

Boolean

camel.dataformat.avro-jackson.auto-discover-schema-resolver

When not disabled, the SchemaResolver will be looked up into the registry.

true

Boolean

camel.dataformat.avro-jackson.collection-type

Refers to a custom collection type to lookup in the registry to use. This option should rarely be used, but allows to use different collection types than java.util.Collection based as default.

 

String

camel.dataformat.avro-jackson.content-type-header

Whether the data format should set the Content-Type header with the type from the data format. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON.

true

Boolean

camel.dataformat.avro-jackson.disable-features

Set of features to disable on the Jackson com.fasterxml.jackson.databind.ObjectMapper. The features should be a name that matches a enum from com.fasterxml.jackson.databind.SerializationFeature, com.fasterxml.jackson.databind.DeserializationFeature, or com.fasterxml.jackson.databind.MapperFeature Multiple features can be separated by comma.

 

String

camel.dataformat.avro-jackson.enable-features

Set of features to enable on the Jackson com.fasterxml.jackson.databind.ObjectMapper. The features should be a name that matches a enum from com.fasterxml.jackson.databind.SerializationFeature, com.fasterxml.jackson.databind.DeserializationFeature, or com.fasterxml.jackson.databind.MapperFeature Multiple features can be separated by comma.

 

String

camel.dataformat.avro-jackson.enabled

Whether to enable auto configuration of the avro-jackson data format. This is enabled by default.

 

Boolean

camel.dataformat.avro-jackson.include

If you want to marshal a pojo to JSON, and the pojo has some fields with null values. And you want to skip these null values, you can set this option to NON_NULL.

 

String

camel.dataformat.avro-jackson.json-view

When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations.

 

String

camel.dataformat.avro-jackson.module-class-names

To use custom Jackson modules com.fasterxml.jackson.databind.Module specified as a String with FQN class names. Multiple classes can be separated by comma.

 

String

camel.dataformat.avro-jackson.module-refs

To use custom Jackson modules referred from the Camel registry. Multiple modules can be separated by comma.

 

String

camel.dataformat.avro-jackson.object-mapper

Lookup and use the existing ObjectMapper with the given id when using Jackson.

 

String

camel.dataformat.avro-jackson.schema-resolver

Optional schema resolver used to lookup schemas for the data in transit.

 

String

camel.dataformat.avro-jackson.timezone

If set then Jackson will use the Timezone when marshalling/unmarshalling.

 

String

camel.dataformat.avro-jackson.unmarshal-type

Class name of the java type to use when unmarshalling.

 

String

camel.dataformat.avro-jackson.use-default-object-mapper

Whether to lookup and use default Jackson ObjectMapper from the registry.

true

Boolean

camel.dataformat.avro-jackson.use-list

To unmarshal to a List of Map or a List of Pojo.

false

Boolean

Chapter 5. AWS CloudWatch

Only producer is supported

The AWS2 Cloudwatch component allows messages to be sent to an Amazon CloudWatch metrics. The implementation of the Amazon API is provided by the AWS SDK.

Prerequisites

You must have a valid Amazon Web Services developer account, and be signed up to use Amazon CloudWatch. More information is available at Amazon CloudWatch.

5.1. Dependencies

When using aws2-cw with Red Hat build of Camel Spring Boot, add the following Maven dependency to your pom.xml to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-aws2-cw-starter</artifactId>
</dependency>

5.2. URI Format

aws2-cw://namespace[?options]

The metrics will be created if they don’t already exists. You can append query options to the URI in the following format, ?options=value&option2=value&…​

5.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

5.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

5.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

5.4. Component Options

The AWS CloudWatch component supports 18 options, which are listed below.

NameDescriptionDefaultType

amazonCwClient (producer)

Autowired To use the AmazonCloudWatch as the client.

 

CloudWatchClient

configuration (producer)

The component configuration.

 

Cw2Configuration

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

name (producer)

The metric name.

 

String

overrideEndpoint (producer)

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

boolean

proxyHost (producer)

To define a proxy host when instantiating the CW client.

 

String

proxyPort (producer)

To define a proxy port when instantiating the CW client.

 

Integer

proxyProtocol (producer)

To define a proxy protocol when instantiating the CW client.

Enum values:

  • HTTP
  • HTTPS

HTTPS

Protocol

region (producer)

The region in which CW client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

String

timestamp (producer)

The metric timestamp.

 

Instant

trustAllCertificates (producer)

If we want to trust all certificates in case of overriding the endpoint.

false

boolean

unit (producer)

The metric unit.

 

String

uriEndpointOverride (producer)

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

useDefaultCredentialsProvider (producer)

Set whether the S3 client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in.

false

boolean

value (producer)

The metric value.

 

Double

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

accessKey (security)

Amazon AWS Access Key.

 

String

secretKey (security)

Amazon AWS Secret Key.

 

String

5.5. Endpoint Options

The AWS CloudWatch endpoint is configured using URI syntax:

aws2-cw:namespace

with the following path and query parameters:

5.5.1. Path Parameters (1 parameters)

NameDescriptionDefaultType

namespace (producer)

Required The metric namespace.

 

String

5.5.2. Query Parameters (16 parameters)

NameDescriptionDefaultType

amazonCwClient (producer)

Autowired To use the AmazonCloudWatch as the client.

 

CloudWatchClient

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

name (producer)

The metric name.

 

String

overrideEndpoint (producer)

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

boolean

proxyHost (producer)

To define a proxy host when instantiating the CW client.

 

String

proxyPort (producer)

To define a proxy port when instantiating the CW client.

 

Integer

proxyProtocol (producer)

To define a proxy protocol when instantiating the CW client.

Enum values:

  • HTTP
  • HTTPS

HTTPS

Protocol

region (producer)

The region in which CW client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

String

timestamp (producer)

The metric timestamp.

 

Instant

trustAllCertificates (producer)

If we want to trust all certificates in case of overriding the endpoint.

false

boolean

unit (producer)

The metric unit.

 

String

uriEndpointOverride (producer)

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

useDefaultCredentialsProvider (producer)

Set whether the S3 client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in.

false

boolean

value (producer)

The metric value.

 

Double

accessKey (security)

Amazon AWS Access Key.

 

String

secretKey (security)

Amazon AWS Secret Key.

 

String

Required CW component options

You have to provide the amazonCwClient in the Registry or your accessKey and secretKey to access the Amazon’s CloudWatch.

5.6. Usage

5.6.1. Static credentials vs Default Credential Provider

You have the possibility of avoiding the usage of explicit static credentials, by specifying the useDefaultCredentialsProvider option and set it to true.

  • Java system properties - aws.accessKeyId and aws.secretKey
  • Environment variables - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
  • Web Identity Token from AWS STS.
  • The shared credentials and config files.
  • Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable AWS_CONTAINER_CREDENTIALS_RELATIVE_URI is set.
  • Amazon EC2 Instance profile credentials.

For more information about this you can look at AWS credentials documentation

5.6.2. Message headers evaluated by the CW producer

HeaderTypeDescription

CamelAwsCwMetricName

String

The Amazon CW metric name.

CamelAwsCwMetricValue

Double

The Amazon CW metric value.

CamelAwsCwMetricUnit

String

The Amazon CW metric unit.

CamelAwsCwMetricNamespace

String

The Amazon CW metric namespace.

CamelAwsCwMetricTimestamp

Date

The Amazon CW metric timestamp.

CamelAwsCwMetricDimensionName

String

The Amazon CW metric dimension name.

CamelAwsCwMetricDimensionValue

String

The Amazon CW metric dimension value.

CamelAwsCwMetricDimensions

Map<String, String>

A map of dimension names and dimension values.

5.6.3. Advanced CloudWatchClient configuration

If you need more control over the CloudWatchClient instance configuration you can create your own instance and refer to it from the URI:

from("direct:start")
.to("aws2-cw://namespace?amazonCwClient=#client");

The #client refers to a CloudWatchClient in the Registry.

5.7. Examples

5.7.1. Producer Example

from("direct:start")
  .to("aws2-cw://http://camel.apache.org/aws-cw");

and sends something like

exchange.getIn().setHeader(Cw2Constants.METRIC_NAME, "ExchangesCompleted");
exchange.getIn().setHeader(Cw2Constants.METRIC_VALUE, "2.0");
exchange.getIn().setHeader(Cw2Constants.METRIC_UNIT, "Count");

5.8. Spring Boot Auto-Configuration

The component supports 19 options, which are listed below.

NameDescriptionDefaultType

camel.component.aws2-cw.access-key

Amazon AWS Access Key.

 

String

camel.component.aws2-cw.amazon-cw-client

To use the AmazonCloudWatch as the client. The option is a software.amazon.awssdk.services.cloudwatch.CloudWatchClient type.

 

CloudWatchClient

camel.component.aws2-cw.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.aws2-cw.configuration

The component configuration. The option is a org.apache.camel.component.aws2.cw.Cw2Configuration type.

 

Cw2Configuration

camel.component.aws2-cw.enabled

Whether to enable auto configuration of the aws2-cw component. This is enabled by default.

 

Boolean

camel.component.aws2-cw.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.aws2-cw.name

The metric name.

 

String

camel.component.aws2-cw.override-endpoint

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

Boolean

camel.component.aws2-cw.proxy-host

To define a proxy host when instantiating the CW client.

 

String

camel.component.aws2-cw.proxy-port

To define a proxy port when instantiating the CW client.

 

Integer

camel.component.aws2-cw.proxy-protocol

To define a proxy protocol when instantiating the CW client.

 

Protocol

camel.component.aws2-cw.region

The region in which CW client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

String

camel.component.aws2-cw.secret-key

Amazon AWS Secret Key.

 

String

camel.component.aws2-cw.timestamp

The metric timestamp. The option is a java.time.Instant type.

 

Instant

camel.component.aws2-cw.trust-all-certificates

If we want to trust all certificates in case of overriding the endpoint.

false

Boolean

camel.component.aws2-cw.unit

The metric unit.

 

String

camel.component.aws2-cw.uri-endpoint-override

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

camel.component.aws2-cw.use-default-credentials-provider

Set whether the S3 client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in.

false

Boolean

camel.component.aws2-cw.value

The metric value.

 

Double

Chapter 6. AWS DynamoDB

Only producer is supported

The AWS2 DynamoDB component supports storing and retrieving data from/to service.

Prerequisites

You must have a valid Amazon Web Services developer account, and be signed up to use Amazon DynamoDB. More information is available at Amazon DynamoDB.

6.1. Dependencies

When using aws2-ddb Red Hat build of Camel Spring Boot, add the following Maven dependency to your pom.xml to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-aws2-ddb-starter</artifactId>
</dependency>

6.2. URI Format

aws2-ddb://domainName[?options]

You can append query options to the URI in the following format, ?options=value&option2=value&…​

6.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

6.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

6.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

6.4. Component Options

The AWS DynamoDB component supports 22 options, which are listed below.

NameDescriptionDefaultType

amazonDDBClient (producer)

Autowired To use the AmazonDynamoDB as the client.

 

DynamoDbClient

configuration (producer)

The component configuration.

 

Ddb2Configuration

consistentRead (producer)

Determines whether or not strong consistency should be enforced when data is read.

false

boolean

enabledInitialDescribeTable (producer)

Set whether the initial Describe table operation in the DDB Endpoint must be done, or not.

true

boolean

keyAttributeName (producer)

Attribute name when creating table.

 

String

keyAttributeType (producer)

Attribute type when creating table.

 

String

keyScalarType (producer)

The key scalar type, it can be S (String), N (Number) and B (Bytes).

 

String

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

operation (producer)

What operation to perform.

Enum values:

  • BatchGetItems
  • DeleteItem
  • DeleteTable
  • DescribeTable
  • GetItem
  • PutItem
  • Query
  • Scan
  • UpdateItem
  • UpdateTable

PutItem

Ddb2Operations

overrideEndpoint (producer)

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

boolean

proxyHost (producer)

To define a proxy host when instantiating the DDB client.

 

String

proxyPort (producer)

The region in which DynamoDB client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

Integer

proxyProtocol (producer)

To define a proxy protocol when instantiating the DDB client.

Enum values:

  • HTTP
  • HTTPS

HTTPS

Protocol

readCapacity (producer)

The provisioned throughput to reserve for reading resources from your table.

 

Long

region (producer)

The region in which DDB client needs to work.

 

String

trustAllCertificates (producer)

If we want to trust all certificates in case of overriding the endpoint.

false

boolean

uriEndpointOverride (producer)

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

useDefaultCredentialsProvider (producer)

Set whether the S3 client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in.

false

boolean

writeCapacity (producer)

The provisioned throughput to reserved for writing resources to your table.

 

Long

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

accessKey (security)

Amazon AWS Access Key.

 

String

secretKey (security)

Amazon AWS Secret Key.

 

String

6.5. Endpoint Options

The AWS DynamoDB endpoint is configured using URI syntax:

aws2-ddb:tableName

with the following path and query parameters:

6.5.1. Path Parameters (1 parameters)

NameDescriptionDefaultType

tableName (producer)

Required The name of the table currently worked with.

 

String

6.5.2. Query Parameters (20 parameters)

NameDescriptionDefaultType

amazonDDBClient (producer)

Autowired To use the AmazonDynamoDB as the client.

 

DynamoDbClient

consistentRead (producer)

Determines whether or not strong consistency should be enforced when data is read.

false

boolean

enabledInitialDescribeTable (producer)

Set whether the initial Describe table operation in the DDB Endpoint must be done, or not.

true

boolean

keyAttributeName (producer)

Attribute name when creating table.

 

String

keyAttributeType (producer)

Attribute type when creating table.

 

String

keyScalarType (producer)

The key scalar type, it can be S (String), N (Number) and B (Bytes).

 

String

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

operation (producer)

What operation to perform.

Enum values:

  • BatchGetItems
  • DeleteItem
  • DeleteTable
  • DescribeTable
  • GetItem
  • PutItem
  • Query
  • Scan
  • UpdateItem
  • UpdateTable

PutItem

Ddb2Operations

overrideEndpoint (producer)

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

boolean

proxyHost (producer)

To define a proxy host when instantiating the DDB client.

 

String

proxyPort (producer)

The region in which DynamoDB client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

Integer

proxyProtocol (producer)

To define a proxy protocol when instantiating the DDB client.

Enum values:

  • HTTP
  • HTTPS

HTTPS

Protocol

readCapacity (producer)

The provisioned throughput to reserve for reading resources from your table.

 

Long

region (producer)

The region in which DDB client needs to work.

 

String

trustAllCertificates (producer)

If we want to trust all certificates in case of overriding the endpoint.

false

boolean

uriEndpointOverride (producer)

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

useDefaultCredentialsProvider (producer)

Set whether the S3 client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in.

false

boolean

writeCapacity (producer)

The provisioned throughput to reserved for writing resources to your table.

 

Long

accessKey (security)

Amazon AWS Access Key.

 

String

secretKey (security)

Amazon AWS Secret Key.

 

String

Required DDB component options

You have to provide the amazonDDBClient in the Registry or your accessKey and secretKey to access the Amazon’s DynamoDB.

6.6. Usage

6.6.1. Static credentials vs Default Credential Provider

You have the possibility of avoiding the usage of explicit static credentials, by specifying the useDefaultCredentialsProvider option and set it to true.

  • Java system properties - aws.accessKeyId and aws.secretKey
  • Environment variables - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
  • Web Identity Token from AWS STS.
  • The shared credentials and config files.
  • Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable AWS_CONTAINER_CREDENTIALS_RELATIVE_URI is set.
  • Amazon EC2 Instance profile credentials.

For more information about this you can look at AWS credentials documentation

6.6.2. Message headers evaluated by the DDB producer

HeaderTypeDescription

CamelAwsDdbBatchItems

Map<String, KeysAndAttributes>

A map of the table name and corresponding items to get by primary key.

CamelAwsDdbTableName

String

Table Name for this operation.

CamelAwsDdbKey

Key

The primary key that uniquely identifies each item in a table.

CamelAwsDdbReturnValues

String

Use this parameter if you want to get the attribute name-value pairs before or after they are modified(NONE, ALL_OLD, UPDATED_OLD, ALL_NEW, UPDATED_NEW).

CamelAwsDdbUpdateCondition

Map<String, ExpectedAttributeValue>

Designates an attribute for a conditional modification.

CamelAwsDdbAttributeNames

Collection<String>

If attribute names are not specified then all attributes will be returned.

CamelAwsDdbConsistentRead

Boolean

If set to true, then a consistent read is issued, otherwise eventually consistent is used.

CamelAwsDdbIndexName

String

If set will be used as Secondary Index for Query operation.

CamelAwsDdbItem

Map<String, AttributeValue>

A map of the attributes for the item, and must include the primary key values that define the item.

CamelAwsDdbExactCount

Boolean

If set to true, Amazon DynamoDB returns a total number of items that match the query parameters, instead of a list of the matching items and their attributes.

CamelAwsDdbKeyConditions

Map<String, Condition>

This header specify the selection criteria for the query, and merge together the two old headers CamelAwsDdbHashKeyValue and CamelAwsDdbScanRangeKeyCondition

CamelAwsDdbStartKey

Key

Primary key of the item from which to continue an earlier query.

CamelAwsDdbHashKeyValue

AttributeValue

Value of the hash component of the composite primary key.

CamelAwsDdbLimit

Integer

The maximum number of items to return.

CamelAwsDdbScanRangeKeyCondition

Condition

A container for the attribute values and comparison operators to use for the query.

CamelAwsDdbScanIndexForward

Boolean

Specifies forward or backward traversal of the index.

CamelAwsDdbScanFilter

Map<String, Condition>

Evaluates the scan results and returns only the desired values.

CamelAwsDdbUpdateValues

Map<String, AttributeValueUpdate>

Map of attribute name to the new value and action for the update.

6.6.3. Message headers set during BatchGetItems operation

HeaderTypeDescription

CamelAwsDdbBatchResponse

Map<String,BatchResponse>

Table names and the respective item attributes from the tables.

CamelAwsDdbUnprocessedKeys

Map<String,KeysAndAttributes>

Contains a map of tables and their respective keys that were not processed with the current response.

6.6.4. Message headers set during DeleteItem operation

HeaderTypeDescription

CamelAwsDdbAttributes

Map<String, AttributeValue>

The list of attributes returned by the operation.

6.6.5. Message headers set during DeleteTable operation

HeaderTypeDescription

CamelAwsDdbProvisionedThroughput

  

ProvisionedThroughputDescription

 

The value of the ProvisionedThroughput property for this table

CamelAwsDdbCreationDate

Date

Creation DateTime of this table.

CamelAwsDdbTableItemCount

Long

Item count for this table.

CamelAwsDdbKeySchema

KeySchema

The KeySchema that identifies the primary key for this table. From Camel 2.16.0 the type of this header is List<KeySchemaElement> and not KeySchema

CamelAwsDdbTableName

String

The table name.

CamelAwsDdbTableSize

Long

The table size in bytes.

CamelAwsDdbTableStatus

String

The status of the table: CREATING, UPDATING, DELETING, ACTIVE

6.6.6. Message headers set during DescribeTable operation

HeaderTypeDescription

CamelAwsDdbProvisionedThroughput

\{{ProvisionedThroughputDescription}}

The value of the ProvisionedThroughput property for this table

CamelAwsDdbCreationDate

Date

Creation DateTime of this table.

CamelAwsDdbTableItemCount

Long

Item count for this table.

CamelAwsDdbKeySchema

\{{KeySchema}}

The KeySchema that identifies the primary key for this table.

CamelAwsDdbTableName

String

The table name.

CamelAwsDdbTableSize

Long

The table size in bytes.

CamelAwsDdbTableStatus

String

The status of the table: CREATING, UPDATING, DELETING, ACTIVE

CamelAwsDdbReadCapacity

Long

ReadCapacityUnits property of this table.

CamelAwsDdbWriteCapacity

Long

WriteCapacityUnits property of this table.

6.6.7. Message headers set during GetItem operation

HeaderTypeDescription

CamelAwsDdbAttributes

Map<String, AttributeValue>

The list of attributes returned by the operation.

6.6.8. Message headers set during PutItem operation

HeaderTypeDescription

CamelAwsDdbAttributes

Map<String, AttributeValue>

The list of attributes returned by the operation.

6.6.9. Message headers set during Query operation

HeaderTypeDescription

CamelAwsDdbItems

List<java.util.Map<String,AttributeValue>>

The list of attributes returned by the operation.

CamelAwsDdbLastEvaluatedKey

Key

Primary key of the item where the query operation stopped, inclusive of the previous result set.

CamelAwsDdbConsumedCapacity

Double

The number of Capacity Units of the provisioned throughput of the table consumed during the operation.

CamelAwsDdbCount

Integer

Number of items in the response.

6.6.10. Message headers set during Scan operation

HeaderTypeDescription

CamelAwsDdbItems

List<java.util.Map<String,AttributeValue>>

The list of attributes returned by the operation.

CamelAwsDdbLastEvaluatedKey

Key

Primary key of the item where the query operation stopped, inclusive of the previous result set.

CamelAwsDdbConsumedCapacity

Double

The number of Capacity Units of the provisioned throughput of the table consumed during the operation.

CamelAwsDdbCount

Integer

Number of items in the response.

CamelAwsDdbScannedCount

Integer

Number of items in the complete scan before any filters are applied.

6.6.11. Message headers set during UpdateItem operation

HeaderTypeDescription

CamelAwsDdbAttributes

Map<String, AttributeValue>

The list of attributes returned by the operation.

6.6.12. Advanced AmazonDynamoDB configuration

If you need more control over the AmazonDynamoDB instance configuration you can create your own instance and refer to it from the URI:

from("direct:start")
.to("aws2-ddb://domainName?amazonDDBClient=#client");

The #client refers to a DynamoDbClient in the Registry.

6.7. Supported producer operations

  • BatchGetItems
  • DeleteItem
  • DeleteTable
  • DescribeTable
  • GetItem
  • PutItem
  • Query
  • Scan
  • UpdateItem
  • UpdateTable

6.8. Examples

6.8.1. Producer Examples

  • PutItem: this operation will create an entry into DynamoDB
from("direct:start")
  .setHeader(Ddb2Constants.OPERATION, Ddb2Operations.PutItem)
  .setHeader(Ddb2Constants.CONSISTENT_READ, "true")
  .setHeader(Ddb2Constants.RETURN_VALUES, "ALL_OLD")
  .setHeader(Ddb2Constants.ITEM, attributeMap)
  .setHeader(Ddb2Constants.ATTRIBUTE_NAMES, attributeMap.keySet());
  .to("aws2-ddb://" + tableName + "?keyAttributeName=" + attributeName + "&keyAttributeType=" + KeyType.HASH
  + "&keyScalarType=" + ScalarAttributeType.S
  + "&readCapacity=1&writeCapacity=1");

Maven users will need to add the following dependency to their pom.xml.

pom.xml

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-aws2-ddb</artifactId>
    <version>${camel-version}</version>
</dependency>

where {camel-version} must be replaced by the actual version of Camel.

6.9. Spring Boot Auto-Configuration

The component supports 40 options, which are listed below.

NameDescriptionDefaultType

camel.component.aws2-ddb.access-key

Amazon AWS Access Key.

 

String

camel.component.aws2-ddb.amazon-d-d-b-client

To use the AmazonDynamoDB as the client. The option is a software.amazon.awssdk.services.dynamodb.DynamoDbClient type.

 

DynamoDbClient

camel.component.aws2-ddb.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.aws2-ddb.configuration

The component configuration. The option is a org.apache.camel.component.aws2.ddb.Ddb2Configuration type.

 

Ddb2Configuration

camel.component.aws2-ddb.consistent-read

Determines whether or not strong consistency should be enforced when data is read.

false

Boolean

camel.component.aws2-ddb.enabled

Whether to enable auto configuration of the aws2-ddb component. This is enabled by default.

 

Boolean

camel.component.aws2-ddb.enabled-initial-describe-table

Set whether the initial Describe table operation in the DDB Endpoint must be done, or not.

true

Boolean

camel.component.aws2-ddb.key-attribute-name

Attribute name when creating table.

 

String

camel.component.aws2-ddb.key-attribute-type

Attribute type when creating table.

 

String

camel.component.aws2-ddb.key-scalar-type

The key scalar type, it can be S (String), N (Number) and B (Bytes).

 

String

camel.component.aws2-ddb.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.aws2-ddb.operation

What operation to perform.

 

Ddb2Operations

camel.component.aws2-ddb.override-endpoint

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

Boolean

camel.component.aws2-ddb.proxy-host

To define a proxy host when instantiating the DDB client.

 

String

camel.component.aws2-ddb.proxy-port

The region in which DynamoDB client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

Integer

camel.component.aws2-ddb.proxy-protocol

To define a proxy protocol when instantiating the DDB client.

 

Protocol

camel.component.aws2-ddb.read-capacity

The provisioned throughput to reserve for reading resources from your table.

 

Long

camel.component.aws2-ddb.region

The region in which DDB client needs to work.

 

String

camel.component.aws2-ddb.secret-key

Amazon AWS Secret Key.

 

String

camel.component.aws2-ddb.trust-all-certificates

If we want to trust all certificates in case of overriding the endpoint.

false

Boolean

camel.component.aws2-ddb.uri-endpoint-override

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

camel.component.aws2-ddb.use-default-credentials-provider

Set whether the S3 client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in.

false

Boolean

camel.component.aws2-ddb.write-capacity

The provisioned throughput to reserved for writing resources to your table.

 

Long

camel.component.aws2-ddbstream.access-key

Amazon AWS Access Key.

 

String

camel.component.aws2-ddbstream.amazon-dynamo-db-streams-client

Amazon DynamoDB client to use for all requests for this endpoint. The option is a software.amazon.awssdk.services.dynamodb.streams.DynamoDbStreamsClient type.

 

DynamoDbStreamsClient

camel.component.aws2-ddbstream.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.aws2-ddbstream.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.aws2-ddbstream.configuration

The component configuration. The option is a org.apache.camel.component.aws2.ddbstream.Ddb2StreamConfiguration type.

 

Ddb2StreamConfiguration

camel.component.aws2-ddbstream.enabled

Whether to enable auto configuration of the aws2-ddbstream component. This is enabled by default.

 

Boolean

camel.component.aws2-ddbstream.max-results-per-request

Maximum number of records that will be fetched in each poll.

 

Integer

camel.component.aws2-ddbstream.override-endpoint

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

Boolean

camel.component.aws2-ddbstream.proxy-host

To define a proxy host when instantiating the DDBStreams client.

 

String

camel.component.aws2-ddbstream.proxy-port

To define a proxy port when instantiating the DDBStreams client.

 

Integer

camel.component.aws2-ddbstream.proxy-protocol

To define a proxy protocol when instantiating the DDBStreams client.

 

Protocol

camel.component.aws2-ddbstream.region

The region in which DDBStreams client needs to work.

 

String

camel.component.aws2-ddbstream.secret-key

Amazon AWS Secret Key.

 

String

camel.component.aws2-ddbstream.stream-iterator-type

Defines where in the DynamoDB stream to start getting records. Note that using FROM_START can cause a significant delay before the stream has caught up to real-time.

 

Ddb2StreamConfiguration$StreamIteratorType

camel.component.aws2-ddbstream.trust-all-certificates

If we want to trust all certificates in case of overriding the endpoint.

false

Boolean

camel.component.aws2-ddbstream.uri-endpoint-override

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

camel.component.aws2-ddbstream.use-default-credentials-provider

Set whether the DynamoDB Streams client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in.

false

Boolean

Chapter 7. AWS Kinesis

Both producer and consumer are supported

The AWS2 Kinesis component supports receiving messages from and sending messages to Amazon Kinesis (no Batch supported) service.

The AWS2 Kinesis component also supports Synchronous and Asynchronous Client. So if you need the connection (client) to be async, configure the 'asyncClient' option (can be found in DSL also) as true.

Prerequisites

You must have a valid Amazon Web Services developer account, and be signed up to use Amazon Kinesis. More information are available at AWS Kinesis.

7.1. Dependencies

When using aws2-kinesis Red Hat build of Camel Spring Boot, add the following Maven dependency to your pom.xml to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-aws2-kinesis-starter</artifactId>
</dependency>

7.2. URI Format

aws2-kinesis://stream-name[?options]

The stream needs to be created prior to it being used. You can append query options to the URI in the following format, ?options=value&option2=value&…​

7.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

7.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

7.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

7.4. Component Options

The AWS Kinesis component supports 28 options, which are listed below.

NameDescriptionDefaultType

amazonKinesisClient (common)

Autowired Amazon Kinesis client to use for all requests for this endpoint.

 

KinesisClient

cborEnabled (common)

This option will set the CBOR_ENABLED property during the execution.

true

boolean

configuration (common)

Component configuration.

 

Kinesis2Configuration

overrideEndpoint (common)

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

boolean

proxyHost (common)

To define a proxy host when instantiating the Kinesis client.

 

String

proxyPort (common)

To define a proxy port when instantiating the Kinesis client.

 

Integer

proxyProtocol (common)

To define a proxy protocol when instantiating the Kinesis client.

Enum values:

  • HTTP
  • HTTPS

HTTPS

Protocol

region (common)

The region in which Kinesis Firehose client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

String

trustAllCertificates (common)

If we want to trust all certificates in case of overriding the endpoint.

false

boolean

uriEndpointOverride (common)

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

useDefaultCredentialsProvider (common)

Set whether the Kinesis client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in.

false

boolean

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

iteratorType (consumer)

Defines where in the Kinesis stream to start getting records.

Enum values:

  • AT_SEQUENCE_NUMBER
  • AFTER_SEQUENCE_NUMBER
  • TRIM_HORIZON
  • LATEST
  • AT_TIMESTAMP
  • null

TRIM_HORIZON

ShardIteratorType

maxResultsPerRequest (consumer)

Maximum number of records that will be fetched in each poll.

1

int

resumeStrategy (consumer)

Defines a resume strategy for AWS Kinesis. The default strategy reads the sequenceNumber if provided.

KinesisUserConfigurationResumeStrategy

KinesisResumeStrategy

sequenceNumber (consumer)

The sequence number to start polling from. Required if iteratorType is set to AFTER_SEQUENCE_NUMBER or AT_SEQUENCE_NUMBER.

 

String

shardClosed (consumer)

Define what will be the behavior in case of shard closed. Possible value are ignore, silent and fail. In case of ignore a message will be logged and the consumer will restart from the beginning,in case of silent there will be no logging and the consumer will start from the beginning,in case of fail a ReachedClosedStateException will be raised.

Enum values:

  • ignore
  • fail
  • silent

ignore

Kinesis2ShardClosedStrategyEnum

shardId (consumer)

Defines which shardId in the Kinesis stream to get records from.

 

String

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

asyncClient (advanced)

If we want to a KinesisAsyncClient instance set it to true.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

healthCheckConsumerEnabled (health)

Used for enabling or disabling all consumer based health checks from this component.

true

boolean

healthCheckProducerEnabled (health)

Used for enabling or disabling all producer based health checks from this component. NOTE: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true.

true

boolean

accessKey (security)

Amazon AWS Access Key.

 

String

profileCredentialsName (security)

If using a profile credentials provider this parameter will set the profile name.

 

String

secretKey (security)

Amazon AWS Secret Key.

 

String

sessionToken (security)

Amazon AWS Session Token used when the user needs to assume a IAM role.

 

String

trustAllCertificates (security)

If we want to trust all certificates in case of overriding the endpoint.

false

boolean

useDefaultCredentialsProvider (security)

Set whether the Kinesis client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in.

false

boolean

useProfileCredentialsProvider (security)

Set whether the Kinesis client should expect to load credentials through a profile credentials provider.

false

boolean

useSessionCredentials (security)

Set whether the Kinesis client should expect to use Session Credentials. This is useful in situation in which the user needs to assume a IAM role for doing operations in Kinesis.

false

boolean

7.5. Endpoint Options

The AWS Kinesis endpoint is configured using URI syntax:

aws2-kinesis:streamName

with the following path and query parameters:

7.5.1. Path Parameters (1 parameters)

NameDescriptionDefaultType

streamName (common)

Required Name of the stream.

 

String

7.5.2. Query Parameters (42 parameters)

NameDescriptionDefaultType

amazonKinesisClient (common)

Autowired Amazon Kinesis client to use for all requests for this endpoint.

 

KinesisClient

cborEnabled (common)

This option will set the CBOR_ENABLED property during the execution.

true

boolean

overrideEndpoint (common)

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

boolean

proxyHost (common)

To define a proxy host when instantiating the Kinesis client.

 

String

proxyPort (common)

To define a proxy port when instantiating the Kinesis client.

 

Integer

proxyProtocol (common)

To define a proxy protocol when instantiating the Kinesis client.

Enum values:

  • HTTP
  • HTTPS

HTTPS

Protocol

region (common)

The region in which Kinesis Firehose client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

String

trustAllCertificates (common)

If we want to trust all certificates in case of overriding the endpoint.

false

boolean

uriEndpointOverride (common)

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

useDefaultCredentialsProvider (common)

Set whether the Kinesis client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in.

false

boolean

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

iteratorType (consumer)

Defines where in the Kinesis stream to start getting records.

Enum values:

  • AT_SEQUENCE_NUMBER
  • AFTER_SEQUENCE_NUMBER
  • TRIM_HORIZON
  • LATEST
  • AT_TIMESTAMP
  • null

TRIM_HORIZON

ShardIteratorType

maxResultsPerRequest (consumer)

Maximum number of records that will be fetched in each poll.

1

int

resumeStrategy (consumer)

Defines a resume strategy for AWS Kinesis. The default strategy reads the sequenceNumber if provided.

KinesisUserConfigurationResumeStrategy

KinesisResumeStrategy

sendEmptyMessageWhenIdle (consumer)

If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead.

false

boolean

sequenceNumber (consumer)

The sequence number to start polling from. Required if iteratorType is set to AFTER_SEQUENCE_NUMBER or AT_SEQUENCE_NUMBER.

 

String

shardClosed (consumer)

Define what will be the behavior in case of shard closed. Possible value are ignore, silent and fail. In case of ignore a message will be logged and the consumer will restart from the beginning,in case of silent there will be no logging and the consumer will start from the beginning,in case of fail a ReachedClosedStateException will be raised.

Enum values:

  • ignore
  • fail
  • silent

ignore

Kinesis2ShardClosedStrategyEnum

shardId (consumer)

Defines which shardId in the Kinesis stream to get records from.

 

String

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

pollStrategy (consumer (advanced))

A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel.

 

PollingConsumerPollStrategy

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

asyncClient (advanced)

If we want to a KinesisAsyncClient instance set it to true.

false

boolean

backoffErrorThreshold (scheduler)

The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in.

 

int

backoffIdleThreshold (scheduler)

The number of subsequent idle polls that should happen before the backoffMultipler should kick-in.

 

int

backoffMultiplier (scheduler)

To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured.

 

int

delay (scheduler)

Milliseconds before the next poll.

500

long

greedy (scheduler)

If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages.

false

boolean

initialDelay (scheduler)

Milliseconds before the first poll starts.

1000

long

repeatCount (scheduler)

Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever.

0

long

runLoggingLevel (scheduler)

The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that.

Enum values:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • OFF

TRACE

LoggingLevel

scheduledExecutorService (scheduler)

Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool.

 

ScheduledExecutorService

scheduler (scheduler)

To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler.

none

Object

schedulerProperties (scheduler)

To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler.

 

Map

startScheduler (scheduler)

Whether the scheduler should be auto started.

true

boolean

timeUnit (scheduler)

Time unit for initialDelay and delay options.

Enum values:

  • NANOSECONDS
  • MICROSECONDS
  • MILLISECONDS
  • SECONDS
  • MINUTES
  • HOURS
  • DAYS

MILLISECONDS

TimeUnit

useFixedDelay (scheduler)

Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details.

true

boolean

accessKey (security)

Amazon AWS Access Key.

 

String

profileCredentialsName (security)

If using a profile credentials provider this parameter will set the profile name.

 

String

secretKey (security)

Amazon AWS Secret Key.

 

String

sessionToken (security)

Amazon AWS Session Token used when the user needs to assume a IAM role.

 

String

trustAllCertificates (security)

If we want to trust all certificates in case of overriding the endpoint.

false

boolean

useDefaultCredentialsProvider (security)

Set whether the Kinesis client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in.

false

boolean

useProfileCredentialsProvider (security)

Set whether the Kinesis client should expect to load credentials through a profile credentials provider.

false

boolean

useSessionCredentials (security)

Set whether the Kinesis client should expect to use Session Credentials. This is useful in situation in which the user needs to assume a IAM role for doing operations in Kinesis.

false

boolean

Required Kinesis component options

You have to provide the KinesisClient in the Registry with proxies and relevant credentials configured.

7.6. Batch Consumer

This component implements the Batch Consumer.

This allows you for instance to know how many messages exists in this batch and for instance let the Aggregator aggregate this number of messages.

The consumer is able to consume either from a single specific shard or all available shards (multiple shards consumption) of Amazon Kinesis. Therefore, if you leave the 'shardId' property in the DSL configuration empty, then it’ll consume all available shards otherwise only the specified shard corresponding to the shardId will be consumed.

7.7. Usage

7.7.1. Static credentials vs Default Credential Provider

You have the possibility of avoiding the usage of explicit static credentials, by specifying the useDefaultCredentialsProvider option and set it to true.

The order of evaluation for Default Credentials Provider is the following:

  • Java system properties - aws.accessKeyId and aws.secretKey
  • Environment variables - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
  • Web Identity Token from AWS STS.
  • The shared credentials and config files.
  • Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable AWS_CONTAINER_CREDENTIALS_RELATIVE_URI is set.
  • Amazon EC2 Instance profile credentials.

You have also the possibility of using Profile Credentials Provider, by specifying the useProfileCredentialsProvider option to true and profileCredentialsName to the profile name.

Only one of static, default and profile credentials could be used at the same time.

For more information see AWS credentials documentation.

7.8. Message headers

NameDescription

CamelAwsKinesisSequenceNumber (common)

Constant: SEQUENCE_NUMBER

The sequence number of the record as defined in PutRecord syntax.

CamelAwsKinesisApproximateArrivalTimestamp (common)

Constant: APPROX_ARRIVAL_TIME

The time AWS assigned as the arrival time of the record.

CamelAwsKinesisPartitionKey (common)

Constant: PARTITION_KEY

Identifies which shard in the stream the data record is assigned to.

CamelMessageTimestamp (common)

Constant: MESSAGE_TIMESTAMP

The timestamp of the message.

CamelAwsKinesisShardId (common)

Constant: SHARD_ID

The shard ID of the shard where the data record was place

7.8.1. AmazonKinesis configuration

You then have to reference the KinesisClient in the amazonKinesisClient URI option.

from("aws2-kinesis://mykinesisstream?amazonKinesisClient=#kinesisClient")
  .to("log:out?showAll=true");

7.8.2. Providing AWS Credentials

It is recommended that the credentials are obtained by using the DefaultAWSCredentialsProviderChain that is the default when creating a new ClientConfiguration instance, however, a different AWSCredentialsProvider can be specified when calling createClient(…​).

7.8.3. AWS Kinesis KCL Consumer

The component supports also the KCL (Kinesis Client Library) for consuming from a Kinesis Data Stream. To enable this feature, set two different parameters in your endpoint:

from("aws2-kinesis://mykinesisstream?asyncClient=true&useDefaultCredentialsProvider=true&useKclConsumers=true")
  .to("log:out?showAll=true");

This feature makes it possible to automatically checkpoint the Shard Iterations by combining the usage of KCL, DynamoDB Table and CloudWatch alarms. This works out of the box, by simply using your AWS Credentials.

Note

AWS Kinesis consumer with KCL needs approximately 60-70 seconds to startup.

7.9. Spring Boot Auto-Configuration

The component supports 50 options, which are listed below.

NameDescriptionDefaultType

camel.component.aws2-kinesis-firehose.access-key

Amazon AWS Access Key.

 

String

camel.component.aws2-kinesis-firehose.amazon-kinesis-firehose-client

Amazon Kinesis Firehose client to use for all requests for this endpoint. The option is a software.amazon.awssdk.services.firehose.FirehoseClient type.

 

FirehoseClient

camel.component.aws2-kinesis-firehose.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.aws2-kinesis-firehose.cbor-enabled

This option will set the CBOR_ENABLED property during the execution.

true

Boolean

camel.component.aws2-kinesis-firehose.configuration

Component configuration. The option is a org.apache.camel.component.aws2.firehose.KinesisFirehose2Configuration type.

 

KinesisFirehose2Configuration

camel.component.aws2-kinesis-firehose.enabled

Whether to enable auto configuration of the aws2-kinesis-firehose component. This is enabled by default.

 

Boolean

camel.component.aws2-kinesis-firehose.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.aws2-kinesis-firehose.operation

The operation to do in case the user don’t want to send only a record.

 

KinesisFirehose2Operations

camel.component.aws2-kinesis-firehose.override-endpoint

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

Boolean

camel.component.aws2-kinesis-firehose.profile-credentials-name

If using a profile credentials provider this parameter will set the profile name.

 

String

camel.component.aws2-kinesis-firehose.proxy-host

To define a proxy host when instantiating the Kinesis Firehose client.

 

String

camel.component.aws2-kinesis-firehose.proxy-port

To define a proxy port when instantiating the Kinesis Firehose client.

 

Integer

camel.component.aws2-kinesis-firehose.proxy-protocol

To define a proxy protocol when instantiating the Kinesis Firehose client.

 

Protocol

camel.component.aws2-kinesis-firehose.region

The region in which Kinesis Firehose client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

String

camel.component.aws2-kinesis-firehose.secret-key

Amazon AWS Secret Key.

 

String

camel.component.aws2-kinesis-firehose.session-token

Amazon AWS Session Token used when the user needs to assume a IAM role.

 

String

camel.component.aws2-kinesis-firehose.trust-all-certificates

If we want to trust all certificates in case of overriding the endpoint.

false

Boolean

camel.component.aws2-kinesis-firehose.uri-endpoint-override

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

camel.component.aws2-kinesis-firehose.use-default-credentials-provider

Set whether the Kinesis Firehose client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in.

false

Boolean

camel.component.aws2-kinesis-firehose.use-profile-credentials-provider

Set whether the Kinesis Firehose client should expect to load credentials through a profile credentials provider.

false

Boolean

camel.component.aws2-kinesis-firehose.use-session-credentials

Set whether the Kinesis Firehose client should expect to use Session Credentials. This is useful in situation in which the user needs to assume a IAM role for doing operations in Kinesis Firehose.

false

Boolean

camel.component.aws2-kinesis.access-key

Amazon AWS Access Key.

 

String

camel.component.aws2-kinesis.amazon-kinesis-client

Amazon Kinesis client to use for all requests for this endpoint. The option is a software.amazon.awssdk.services.kinesis.KinesisClient type.

 

KinesisClient

camel.component.aws2-kinesis.async-client

If we want to a KinesisAsyncClient instance set it to true.

false

Boolean

camel.component.aws2-kinesis.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.aws2-kinesis.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.aws2-kinesis.cbor-enabled

This option will set the CBOR_ENABLED property during the execution.

true

Boolean

camel.component.aws2-kinesis.configuration

Component configuration. The option is a org.apache.camel.component.aws2.kinesis.Kinesis2Configuration type.

 

Kinesis2Configuration

camel.component.aws2-kinesis.enabled

Whether to enable auto configuration of the aws2-kinesis component. This is enabled by default.

 

Boolean

camel.component.aws2-kinesis.health-check-consumer-enabled

Used for enabling or disabling all consumer based health checks from this component.

true

Boolean

camel.component.aws2-kinesis.health-check-producer-enabled

Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true.

true

Boolean

camel.component.aws2-kinesis.iterator-type

Defines where in the Kinesis stream to start getting records.

 

ShardIteratorType

camel.component.aws2-kinesis.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.aws2-kinesis.max-results-per-request

Maximum number of records that will be fetched in each poll.

1

Integer

camel.component.aws2-kinesis.override-endpoint

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

Boolean

camel.component.aws2-kinesis.profile-credentials-name

If using a profile credentials provider this parameter will set the profile name.

 

String

camel.component.aws2-kinesis.proxy-host

To define a proxy host when instantiating the Kinesis client.

 

String

camel.component.aws2-kinesis.proxy-port

To define a proxy port when instantiating the Kinesis client.

 

Integer

camel.component.aws2-kinesis.proxy-protocol

To define a proxy protocol when instantiating the Kinesis client.

 

Protocol

camel.component.aws2-kinesis.region

The region in which Kinesis Firehose client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

String

camel.component.aws2-kinesis.resume-strategy

Defines a resume strategy for AWS Kinesis. The default strategy reads the sequenceNumber if provided. The option is a org.apache.camel.component.aws2.kinesis.consumer.KinesisResumeStrategy type.

 

KinesisResumeStrategy

camel.component.aws2-kinesis.secret-key

Amazon AWS Secret Key.

 

String

camel.component.aws2-kinesis.sequence-number

The sequence number to start polling from. Required if iteratorType is set to AFTER_SEQUENCE_NUMBER or AT_SEQUENCE_NUMBER.

 

String

camel.component.aws2-kinesis.session-token

Amazon AWS Session Token used when the user needs to assume a IAM role.

 

String

camel.component.aws2-kinesis.shard-closed

Define what will be the behavior in case of shard closed. Possible value are ignore, silent and fail. In case of ignore a message will be logged and the consumer will restart from the beginning,in case of silent there will be no logging and the consumer will start from the beginning,in case of fail a ReachedClosedStateException will be raised.

 

Kinesis2ShardClosedStrategyEnum

camel.component.aws2-kinesis.shard-id

Defines which shardId in the Kinesis stream to get records from.

 

String

camel.component.aws2-kinesis.trust-all-certificates

If we want to trust all certificates in case of overriding the endpoint.

false

Boolean

camel.component.aws2-kinesis.uri-endpoint-override

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

camel.component.aws2-kinesis.use-default-credentials-provider

Set whether the Kinesis client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in.

false

Boolean

camel.component.aws2-kinesis.use-profile-credentials-provider

Set whether the Kinesis client should expect to load credentials through a profile credentials provider.

false

Boolean

camel.component.aws2-kinesis.use-session-credentials

Set whether the Kinesis client should expect to use Session Credentials. This is useful in situation in which the user needs to assume a IAM role for doing operations in Kinesis.

false

Boolean

Chapter 8. AWS 2 Lambda

Only producer is supported

The AWS2 Lambda component supports create, get, list, delete and invoke AWS Lambda functions.

Prerequisites

You must have a valid Amazon Web Services developer account, and be signed up to use Amazon Lambda. More information is available at AWS Lambda.

When creating a Lambda function, you need to specify a IAM role which has at least the AWSLambdaBasicExecuteRole policy attached.

8.1. Dependencies

When using aws2-lambda with Red Hat build of Camel Spring Boot, add the following Maven dependency to your pom.xml to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-aws2-lambda-starter</artifactId>
</dependency>

8.2. URI Format

aws2-lambda://functionName[?options]

You can append query options to the URI in the following format, options=value&option2=value&…​

8.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

8.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

8.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

8.4. Component Options

The AWS Lambda component supports 16 options, which are listed below.

NameDescriptionDefaultType

configuration (producer)

Component configuration.

 

Lambda2Configuration

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

operation (producer)

The operation to perform. It can be listFunctions, getFunction, createFunction, deleteFunction or invokeFunction.

Enum values:

  • listFunctions
  • getFunction
  • createAlias
  • deleteAlias
  • getAlias
  • listAliases
  • createFunction
  • deleteFunction
  • invokeFunction
  • updateFunction
  • createEventSourceMapping
  • deleteEventSourceMapping
  • listEventSourceMapping
  • listTags
  • tagResource
  • untagResource
  • publishVersion
  • listVersions

invokeFunction

Lambda2Operations

overrideEndpoint (producer)

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

boolean

pojoRequest (producer)

If we want to use a POJO request as body or not.

false

boolean

region (producer)

The region in which Lambda client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

String

trustAllCertificates (producer)

If we want to trust all certificates in case of overriding the endpoint.

false

boolean

uriEndpointOverride (producer)

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

useDefaultCredentialsProvider (producer)

Set whether the Lambda client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

awsLambdaClient (advanced)

Autowired To use a existing configured AwsLambdaClient as client.

 

LambdaClient

proxyHost (proxy)

To define a proxy host when instantiating the Lambda client.

 

String

proxyPort (proxy)

To define a proxy port when instantiating the Lambda client.

 

Integer

proxyProtocol (proxy)

To define a proxy protocol when instantiating the Lambda client.

Enum values:

  • HTTP
  • HTTPS

HTTPS

Protocol

accessKey (security)

Amazon AWS Access Key.

 

String

secretKey (security)

Amazon AWS Secret Key.

 

String

8.5. Endpoint Options

The AWS Lambda endpoint is configured using URI syntax:

aws2-lambda:function

with the following path and query parameters:

8.5.1. Path Parameters (1 parameters)

NameDescriptionDefaultType

function (producer)

Required Name of the Lambda function.

 

String

8.5.2. Query Parameters (14 parameters)

NameDescriptionDefaultType

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

operation (producer)

The operation to perform. It can be listFunctions, getFunction, createFunction, deleteFunction or invokeFunction.

Enum values:

  • listFunctions
  • getFunction
  • createAlias
  • deleteAlias
  • getAlias
  • listAliases
  • createFunction
  • deleteFunction
  • invokeFunction
  • updateFunction
  • createEventSourceMapping
  • deleteEventSourceMapping
  • listEventSourceMapping
  • listTags
  • tagResource
  • untagResource
  • publishVersion
  • listVersions

invokeFunction

Lambda2Operations

overrideEndpoint (producer)

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

boolean

pojoRequest (producer)

If we want to use a POJO request as body or not.

false

boolean

region (producer)

The region in which Lambda client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

String

trustAllCertificates (producer)

If we want to trust all certificates in case of overriding the endpoint.

false

boolean

uriEndpointOverride (producer)

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

useDefaultCredentialsProvider (producer)

Set whether the Lambda client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in.

false

boolean

awsLambdaClient (advanced)

Autowired To use a existing configured AwsLambdaClient as client.

 

LambdaClient

proxyHost (proxy)

To define a proxy host when instantiating the Lambda client.

 

String

proxyPort (proxy)

To define a proxy port when instantiating the Lambda client.

 

Integer

proxyProtocol (proxy)

To define a proxy protocol when instantiating the Lambda client.

Enum values:

  • HTTP
  • HTTPS

HTTPS

Protocol

accessKey (security)

Amazon AWS Access Key.

 

String

secretKey (security)

Amazon AWS Secret Key.

 

String

Required Lambda component options

You have to provide the awsLambdaClient in the Registry or your accessKey and secretKey to access the Amazon Lambda service..

8.6. Usage

8.6.1. Static credentials vs Default Credential Provider

You have the possibility of avoiding the usage of explicit static credentials, by specifying the useDefaultCredentialsProvider option and set it to true.

  • Java system properties - aws.accessKeyId and aws.secretKey
  • Environment variables - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
  • Web Identity Token from AWS STS.
  • The shared credentials and config files.
  • Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable AWS_CONTAINER_CREDENTIALS_RELATIVE_URI is set.
  • Amazon EC2 Instance profile credentials.

For more information about this you can look at AWS credentials documentation

8.6.2. Message headers evaluated by the Lambda producer

OperationHeaderTypeDescriptionRequired

All

CamelAwsLambdaOperation

String

The operation we want to perform. Override operation passed as query parameter

Yes

createFunction

CamelAwsLambdaS3Bucket

String

Amazon S3 bucket name where the .zip file containing your deployment package is stored. This bucket must reside in the same AWS region where you are creating the Lambda function.

No

createFunction

CamelAwsLambdaS3Key

String

The Amazon S3 object (the deployment package) key name you want to upload.

No

createFunction

CamelAwsLambdaS3ObjectVersion

String

The Amazon S3 object (the deployment package) version you want to upload.

No

createFunction

CamelAwsLambdaZipFile

String

The local path of the zip file (the deployment package). Content of zip file can also be put in Message body.

No

createFunction

CamelAwsLambdaRole

String

The Amazon Resource Name (ARN) of the IAM role that Lambda assumes when it executes your function to access any other Amazon Web Services (AWS) resources.

Yes

createFunction

CamelAwsLambdaRuntime

String

The runtime environment for the Lambda function you are uploading. (nodejs, nodejs4.3, nodejs6.10, java8, python2.7, python3.6, dotnetcore1.0, odejs4.3-edge)

Yes

createFunction

CamelAwsLambdaHandler

String

The function within your code that Lambda calls to begin execution. For Node.js, it is the module-name.export value in your function. For Java, it can be package.class-name::handler or package.class-name.

Yes

createFunction

CamelAwsLambdaDescription

String

The user-provided description.

No

createFunction

CamelAwsLambdaTargetArn

String

The parent object that contains the target ARN (Amazon Resource Name) of an Amazon SQS queue or Amazon SNS topic.

No

createFunction

CamelAwsLambdaMemorySize

Integer

The memory size, in MB, you configured for the function. Must be a multiple of 64 MB.

No

createFunction

CamelAwsLambdaKMSKeyArn

String

The Amazon Resource Name (ARN) of the KMS key used to encrypt your function’s environment variables. If not provided, AWS Lambda will use a default service key.

No

createFunction

CamelAwsLambdaPublish

Boolean

This boolean parameter can be used to request AWS Lambda to create the Lambda function and publish a version as an atomic operation.

No

createFunction

CamelAwsLambdaTimeout

Integer

The function execution time at which Lambda should terminate the function. The default is 3 seconds.

No

createFunction

CamelAwsLambdaTracingConfig

String

Your function’s tracing settings (Active or PassThrough).

No

createFunction

CamelAwsLambdaEnvironmentVariables

Map<String, String>

The key-value pairs that represent your environment’s configuration settings.

No

createFunction

CamelAwsLambdaEnvironmentTags

Map<String, String>

The list of tags (key-value pairs) assigned to the new function.

No

createFunction

CamelAwsLambdaSecurityGroupIds

List<String>

If your Lambda function accesses resources in a VPC, a list of one or more security groups IDs in your VPC.

No

createFunction

CamelAwsLambdaSubnetIds

List<String>

If your Lambda function accesses resources in a VPC, a list of one or more subnet IDs in your VPC.

No

createAlias

CamelAwsLambdaFunctionVersion

String

The function version to set in the alias

Yes

createAlias

CamelAwsLambdaAliasFunctionName

String

The function name to set in the alias

Yes

createAlias

CamelAwsLambdaAliasFunctionDescription

String

The function description to set in the alias

No

deleteAlias

CamelAwsLambdaAliasFunctionName

String

The function name of the alias

Yes

getAlias

CamelAwsLambdaAliasFunctionName

String

The function name of the alias

Yes

listAliases

CamelAwsLambdaFunctionVersion

String

The function version to set in the alias

No

8.7. List of Avalaible Operations

  • listFunctions
  • getFunction
  • createFunction
  • deleteFunction
  • invokeFunction
  • updateFunction
  • createEventSourceMapping
  • deleteEventSourceMapping
  • listEventSourceMapping
  • listTags
  • tagResource
  • untagResource
  • publishVersion
  • listVersions
  • createAlias
  • deleteAlias
  • getAlias
  • listAliases

8.8. Examples

8.8.1. Producer Example

To have a full understanding of how the component works, you may have a look at these integration tests.

8.8.2. Producer Examples

  • CreateFunction: this operation will create a function for you in AWS Lambda
  from("direct:createFunction").to("aws2-lambda://GetHelloWithName?operation=createFunction").to("mock:result");

and by sending

template.send("direct:createFunction", ExchangePattern.InOut, new Processor() {
    @Override
    public void process(Exchange exchange) throws Exception {
        exchange.getIn().setHeader(Lambda2Constants.RUNTIME, "nodejs6.10");
        exchange.getIn().setHeader(Lambda2Constants.HANDLER, "GetHelloWithName.handler");
        exchange.getIn().setHeader(Lambda2Constants.DESCRIPTION, "Hello with node.js on Lambda");
        exchange.getIn().setHeader(Lambda2Constants.ROLE,
            "arn:aws:iam::643534317684:role/lambda-execution-role");
        ClassLoader classLoader = getClass().getClassLoader();
        File file = new File(
             classLoader
                 .getResource("org/apache/camel/component/aws2/lambda/function/node/GetHelloWithName.zip")
                 .getFile());
        FileInputStream inputStream = new FileInputStream(file);
        exchange.getIn().setBody(inputStream);
    }
});

8.9. Using a POJO as body

Sometimes build an AWS Request can be complex, because of multiple options. We introduce the possibility to use a POJO as body. In AWS Lambda there are multiple operations you can submit, as an example for Get Function request, you can do something like:

from("direct:getFunction")
     .setBody(GetFunctionRequest.builder().functionName("test").build())
     .to("aws2-lambda://GetHelloWithName?awsLambdaClient=#awsLambdaClient&operation=getFunction&pojoRequest=true")

In this way you’ll pass the request directly without the need of passing headers and options specifically related to this operation.

8.10. Dependencies

Maven users will need to add the following dependency to their pom.xml.

pom.xml

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-aws2-lambda</artifactId>
    <version>${camel-version}</version>
</dependency>

where {camel-version} must be replaced by the actual version of Camel.

8.11. Spring Boot Auto-Configuration

The component supports 17 options, which are listed below.

NameDescriptionDefaultType

camel.component.aws2-lambda.access-key

Amazon AWS Access Key.

 

String

camel.component.aws2-lambda.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.aws2-lambda.aws-lambda-client

To use a existing configured AwsLambdaClient as client. The option is a software.amazon.awssdk.services.lambda.LambdaClient type.

 

LambdaClient

camel.component.aws2-lambda.configuration

Component configuration. The option is a org.apache.camel.component.aws2.lambda.Lambda2Configuration type.

 

Lambda2Configuration

camel.component.aws2-lambda.enabled

Whether to enable auto configuration of the aws2-lambda component. This is enabled by default.

 

Boolean

camel.component.aws2-lambda.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.aws2-lambda.operation

The operation to perform. It can be listFunctions, getFunction, createFunction, deleteFunction or invokeFunction.

 

Lambda2Operations

camel.component.aws2-lambda.override-endpoint

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

Boolean

camel.component.aws2-lambda.pojo-request

If we want to use a POJO request as body or not.

false

Boolean

camel.component.aws2-lambda.proxy-host

To define a proxy host when instantiating the Lambda client.

 

String

camel.component.aws2-lambda.proxy-port

To define a proxy port when instantiating the Lambda client.

 

Integer

camel.component.aws2-lambda.proxy-protocol

To define a proxy protocol when instantiating the Lambda client.

 

Protocol

camel.component.aws2-lambda.region

The region in which Lambda client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

String

camel.component.aws2-lambda.secret-key

Amazon AWS Secret Key.

 

String

camel.component.aws2-lambda.trust-all-certificates

If we want to trust all certificates in case of overriding the endpoint.

false

Boolean

camel.component.aws2-lambda.uri-endpoint-override

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

camel.component.aws2-lambda.use-default-credentials-provider

Set whether the Lambda client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in.

false

Boolean

Chapter 9. AWS S3 Storage Service

Both producer and consumer are supported

The AWS2 S3 component supports storing and retrieving objects from/to Amazon’s S3 service.

Prerequisites

You must have a valid Amazon Web Services developer account, and be signed up to use Amazon S3. More information is available at link:https://aws.amazon.com/s3 [Amazon S3].

9.1. Dependencies

When using aws2-s3 with Red Hat build of Camel Spring Boot, add the following Maven dependency to your pom.xml to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-aws2-s3-starter</artifactId>
</dependency>

9.2. URI Format

aws2-s3://bucketNameOrArn[?options]

The bucket will be created if it don’t already exists. You can append query options to the URI in the following format,

options=value&option2=value&…​

9.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

9.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

9.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

9.4. Component Options

The AWS S3 Storage Service component supports 50 options, which are listed below.

NameDescriptionDefaultType

amazonS3Client (common)

Autowired Reference to a com.amazonaws.services.s3.AmazonS3 in the registry.

 

S3Client

amazonS3Presigner (common)

Autowired An S3 Presigner for Request, used mainly in createDownloadLink operation.

 

S3Presigner

autoCreateBucket (common)

Setting the autocreation of the S3 bucket bucketName. This will apply also in case of moveAfterRead option enabled and it will create the destinationBucket if it doesn’t exist already.

false

boolean

configuration (common)

The component configuration.

 

AWS2S3Configuration

overrideEndpoint (common)

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

boolean

pojoRequest (common)

If we want to use a POJO request as body or not.

false

boolean

policy (common)

The policy for this queue to set in the com.amazonaws.services.s3.AmazonS3#setBucketPolicy() method.

 

String

proxyHost (common)

To define a proxy host when instantiating the SQS client.

 

String

proxyPort (common)

Specify a proxy port to be used inside the client definition.

 

Integer

proxyProtocol (common)

To define a proxy protocol when instantiating the S3 client.

Enum values:

  • HTTP
  • HTTPS

HTTPS

Protocol

region (common)

The region in which S3 client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

String

trustAllCertificates (common)

If we want to trust all certificates in case of overriding the endpoint.

false

boolean

uriEndpointOverride (common)

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

useDefaultCredentialsProvider (common)

Set whether the S3 client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in.

false

boolean

customerAlgorithm (common (advanced))

Define the customer algorithm to use in case CustomerKey is enabled.

 

String

customerKeyId (common (advanced))

Define the id of Customer key to use in case CustomerKey is enabled.

 

String

customerKeyMD5 (common (advanced))

Define the MD5 of Customer key to use in case CustomerKey is enabled.

 

String

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

deleteAfterRead (consumer)

Delete objects from S3 after they have been retrieved. The delete is only performed if the Exchange is committed. If a rollback occurs, the object is not deleted. If this option is false, then the same objects will be retrieve over and over again on the polls. Therefore you need to use the Idempotent Consumer EIP in the route to filter out duplicates. You can filter using the AWS2S3Constants#BUCKET_NAME and AWS2S3Constants#KEY headers, or only the AWS2S3Constants#KEY header.

true

boolean

delimiter (consumer)

The delimiter which is used in the com.amazonaws.services.s3.model.ListObjectsRequest to only consume objects we are interested in.

 

String

destinationBucket (consumer)

Define the destination bucket where an object must be moved when moveAfterRead is set to true.

 

String

destinationBucketPrefix (consumer)

Define the destination bucket prefix to use when an object must be moved and moveAfterRead is set to true.

 

String

destinationBucketSuffix (consumer)

Define the destination bucket suffix to use when an object must be moved and moveAfterRead is set to true.

 

String

doneFileName (consumer)

If provided, Camel will only consume files if a done file exists.

 

String

fileName (consumer)

To get the object from the bucket with the given file name.

 

String

ignoreBody (consumer)

If it is true, the S3 Object Body will be ignored completely, if it is set to false the S3 Object will be put in the body. Setting this to true, will override any behavior defined by includeBody option.

false

boolean

includeBody (consumer)

If it is true, the S3Object exchange will be consumed and put into the body and closed. If false the S3Object stream will be put raw into the body and the headers will be set with the S3 object metadata. This option is strongly related to autocloseBody option. In case of setting includeBody to true because the S3Object stream will be consumed then it will also be closed, while in case of includeBody false then it will be up to the caller to close the S3Object stream. However setting autocloseBody to true when includeBody is false it will schedule to close the S3Object stream automatically on exchange completion.

true

boolean

includeFolders (consumer)

If it is true, the folders/directories will be consumed. If it is false, they will be ignored, and Exchanges will not be created for those.

true

boolean

moveAfterRead (consumer)

Move objects from S3 bucket to a different bucket after they have been retrieved. To accomplish the operation the destinationBucket option must be set. The copy bucket operation is only performed if the Exchange is committed. If a rollback occurs, the object is not moved.

false

boolean

prefix (consumer)

The prefix which is used in the com.amazonaws.services.s3.model.ListObjectsRequest to only consume objects we are interested in.

 

String

autocloseBody (consumer (advanced))

If this option is true and includeBody is false, then the S3Object.close() method will be called on exchange completion. This option is strongly related to includeBody option. In case of setting includeBody to false and autocloseBody to false, it will be up to the caller to close the S3Object stream. Setting autocloseBody to true, will close the S3Object stream automatically.

true

boolean

batchMessageNumber (producer)

The number of messages composing a batch in streaming upload mode.

10

int

batchSize (producer)

The batch size (in bytes) in streaming upload mode.

1000000

int

deleteAfterWrite (producer)

Delete file object after the S3 file has been uploaded.

false

boolean

keyName (producer)

Setting the key name for an element in the bucket through endpoint parameter.

 

String

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

multiPartUpload (producer)

If it is true, camel will upload the file with multi part format, the part size is decided by the option of partSize.

false

boolean

namingStrategy (producer)

The naming strategy to use in streaming upload mode.

Enum values:

  • progressive
  • random

progressive

AWSS3NamingStrategyEnum

operation (producer)

The operation to do in case the user don’t want to do only an upload.

Enum values:

  • copyObject
  • listObjects
  • deleteObject
  • deleteBucket
  • listBuckets
  • getObject
  • getObjectRange
  • createDownloadLink
 

AWS2S3Operations

partSize (producer)

Setup the partSize which is used in multi part upload, the default size is 25M.

26214400

long

restartingPolicy (producer)

The restarting policy to use in streaming upload mode.

Enum values:

  • override
  • lastPart

override

AWSS3RestartingPolicyEnum

storageClass (producer)

The storage class to set in the com.amazonaws.services.s3.model.PutObjectRequest request.

 

String

streamingUploadMode (producer)

When stream mode is true the upload to bucket will be done in streaming.

false

boolean

streamingUploadTimeout (producer)

While streaming upload mode is true, this option set the timeout to complete upload.

 

long

awsKMSKeyId (producer (advanced))

Define the id of KMS key to use in case KMS is enabled.

 

String

useAwsKMS (producer (advanced))

Define if KMS must be used or not.

false

boolean

useCustomerKey (producer (advanced))

Define if Customer Key must be used or not.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

accessKey (security)

Amazon AWS Access Key.

 

String

secretKey (security)

Amazon AWS Secret Key.

 

String

9.5. Endpoint Options

The AWS S3 Storage Service endpoint is configured using URI syntax:

aws2-s3://bucketNameOrArn

with the following path and query parameters:

9.5.1. Path Parameters (1 parameters)

NameDescriptionDefaultType

bucketNameOrArn (common)

Required Bucket name or ARN.

 

String

9.5.2. Query Parameters (68 parameters)

NameDescriptionDefaultType

amazonS3Client (common)

Autowired Reference to a com.amazonaws.services.s3.AmazonS3 in the registry.

 

S3Client

amazonS3Presigner (common)

Autowired An S3 Presigner for Request, used mainly in createDownloadLink operation.

 

S3Presigner

autoCreateBucket (common)

Setting the autocreation of the S3 bucket bucketName. This will apply also in case of moveAfterRead option enabled and it will create the destinationBucket if it doesn’t exist already.

false

boolean

overrideEndpoint (common)

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

boolean

pojoRequest (common)

If we want to use a POJO request as body or not.

false

boolean

policy (common)

The policy for this queue to set in the com.amazonaws.services.s3.AmazonS3#setBucketPolicy() method.

 

String

proxyHost (common)

To define a proxy host when instantiating the SQS client.

 

String

proxyPort (common)

Specify a proxy port to be used inside the client definition.

 

Integer

proxyProtocol (common)

To define a proxy protocol when instantiating the S3 client.

Enum values:

  • HTTP
  • HTTPS

HTTPS

Protocol

region (common)

The region in which S3 client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

String

trustAllCertificates (common)

If we want to trust all certificates in case of overriding the endpoint.

false

boolean

uriEndpointOverride (common)

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

useDefaultCredentialsProvider (common)

Set whether the S3 client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in.

false

boolean

customerAlgorithm (common (advanced))

Define the customer algorithm to use in case CustomerKey is enabled.

 

String

customerKeyId (common (advanced))

Define the id of Customer key to use in case CustomerKey is enabled.

 

String

customerKeyMD5 (common (advanced))

Define the MD5 of Customer key to use in case CustomerKey is enabled.

 

String

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

deleteAfterRead (consumer)

Delete objects from S3 after they have been retrieved. The delete is only performed if the Exchange is committed. If a rollback occurs, the object is not deleted. If this option is false, then the same objects will be retrieve over and over again on the polls. Therefore you need to use the Idempotent Consumer EIP in the route to filter out duplicates. You can filter using the AWS2S3Constants#BUCKET_NAME and AWS2S3Constants#KEY headers, or only the AWS2S3Constants#KEY header.

true

boolean

delimiter (consumer)

The delimiter which is used in the com.amazonaws.services.s3.model.ListObjectsRequest to only consume objects we are interested in.

 

String

destinationBucket (consumer)

Define the destination bucket where an object must be moved when moveAfterRead is set to true.

 

String

destinationBucketPrefix (consumer)

Define the destination bucket prefix to use when an object must be moved and moveAfterRead is set to true.

 

String

destinationBucketSuffix (consumer)

Define the destination bucket suffix to use when an object must be moved and moveAfterRead is set to true.

 

String

doneFileName (consumer)

If provided, Camel will only consume files if a done file exists.

 

String

fileName (consumer)

To get the object from the bucket with the given file name.

 

String

ignoreBody (consumer)

If it is true, the S3 Object Body will be ignored completely, if it is set to false the S3 Object will be put in the body. Setting this to true, will override any behavior defined by includeBody option.

false

boolean

includeBody (consumer)

If it is true, the S3Object exchange will be consumed and put into the body and closed. If false the S3Object stream will be put raw into the body and the headers will be set with the S3 object metadata. This option is strongly related to autocloseBody option. In case of setting includeBody to true because the S3Object stream will be consumed then it will also be closed, while in case of includeBody false then it will be up to the caller to close the S3Object stream. However setting autocloseBody to true when includeBody is false it will schedule to close the S3Object stream automatically on exchange completion.

true

boolean

includeFolders (consumer)

If it is true, the folders/directories will be consumed. If it is false, they will be ignored, and Exchanges will not be created for those.

true

boolean

maxConnections (consumer)

Set the maxConnections parameter in the S3 client configuration.

60

int

maxMessagesPerPoll (consumer)

Gets the maximum number of messages as a limit to poll at each polling. Gets the maximum number of messages as a limit to poll at each polling. The default value is 10. Use 0 or a negative number to set it as unlimited.

10

int

moveAfterRead (consumer)

Move objects from S3 bucket to a different bucket after they have been retrieved. To accomplish the operation the destinationBucket option must be set. The copy bucket operation is only performed if the Exchange is committed. If a rollback occurs, the object is not moved.

false

boolean

prefix (consumer)

The prefix which is used in the com.amazonaws.services.s3.model.ListObjectsRequest to only consume objects we are interested in.

 

String

sendEmptyMessageWhenIdle (consumer)

If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead.

false

boolean

autocloseBody (consumer (advanced))

If this option is true and includeBody is false, then the S3Object.close() method will be called on exchange completion. This option is strongly related to includeBody option. In case of setting includeBody to false and autocloseBody to false, it will be up to the caller to close the S3Object stream. Setting autocloseBody to true, will close the S3Object stream automatically.

true

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

pollStrategy (consumer (advanced))

A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel.

 

PollingConsumerPollStrategy

batchMessageNumber (producer)

The number of messages composing a batch in streaming upload mode.

10

int

batchSize (producer)

The batch size (in bytes) in streaming upload mode.

1000000

int

deleteAfterWrite (producer)

Delete file object after the S3 file has been uploaded.

false

boolean

keyName (producer)

Setting the key name for an element in the bucket through endpoint parameter.

 

String

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

multiPartUpload (producer)

If it is true, camel will upload the file with multi part format, the part size is decided by the option of partSize.

false

boolean

namingStrategy (producer)

The naming strategy to use in streaming upload mode.

Enum values:

  • progressive
  • random

progressive

AWSS3NamingStrategyEnum

operation (producer)

The operation to do in case the user don’t want to do only an upload.

Enum values:

  • copyObject
  • listObjects
  • deleteObject
  • deleteBucket
  • listBuckets
  • getObject
  • getObjectRange
  • createDownloadLink
 

AWS2S3Operations

partSize (producer)

Setup the partSize which is used in multi part upload, the default size is 25M.

26214400

long

restartingPolicy (producer)

The restarting policy to use in streaming upload mode.

Enum values:

  • override
  • lastPart

override

AWSS3RestartingPolicyEnum

storageClass (producer)

The storage class to set in the com.amazonaws.services.s3.model.PutObjectRequest request.

 

String

streamingUploadMode (producer)

When stream mode is true the upload to bucket will be done in streaming.

false

boolean

streamingUploadTimeout (producer)

While streaming upload mode is true, this option set the timeout to complete upload.

 

long

awsKMSKeyId (producer (advanced))

Define the id of KMS key to use in case KMS is enabled.

 

String

useAwsKMS (producer (advanced))

Define if KMS must be used or not.

false

boolean

useCustomerKey (producer (advanced))

Define if Customer Key must be used or not.

false

boolean

backoffErrorThreshold (scheduler)

The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in.

 

int

backoffIdleThreshold (scheduler)

The number of subsequent idle polls that should happen before the backoffMultipler should kick-in.

 

int

backoffMultiplier (scheduler)

To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured.

 

int

delay (scheduler)

Milliseconds before the next poll.

500

long

greedy (scheduler)

If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages.

false

boolean

initialDelay (scheduler)

Milliseconds before the first poll starts.

1000

long

repeatCount (scheduler)

Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever.

0

long

runLoggingLevel (scheduler)

The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that.

Enum values:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • OFF

TRACE

LoggingLevel

scheduledExecutorService (scheduler)

Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool.

 

ScheduledExecutorService

scheduler (scheduler)

To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler.

none

Object

schedulerProperties (scheduler)

To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler.

 

Map

startScheduler (scheduler)

Whether the scheduler should be auto started.

true

boolean

timeUnit (scheduler)

Time unit for initialDelay and delay options.

Enum values:

  • NANOSECONDS
  • MICROSECONDS
  • MILLISECONDS
  • SECONDS
  • MINUTES
  • HOURS
  • DAYS

MILLISECONDS

TimeUnit

useFixedDelay (scheduler)

Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details.

true

boolean

accessKey (security)

Amazon AWS Access Key.

 

String

secretKey (security)

Amazon AWS Secret Key.

 

String

Required S3 component options

You have to provide the amazonS3Client in the Registry or your accessKey and secretKey to access the Amazon’s S3.

9.6. Batch Consumer

This component implements the Batch Consumer.

This allows you for instance to know how many messages exists in this batch and for instance let the Aggregator aggregate this number of messages.

9.7. Usage

For example in order to read file hello.txt from bucket helloBucket, use the following snippet:

from("aws2-s3://helloBucket?accessKey=yourAccessKey&secretKey=yourSecretKey&prefix=hello.txt")
  .to("file:/var/downloaded");

9.7.1. Message headers evaluated by the S3 producer

HeaderTypeDescription

CamelAwsS3BucketName

String

The bucket Name which this object will be stored or which will be used for the current operation

CamelAwsS3BucketDestinationName

String

The bucket Destination Name which will be used for the current operation

CamelAwsS3ContentLength

Long

The content length of this object.

CamelAwsS3ContentType

String

The content type of this object.

CamelAwsS3ContentControl

String

The content control of this object.

CamelAwsS3ContentDisposition

String

The content disposition of this object.

CamelAwsS3ContentEncoding

String

The content encoding of this object.

CamelAwsS3ContentMD5

String

The md5 checksum of this object.

CamelAwsS3DestinationKey

String

The Destination key which will be used for the current operation

CamelAwsS3Key

String

The key under which this object will be stored or which will be used for the current operation

CamelAwsS3LastModified

java.util.Date

The last modified timestamp of this object.

CamelAwsS3Operation

String

The operation to perform. Permitted values are copyObject, deleteObject, listBuckets, deleteBucket, listObjects

CamelAwsS3StorageClass

String

The storage class of this object.

CamelAwsS3CannedAcl

String

The canned acl that will be applied to the object. see software.amazon.awssdk.services.s3.model.ObjectCannedACL for allowed values.

CamelAwsS3Acl

software.amazon.awssdk.services.s3.model.BucketCannedACL

A well constructed Amazon S3 Access Control List object. see software.amazon.awssdk.services.s3.model.BucketCannedACL for more details

CamelAwsS3ServerSideEncryption

String

Sets the server-side encryption algorithm when encrypting the object using AWS-managed keys. For example use AES256.

CamelAwsS3VersionId

String

The version Id of the object to be stored or returned from the current operation

CamelAwsS3Metadata

Map<String, String>

A map of metadata to be stored with the object in S3. More details about metadata .

9.7.2. Message headers set by the S3 producer

HeaderTypeDescription

CamelAwsS3ETag

String

The ETag value for the newly uploaded object.

CamelAwsS3VersionId

String

The optional version ID of the newly uploaded object.

9.7.3. Message headers set by the S3 consumer

HeaderTypeDescription

CamelAwsS3Key

String

The key under which this object is stored.

CamelAwsS3BucketName

String

The name of the bucket in which this object is contained.

CamelAwsS3ETag

String

The hex encoded 128-bit MD5 digest of the associated object according to RFC 1864. This data is used as an integrity check to verify that the data received by the caller is the same data that was sent by Amazon S3.

CamelAwsS3LastModified

Date

The value of the Last-Modified header, indicating the date and time at which Amazon S3 last recorded a modification to the associated object.

CamelAwsS3VersionId

String

The version ID of the associated Amazon S3 object if available. Version IDs are only assigned to objects when an object is uploaded to an Amazon S3 bucket that has object versioning enabled.

CamelAwsS3ContentType

String

The Content-Type HTTP header, which indicates the type of content stored in the associated object. The value of this header is a standard MIME type.

CamelAwsS3ContentMD5

String

The base64 encoded 128-bit MD5 digest of the associated object (content - not including headers) according to RFC 1864. This data is used as a message integrity check to verify that the data received by Amazon S3 is the same data that the caller sent.

CamelAwsS3ContentLength

Long

The Content-Length HTTP header indicating the size of the associated object in bytes.

CamelAwsS3ContentEncoding

String

The optional Content-Encoding HTTP header specifying what content encodings have been applied to the object and what decoding mechanisms must be applied in order to obtain the media-type referenced by the Content-Type field.

CamelAwsS3ContentDisposition

String

The optional Content-Disposition HTTP header, which specifies presentational information such as the recommended filename for the object to be saved as.

CamelAwsS3ContentControl

String

The optional Cache-Control HTTP header which allows the user to specify caching behavior along the HTTP request/reply chain.

CamelAwsS3ServerSideEncryption

String

The server-side encryption algorithm when encrypting the object using AWS-managed keys.

CamelAwsS3Metadata

Map<String, String>

A map of metadata stored with the object in S3. More details about metadata .

9.7.4. S3 Producer operations

Camel-AWS2-S3 component provides the following operation on the producer side:

  • copyObject
  • deleteObject
  • listBuckets
  • deleteBucket
  • listObjects
  • getObject (this will return an S3Object instance)
  • getObjectRange (this will return an S3Object instance)
  • createDownloadLink

If you don’t specify an operation explicitly the producer will do: - a single file upload - a multipart upload if multiPartUpload option is enabled.

9.7.5. Advanced AmazonS3 configuration

If your Camel Application is running behind a firewall or if you need to have more control over the S3Client instance configuration, you can create your own instance and refer to it in your Camel aws2-s3 component configuration:

from("aws2-s3://MyBucket?amazonS3Client=#client&delay=5000&maxMessagesPerPoll=5")
.to("mock:result");

9.7.6. Use KMS with the S3 component

To use AWS KMS to encrypt/decrypt data by using AWS infrastructure you can use the options introduced in 2.21.x like in the following example

from("file:tmp/test?fileName=test.txt")
     .setHeader(S3Constants.KEY, constant("testFile"))
     .to("aws2-s3://mybucket?amazonS3Client=#client&useAwsKMS=true&awsKMSKeyId=3f0637ad-296a-3dfe-a796-e60654fb128c");

In this way you’ll ask to S3, to use the KMS key 3f0637ad-296a-3dfe-a796-e60654fb128c, to encrypt the file test.txt. When you’ll ask to download this file, the decryption will be done directly before the download.

9.7.7. Static credentials vs Default Credential Provider

You have the possibility of avoiding the usage of explicit static credentials, by specifying the useDefaultCredentialsProvider option and set it to true.

  • Java system properties - aws.accessKeyId and aws.secretKey
  • Environment variables - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
  • Web Identity Token from AWS STS.
  • The shared credentials and config files.
  • Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable AWS_CONTAINER_CREDENTIALS_RELATIVE_URI is set.
  • Amazon EC2 Instance profile credentials.

For more information about this you can look at AWS credentials documentation

9.7.8. S3 Producer Operation examples

  • Single Upload: This operation will upload a file to S3 based on the body content
  from("direct:start").process(new Processor() {

      @Override
      public void process(Exchange exchange) throws Exception {
          exchange.getIn().setHeader(S3Constants.KEY, "camel.txt");
          exchange.getIn().setBody("Camel rocks!");
      }
  })
  .to("aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client")
  .to("mock:result");

This operation will upload the file camel.txt with the content "Camel rocks!" in the mycamelbucket bucket

  • Multipart Upload: This operation will perform a multipart upload of a file to S3 based on the body content
  from("direct:start").process(new Processor() {

      @Override
      public void process(Exchange exchange) throws Exception {
          exchange.getIn().setHeader(AWS2S3Constants.KEY, "empty.txt");
          exchange.getIn().setBody(new File("src/empty.txt"));
      }
  })
  .to("aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&multiPartUpload=true&autoCreateBucket=true&partSize=1048576")
  .to("mock:result");

This operation will perform a multipart upload of the file empty.txt with based on the content the file src/empty.txt in the mycamelbucket bucket

  • CopyObject: this operation copy an object from one bucket to a different one
  from("direct:start").process(new Processor() {

      @Override
      public void process(Exchange exchange) throws Exception {
          exchange.getIn().setHeader(S3Constants.BUCKET_DESTINATION_NAME, "camelDestinationBucket");
          exchange.getIn().setHeader(S3Constants.KEY, "camelKey");
          exchange.getIn().setHeader(S3Constants.DESTINATION_KEY, "camelDestinationKey");
      }
  })
  .to("aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&operation=copyObject")
  .to("mock:result");

This operation will copy the object with the name expressed in the header camelDestinationKey to the camelDestinationBucket bucket, from the bucket mycamelbucket.

  • DeleteObject: this operation deletes an object from a bucket
  from("direct:start").process(new Processor() {

      @Override
      public void process(Exchange exchange) throws Exception {
          exchange.getIn().setHeader(S3Constants.KEY, "camelKey");
      }
  })
  .to("aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&operation=deleteObject")
  .to("mock:result");

This operation will delete the object camelKey from the bucket mycamelbucket.

  • ListBuckets: this operation list the buckets for this account in this region
  from("direct:start")
  .to("aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&operation=listBuckets")
  .to("mock:result");

This operation will list the buckets for this account

  • DeleteBucket: this operation delete the bucket specified as URI parameter or header
  from("direct:start")
  .to("aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&operation=deleteBucket")
  .to("mock:result");

This operation will delete the bucket mycamelbucket

  • ListObjects: this operation list object in a specific bucket
  from("direct:start")
  .to("aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&operation=listObjects")
  .to("mock:result");

This operation will list the objects in the mycamelbucket bucket

  • GetObject: this operation get a single object in a specific bucket
  from("direct:start").process(new Processor() {

      @Override
      public void process(Exchange exchange) throws Exception {
          exchange.getIn().setHeader(S3Constants.KEY, "camelKey");
      }
  })
  .to("aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&operation=getObject")
  .to("mock:result");

This operation will return an S3Object instance related to the camelKey object in mycamelbucket bucket.

  • GetObjectRange: this operation get a single object range in a specific bucket
  from("direct:start").process(new Processor() {

      @Override
      public void process(Exchange exchange) throws Exception {
          exchange.getIn().setHeader(S3Constants.KEY, "camelKey");
          exchange.getIn().setHeader(S3Constants.RANGE_START, "0");
          exchange.getIn().setHeader(S3Constants.RANGE_END, "9");
      }
  })
  .to("aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&operation=getObjectRange")
  .to("mock:result");

This operation will return an S3Object instance related to the camelKey object in mycamelbucket bucket, containing a the bytes from 0 to 9.

  • CreateDownloadLink: this operation will return a download link through S3 Presigner
  from("direct:start").process(new Processor() {

      @Override
      public void process(Exchange exchange) throws Exception {
          exchange.getIn().setHeader(S3Constants.KEY, "camelKey");
      }
  })
  .to("aws2-s3://mycamelbucket?accessKey=xxx&secretKey=yyy&region=region&operation=createDownloadLink")
  .to("mock:result");

This operation will return a download link url for the file camel-key in the bucket mycamelbucket and region region

9.8. Streaming Upload mode

With the stream mode enabled users will be able to upload data to S3 without knowing ahead of time the dimension of the data, by leveraging multipart upload. The upload will be completed when: the batchSize has been completed or the batchMessageNumber has been reached. There are two possible naming strategy:

  • progressive

    With the progressive strategy each file will have the name composed by keyName option and a progressive counter, and eventually the file extension (if any)

  • random.

    With the random strategy a UUID will be added after keyName and eventually the file extension will appended.

As an example:

from(kafka("topic1").brokers("localhost:9092"))
        .log("Kafka Message is: ${body}")
        .to(aws2S3("camel-bucket").streamingUploadMode(true).batchMessageNumber(25).namingStrategy(AWS2S3EndpointBuilderFactory.AWSS3NamingStrategyEnum.progressive).keyName("{{kafkaTopic1}}/{{kafkaTopic1}}.txt"));

from(kafka("topic2").brokers("localhost:9092"))
         .log("Kafka Message is: ${body}")
         .to(aws2S3("camel-bucket").streamingUploadMode(true).batchMessageNumber(25).namingStrategy(AWS2S3EndpointBuilderFactory.AWSS3NamingStrategyEnum.progressive).keyName("{{kafkaTopic2}}/{{kafkaTopic2}}.txt"));

The default size for a batch is 1 Mb, but you can adjust it according to your requirements.

When you’ll stop your producer route, the producer will take care of flushing the remaining buffered messaged and complete the upload.

In Streaming upload you’ll be able restart the producer from the point where it left. It’s important to note that this feature is critical only when using the progressive naming strategy.

By setting the restartingPolicy to lastPart, you will restart uploading files and contents from the last part number the producer left.

Example

  1. Start the route with progressive naming strategy and keyname equals to camel.txt, with batchMessageNumber equals to 20, and restartingPolicy equals to lastPart - Send 70 messages.
  2. Stop the route
  3. On your S3 bucket you should now see 4 files: * camel.txt

    • camel-1.txt
    • camel-2.txt
    • camel-3.txt

      The first three will have 20 messages, while the last one only 10.

  4. Restart the route.
  5. Send 25 messages.
  6. Stop the route.
  7. You’ll now have 2 other files in your bucket: camel-5.txt and camel-6.txt, the first with 20 messages and second with 5 messages.
  8. Go ahead

This won’t be needed when using the random naming strategy.

On the opposite you can specify the override restartingPolicy. In that case you’ll be able to override whatever you written before (for that particular keyName) on your bucket.

Note

In Streaming upload mode the only keyName option that will be taken into account is the endpoint option. Using the header will throw an NPE and this is done by design. Setting the header means potentially change the file name on each exchange and this is against the aim of the streaming upload producer. The keyName needs to be fixed and static. The selected naming strategy will do the rest of the of the work.

Another possibility is specifying a streamingUploadTimeout with batchMessageNumber and batchSize options. With this option the user will be able to complete the upload of a file after a certain time passed. In this way the upload completion will be passed on three tiers: the timeout, the number of messages and the batch size.

As an example:

from(kafka("topic1").brokers("localhost:9092"))
        .log("Kafka Message is: ${body}")
        .to(aws2S3("camel-bucket").streamingUploadMode(true).batchMessageNumber(25).streamingUploadTimeout(10000).namingStrategy(AWS2S3EndpointBuilderFactory.AWSS3NamingStrategyEnum.progressive).keyName("{{kafkaTopic1}}/{{kafkaTopic1}}.txt"));

In this case the upload will be completed after 10 seconds.

9.9. Bucket Autocreation

With the option autoCreateBucket users are able to avoid the autocreation of an S3 Bucket in case it doesn’t exist. The default for this option is true. If set to false any operation on a not-existent bucket in AWS won’t be successful and an error will be returned.

9.10. Moving stuff between a bucket and another bucket

Some users like to consume stuff from a bucket and move the content in a different one without using the copyObject feature of this component. If this is case for you, don’t forget to remove the bucketName header from the incoming exchange of the consumer, otherwise the file will be always overwritten on the same original bucket.

9.11. MoveAfterRead consumer option

In addition to deleteAfterRead it has been added another option, moveAfterRead. With this option enabled the consumed object will be moved to a target destinationBucket instead of being only deleted. This will require specifying the destinationBucket option. As example:

  from("aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&moveAfterRead=true&destinationBucket=myothercamelbucket")
  .to("mock:result");

In this case the objects consumed will be moved to myothercamelbucket bucket and deleted from the original one (because of deleteAfterRead set to true as default).

You have also the possibility of using a key prefix/suffix while moving the file to a different bucket. The options are destinationBucketPrefix and destinationBucketSuffix.

Taking the above example, you could do something like:

  from("aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&moveAfterRead=true&destinationBucket=myothercamelbucket&destinationBucketPrefix=RAW(pre-)&destinationBucketSuffix=RAW(-suff)")
  .to("mock:result");

In this case the objects consumed will be moved to myothercamelbucket bucket and deleted from the original one (because of deleteAfterRead set to true as default).

So if the file name is test, in the myothercamelbucket you should see a file called pre-test-suff.

9.12. Using customer key as encryption

We introduced also the customer key support (an alternative of using KMS). The following code shows an example.

String key = UUID.randomUUID().toString();
byte[] secretKey = generateSecretKey();
String b64Key = Base64.getEncoder().encodeToString(secretKey);
String b64KeyMd5 = Md5Utils.md5AsBase64(secretKey);

String awsEndpoint = "aws2-s3://mycamel?autoCreateBucket=false&useCustomerKey=true&customerKeyId=RAW(" + b64Key + ")&customerKeyMD5=RAW(" + b64KeyMd5 + ")&customerAlgorithm=" + AES256.name();

from("direct:putObject")
    .setHeader(AWS2S3Constants.KEY, constant("test.txt"))
    .setBody(constant("Test"))
    .to(awsEndpoint);

9.13. Using a POJO as body

Sometimes build an AWS Request can be complex, because of multiple options. We introduce the possibility to use a POJO as body. In AWS S3 there are multiple operations you can submit, as an example for List brokers request, you can do something like:

from("direct:aws2-s3")
     .setBody(ListObjectsRequest.builder().bucket(bucketName).build())
     .to("aws2-s3://test?amazonS3Client=#amazonS3Client&operation=listObjects&pojoRequest=true")

In this way you’ll pass the request directly without the need of passing headers and options specifically related to this operation.

9.14. Create S3 client and add component to registry

Sometimes you would want to perform some advanced configuration using AWS2S3Configuration which also allows to set the S3 client. You can create and set the S3 client in the component configuration as shown in the following example

String awsBucketAccessKey = "your_access_key";
String awsBucketSecretKey = "your_secret_key";

S3Client s3Client = S3Client.builder().credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(awsBucketAccessKey, awsBucketSecretKey)))
                .region(Region.US_EAST_1).build();

AWS2S3Configuration configuration = new AWS2S3Configuration();
configuration.setAmazonS3Client(s3Client);
configuration.setAutoDiscoverClient(true);
configuration.setBucketName("s3bucket2020");
configuration.setRegion("us-east-1");

Now you can configure the S3 component (using the configuration object created above) and add it to the registry in the configure method before initialization of routes.

AWS2S3Component s3Component = new AWS2S3Component(getContext());
s3Component.setConfiguration(configuration);
s3Component.setLazyStartProducer(true);
camelContext.addComponent("aws2-s3", s3Component);

Now your component will be used for all the operations implemented in camel routes.

9.15. Dependencies

Maven users will need to add the following dependency to their pom.xml.

pom.xml

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-aws2-s3</artifactId>
    <version>${camel-version}</version>
</dependency>

where {camel-version} must be replaced by the actual version of Camel.

9.16. Spring Boot Auto-Configuration

The component supports 51 options, which are listed below.

NameDescriptionDefaultType

camel.component.aws2-s3.access-key

Amazon AWS Access Key.

 

String

camel.component.aws2-s3.amazon-s3-client

Reference to a com.amazonaws.services.s3.AmazonS3 in the registry. The option is a software.amazon.awssdk.services.s3.S3Client type.

 

S3Client

camel.component.aws2-s3.amazon-s3-presigner

An S3 Presigner for Request, used mainly in createDownloadLink operation. The option is a software.amazon.awssdk.services.s3.presigner.S3Presigner type.

 

S3Presigner

camel.component.aws2-s3.auto-create-bucket

Setting the autocreation of the S3 bucket bucketName. This will apply also in case of moveAfterRead option enabled and it will create the destinationBucket if it doesn’t exist already.

false

Boolean

camel.component.aws2-s3.autoclose-body

If this option is true and includeBody is false, then the S3Object.close() method will be called on exchange completion. This option is strongly related to includeBody option. In case of setting includeBody to false and autocloseBody to false, it will be up to the caller to close the S3Object stream. Setting autocloseBody to true, will close the S3Object stream automatically.

true

Boolean

camel.component.aws2-s3.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.aws2-s3.aws-k-m-s-key-id

Define the id of KMS key to use in case KMS is enabled.

 

String

camel.component.aws2-s3.batch-message-number

The number of messages composing a batch in streaming upload mode.

10

Integer

camel.component.aws2-s3.batch-size

The batch size (in bytes) in streaming upload mode.

1000000

Integer

camel.component.aws2-s3.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.aws2-s3.configuration

The component configuration. The option is a org.apache.camel.component.aws2.s3.AWS2S3Configuration type.

 

AWS2S3Configuration

camel.component.aws2-s3.customer-algorithm

Define the customer algorithm to use in case CustomerKey is enabled.

 

String

camel.component.aws2-s3.customer-key-id

Define the id of Customer key to use in case CustomerKey is enabled.

 

String

camel.component.aws2-s3.customer-key-m-d5

Define the MD5 of Customer key to use in case CustomerKey is enabled.

 

String

camel.component.aws2-s3.delete-after-read

Delete objects from S3 after they have been retrieved. The delete is only performed if the Exchange is committed. If a rollback occurs, the object is not deleted. If this option is false, then the same objects will be retrieve over and over again on the polls. Therefore you need to use the Idempotent Consumer EIP in the route to filter out duplicates. You can filter using the AWS2S3Constants#BUClKET_NAME and AWS2S3Constants#KEY headers, or only the AWS2S3Constants#KEY header.

true

Boolean

camel.component.aws2-s3.delete-after-write

Delete file object after the S3 file has been uploaded.

false

Boolean

camel.component.aws2-s3.delimiter

The delimiter which is used in the com.amazonaws.services.s3.model.ListObjectsRequest to only consume objects we are interested in.

 

String

camel.component.aws2-s3.destination-bucket

Define the destination bucket where an object must be moved when moveAfterRead is set to true.

 

String

camel.component.aws2-s3.destination-bucket-prefix

Define the destination bucket prefix to use when an object must be moved and moveAfterRead is set to true.

 

String

camel.component.aws2-s3.destination-bucket-suffix

Define the destination bucket suffix to use when an object must be moved and moveAfterRead is set to true.

 

String

camel.component.aws2-s3.done-file-name

If provided, Camel will only consume files if a done file exists.

 

String

camel.component.aws2-s3.enabled

Whether to enable auto configuration of the aws2-s3 component. This is enabled by default.

 

Boolean

camel.component.aws2-s3.file-name

To get the object from the bucket with the given file name.

 

String

camel.component.aws2-s3.ignore-body

If it is true, the S3 Object Body will be ignored completely, if it is set to false the S3 Object will be put in the body. Setting this to true, will override any behavior defined by includeBody option.

false

Boolean

camel.component.aws2-s3.include-body

If it is true, the S3Object exchange will be consumed and put into the body and closed. If false the S3Object stream will be put raw into the body and the headers will be set with the S3 object metadata. This option is strongly related to autocloseBody option. In case of setting includeBody to true because the S3Object stream will be consumed then it will also be closed, while in case of includeBody false then it will be up to the caller to close the S3Object stream. However setting autocloseBody to true when includeBody is false it will schedule to close the S3Object stream automatically on exchange completion.

true

Boolean

camel.component.aws2-s3.include-folders

If it is true, the folders/directories will be consumed. If it is false, they will be ignored, and Exchanges will not be created for those.

true

Boolean

camel.component.aws2-s3.key-name

Setting the key name for an element in the bucket through endpoint parameter.

 

String

camel.component.aws2-s3.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.aws2-s3.move-after-read

Move objects from S3 bucket to a different bucket after they have been retrieved. To accomplish the operation the destinationBucket option must be set. The copy bucket operation is only performed if the Exchange is committed. If a rollback occurs, the object is not moved.

false

Boolean

camel.component.aws2-s3.multi-part-upload

If it is true, camel will upload the file with multi part format, the part size is decided by the option of partSize.

false

Boolean

camel.component.aws2-s3.naming-strategy

The naming strategy to use in streaming upload mode.

 

AWSS3NamingStrategyEnum

camel.component.aws2-s3.operation

The operation to do in case the user don’t want to do only an upload.

 

AWS2S3Operations

camel.component.aws2-s3.override-endpoint

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

Boolean

camel.component.aws2-s3.part-size

Setup the partSize which is used in multi part upload, the default size is 25M.

26214400

Long

camel.component.aws2-s3.pojo-request

If we want to use a POJO request as body or not.

false

Boolean

camel.component.aws2-s3.policy

The policy for this queue to set in the com.amazonaws.services.s3.AmazonS3#setBucketPolicy() method.

 

String

camel.component.aws2-s3.prefix

The prefix which is used in the com.amazonaws.services.s3.model.ListObjectsRequest to only consume objects we are interested in.

 

String

camel.component.aws2-s3.proxy-host

To define a proxy host when instantiating the SQS client.

 

String

camel.component.aws2-s3.proxy-port

Specify a proxy port to be used inside the client definition.

 

Integer

camel.component.aws2-s3.proxy-protocol

To define a proxy protocol when instantiating the S3 client.

 

Protocol

camel.component.aws2-s3.region

The region in which S3 client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

String

camel.component.aws2-s3.restarting-policy

The restarting policy to use in streaming upload mode.

 

AWSS3RestartingPolicyEnum

camel.component.aws2-s3.secret-key

Amazon AWS Secret Key.

 

String

camel.component.aws2-s3.storage-class

The storage class to set in the com.amazonaws.services.s3.model.PutObjectRequest request.

 

String

camel.component.aws2-s3.streaming-upload-mode

When stream mode is true the upload to bucket will be done in streaming.

false

Boolean

camel.component.aws2-s3.streaming-upload-timeout

While streaming upload mode is true, this option set the timeout to complete upload.

 

Long

camel.component.aws2-s3.trust-all-certificates

If we want to trust all certificates in case of overriding the endpoint.

false

Boolean

camel.component.aws2-s3.uri-endpoint-override

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

camel.component.aws2-s3.use-aws-k-m-s

Define if KMS must be used or not.

false

Boolean

camel.component.aws2-s3.use-customer-key

Define if Customer Key must be used or not.

false

Boolean

camel.component.aws2-s3.use-default-credentials-provider

Set whether the S3 client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in.

false

Boolean

Chapter 10. AWS Simple Notification System (SNS)

Only producer is supported

The AWS2 SNS component allows messages to be sent to an Amazon Simple Notification Topic. The implementation of the Amazon API is provided by the AWS SDK.

Prerequisites

You must have a valid Amazon Web Services developer account, and be signed up to use Amazon SNS. More information is available at Amazon SNS.

10.1. Dependencies

When using aws2-sns with Red Hat build of Camel Spring Boot, add the following Maven dependency to your pom.xml to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-aws2-sns-starter</artifactId>
</dependency>

10.2. URI Format

aws2-sns://topicNameOrArn[?options]

The topic will be created if they don’t already exists. You can append query options to the URI in the following format, ?options=value&option2=value&…​

10.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

10.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

10.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

10.4. Component Options

The AWS Simple Notification System (SNS) component supports 24 options, which are listed below.

NameDescriptionDefaultType

amazonSNSClient (producer)

Autowired To use the AmazonSNS as the client.

 

SnsClient

autoCreateTopic (producer)

Setting the autocreation of the topic.

false

boolean

configuration (producer)

Component configuration.

 

Sns2Configuration

kmsMasterKeyId (producer)

The ID of an AWS-managed customer master key (CMK) for Amazon SNS or a custom CMK.

 

String

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

messageDeduplicationIdStrategy (producer)

Only for FIFO Topic. Strategy for setting the messageDeduplicationId on the message. Can be one of the following options: useExchangeId, useContentBasedDeduplication. For the useContentBasedDeduplication option, no messageDeduplicationId will be set on the message.

Enum values:

  • useExchangeId
  • useContentBasedDeduplication

useExchangeId

String

messageGroupIdStrategy (producer)

Only for FIFO Topic. Strategy for setting the messageGroupId on the message. Can be one of the following options: useConstant, useExchangeId, usePropertyValue. For the usePropertyValue option, the value of property CamelAwsMessageGroupId will be used.

Enum values:

  • useConstant
  • useExchangeId
  • usePropertyValue
 

String

messageStructure (producer)

The message structure to use such as json.

 

String

overrideEndpoint (producer)

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

boolean

policy (producer)

The policy for this topic. Is loaded by default from classpath, but you can prefix with classpath:, file:, or http: to load the resource from different systems.

 

String

proxyHost (producer)

To define a proxy host when instantiating the SNS client.

 

String

proxyPort (producer)

To define a proxy port when instantiating the SNS client.

 

Integer

proxyProtocol (producer)

To define a proxy protocol when instantiating the SNS client.

Enum values:

  • HTTP
  • HTTPS

HTTPS

Protocol

queueUrl (producer)

The queueUrl to subscribe to.

 

String

region (producer)

The region in which SNS client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

String

serverSideEncryptionEnabled (producer)

Define if Server Side Encryption is enabled or not on the topic.

false

boolean

subject (producer)

The subject which is used if the message header 'CamelAwsSnsSubject' is not present.

 

String

subscribeSNStoSQS (producer)

Define if the subscription between SNS Topic and SQS must be done or not.

false

boolean

trustAllCertificates (producer)

If we want to trust all certificates in case of overriding the endpoint.

false

boolean

uriEndpointOverride (producer)

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

useDefaultCredentialsProvider (producer)

Set whether the SNS client should expect to load credentials on an AWS infra instance or to expect static credentials to be passed in.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

accessKey (security)

Amazon AWS Access Key.

 

String

secretKey (security)

Amazon AWS Secret Key.

 

String

10.5. Endpoint Options

The AWS Simple Notification System (SNS) endpoint is configured using URI syntax:

aws2-sns:topicNameOrArn

with the following path and query parameters:

10.5.1. Path Parameters (1 parameters)

NameDescriptionDefaultType

topicNameOrArn (producer)

Required Topic name or ARN.

 

String

10.5.2. Query Parameters (23 parameters)

NameDescriptionDefaultType

amazonSNSClient (producer)

Autowired To use the AmazonSNS as the client.

 

SnsClient

autoCreateTopic (producer)

Setting the autocreation of the topic.

false

boolean

headerFilterStrategy (producer)

To use a custom HeaderFilterStrategy to map headers to/from Camel.

 

HeaderFilterStrategy

kmsMasterKeyId (producer)

The ID of an AWS-managed customer master key (CMK) for Amazon SNS or a custom CMK.

 

String

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

messageDeduplicationIdStrategy (producer)

Only for FIFO Topic. Strategy for setting the messageDeduplicationId on the message. Can be one of the following options: useExchangeId, useContentBasedDeduplication. For the useContentBasedDeduplication option, no messageDeduplicationId will be set on the message.

Enum values:

  • useExchangeId
  • useContentBasedDeduplication

useExchangeId

String

messageGroupIdStrategy (producer)

Only for FIFO Topic. Strategy for setting the messageGroupId on the message. Can be one of the following options: useConstant, useExchangeId, usePropertyValue. For the usePropertyValue option, the value of property CamelAwsMessageGroupId will be used.

Enum values:

  • useConstant
  • useExchangeId
  • usePropertyValue
 

String

messageStructure (producer)

The message structure to use such as json.

 

String

overrideEndpoint (producer)

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

boolean

policy (producer)

The policy for this topic. Is loaded by default from classpath, but you can prefix with classpath:, file:, or http: to load the resource from different systems.

 

String

proxyHost (producer)

To define a proxy host when instantiating the SNS client.

 

String

proxyPort (producer)

To define a proxy port when instantiating the SNS client.

 

Integer

proxyProtocol (producer)

To define a proxy protocol when instantiating the SNS client.

Enum values:

  • HTTP
  • HTTPS

HTTPS

Protocol

queueUrl (producer)

The queueUrl to subscribe to.

 

String

region (producer)

The region in which SNS client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

String

serverSideEncryptionEnabled (producer)

Define if Server Side Encryption is enabled or not on the topic.

false

boolean

subject (producer)

The subject which is used if the message header 'CamelAwsSnsSubject' is not present.

 

String

subscribeSNStoSQS (producer)

Define if the subscription between SNS Topic and SQS must be done or not.

false

boolean

trustAllCertificates (producer)

If we want to trust all certificates in case of overriding the endpoint.

false

boolean

uriEndpointOverride (producer)

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

useDefaultCredentialsProvider (producer)

Set whether the SNS client should expect to load credentials on an AWS infra instance or to expect static credentials to be passed in.

false

boolean

accessKey (security)

Amazon AWS Access Key.

 

String

secretKey (security)

Amazon AWS Secret Key.

 

String

Required SNS component options

You have to provide the amazonSNSClient in the Registry or your accessKey and secretKey to access the Amazon’s SNS.

10.6. Usage

10.6.1. Static credentials vs Default Credential Provider

You have the possibility of avoiding the usage of explicit static credentials, by specifying the useDefaultCredentialsProvider option and set it to true.

  • Java system properties - aws.accessKeyId and aws.secretKey
  • Environment variables - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
  • Web Identity Token from AWS STS.
  • The shared credentials and config files.
  • Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable AWS_CONTAINER_CREDENTIALS_RELATIVE_URI is set.
  • Amazon EC2 Instance profile credentials.

For more information about this you can look at AWS credentials documentation.

10.6.2. Message headers evaluated by the SNS producer

HeaderTypeDescription

CamelAwsSnsSubject

String

The Amazon SNS message subject. If not set, the subject from the SnsConfiguration is used.

10.6.3. Message headers set by the SNS producer

HeaderTypeDescription

CamelAwsSnsMessageId

String

The Amazon SNS message ID.

10.6.4. Advanced AmazonSNS configuration

If you need more control over the SnsClient instance configuration you can create your own instance and refer to it from the URI:

from("direct:start")
.to("aws2-sns://MyTopic?amazonSNSClient=#client");

The #client refers to a AmazonSNS in the Registry.

10.6.5. Create a subscription between an AWS SNS Topic and an AWS SQS Queue

You can create a subscription of an SQS Queue to an SNS Topic in this way:

from("direct:start")
.to("aws2-sns://test-camel-sns1?amazonSNSClient=#amazonSNSClient&subscribeSNStoSQS=true&queueUrl=https://sqs.eu-central-1.amazonaws.com/780410022472/test-camel");

The #amazonSNSClient refers to a SnsClient in the Registry. By specifying subscribeSNStoSQS to true and a queueUrl of an existing SQS Queue, you’ll be able to subscribe your SQS Queue to your SNS Topic.

At this point you can consume messages coming from SNS Topic through your SQS Queue

from("aws2-sqs://test-camel?amazonSQSClient=#amazonSQSClient&delay=50&maxMessagesPerPoll=5")
    .to(...);

10.7. Topic Autocreation

With the option autoCreateTopic users are able to avoid the autocreation of an SNS Topic in case it doesn’t exist. The default for this option is true. If set to false any operation on a not-existent topic in AWS won’t be successful and an error will be returned.

10.8. SNS FIFO

SNS FIFO are supported. While creating the SQS queue you will subscribe to the SNS topic there is an important point to remember, you’ll need to make possible for the SNS Topic to send message to the SQS Queue.

Example

Suppose you created an SNS FIFO Topic called Order.fifo and an SQS Queue called QueueSub.fifo.

In the access Policy of the QueueSub.fifo you should submit something like this:

{
  "Version": "2008-10-17",
  "Id": "__default_policy_ID",
  "Statement": [
    {
      "Sid": "__owner_statement",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::780560123482:root"
      },
      "Action": "SQS:*",
      "Resource": "arn:aws:sqs:eu-west-1:780560123482:QueueSub.fifo"
    },
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "sns.amazonaws.com"
      },
      "Action": "SQS:SendMessage",
      "Resource": "arn:aws:sqs:eu-west-1:780560123482:QueueSub.fifo",
      "Condition": {
        "ArnLike": {
          "aws:SourceArn": "arn:aws:sns:eu-west-1:780410022472:Order.fifo"
        }
      }
    }
  ]
}

This is a critical step to make the subscription work correctly.

10.8.1. SNS Fifo Topic Message group Id Strategy and message Deduplication Id Strategy

When sending something to the FIFO topic you’ll need to always set up a message group Id strategy.

If the content-based message deduplication has been enabled on the SNS Fifo topic, where won’t be the need of setting a message deduplication id strategy, otherwise you’ll have to set it.

10.9. Examples

10.9.1. Producer Examples

Sending to a topic

from("direct:start")
  .to("aws2-sns://camel-topic?subject=The+subject+message&autoCreateTopic=true");

10.10. Dependencies

Maven users will need to add the following dependency to their pom.xml.

pom.xml

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-aws2-sns</artifactId>
    <version>${camel-version}</version>
</dependency>

where {camel-version} must be replaced by the actual version of Camel.

10.11. Spring Boot Auto-Configuration

The component supports 25 options, which are listed below.

NameDescriptionDefaultType

camel.component.aws2-sns.access-key

Amazon AWS Access Key.

 

String

camel.component.aws2-sns.amazon-s-n-s-client

To use the AmazonSNS as the client. The option is a software.amazon.awssdk.services.sns.SnsClient type.

 

SnsClient

camel.component.aws2-sns.auto-create-topic

Setting the autocreation of the topic.

false

Boolean

camel.component.aws2-sns.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.aws2-sns.configuration

Component configuration. The option is a org.apache.camel.component.aws2.sns.Sns2Configuration type.

 

Sns2Configuration

camel.component.aws2-sns.enabled

Whether to enable auto configuration of the aws2-sns component. This is enabled by default.

 

Boolean

camel.component.aws2-sns.kms-master-key-id

The ID of an AWS-managed customer master key (CMK) for Amazon SNS or a custom CMK.

 

String

camel.component.aws2-sns.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.aws2-sns.message-deduplication-id-strategy

Only for FIFO Topic. Strategy for setting the messageDeduplicationId on the message. Can be one of the following options: useExchangeId, useContentBasedDeduplication. For the useContentBasedDeduplication option, no messageDeduplicationId will be set on the message.

useExchangeId

String

camel.component.aws2-sns.message-group-id-strategy

Only for FIFO Topic. Strategy for setting the messageGroupId on the message. Can be one of the following options: useConstant, useExchangeId, usePropertyValue. For the usePropertyValue option, the value of property CamelAwsMessageGroupId will be used.

 

String

camel.component.aws2-sns.message-structure

The message structure to use such as json.

 

String

camel.component.aws2-sns.override-endpoint

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

Boolean

camel.component.aws2-sns.policy

The policy for this topic. Is loaded by default from classpath, but you can prefix with classpath:, file:, or http: to load the resource from different systems.

 

String

camel.component.aws2-sns.proxy-host

To define a proxy host when instantiating the SNS client.

 

String

camel.component.aws2-sns.proxy-port

To define a proxy port when instantiating the SNS client.

 

Integer

camel.component.aws2-sns.proxy-protocol

To define a proxy protocol when instantiating the SNS client.

 

Protocol

camel.component.aws2-sns.queue-url

The queueUrl to subscribe to.

 

String

camel.component.aws2-sns.region

The region in which SNS client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

String

camel.component.aws2-sns.secret-key

Amazon AWS Secret Key.

 

String

camel.component.aws2-sns.server-side-encryption-enabled

Define if Server Side Encryption is enabled or not on the topic.

false

Boolean

camel.component.aws2-sns.subject

The subject which is used if the message header 'CamelAwsSnsSubject' is not present.

 

String

camel.component.aws2-sns.subscribe-s-n-sto-s-q-s

Define if the subscription between SNS Topic and SQS must be done or not.

false

Boolean

camel.component.aws2-sns.trust-all-certificates

If we want to trust all certificates in case of overriding the endpoint.

false

Boolean

camel.component.aws2-sns.uri-endpoint-override

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

camel.component.aws2-sns.use-default-credentials-provider

Set whether the SNS client should expect to load credentials on an AWS infra instance or to expect static credentials to be passed in.

false

Boolean

Chapter 11. AWS Simple Queue Service (SQS)

Both producer and consumer are supported

The AWS2 SQS component supports sending and receiving messages to Amazon’s SQS service.

Prerequisites

You must have a valid Amazon Web Services developer account, and be signed up to use Amazon SQS. More information is available at Amazon SQS.

11.1. Dependencies

When using aws2-sqs with Red Hat build of Camel Spring Boot, add the following Maven dependency to your pom.xml to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-aws2-sqs-starter</artifactId>
</dependency>

11.2. URI Format

aws2-sqs://queueNameOrArn[?options]

The queue will be created if they don’t already exists. You can append query options to the URI in the following format,

?options=value&option2=value&…​

11.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

11.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

11.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

11.4. Component Options

The AWS Simple Queue Service (SQS) component supports 43 options, which are listed below.

NameDescriptionDefaultType

amazonAWSHost (common)

The hostname of the Amazon AWS cloud.

amazonaws.com

String

amazonSQSClient (common)

Autowired To use the AmazonSQS as client.

 

SqsClient

autoCreateQueue (common)

Setting the autocreation of the queue.

false

boolean

configuration (common)

The AWS SQS default configuration.

 

Sqs2Configuration

overrideEndpoint (common)

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

boolean

protocol (common)

The underlying protocol used to communicate with SQS.

https

String

proxyProtocol (common)

To define a proxy protocol when instantiating the SQS client.

Enum values:

  • HTTP
  • HTTPS

HTTPS

Protocol

queueOwnerAWSAccountId (common)

Specify the queue owner aws account id when you need to connect the queue with different account owner.

 

String

region (common)

The region in which SQS client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

String

trustAllCertificates (common)

If we want to trust all certificates in case of overriding the endpoint.

false

boolean

uriEndpointOverride (common)

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

useDefaultCredentialsProvider (common)

Set whether the SQS client should expect to load credentials on an AWS infra instance or to expect static credentials to be passed in.

false

boolean

attributeNames (consumer)

A list of attribute names to receive when consuming. Multiple names can be separated by comma.

 

String

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

concurrentConsumers (consumer)

Allows you to use multiple threads to poll the sqs queue to increase throughput.

1

int

defaultVisibilityTimeout (consumer)

The default visibility timeout (in seconds).

 

Integer

deleteAfterRead (consumer)

Delete message from SQS after it has been read.

true

boolean

deleteIfFiltered (consumer)

Whether or not to send the DeleteMessage to the SQS queue if the exchange has property with key Sqs2Constants#SQS_DELETE_FILTERED (CamelAwsSqsDeleteFiltered) set to true.

true

boolean

extendMessageVisibility (consumer)

If enabled then a scheduled background task will keep extending the message visibility on SQS. This is needed if it takes a long time to process the message. If set to true defaultVisibilityTimeout must be set.

false

boolean

kmsDataKeyReusePeriodSeconds (consumer)

The length of time, in seconds, for which Amazon SQS can reuse a data key to encrypt or decrypt messages before calling AWS KMS again. An integer representing seconds, between 60 seconds (1 minute) and 86,400 seconds (24 hours). Default: 300 (5 minutes).

 

Integer

kmsMasterKeyId (consumer)

The ID of an AWS-managed customer master key (CMK) for Amazon SQS or a custom CMK.

 

String

messageAttributeNames (consumer)

A list of message attribute names to receive when consuming. Multiple names can be separated by comma.

 

String

serverSideEncryptionEnabled (consumer)

Define if Server Side Encryption is enabled or not on the queue.

false

boolean

visibilityTimeout (consumer)

The duration (in seconds) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request to set in the com.amazonaws.services.sqs.model.SetQueueAttributesRequest. This only make sense if its different from defaultVisibilityTimeout. It changes the queue visibility timeout attribute permanently.

 

Integer

waitTimeSeconds (consumer)

Duration in seconds (0 to 20) that the ReceiveMessage action call will wait until a message is in the queue to include in the response.

 

Integer

batchSeparator (producer)

Set the separator when passing a String to send batch message operation.

,

String

delaySeconds (producer)

Delay sending messages for a number of seconds.

 

Integer

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

messageDeduplicationIdStrategy (producer)

Only for FIFO queues. Strategy for setting the messageDeduplicationId on the message. Can be one of the following options: useExchangeId, useContentBasedDeduplication. For the useContentBasedDeduplication option, no messageDeduplicationId will be set on the message.

Enum values:

  • useExchangeId
  • useContentBasedDeduplication

useExchangeId

String

messageGroupIdStrategy (producer)

Only for FIFO queues. Strategy for setting the messageGroupId on the message. Can be one of the following options: useConstant, useExchangeId, usePropertyValue. For the usePropertyValue option, the value of property CamelAwsMessageGroupId will be used.

Enum values:

  • useConstant
  • useExchangeId
  • usePropertyValue
 

String

operation (producer)

The operation to do in case the user don’t want to send only a message.

Enum values:

  • sendBatchMessage
  • deleteMessage
  • listQueues
  • purgeQueue
  • deleteQueue
 

Sqs2Operations

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

delayQueue (advanced)

Define if you want to apply delaySeconds option to the queue or on single messages.

false

boolean

queueUrl (advanced)

To define the queueUrl explicitly. All other parameters, which would influence the queueUrl, are ignored. This parameter is intended to be used, to connect to a mock implementation of SQS, for testing purposes.

 

String

proxyHost (proxy)

To define a proxy host when instantiating the SQS client.

 

String

proxyPort (proxy)

To define a proxy port when instantiating the SQS client.

 

Integer

maximumMessageSize (queue)

The maximumMessageSize (in bytes) an SQS message can contain for this queue.

 

Integer

messageRetentionPeriod (queue)

The messageRetentionPeriod (in seconds) a message will be retained by SQS for this queue.

 

Integer

policy (queue)

The policy for this queue. It can be loaded by default from classpath, but you can prefix with classpath:, file:, or http: to load the resource from different systems.

 

String

receiveMessageWaitTimeSeconds (queue)

If you do not specify WaitTimeSeconds in the request, the queue attribute ReceiveMessageWaitTimeSeconds is used to determine how long to wait.

 

Integer

redrivePolicy (queue)

Specify the policy that send message to DeadLetter queue. See detail at Amazon docs.

 

String

accessKey (security)

Amazon AWS Access Key.

 

String

secretKey (security)

Amazon AWS Secret Key.

 

String

11.5. Endpoint Options

The AWS Simple Queue Service (SQS) endpoint is configured using URI syntax:

aws2-sqs:queueNameOrArn

with the following path and query parameters:

11.5.1. Path Parameters (1 parameters)

NameDescriptionDefaultType

queueNameOrArn (common)

Required Queue name or ARN.

 

String

11.5.2. Query Parameters (61 parameters)

NameDescriptionDefaultType

amazonAWSHost (common)

The hostname of the Amazon AWS cloud.

amazonaws.com

String

amazonSQSClient (common)

Autowired To use the AmazonSQS as client.

 

SqsClient

autoCreateQueue (common)

Setting the autocreation of the queue.

false

boolean

headerFilterStrategy (common)

To use a custom HeaderFilterStrategy to map headers to/from Camel.

 

HeaderFilterStrategy

overrideEndpoint (common)

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

boolean

protocol (common)

The underlying protocol used to communicate with SQS.

https

String

proxyProtocol (common)

To define a proxy protocol when instantiating the SQS client.

Enum values:

  • HTTP
  • HTTPS

HTTPS

Protocol

queueOwnerAWSAccountId (common)

Specify the queue owner aws account id when you need to connect the queue with different account owner.

 

String

region (common)

The region in which SQS client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

String

trustAllCertificates (common)

If we want to trust all certificates in case of overriding the endpoint.

false

boolean

uriEndpointOverride (common)

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

useDefaultCredentialsProvider (common)

Set whether the SQS client should expect to load credentials on an AWS infra instance or to expect static credentials to be passed in.

false

boolean

attributeNames (consumer)

A list of attribute names to receive when consuming. Multiple names can be separated by comma.

 

String

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

concurrentConsumers (consumer)

Allows you to use multiple threads to poll the sqs queue to increase throughput.

1

int

defaultVisibilityTimeout (consumer)

The default visibility timeout (in seconds).

 

Integer

deleteAfterRead (consumer)

Delete message from SQS after it has been read.

true

boolean

deleteIfFiltered (consumer)

Whether or not to send the DeleteMessage to the SQS queue if the exchange has property with key Sqs2Constants#SQS_DELETE_FILTERED (CamelAwsSqsDeleteFiltered) set to true.

true

boolean

extendMessageVisibility (consumer)

If enabled then a scheduled background task will keep extending the message visibility on SQS. This is needed if it takes a long time to process the message. If set to true defaultVisibilityTimeout must be set. See details at Amazon docs.

false

boolean

kmsDataKeyReusePeriodSeconds (consumer)

The length of time, in seconds, for which Amazon SQS can reuse a data key to encrypt or decrypt messages before calling AWS KMS again. An integer representing seconds, between 60 seconds (1 minute) and 86,400 seconds (24 hours). Default: 300 (5 minutes).

 

Integer

kmsMasterKeyId (consumer)

The ID of an AWS-managed customer master key (CMK) for Amazon SQS or a custom CMK.

 

String

maxMessagesPerPoll (consumer)

Gets the maximum number of messages as a limit to poll at each polling. Is default unlimited, but use 0 or negative number to disable it as unlimited.

 

int

messageAttributeNames (consumer)

A list of message attribute names to receive when consuming. Multiple names can be separated by comma.

 

String

sendEmptyMessageWhenIdle (consumer)

If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead.

false

boolean

serverSideEncryptionEnabled (consumer)

Define if Server Side Encryption is enabled or not on the queue.

false

boolean

visibilityTimeout (consumer)

The duration (in seconds) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request to set in the com.amazonaws.services.sqs.model.SetQueueAttributesRequest. This only make sense if its different from defaultVisibilityTimeout. It changes the queue visibility timeout attribute permanently.

 

Integer

waitTimeSeconds (consumer)

Duration in seconds (0 to 20) that the ReceiveMessage action call will wait until a message is in the queue to include in the response.

 

Integer

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

pollStrategy (consumer (advanced))

A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel.

 

PollingConsumerPollStrategy

batchSeparator (producer)

Set the separator when passing a String to send batch message operation.

,

String

delaySeconds (producer)

Delay sending messages for a number of seconds.

 

Integer

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

messageDeduplicationIdStrategy (producer)

Only for FIFO queues. Strategy for setting the messageDeduplicationId on the message. Can be one of the following options: useExchangeId, useContentBasedDeduplication. For the useContentBasedDeduplication option, no messageDeduplicationId will be set on the message.

Enum values:

  • useExchangeId
  • useContentBasedDeduplication

useExchangeId

String

messageGroupIdStrategy (producer)

Only for FIFO queues. Strategy for setting the messageGroupId on the message. Can be one of the following options: useConstant, useExchangeId, usePropertyValue. For the usePropertyValue option, the value of property CamelAwsMessageGroupId will be used.

Enum values:

  • useConstant
  • useExchangeId
  • usePropertyValue
 

String

operation (producer)

The operation to do in case the user don’t want to send only a message.

Enum values:

  • sendBatchMessage
  • deleteMessage
  • listQueues
  • purgeQueue
  • deleteQueue
 

Sqs2Operations

delayQueue (advanced)

Define if you want to apply delaySeconds option to the queue or on single messages.

false

boolean

queueUrl (advanced)

To define the queueUrl explicitly. All other parameters, which would influence the queueUrl, are ignored. This parameter is intended to be used, to connect to a mock implementation of SQS, for testing purposes.

 

String

proxyHost (proxy)

To define a proxy host when instantiating the SQS client.

 

String

proxyPort (proxy)

To define a proxy port when instantiating the SQS client.

 

Integer

maximumMessageSize (queue)

The maximumMessageSize (in bytes) an SQS message can contain for this queue.

 

Integer

messageRetentionPeriod (queue)

The messageRetentionPeriod (in seconds) a message will be retained by SQS for this queue.

 

Integer

policy (queue)

The policy for this queue. It can be loaded by default from classpath, but you can prefix with classpath:, file:, or http: to load the resource from different systems.

 

String

receiveMessageWaitTimeSeconds (queue)

If you do not specify WaitTimeSeconds in the request, the queue attribute ReceiveMessageWaitTimeSeconds is used to determine how long to wait.

 

Integer

redrivePolicy (queue)

Specify the policy that send message to DeadLetter queue. See detail at Amazon docs.

 

String

backoffErrorThreshold (scheduler)

The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in.

 

int

backoffIdleThreshold (scheduler)

The number of subsequent idle polls that should happen before the backoffMultipler should kick-in.

 

int

backoffMultiplier (scheduler)

To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured.

 

int

delay (scheduler)

Milliseconds before the next poll.

500

long

greedy (scheduler)

If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages.

false

boolean

initialDelay (scheduler)

Milliseconds before the first poll starts.

1000

long

repeatCount (scheduler)

Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever.

0

long

runLoggingLevel (scheduler)

The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that.

Enum values:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • OFF

TRACE

LoggingLevel

scheduledExecutorService (scheduler)

Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool.

 

ScheduledExecutorService

scheduler (scheduler)

To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler.

none

Object

schedulerProperties (scheduler)

To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler.

 

Map

startScheduler (scheduler)

Whether the scheduler should be auto started.

true

boolean

timeUnit (scheduler)

Time unit for initialDelay and delay options.

Enum values:

  • NANOSECONDS
  • MICROSECONDS
  • MILLISECONDS
  • SECONDS
  • MINUTES
  • HOURS
  • DAYS

MILLISECONDS

TimeUnit

useFixedDelay (scheduler)

Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details.

true

boolean

accessKey (security)

Amazon AWS Access Key.

 

String

secretKey (security)

Amazon AWS Secret Key.

 

String

Required SQS component options

You have to provide the amazonSQSClient in the Registry or your accessKey and secretKey to access the Amazon’s SQS.

11.6. Batch Consumer

This component implements the Batch Consumer.

This allows you for instance to know how many messages exists in this batch and for instance let the Aggregator aggregate this number of messages.

11.7. Usage

11.7.1. Static credentials vs Default Credential Provider

You have the possibility of avoiding the usage of explicit static credentials, by specifying the useDefaultCredentialsProvider option and set it to true.

  • Java system properties - aws.accessKeyId and aws.secretKey
  • Environment variables - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
  • Web Identity Token from AWS STS.
  • The shared credentials and config files.
  • Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable AWS_CONTAINER_CREDENTIALS_RELATIVE_URI is set.
  • Amazon EC2 Instance profile credentials.

For more information about this you can look at AWS credentials documentation

11.7.2. Message headers set by the SQS producer

HeaderTypeDescription

CamelAwsSqsMD5OfBody

String

The MD5 checksum of the Amazon SQS message.

CamelAwsSqsMessageId

String

The Amazon SQS message ID.

CamelAwsSqsDelaySeconds

Integer

The delay seconds that the Amazon SQS message can be see by others.

11.7.3. Message headers set by the SQS consumer

HeaderTypeDescription

CamelAwsSqsMD5OfBody

String

The MD5 checksum of the Amazon SQS message.

CamelAwsSqsMessageId

String

The Amazon SQS message ID.

CamelAwsSqsReceiptHandle

String

The Amazon SQS message receipt handle.

CamelAwsSqsMessageAttributes

Map<String, String>

The Amazon SQS message attributes.

11.7.4. Advanced AmazonSQS configuration

If your Camel Application is running behind a firewall or if you need to have more control over the SqsClient instance configuration, you can create your own instance:

from("aws2-sqs://MyQueue?amazonSQSClient=#client&delay=5000&maxMessagesPerPoll=5")
.to("mock:result");

11.7.5. Creating or updating an SQS Queue

In the SQS Component, when an endpoint is started, a check is executed to obtain information about the existence of the queue or not. You’re able to customize the creation through the QueueAttributeName mapping with the SQSConfiguration option.

from("aws2-sqs://MyQueue?amazonSQSClient=#client&delay=5000&maxMessagesPerPoll=5")
.to("mock:result");

In this example if the MyQueue queue is not already created on AWS (and the autoCreateQueue option is set to true), it will be created with default parameters from the SQS configuration. If it’s already up on AWS, the SQS configuration options will be used to override the existent AWS configuration.

11.7.6. DelayQueue VS Delay for Single message

When the option delayQueue is set to true, the SQS Queue will be a DelayQueue with the DelaySeconds option as delay. For more information about DelayQueue you can read the AWS SQS documentation. One important information to take into account is the following:

  • For standard queues, the per-queue delay setting is not retroactive—changing the setting doesn’t affect the delay of messages already in the queue.
  • For FIFO queues, the per-queue delay setting is retroactive—changing the setting affects the delay of messages already in the queue.

as stated in the official documentation. If you want to specify a delay on single messages, you can ignore the delayQueue option, while you can set this option to true, if you need to add a fixed delay to all messages enqueued.

11.7.7. Server Side Encryption

There is a set of Server Side Encryption attributes for a queue. The related option are serverSideEncryptionEnabled, keyMasterKeyId and kmsDataKeyReusePeriod. The SSE is disabled by default. You need to explicitly set the option to true and set the related parameters as queue attributes.

11.8. JMS-style Selectors

SQS does not allow selectors, but you can effectively achieve this by using the Camel Filter EIP and setting an appropriate visibilityTimeout. When SQS dispatches a message, it will wait up to the visibility timeout before it will try to dispatch the message to a different consumer unless a DeleteMessage is received. By default, Camel will always send the DeleteMessage at the end of the route, unless the route ended in failure. To achieve appropriate filtering and not send the DeleteMessage even on successful completion of the route, use a Filter:

from("aws2-sqs://MyQueue?amazonSQSClient=#client&defaultVisibilityTimeout=5000&deleteIfFiltered=false&deleteAfterRead=false")
.filter("${header.login} == true")
  .setProperty(Sqs2Constants.SQS_DELETE_FILTERED, constant(true))
  .to("mock:filter");

In the above code, if an exchange doesn’t have an appropriate header, it will not make it through the filter AND also not be deleted from the SQS queue. After 5000 milliseconds, the message will become visible to other consumers.

Note we must set the property Sqs2Constants.SQS_DELETE_FILTERED to true to instruct Camel to send the DeleteMessage, if being filtered.

11.9. Available Producer Operations

  • single message (default)
  • sendBatchMessage
  • deleteMessage
  • listQueues

11.10. Send Message

You can set a SendMessageBatchRequest or an Iterable

from("direct:start")
  .setBody(constant("Camel rocks!"))
  .to("aws2-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)&region=eu-west-1");

11.11. Send Batch Message

You can set a SendMessageBatchRequest or an Iterable

from("direct:start")
  .setHeader(SqsConstants.SQS_OPERATION, constant("sendBatchMessage"))
  .process(new Processor() {
      @Override
      public void process(Exchange exchange) throws Exception {
          Collection c = new ArrayList();
          c.add("team1");
          c.add("team2");
          c.add("team3");
          c.add("team4");
          exchange.getIn().setBody(c);
      }
  })
  .to("aws2-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)&region=eu-west-1");

As result you’ll get an exchange containing a SendMessageBatchResponse instance, that you can examinate to check what messages were successfull and what not. The id set on each message of the batch will be a Random UUID.

11.12. Delete single Message

Use deleteMessage operation to delete a single message. You’ll need to set a receipt handle header for the message you want to delete.

from("direct:start")
  .setHeader(SqsConstants.SQS_OPERATION, constant("deleteMessage"))
  .setHeader(SqsConstants.RECEIPT_HANDLE, constant("123456"))
  .to("aws2-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)&region=eu-west-1");

As result you’ll get an exchange containing a DeleteMessageResponse instance, that you can use to check if the message was deleted or not.

11.13. List Queues

Use listQueues operation to list queues.

from("direct:start")
  .setHeader(SqsConstants.SQS_OPERATION, constant("listQueues"))
  .to("aws2-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)&region=eu-west-1");

As result you’ll get an exchange containing a ListQueuesResponse instance, that you can examinate to check the actual queues.

11.14. Purge Queue

Use purgeQueue operation to purge queue.

from("direct:start")
  .setHeader(SqsConstants.SQS_OPERATION, constant("purgeQueue"))
  .to("aws2-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)&region=eu-west-1");

As result you’ll get an exchange containing a PurgeQueueResponse instance.

11.15. Queue Autocreation

With the option autoCreateQueue users are able to avoid the autocreation of an SQS Queue in case it doesn’t exist. The default for this option is true. If set to false any operation on a not-existent queue in AWS won’t be successful and an error will be returned.

11.16. Send Batch Message and Message Deduplication Strategy

In case you’re using a SendBatchMessage Operation, you can set two different kind of Message Deduplication Strategy: - useExchangeId - useContentBasedDeduplication

The first one will use a ExchangeIdMessageDeduplicationIdStrategy, that will use the Exchange ID as parameter The other one will use a NullMessageDeduplicationIdStrategy, that will use the body as deduplication element.

In case of send batch message operation, you’ll need to use the useContentBasedDeduplication and on the Queue you’re pointing you’ll need to enable the content based deduplication option.

11.17. Dependencies

Maven users will need to add the following dependency to their pom.xml.

pom.xml

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-aws2-sqs</artifactId>
    <version>${camel-version}</version>
</dependency>

where {camel-version} must be replaced by the actual version of Camel.

11.18. Spring Boot Auto-Configuration

The component supports 44 options, which are listed below.

NameDescriptionDefaultType

camel.component.aws2-sqs.access-key

Amazon AWS Access Key.

 

String

camel.component.aws2-sqs.amazon-a-w-s-host

The hostname of the Amazon AWS cloud.

amazonaws.com

String

camel.component.aws2-sqs.amazon-s-q-s-client

To use the AmazonSQS as client. The option is a software.amazon.awssdk.services.sqs.SqsClient type.

 

SqsClient

camel.component.aws2-sqs.attribute-names

A list of attribute names to receive when consuming. Multiple names can be separated by comma.

 

String

camel.component.aws2-sqs.auto-create-queue

Setting the autocreation of the queue.

false

Boolean

camel.component.aws2-sqs.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.aws2-sqs.batch-separator

Set the separator when passing a String to send batch message operation.

,

String

camel.component.aws2-sqs.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.aws2-sqs.concurrent-consumers

Allows you to use multiple threads to poll the sqs queue to increase throughput.

1

Integer

camel.component.aws2-sqs.configuration

The AWS SQS default configuration. The option is a org.apache.camel.component.aws2.sqs.Sqs2Configuration type.

 

Sqs2Configuration

camel.component.aws2-sqs.default-visibility-timeout

The default visibility timeout (in seconds).

 

Integer

camel.component.aws2-sqs.delay-queue

Define if you want to apply delaySeconds option to the queue or on single messages.

false

Boolean

camel.component.aws2-sqs.delay-seconds

Delay sending messages for a number of seconds.

 

Integer

camel.component.aws2-sqs.delete-after-read

Delete message from SQS after it has been read.

true

Boolean

camel.component.aws2-sqs.delete-if-filtered

Whether or not to send the DeleteMessage to the SQS queue if the exchange has property with key Sqs2Constants#SQS_DELETE_FILTERED (CamelAwsSqsDeleteFiltered) set to true.

true

Boolean

camel.component.aws2-sqs.enabled

Whether to enable auto configuration of the aws2-sqs component. This is enabled by default.

 

Boolean

camel.component.aws2-sqs.extend-message-visibility

If enabled then a scheduled background task will keep extending the message visibility on SQS. This is needed if it takes a long time to process the message. If set to true defaultVisibilityTimeout must be set. See details at Amazon docs.

false

Boolean

camel.component.aws2-sqs.kms-data-key-reuse-period-seconds

The length of time, in seconds, for which Amazon SQS can reuse a data key to encrypt or decrypt messages before calling AWS KMS again. An integer representing seconds, between 60 seconds (1 minute) and 86,400 seconds (24 hours). Default: 300 (5 minutes).

 

Integer

camel.component.aws2-sqs.kms-master-key-id

The ID of an AWS-managed customer master key (CMK) for Amazon SQS or a custom CMK.

 

String

camel.component.aws2-sqs.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.aws2-sqs.maximum-message-size

The maximumMessageSize (in bytes) an SQS message can contain for this queue.

 

Integer

camel.component.aws2-sqs.message-attribute-names

A list of message attribute names to receive when consuming. Multiple names can be separated by comma.

 

String

camel.component.aws2-sqs.message-deduplication-id-strategy

Only for FIFO queues. Strategy for setting the messageDeduplicationId on the message. Can be one of the following options: useExchangeId, useContentBasedDeduplication. For the useContentBasedDeduplication option, no messageDeduplicationId will be set on the message.

useExchangeId

String

camel.component.aws2-sqs.message-group-id-strategy

Only for FIFO queues. Strategy for setting the messageGroupId on the message. Can be one of the following options: useConstant, useExchangeId, usePropertyValue. For the usePropertyValue option, the value of property CamelAwsMessageGroupId will be used.

 

String

camel.component.aws2-sqs.message-retention-period

The messageRetentionPeriod (in seconds) a message will be retained by SQS for this queue.

 

Integer

camel.component.aws2-sqs.operation

The operation to do in case the user don’t want to send only a message.

 

Sqs2Operations

camel.component.aws2-sqs.override-endpoint

Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option.

false

Boolean

camel.component.aws2-sqs.policy

The policy for this queue. It can be loaded by default from classpath, but you can prefix with classpath:, file:, or http: to load the resource from different systems.

 

String

camel.component.aws2-sqs.protocol

The underlying protocol used to communicate with SQS.

https

String

camel.component.aws2-sqs.proxy-host

To define a proxy host when instantiating the SQS client.

 

String

camel.component.aws2-sqs.proxy-port

To define a proxy port when instantiating the SQS client.

 

Integer

camel.component.aws2-sqs.proxy-protocol

To define a proxy protocol when instantiating the SQS client.

 

Protocol

camel.component.aws2-sqs.queue-owner-a-w-s-account-id

Specify the queue owner aws account id when you need to connect the queue with different account owner.

 

String

camel.component.aws2-sqs.queue-url

To define the queueUrl explicitly. All other parameters, which would influence the queueUrl, are ignored. This parameter is intended to be used, to connect to a mock implementation of SQS, for testing purposes.

 

String

camel.component.aws2-sqs.receive-message-wait-time-seconds

If you do not specify WaitTimeSeconds in the request, the queue attribute ReceiveMessageWaitTimeSeconds is used to determine how long to wait.

 

Integer

camel.component.aws2-sqs.redrive-policy

Specify the policy that send message to DeadLetter queue. See detail at Amazon docs.

 

String

camel.component.aws2-sqs.region

The region in which SQS client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id().

 

String

camel.component.aws2-sqs.secret-key

Amazon AWS Secret Key.

 

String

camel.component.aws2-sqs.server-side-encryption-enabled

Define if Server Side Encryption is enabled or not on the queue.

false

Boolean

camel.component.aws2-sqs.trust-all-certificates

If we want to trust all certificates in case of overriding the endpoint.

false

Boolean

camel.component.aws2-sqs.uri-endpoint-override

Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option.

 

String

camel.component.aws2-sqs.use-default-credentials-provider

Set whether the SQS client should expect to load credentials on an AWS infra instance or to expect static credentials to be passed in.

false

Boolean

camel.component.aws2-sqs.visibility-timeout

The duration (in seconds) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request to set in the com.amazonaws.services.sqs.model.SetQueueAttributesRequest. This only make sense if its different from defaultVisibilityTimeout. It changes the queue visibility timeout attribute permanently.

 

Integer

camel.component.aws2-sqs.wait-time-seconds

Duration in seconds (0 to 20) that the ReceiveMessage action call will wait until a message is in the queue to include in the response.

 

Integer

Chapter 12. Azure ServiceBus

Since Camel 3.12

Both producer and consumer are supported

The azure-servicebus component that integrates Azure ServiceBus. Azure ServiceBus is a fully managed enterprise integration message broker. Service Bus can decouple applications and services. Service Bus offers a reliable and secure platform for asynchronous transfer of data and state. Data is transferred between different applications and services using messages.

Prerequisites

You must have a valid Windows Azure Storage account. More information is available at Azure Documentation Portal.

12.1. Dependencies

When using azure-servicebus with Red Hat build of Camel Spring Boot, add the following Maven dependency to your pom.xml to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-azure-servicebus-starter</artifactId>
</dependency>

12.2. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

12.2.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

12.2.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

12.3. Component Options

The Azure ServiceBus component supports 25 options, which are listed below.

NameDescriptionDefaultType

amqpRetryOptions (common)

Sets the retry options for Service Bus clients. If not specified, the default retry options are used.

 

AmqpRetryOptions

amqpTransportType (common)

Sets the transport type by which all the communication with Azure Service Bus occurs. Default value is AmqpTransportType#AMQP.

Enum values:

  • Amqp
  • AmqpWebSockets

AMQP

AmqpTransportType

clientOptions (common)

Sets the ClientOptions to be sent from the client built from this builder, enabling customization of certain properties, as well as support the addition of custom header information. Refer to the ClientOptions documentation for more information.

 

ClientOptions

configuration (common)

The component configurations.

 

ServiceBusConfiguration

proxyOptions (common)

Sets the proxy configuration to use for ServiceBusSenderAsyncClient. When a proxy is configured, AmqpTransportType#AMQP_WEB_SOCKETS must be used for the transport type.

 

ProxyOptions

serviceBusType (common)

Required The service bus type of connection to execute. Queue is for typical queue option and topic for subscription based model.

Enum values:

  • queue
  • topic

queue

ServiceBusType

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

consumerOperation (consumer)

Sets the desired operation to be used in the consumer.

Enum values:

  • receiveMessages
  • peekMessages

receiveMessages

ServiceBusConsumerOperationDefinition

disableAutoComplete (consumer)

Disables auto-complete and auto-abandon of received messages. By default, a successfully processed message is \\{link ServiceBusReceiverAsyncClient#complete(ServiceBusReceivedMessage) completed}. If an error happens when the message is processed, it is \\{link ServiceBusReceiverAsyncClient#abandon(ServiceBusReceivedMessage) abandoned}.

false

boolean

maxAutoLockRenewDuration (consumer)

Sets the amount of time to continue auto-renewing the lock. Setting Duration#ZERO or null disables auto-renewal. For \\{link ServiceBusReceiveMode#RECEIVE_AND_DELETE RECEIVE_AND_DELETE} mode, auto-renewal is disabled.

5m

Duration

peekNumMaxMessages (consumer)

Set the max number of messages to be peeked during the peek operation.

 

Integer

prefetchCount (consumer)

Sets the prefetch count of the receiver. For both \\{link ServiceBusReceiveMode#PEEK_LOCK PEEK_LOCK} and \\{link ServiceBusReceiveMode#RECEIVE_AND_DELETE RECEIVE_AND_DELETE} modes the default value is 1. Prefetch speeds up the message flow by aiming to have a message readily available for local retrieval when and before the application asks for one using ServiceBusReceiverAsyncClient#receiveMessages(). Setting a non-zero value will prefetch that number of messages. Setting the value to zero turns prefetch off.

 

int

receiverAsyncClient (consumer)

Autowired Sets the receiverAsyncClient in order to consume messages by the consumer.

 

ServiceBusReceiverAsyncClient

serviceBusReceiveMode (consumer)

Sets the receive mode for the receiver.

Enum values:

  • PEEK_LOCK
  • RECEIVE_AND_DELETE

PEEK_LOCK

ServiceBusReceiveMode

subQueue (consumer)

Sets the type of the SubQueue to connect to.

Enum values:

  • NONE
  • DEAD_LETTER_QUEUE
  • TRANSFER_DEAD_LETTER_QUEUE
 

SubQueue

subscriptionName (consumer)

Sets the name of the subscription in the topic to listen to. topicOrQueueName and serviceBusType=topic must also be set. This property is required if serviceBusType=topic and the consumer is in use.

 

String

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

producerOperation (producer)

Sets the desired operation to be used in the producer.

Enum values:

  • sendMessages
  • scheduleMessages

sendMessages

ServiceBusProducerOperationDefinition

scheduledEnqueueTime (producer)

Sets OffsetDateTime at which the message should appear in the Service Bus queue or topic.

 

OffsetDateTime

senderAsyncClient (producer)

Autowired Sets SenderAsyncClient to be used in the producer.

 

ServiceBusSenderAsyncClient

serviceBusTransactionContext (producer)

Represents transaction in service. This object just contains transaction id.

 

ServiceBusTransactionContext

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

connectionString (security)

Sets the connection string for a Service Bus namespace or a specific Service Bus resource.

 

String

fullyQualifiedNamespace (security)

Fully Qualified Namespace of the service bus.

 

String

tokenCredential (security)

A TokenCredential for Azure AD authentication, implemented in com.azure.identity.

 

TokenCredential

12.4. Endpoint Options

The Azure ServiceBus endpoint is configured using URI syntax:

azure-servicebus:topicOrQueueName

with the following path and query parameters:

12.4.1. Path Parameters (1 parameters)

NameDescriptionDefaultType

topicOrQueueName (common)

Selected topic name or the queue name, that is depending on serviceBusType config. For example if serviceBusType=queue, then this will be the queue name and if serviceBusType=topic, this will be the topic name.

 

String

12.4.2. Query Parameters (25 parameters)

NameDescriptionDefaultType

amqpRetryOptions (common)

Sets the retry options for Service Bus clients. If not specified, the default retry options are used.

 

AmqpRetryOptions

amqpTransportType (common)

Sets the transport type by which all the communication with Azure Service Bus occurs. Default value is AmqpTransportType#AMQP.

Enum values:

  • Amqp
  • AmqpWebSockets

AMQP

AmqpTransportType

clientOptions (common)

Sets the ClientOptions to be sent from the client built from this builder, enabling customization of certain properties, as well as support the addition of custom header information. Refer to the ClientOptions documentation for more information.

 

ClientOptions

proxyOptions (common)

Sets the proxy configuration to use for ServiceBusSenderAsyncClient. When a proxy is configured, AmqpTransportType#AMQP_WEB_SOCKETS must be used for the transport type.

 

ProxyOptions

serviceBusType (common)

Required The service bus type of connection to execute. Queue is for typical queue option and topic for subscription based model.

Enum values:

  • queue
  • topic

queue

ServiceBusType

consumerOperation (consumer)

Sets the desired operation to be used in the consumer.

Enum values:

  • receiveMessages
  • peekMessages

receiveMessages

ServiceBusConsumerOperationDefinition

disableAutoComplete (consumer)

Disables auto-complete and auto-abandon of received messages. By default, a successfully processed message is \\{link ServiceBusReceiverAsyncClient#complete(ServiceBusReceivedMessage) completed}. If an error happens when the message is processed, it is \\{link ServiceBusReceiverAsyncClient#abandon(ServiceBusReceivedMessage) abandoned}.

false

boolean

maxAutoLockRenewDuration (consumer)

Sets the amount of time to continue auto-renewing the lock. Setting Duration#ZERO or null disables auto-renewal. For \\{link ServiceBusReceiveMode#RECEIVE_AND_DELETE RECEIVE_AND_DELETE} mode, auto-renewal is disabled.

5m

Duration

peekNumMaxMessages (consumer)

Set the max number of messages to be peeked during the peek operation.

 

Integer

prefetchCount (consumer)

Sets the prefetch count of the receiver. For both \\{link ServiceBusReceiveMode#PEEK_LOCK PEEK_LOCK} and \\{link ServiceBusReceiveMode#RECEIVE_AND_DELETE RECEIVE_AND_DELETE} modes the default value is 1. Prefetch speeds up the message flow by aiming to have a message readily available for local retrieval when and before the application asks for one using ServiceBusReceiverAsyncClient#receiveMessages(). Setting a non-zero value will prefetch that number of messages. Setting the value to zero turns prefetch off.

 

int

receiverAsyncClient (consumer)

Autowired Sets the receiverAsyncClient in order to consume messages by the consumer.

 

ServiceBusReceiverAsyncClient

serviceBusReceiveMode (consumer)

Sets the receive mode for the receiver.

Enum values:

  • PEEK_LOCK
  • RECEIVE_AND_DELETE

PEEK_LOCK

ServiceBusReceiveMode

subQueue (consumer)

Sets the type of the SubQueue to connect to.

Enum values:

  • NONE
  • DEAD_LETTER_QUEUE
  • TRANSFER_DEAD_LETTER_QUEUE
 

SubQueue

subscriptionName (consumer)

Sets the name of the subscription in the topic to listen to. topicOrQueueName and serviceBusType=topic must also be set. This property is required if serviceBusType=topic and the consumer is in use.

 

String

bridgeErrorHandler (consumer (advanced))

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

producerOperation (producer)

Sets the desired operation to be used in the producer.

Enum values:

  • sendMessages
  • scheduleMessages

sendMessages

ServiceBusProducerOperationDefinition

scheduledEnqueueTime (producer)

Sets OffsetDateTime at which the message should appear in the Service Bus queue or topic.

 

OffsetDateTime

senderAsyncClient (producer)

Autowired Sets SenderAsyncClient to be used in the producer.

 

ServiceBusSenderAsyncClient

serviceBusTransactionContext (producer)

Represents transaction in service. This object just contains transaction id.

 

ServiceBusTransactionContext

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

connectionString (security)

Sets the connection string for a Service Bus namespace or a specific Service Bus resource.

 

String

fullyQualifiedNamespace (security)

Fully Qualified Namespace of the service bus.

 

String

tokenCredential (security)

A TokenCredential for Azure AD authentication, implemented in com.azure.identity.

 

TokenCredential

12.5. Async Consumer and Producer

This component implements the async Consumer and producer. This allows camel route to consume and produce events asynchronously without blocking any threads.

12.6. Message Headers

The Azure ServiceBus component supports 25 message header(s), which is/are listed below:

NameDescriptionDefaultType

CamelAzureServiceBusApplicationProperties (common)

Constant: APPLICATION_PROPERTIES

The application properties (also known as custom properties) on messages sent and received by the producer and consumer, respectively.

 

Map

CamelAzureServiceBusContentType (consumer)

Constant: CONTENT_TYPE

Gets the content type of the message.

 

String

CamelAzureServiceBusCorrelationId (consumer)

Constant: CORRELATION_ID

Gets a correlation identifier.

 

String

CamelAzureServiceBusDeadLetterErrorDescription (consumer)

Constant: DEAD_LETTER_ERROR_DESCRIPTION

Gets the description for a message that has been dead-lettered.

 

String

CamelAzureServiceBusDeadLetterReason (consumer)

Constant: DEAD_LETTER_REASON

Gets the reason a message was dead-lettered.

 

String

CamelAzureServiceBusDeadLetterSource (consumer)

Constant: DEAD_LETTER_SOURCE

Gets the name of the queue or subscription that this message was enqueued on, before it was dead-lettered.

 

String

CamelAzureServiceBusDeliveryCount (consumer)

Constant: DELIVERY_COUNT

Gets the number of the times this message was delivered to clients.

 

long

CamelAzureServiceBusEnqueuedSequenceNumber (consumer)

Constant: ENQUEUED_SEQUENCE_NUMBER

Gets the enqueued sequence number assigned to a message by Service Bus.

 

long

CamelAzureServiceBusEnqueuedTime (consumer)

Constant: ENQUEUED_TIME

Gets the datetime at which this message was enqueued in Azure Service Bus.

 

OffsetDateTime

CamelAzureServiceBusExpiresAt (consumer)

Constant: EXPIRES_AT

Gets the datetime at which this message will expire.

 

OffsetDateTime

CamelAzureServiceBusLockToken (consumer)

Constant: LOCK_TOKEN

Gets the lock token for the current message.

 

String

CamelAzureServiceBusLockedUntil (consumer)

Constant: LOCKED_UNTIL

Gets the datetime at which the lock of this message expires.

 

OffsetDateTime

CamelAzureServiceBusMessageId (consumer)

Constant: MESSAGE_ID

Gets the identifier for the message.

 

String

CamelAzureServiceBusPartitionKey (consumer)

Constant: PARTITION_KEY

Gets the partition key for sending a message to a partitioned entity.

 

String

CamelAzureServiceBusRawAmqpMessage (consumer)

Constant: RAW_AMQP_MESSAGE

The representation of message as defined by AMQP protocol.

 

AmqpAnnotatedMessage

CamelAzureServiceBusReplyTo (consumer)

Constant: REPLY_TO

Gets the address of an entity to send replies to.

 

String

CamelAzureServiceBusReplyToSessionId (consumer)

Constant: REPLY_TO_SESSION_ID

Gets or sets a session identifier augmenting the ReplyTo address.

 

String

CamelAzureServiceBusSequenceNumber (consumer)

Constant: SEQUENCE_NUMBER

Gets the unique number assigned to a message by Service Bus.

 

long

CamelAzureServiceBusSessionId (consumer)

Constant: SESSION_ID

Gets the session id of the message.

 

String

CamelAzureServiceBusSubject (consumer)

Constant: SUBJECT

Gets the subject for the message.

 

String

CamelAzureServiceBusTimeToLive (consumer)

Constant: TIME_TO_LIVE

Gets the duration before this message expires.

 

Duration

CamelAzureServiceBusTo (consumer)

Constant: TO

Gets the to address.

 

String

CamelAzureServiceBusScheduledEnqueueTime (common)

Constant: SCHEDULED_ENQUEUE_TIME

(producer)Overrides the OffsetDateTime at which the message should appear in the Service Bus queue or topic. (consumer) Gets the scheduled enqueue time of this message.

 

OffsetDateTime

CamelAzureServiceBusServiceBusTransactionContext (producer)

Constant: SERVICE_BUS_TRANSACTION_CONTEXT

Overrides the transaction in service. This object just contains transaction id.

 

ServiceBusTransactionContext

CamelAzureServiceBusProducerOperation (producer)

Constant: PRODUCER_OPERATION

Overrides the desired operation to be used in the producer.

Enum values:

  • sendMessages
  • scheduleMessages
 

ServiceBusProducerOperationDefinition

12.6.1. Message Body

In the producer, this component accepts message body of String type or List<String> to send batch messages.

In the consumer, the returned message body will be of type `String.

12.6.2. Azure ServiceBus Producer operations

OperationDescription

sendMessages

Sends a set of messages to a Service Bus queue or topic using a batched approach.

scheduleMessages

Sends a scheduled message to the Azure Service Bus entity this sender is connected to. A scheduled message is enqueued and made available to receivers only at the scheduled enqueue time.

12.6.3. Azure ServiceBus Consumer operations

OperationDescription

receiveMessages

Receives an <b>infinite</b> stream of messages from the Service Bus entity.

peekMessages

Reads the next batch of active messages without changing the state of the receiver or the message source.

12.6.3.1. Examples
  • sendMessages
from("direct:start")
  .process(exchange -> {
         final List<Object> inputBatch = new LinkedList<>();
            inputBatch.add("test batch 1");
            inputBatch.add("test batch 2");
            inputBatch.add("test batch 3");
            inputBatch.add(123456);

            exchange.getIn().setBody(inputBatch);
       })
  .to("azure-servicebus:test//?connectionString=test")
  .to("mock:result");
  • scheduleMessages
from("direct:start")
  .process(exchange -> {
         final List<Object> inputBatch = new LinkedList<>();
            inputBatch.add("test batch 1");
            inputBatch.add("test batch 2");
            inputBatch.add("test batch 3");
            inputBatch.add(123456);

            exchange.getIn().setHeader(ServiceBusConstants.SCHEDULED_ENQUEUE_TIME, OffsetDateTime.now());
            exchange.getIn().setBody(inputBatch);
       })
  .to("azure-servicebus:test//?connectionString=test&producerOperation=scheduleMessages")
  .to("mock:result");
  • receiveMessages
from("azure-servicebus:test//?connectionString=test")
  .log("${body}")
  .to("mock:result");
  • peekMessages
from("azure-servicebus:test//?connectionString=test&consumerOperation=peekMessages&peekNumMaxMessages=3")
  .log("${body}")
  .to("mock:result");

12.7. Spring Boot Auto-Configuration

The component supports 26 options, which are listed below.

NameDescriptionDefaultType

camel.component.azure-servicebus.amqp-retry-options

Sets the retry options for Service Bus clients. If not specified, the default retry options are used. The option is a com.azure.core.amqp.AmqpRetryOptions type.

 

AmqpRetryOptions

camel.component.azure-servicebus.amqp-transport-type

Sets the transport type by which all the communication with Azure Service Bus occurs. Default value is AmqpTransportType#AMQP.

 

AmqpTransportType

camel.component.azure-servicebus.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.azure-servicebus.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.azure-servicebus.client-options

Sets the ClientOptions to be sent from the client built from this builder, enabling customization of certain properties, as well as support the addition of custom header information. Refer to the ClientOptions documentation for more information. The option is a com.azure.core.util.ClientOptions type.

 

ClientOptions

camel.component.azure-servicebus.configuration

The component configurations. The option is a org.apache.camel.component.azure.servicebus.ServiceBusConfiguration type.

 

ServiceBusConfiguration

camel.component.azure-servicebus.connection-string

Sets the connection string for a Service Bus namespace or a specific Service Bus resource.

 

String

camel.component.azure-servicebus.consumer-operation

Sets the desired operation to be used in the consumer.

 

ServiceBusConsumerOperationDefinition

camel.component.azure-servicebus.disable-auto-complete

Disables auto-complete and auto-abandon of received messages. By default, a successfully processed message is \\{link ServiceBusReceiverAsyncClient#complete(ServiceBusReceivedMessage) completed}. If an error happens when the message is processed, it is \\{link ServiceBusReceiverAsyncClient#abandon(ServiceBusReceivedMessage) abandoned}.

false

Boolean

camel.component.azure-servicebus.enabled

Whether to enable auto configuration of the azure-servicebus component. This is enabled by default.

 

Boolean

camel.component.azure-servicebus.fully-qualified-namespace

Fully Qualified Namespace of the service bus.

 

String

camel.component.azure-servicebus.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.azure-servicebus.max-auto-lock-renew-duration

Sets the amount of time to continue auto-renewing the lock. Setting Duration#ZERO or null disables auto-renewal. For \\{link ServiceBusReceiveMode#RECEIVE_AND_DELETE RECEIVE_AND_DELETE} mode, auto-renewal is disabled. The option is a java.time.Duration type.

 

Duration

camel.component.azure-servicebus.peek-num-max-messages

Set the max number of messages to be peeked during the peek operation.

 

Integer

camel.component.azure-servicebus.prefetch-count

Sets the prefetch count of the receiver. For both \\{link ServiceBusReceiveMode#PEEK_LOCK PEEK_LOCK} and \\{link ServiceBusReceiveMode#RECEIVE_AND_DELETE RECEIVE_AND_DELETE} modes the default value is 1. Prefetch speeds up the message flow by aiming to have a message readily available for local retrieval when and before the application asks for one using ServiceBusReceiverAsyncClient#receiveMessages(). Setting a non-zero value will prefetch that number of messages. Setting the value to zero turns prefetch off.

 

Integer

camel.component.azure-servicebus.producer-operation

Sets the desired operation to be used in the producer.

 

ServiceBusProducerOperationDefinition

camel.component.azure-servicebus.proxy-options

Sets the proxy configuration to use for ServiceBusSenderAsyncClient. When a proxy is configured, AmqpTransportType#AMQP_WEB_SOCKETS must be used for the transport type. The option is a com.azure.core.amqp.ProxyOptions type.

 

ProxyOptions

camel.component.azure-servicebus.receiver-async-client

Sets the receiverAsyncClient in order to consume messages by the consumer. The option is a com.azure.messaging.servicebus.ServiceBusReceiverAsyncClient type.

 

ServiceBusReceiverAsyncClient

camel.component.azure-servicebus.scheduled-enqueue-time

Sets OffsetDateTime at which the message should appear in the Service Bus queue or topic. The option is a java.time.OffsetDateTime type.

 

OffsetDateTime

camel.component.azure-servicebus.sender-async-client

Sets SenderAsyncClient to be used in the producer. The option is a com.azure.messaging.servicebus.ServiceBusSenderAsyncClient type.

 

ServiceBusSenderAsyncClient

camel.component.azure-servicebus.service-bus-receive-mode

Sets the receive mode for the receiver.

 

ServiceBusReceiveMode

camel.component.azure-servicebus.service-bus-transaction-context

Represents transaction in service. This object just contains transaction id. The option is a com.azure.messaging.servicebus.ServiceBusTransactionContext type.

 

ServiceBusTransactionContext

camel.component.azure-servicebus.service-bus-type

The service bus type of connection to execute. Queue is for typical queue option and topic for subscription based model.

 

ServiceBusType

camel.component.azure-servicebus.sub-queue

Sets the type of the SubQueue to connect to.

 

SubQueue

camel.component.azure-servicebus.subscription-name

Sets the name of the subscription in the topic to listen to. topicOrQueueName and serviceBusType=topic must also be set. This property is required if serviceBusType=topic and the consumer is in use.

 

String

camel.component.azure-servicebus.token-credential

A TokenCredential for Azure AD authentication, implemented in com.azure.identity. The option is a com.azure.core.credential.TokenCredential type.

 

TokenCredential

Chapter 13. Azure Storage Blob Service

Both producer and consumer are supported

The Azure Storage Blob component is used for storing and retrieving blobs from Azure Storage Blob Service using Azure APIs v12. However in case of versions above v12, we will see if this component can adopt these changes depending on how much breaking changes can result.

Prerequisites

You must have a valid Windows Azure Storage account. More information is available at Azure Documentation Portal .

13.1. Dependencies

When using azure-storage-blob with Red Hat build of Camel Spring Boot, add the following Maven dependency to your pom.xml to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-azure-storage-blob-starter</artifactId>
</dependency>

13.2. URI Format

azure-storage-blob://accountName[/containerName][?options]

In case of consumer, accountName, containerName are required. In case of producer, it depends on the operation that being requested, for example if operation is on a container level, for example, createContainer, accountName and containerName are only required, but in case of operation being requested in blob level, for example, getBlob, accountName, containerName and blobName are required.

The blob will be created if it does not already exist. You can append query options to the URI in the following format,

?options=value&option2=value&…

13.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

13.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

13.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

13.4. Component Options

The Azure Storage Blob Service component supports 35 options, which are listed below.

NameDescriptionDefaultType

blobName (common)

The blob name, to consume specific blob from a container. However on producer, is only required for the operations on the blob level.

 

String

blobOffset (common)

Set the blob offset for the upload or download operations, default is 0.

0

long

blobType (common)

The blob type in order to initiate the appropriate settings for each blob type.

Enum values:

  • blockblob
  • appendblob
  • pageblob

blockblob

BlobType

closeStreamAfterRead (common)

Close the stream after read or keep it open, default is true.

true

boolean

configuration (common)

The component configurations.

 

BlobConfiguration

credentials (common)

StorageSharedKeyCredential can be injected to create the azure client, this holds the important authentication information.

 

StorageSharedKeyCredential

credentialType (common)

Determines the credential strategy to adopt.

Enum values:

  • SHARED_ACCOUNT_KEY
  • SHARED_KEY_CREDENTIAL
  • AZURE_IDENTITY
  • AZURE_SAS

AZURE_IDENTITY

CredentialType

dataCount (common)

How many bytes to include in the range. Must be greater than or equal to 0 if specified.

 

Long

fileDir (common)

The file directory where the downloaded blobs will be saved to, this can be used in both, producer and consumer.

 

String

maxResultsPerPage (common)

Specifies the maximum number of blobs to return, including all BlobPrefix elements. If the request does not specify maxResultsPerPage or specifies a value greater than 5,000, the server will return up to 5,000 items.

 

Integer

maxRetryRequests (common)

Specifies the maximum number of additional HTTP Get requests that will be made while reading the data from a response body.

0

int

prefix (common)

Filters the results to return only blobs whose names begin with the specified prefix. May be null to return all blobs.

 

String

regex (common)

Filters the results to return only blobs whose names match the specified regular expression. May be null to return all if both prefix and regex are set, regex takes the priority and prefix is ignored.

 

String

sasToken (common)

Set a SAS Token in case of usage of Shared Access Signature

 

String

serviceClient (common)

Autowired Client to a storage account. This client does not hold any state about a particular storage account but is instead a convenient way of sending off appropriate requests to the resource on the service. It may also be used to construct URLs to blobs and containers. This client contains operations on a service account. Operations on a container are available on BlobContainerClient through BlobServiceClient#getBlobContainerClient(String), and operations on a blob are available on BlobClient through BlobContainerClient#getBlobClient(String).

 

BlobServiceClient

timeout (common)

An optional timeout value beyond which a RuntimeException will be raised.

 

Duration

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

blobSequenceNumber (producer)

A user-controlled value that you can use to track requests. The value of the sequence number must be between 0 and 263 - 1.The default value is 0.

0

Long

blockListType (producer)

Specifies which type of blocks to return.

Enum values:

  • committed
  • uncommitted
  • all

COMMITTED

BlockListType

changeFeedContext (producer)

When using getChangeFeed producer operation, this gives additional context that is passed through the Http pipeline during the service call.

 

Context

changeFeedEndTime (producer)

When using getChangeFeed producer operation, this filters the results to return events approximately before the end time. Note: A few events belonging to the next hour can also be returned. A few events belonging to this hour can be missing; to ensure all events from the hour are returned, round the end time up by an hour.

 

OffsetDateTime

changeFeedStartTime (producer)

When using getChangeFeed producer operation, this filters the results to return events approximately after the start time. Note: A few events belonging to the previous hour can also be returned. A few events belonging to this hour can be missing; to ensure all events from the hour are returned, round the start time down by an hour.

 

OffsetDateTime

closeStreamAfterWrite (producer)

Close the stream after write or keep it open, default is true.

true

boolean

commitBlockListLater (producer)

When is set to true, the staged blocks will not be committed directly.

true

boolean

createAppendBlob (producer)

When is set to true, the append blocks will be created when committing append blocks.

true

boolean

createPageBlob (producer)

When is set to true, the page blob will be created when uploading page blob.

true

boolean

downloadLinkExpiration (producer)

Override the default expiration (millis) of URL download link.

 

Long

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

operation (producer)

The blob operation that can be used with this component on the producer.

Enum values:

  • listBlobContainers
  • createBlobContainer
  • deleteBlobContainer
  • listBlobs
  • getBlob
  • deleteBlob
  • downloadBlobToFile
  • downloadLink
  • uploadBlockBlob
  • stageBlockBlobList
  • commitBlobBlockList
  • getBlobBlockList
  • createAppendBlob
  • commitAppendBlob
  • createPageBlob
  • uploadPageBlob
  • resizePageBlob
  • clearPageBlob
  • getPageBlobRanges

listBlobContainers

BlobOperationsDefinition

pageBlobSize (producer)

Specifies the maximum size for the page blob, up to 8 TB. The page blob size must be aligned to a 512-byte boundary.

512

Long

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

healthCheckConsumerEnabled (health)

Used for enabling or disabling all consumer based health checks from this component.

true

boolean

healthCheckProducerEnabled (health)

Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true.

true

boolean

accessKey (security)

Access key for the associated azure account name to be used for authentication with azure blob services.

 

String

sourceBlobAccessKey (security)

Source Blob Access Key: for copyblob operation, sadly, we need to have an accessKey for the source blob we want to copy Passing an accessKey as header, it’s unsafe so we could set as key.

 

String

13.5. Endpoint Options

The Azure Storage Blob Service endpoint is configured using URI syntax:

azure-storage-blob:accountName/containerName

with the following path and query parameters:

13.5.1. Path Parameters (2 parameters)

NameDescriptionDefaultType

accountName (common)

Azure account name to be used for authentication with azure blob services.

 

String

containerName (common)

The blob container name.

 

String

13.5.2. Query Parameters (50 parameters)

NameDescriptionDefaultType

blobName (common)

The blob name, to consume specific blob from a container. However on producer, is only required for the operations on the blob level.

 

String

blobOffset (common)

Set the blob offset for the upload or download operations, default is 0.

0

long

blobServiceClient (common)

Client to a storage account. This client does not hold any state about a particular storage account but is instead a convenient way of sending off appropriate requests to the resource on the service. It may also be used to construct URLs to blobs and containers. This client contains operations on a service account. Operations on a container are available on BlobContainerClient through getBlobContainerClient(String), and operations on a blob are available on BlobClient through getBlobContainerClient(String).getBlobClient(String).

 

BlobServiceClient

blobType (common)

The blob type in order to initiate the appropriate settings for each blob type.

Enum values:

  • blockblob
  • appendblob
  • pageblob

blockblob

BlobType

closeStreamAfterRead (common)

Close the stream after read or keep it open, default is true.

true

boolean

credentials (common)

StorageSharedKeyCredential can be injected to create the azure client, this holds the important authentication information.

 

StorageSharedKeyCredential

credentialType (common)

Determines the credential strategy to adopt.

Enum values:

  • SHARED_ACCOUNT_KEY
  • SHARED_KEY_CREDENTIAL
  • AZURE_IDENTITY
  • AZURE_SAS

AZURE_IDENTITY

CredentialType

dataCount (common)

How many bytes to include in the range. Must be greater than or equal to 0 if specified.

 

Long

fileDir (common)

The file directory where the downloaded blobs will be saved to, this can be used in both, producer and consumer.

 

String

maxResultsPerPage (common)

Specifies the maximum number of blobs to return, including all BlobPrefix elements. If the request does not specify maxResultsPerPage or specifies a value greater than 5,000, the server will return up to 5,000 items.

 

Integer

maxRetryRequests (common)

Specifies the maximum number of additional HTTP Get requests that will be made while reading the data from a response body.

0

int

prefix (common)

Filters the results to return only blobs whose names begin with the specified prefix. May be null to return all blobs.

 

String

regex (common)

Filters the results to return only blobs whose names match the specified regular expression. May be null to return all if both prefix and regex are set, regex takes the priority and prefix is ignored.

 

String

sasToken (common)

Set a SAS Token in case of usage of Shared Access Signature.

 

String

serviceClient (common)

Autowired Client to a storage account. This client does not hold any state about a particular storage account but is instead a convenient way of sending off appropriate requests to the resource on the service. It may also be used to construct URLs to blobs and containers. This client contains operations on a service account. Operations on a container are available on BlobContainerClient through BlobServiceClient#getBlobContainerClient(String), and operations on a blob are available on BlobClient through BlobContainerClient#getBlobClient(String).

 

BlobServiceClient

timeout (common)

An optional timeout value beyond which a RuntimeException will be raised.

 

Duration

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

sendEmptyMessageWhenIdle (consumer)

If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead.

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

pollStrategy (consumer (advanced))

A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel.

 

PollingConsumerPollStrategy

blobSequenceNumber (producer)

A user-controlled value that you can use to track requests. The value of the sequence number must be between 0 and 263 - 1.The default value is 0.

0

Long

blockListType (producer)

Specifies which type of blocks to return.

Enum values:

  • committed
  • uncommitted
  • all

COMMITTED

BlockListType

changeFeedContext (producer)

When using getChangeFeed producer operation, this gives additional context that is passed through the Http pipeline during the service call.

 

Context

changeFeedEndTime (producer)

When using getChangeFeed producer operation, this filters the results to return events approximately before the end time. Note: A few events belonging to the next hour can also be returned. A few events belonging to this hour can be missing; to ensure all events from the hour are returned, round the end time up by an hour.

 

OffsetDateTime

changeFeedStartTime (producer)

When using getChangeFeed producer operation, this filters the results to return events approximately after the start time. Note: A few events belonging to the previous hour can also be returned. A few events belonging to this hour can be missing; to ensure all events from the hour are returned, round the start time down by an hour.

 

OffsetDateTime

closeStreamAfterWrite (producer)

Close the stream after write or keep it open, default is true.

true

boolean

commitBlockListLater (producer)

When is set to true, the staged blocks will not be committed directly.

true

boolean

createAppendBlob (producer)

When is set to true, the append blocks will be created when committing append blocks.

true

boolean

createPageBlob (producer)

When is set to true, the page blob will be created when uploading page blob.

true

boolean

downloadLinkExpiration (producer)

Override the default expiration (millis) of URL download link.

 

Long

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

operation (producer)

The blob operation that can be used with this component on the producer.

Enum values:

  • listBlobContainers
  • createBlobContainer
  • deleteBlobContainer
  • listBlobs
  • getBlob
  • deleteBlob
  • downloadBlobToFile
  • downloadLink
  • uploadBlockBlob
  • stageBlockBlobList
  • commitBlobBlockList
  • getBlobBlockList
  • createAppendBlob
  • commitAppendBlob
  • createPageBlob
  • uploadPageBlob
  • resizePageBlob
  • clearPageBlob
  • getPageBlobRanges

listBlobContainers

BlobOperationsDefinition

pageBlobSize (producer)

Specifies the maximum size for the page blob, up to 8 TB. The page blob size must be aligned to a 512-byte boundary.

512

Long

backoffErrorThreshold (scheduler)

The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in.

 

int

backoffIdleThreshold (scheduler)

The number of subsequent idle polls that should happen before the backoffMultipler should kick-in.

 

int

backoffMultiplier (scheduler)

To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured.

 

int

delay (scheduler)

Milliseconds before the next poll.

500

long

greedy (scheduler)

If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages.

false

boolean

initialDelay (scheduler)

Milliseconds before the first poll starts.

1000

long

repeatCount (scheduler)

Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever.

0

long

runLoggingLevel (scheduler)

The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that.

Enum values:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • OFF

TRACE

LoggingLevel

scheduledExecutorService (scheduler)

Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool.

 

ScheduledExecutorService

scheduler (scheduler)

To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler.

none

Object

schedulerProperties (scheduler)

To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler.

 

Map

startScheduler (scheduler)

Whether the scheduler should be auto started.

true

boolean

timeUnit (scheduler)

Time unit for initialDelay and delay options.

Enum values:

  • NANOSECONDS
  • MICROSECONDS
  • MILLISECONDS
  • SECONDS
  • MINUTES
  • HOURS
  • DAYS

MILLISECONDS

TimeUnit

useFixedDelay (scheduler)

Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details.

true

boolean

accessKey (security)

Access key for the associated azure account name to be used for authentication with azure blob services.

 

String

sourceBlobAccessKey (security)

Source Blob Access Key: for copyblob operation, sadly, we need to have an accessKey for the source blob we want to copy Passing an accessKey as header, it’s unsafe so we could set as key.

 

String

Required information options

To use this component, you have 3 options in order to provide the required Azure authentication information:

  • Provide a link: BlobServiceClient instance which can be injected into blobServiceClient. Note: No need to create a specific client, for Examples: BlockBlobClient, the BlobServiceClient represents the upper level which can be used to retrieve lower level clients.
  • Provide an Azure Identity, when specifying credentialType=AZURE_IDENTITY and providing required environment variables. This enables service principal (for example, app registration) authentication with secret/certificate as well as username password. Note that this is the default authentication strategy.
  • Provide a shared storage account key, when specifying credentialType=SHARED_ACCOUNT_KEY and providing accountName and accessKey for your Azure account, this is the simplest way to get started. The accessKey can be generated through your Azure portal.
  • Provide a shared storage account key, when specifying credentialType=SHARED_KEY_CREDENTIAL and providing a StorageSharedKeyCredential instance which can be injected into credentials option.
  • Via Azure SAS, when specifying credentialType=AZURE_SAS and providing a SAS Token parameter through the sasToken parameter.

13.6. Usage

For example, in order to download a blob content from the block blob hello.txt located on the container1 in the camelazure storage account, use the following snippet:

from("azure-storage-blob://camelazure/container1?blobName=hello.txt&credentialType=SHARED_ACCOUNT_KEY&accessKey=RAW(yourAccessKey)").to("file://blobdirectory");

13.6.1. Message headers

The Azure Storage Blob Service component supports 63 message header(s), which is/are listed below:

HeaderVariable NameTypeOperationsDescription

CamelAzureStorageBlobTimeout

BlobConstants.TIMEOUT

Duration

All

An optional timeout value beyond which a {@link RuntimeException} will be raised.

CamelAzureStorageBlobMetadata

BlobConstants.METADATA

Map<String,String>

Operations related to container and blob

Metadata to associate with the container or blob.

CamelAzureStorageBlobPublicAccessType

BlobConstants.PUBLIC_ACCESS_TYPE

PublicAccessType

createContainer

Specifies how the data in this container is available to the public. Pass null for no public access.

CamelAzureStorageBlobRequestCondition

BlobConstants.BLOB_REQUEST_CONDITION

BlobRequestConditions

Operations related to container and blob

This contains values which will restrict the successful operation of a variety of requests to the conditions present. These conditions are entirely optional.

CamelAzureStorageBlobListDetails

BlobConstants.BLOB_LIST_DETAILS

BlobListDetails

listBlobs

The details for listing specific blobs

CamelAzureStorageBlobPrefix

BlobConstants.PREFIX

String

listBlobs,getBlob

Filters the results to return only blobs whose names begin with the specified prefix. May be null to return all blobs.

CamelAzureStorageBlobMaxResultsPerPage

BlobConstants.MAX_RESULTS_PER_PAGE

Integer

listBlobs

Specifies the maximum number of blobs to return, including all BlobPrefix elements. If the request does not specify maxResultsPerPage or specifies a value greater than 5,000, the server will return up to 5,000 items.

CamelAzureStorageBlobListBlobOptions

BlobConstants.LIST_BLOB_OPTIONS

ListBlobsOptions

listBlobs

Defines options available to configure the behavior of a call to listBlobsFlatSegment on a {@link BlobContainerClient} object.

CamelAzureStorageBlobHttpHeaders

BlobConstants.BLOB_HTTP_HEADERS

BlobHttpHeaders

uploadBlockBlob, commitBlobBlockList, createAppendBlob, createPageBlob

Additional parameters for a set of operations.

CamelAzureStorageBlobAccessTier

BlobConstants.ACCESS_TIER

AccessTier

uploadBlockBlob, commitBlobBlockList

Defines values for AccessTier.

CamelAzureStorageBlobContentMD5

BlobConstants.CONTENT_MD5

byte[]

Most operations related to upload blob

An MD5 hash of the block content. This hash is used to verify the integrity of the block during transport. When this header is specified, the storage service compares the hash of the content that has arrived with this header value. Note that this MD5 hash is not stored with the blob. If the two hashes do not match, the operation will fail.

CamelAzureStorageBlobPageBlobRange

BlobConstants.PAGE_BLOB_RANGE

PageRange

Operations related to page blob

A {@link PageRange} object. Given that pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the end offset must be a modulus of 512 - 1. Examples of valid byte ranges are 0-511, 512-1023, etc.

CamelAzureStorageBlobCommitBlobBlockListLater

BlobConstants.COMMIT_BLOCK_LIST_LATER

boolean

stageBlockBlobList

When is set to true, the staged blocks will not be committed directly.

CamelAzureStorageBlobCreateAppendBlob

BlobConstants.CREATE_APPEND_BLOB

boolean

commitAppendBlob

When is set to true, the append blocks will be created when committing append blocks.

CamelAzureStorageBlobCreatePageBlob

BlobConstants.CREATE_PAGE_BLOB

boolean

uploadPageBlob

When is set to true, the page blob will be created when uploading page blob.

CamelAzureStorageBlobBlockListType

BlobConstants.BLOCK_LIST_TYPE

BlockListType

getBlobBlockList

Specifies which type of blocks to return.

CamelAzureStorageBlobPageBlobSize

BlobConstants.PAGE_BLOB_SIZE

Long

createPageBlob, resizePageBlob

Specifies the maximum size for the page blob, up to 8 TB. The page blob size must be aligned to a 512-byte boundary.

CamelAzureStorageBlobSequenceNumber

BlobConstants.BLOB_SEQUENCE_NUMBER

Long

createPageBlob

A user-controlled value that you can use to track requests. The value of the sequence number must be between 0 and 2^63 - 1.The default value is 0.

CamelAzureStorageBlobDeleteSnapshotsOptionType

BlobConstants.DELETE_SNAPSHOT_OPTION_TYPE

DeleteSnapshotsOptionType

deleteBlob

Specifies the behavior for deleting the snapshots on this blob. \{@code Include} will delete the base blob and all snapshots. \{@code Only} will delete only the snapshots. If a snapshot is being deleted, you must pass null.

CamelAzureStorageBlobListBlobContainersOptions

BlobConstants.LIST_BLOB_CONTAINERS_OPTIONS

ListBlobContainersOptions

listBlobContainers

A {@link ListBlobContainersOptions} which specifies what data should be returned by the service.

CamelAzureStorageBlobParallelTransferOptions

BlobConstants.PARALLEL_TRANSFER_OPTIONS

ParallelTransferOptions

downloadBlobToFile

{@link ParallelTransferOptions} to use to download to file. Number of parallel transfers parameter is ignored.

CamelAzureStorageBlobFileDir

BlobConstants.FILE_DIR

String

downloadBlobToFile

The file directory where the downloaded blobs will be saved to.

CamelAzureStorageBlobDownloadLinkExpiration

BlobConstants.DOWNLOAD_LINK_EXPIRATION

Long

downloadLink

Override the default expiration (millis) of URL download link.

CamelAzureStorageBlobBlobName

BlobConstants.BLOB_NAME

String

Operations related to blob

Override/set the blob name on the exchange headers.

CamelAzureStorageBlobContainerName

BlobConstants.BLOB_CONTAINER_NAME

String

Operations related to container and blob

Override/set the container name on the exchange headers.

CamelAzureStorageBlobOperation

BlobConstants.BLOB_OPERATION

BlobOperationsDefinition

All

Specify the producer operation to execute, please see the doc on this page related to producer operation.

CamelAzureStorageBlobRegex

BlobConstants.REGEX

String

listBlobs,getBlob

Filters the results to return only blobs whose names match the specified regular expression. May be null to return all. If both prefix and regex are set, regex takes the priority and prefix is ignored.

CamelAzureStorageBlobChangeFeedStartTime

BlobConstants.CHANGE_FEED_START_TIME

OffsetDateTime

getChangeFeed

It filters the results to return events approximately after the start time. Note: A few events belonging to the previous hour can also be returned. A few events belonging to this hour can be missing; to ensure all events from the hour are returned, round the start time down by an hour.

CamelAzureStorageBlobChangeFeedEndTime

BlobConstants.CHANGE_FEED_END_TIME

OffsetDateTime

getChangeFeed

It filters the results to return events approximately before the end time. Note: A few events belonging to the next hour can also be returned. A few events belonging to this hour can be missing; to ensure all events from the hour are returned, round the end time up by an hour.

CamelAzureStorageBlobChangeFeedContext

BlobConstants.CHANGE_FEED_CONTEXT

Context

getChangeFeed

This gives additional context that is passed through the Http pipeline during the service call.

CamelAzureStorageBlobSourceBlobAccountName

BlobConstants.SOURCE_BLOB_ACCOUNT_NAME

String

copyBlob

The source blob account name to be used as source account name in a copy blob operation

CamelAzureStorageBlobSourceBlobContainerName

BlobConstants.SOURCE_BLOB_CONTAINER_NAME

String

copyBlob

The source blob container name to be used as source container name in a copy blob operation

13.6.2. Message headers set by either component producer or consumer

HeaderVariable NameTypeDescription

CamelAzureStorageBlobAccessTier

BlobConstants.ACCESS_TIER

AccessTier

Access tier of the blob.

CamelAzureStorageBlobAccessTierChangeTime

BlobConstants.ACCESS_TIER_CHANGE_TIME

OffsetDateTime

Datetime when the access tier of the blob last changed.

CamelAzureStorageBlobArchiveStatus

BlobConstants.ARCHIVE_STATUS

ArchiveStatus

Archive status of the blob.

CamelAzureStorageBlobCreationTime

BlobConstants.CREATION_TIME

OffsetDateTime

Creation time of the blob.

CamelAzureStorageBlobSequenceNumber

BlobConstants.BLOB_SEQUENCE_NUMBER

Long

The current sequence number for a page blob.

CamelAzureStorageBlobBlobSize

BlobConstants.BLOB_SIZE

long

The size of the blob.

CamelAzureStorageBlobBlobType

BlobConstants.BLOB_TYPE

BlobType

The type of the blob.

CamelAzureStorageBlobCacheControl

BlobConstants.CACHE_CONTROL

String

Cache control specified for the blob.

CamelAzureStorageBlobCommittedBlockCount

BlobConstants.COMMITTED_BLOCK_COUNT

Integer

Number of blocks committed to an append blob

CamelAzureStorageBlobContentDisposition

BlobConstants.CONTENT_DISPOSITION

String

Content disposition specified for the blob.

CamelAzureStorageBlobContentEncoding

BlobConstants.CONTENT_ENCODING

String

Content encoding specified for the blob.

CamelAzureStorageBlobContentLanguage

BlobConstants.CONTENT_LANGUAGE

String

Content language specified for the blob.

CamelAzureStorageBlobContentMd5

BlobConstants.CONTENT_MD5

byte[]

Content MD5 specified for the blob.

CamelAzureStorageBlobContentType

BlobConstants.CONTENT_TYPE

String

Content type specified for the blob.

CamelAzureStorageBlobCopyCompletionTime

BlobConstants.COPY_COMPILATION_TIME

OffsetDateTime

Datetime when the last copy operation on the blob completed.

CamelAzureStorageBlobCopyDestinationSnapshot

BlobConstants.COPY_DESTINATION_SNAPSHOT

String

Snapshot identifier of the last incremental copy snapshot for the blob.

CamelAzureStorageBlobCopyId

BlobConstants.COPY_ID

String

Identifier of the last copy operation performed on the blob.

CamelAzureStorageBlobCopyProgress

BlobConstants.COPY_PROGRESS

String

Progress of the last copy operation performed on the blob.

CamelAzureStorageBlobCopySource

BlobConstants.COPY_SOURCE

String

Source of the last copy operation performed on the blob.

CamelAzureStorageBlobCopyStatus

BlobConstants.COPY_STATUS

CopyStatusType

Status of the last copy operation performed on the blob.

CamelAzureStorageBlobCopyStatusDescription

BlobConstants.COPY_STATUS_DESCRIPTION

String

Description of the last copy operation on the blob.

CamelAzureStorageBlobETag

BlobConstants.E_TAG

String

The E Tag of the blob

CamelAzureStorageBlobIsAccessTierInferred

BlobConstants.IS_ACCESS_TIER_INFRRRED

boolean

Flag indicating if the access tier of the blob was inferred from properties of the blob.

CamelAzureStorageBlobIsIncrementalCopy

BlobConstants.IS_INCREMENTAL_COPY

boolean

Flag indicating if the blob was incrementally copied.

CamelAzureStorageBlobIsServerEncrypted

BlobConstants.IS_SERVER_ENCRYPTED

boolean

Flag indicating if the blob’s content is encrypted on the server.

CamelAzureStorageBlobLastModified

BlobConstants.LAST_MODIFIED

OffsetDateTime

Datetime when the blob was last modified.

CamelAzureStorageBlobLeaseDuration

BlobConstants.LEASE_DURATION

LeaseDurationType

Type of lease on the blob.

CamelAzureStorageBlobLeaseState

BlobConstants.LEASE_STATE

LeaseStateType

State of the lease on the blob.

CamelAzureStorageBlobLeaseStatus

BlobConstants.LEASE_STATUS

LeaseStatusType

Status of the lease on the blob.

CamelAzureStorageBlobMetadata

BlobConstants.METADATA

Map<String, String>

Additional metadata associated with the blob.

CamelAzureStorageBlobAppendOffset

BlobConstants.APPEND_OFFSET

String

The offset at which the block was committed to the block blob.

CamelAzureStorageBlobFileName

BlobConstants.FILE_NAME

String

The downloaded filename from the operation downloadBlobToFile.

CamelAzureStorageBlobDownloadLink

BlobConstants.DOWNLOAD_LINK

String

The download link generated by downloadLink operation.

CamelAzureStorageBlobRawHttpHeaders

BlobConstants.RAW_HTTP_HEADERS

HttpHeaders

Returns non-parsed httpHeaders that can be used by the user.

13.6.3. Advanced Azure Storage Blob configuration

If your Camel Application is running behind a firewall or if you need to have more control over the BlobServiceClient instance configuration, you can create your own instance:

StorageSharedKeyCredential credential = new StorageSharedKeyCredential("yourAccountName", "yourAccessKey");
String uri = String.format("https://%s.blob.core.windows.net", "yourAccountName");

BlobServiceClient client = new BlobServiceClientBuilder()
                          .endpoint(uri)
                          .credential(credential)
                          .buildClient();
// This is camel context
context.getRegistry().bind("client", client);

Then refer to this instance in your Camel azure-storage-blob component configuration:

from("azure-storage-blob://cameldev/container1?blobName=myblob&serviceClient=#client")
.to("mock:result");

13.6.4. Automatic detection of BlobServiceClient client in registry

The component is capable of detecting the presence of an BlobServiceClient bean into the registry. If it’s the only instance of that type it will be used as client and you won’t have to define it as uri parameter, like the example above. This may be really useful for smarter configuration of the endpoint.

13.6.5. Azure Storage Blob Producer operations

Camel Azure Storage Blob component provides wide range of operations on the producer side:

Operations on the service level

For these operations, accountName is required.

OperationDescription

listBlobContainers

Get the content of the blob. You can restrict the output of this operation to a blob range.

getChangeFeed

Returns transaction logs of all the changes that occur to the blobs and the blob metadata in your storage account. The change feed provides ordered, guaranteed, durable, immutable, read-only log of these changes.

Operations on the container level

For these operations, accountName and containerName are required.

OperationDescription

createBlobContainer

Creates a new container within a storage account. If a container with the same name already exists, the producer will ignore it.

deleteBlobContainer

Deletes the specified container in the storage account. If the container doesn’t exist the operation fails.

listBlobs

Returns a list of blobs in this container, with folder structures flattened.

Operations on the blob level

For these operations, accountName, containerName and blobName are required.

OperationBlob TypeDescription

getBlob

Common

Get the content of the blob. You can restrict the output of this operation to a blob range.

deleteBlob

Common

Delete a blob.

downloadBlobToFile

Common

Downloads the entire blob into a file specified by the path.The file will be created and must not exist, if the file already exists a {@link FileAlreadyExistsException} will be thrown.

downloadLink

Common

Generates the download link for the specified blob using shared access signatures (SAS). This by default only limit to 1hour of allowed access. However, you can override the default expiration duration through the headers.

uploadBlockBlob

BlockBlob

Creates a new block blob, or updates the content of an existing block blob. Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with PutBlob; the content of the existing blob is overwritten with the new content.

stageBlockBlobList

BlockBlob

Uploads the specified block to the block blob’s "staging area" to be later committed by a call to commitBlobBlockList. However in case header CamelAzureStorageBlobCommitBlobBlockListLater or config commitBlockListLater is set to false, this will commit the blocks immediately after staging the blocks.

commitBlobBlockList

BlockBlob

Writes a blob by specifying the list of block IDs that are to make up the blob. In order to be written as part of a blob, a block must have been successfully written to the server in a prior stageBlockBlobList operation. You can call commitBlobBlockList to update a blob by uploading only those blocks that have changed, then committing the new and existing blocks together. Any blocks not specified in the block list and permanently deleted.

getBlobBlockList

BlockBlob

Returns the list of blocks that have been uploaded as part of a block blob using the specified block list filter.

createAppendBlob

AppendBlob

Creates a 0-length append blob. Call commitAppendBlo`b operation to append data to an append blob.

commitAppendBlob

AppendBlob

Commits a new block of data to the end of the existing append blob. In case of header CamelAzureStorageBlobCreateAppendBlob or config createAppendBlob is set to true, it will attempt to create the appendBlob through internal call to createAppendBlob operation first before committing.

createPageBlob

PageBlob

Creates a page blob of the specified length. Call uploadPageBlob operation to upload data data to a page blob.

uploadPageBlob

PageBlob

Writes one or more pages to the page blob. The write size must be a multiple of 512. In case of header CamelAzureStorageBlobCreatePageBlob or config createPageBlob is set to true, it will attempt to create the appendBlob through internal call to createPageBlob operation first before uploading.

resizePageBlob

PageBlob

Resizes the page blob to the specified size (which must be a multiple of 512).

clearPageBlob

PageBlob

Frees the specified pages from the page blob. The size of the range must be a multiple of 512.

getPageBlobRanges

PageBlob

Returns the list of valid page ranges for a page blob or snapshot of a page blob.

copyBlob

Common

Copy a blob from one container to another one, even from different accounts.

Refer to the example section in this page to learn how to use these operations into your camel application.

13.6.6. Consumer Examples

To consume a blob into a file using file component, this can be done like this:

from("azure-storage-blob://camelazure/container1?blobName=hello.txt&accountName=yourAccountName&accessKey=yourAccessKey").
to("file://blobdirectory");

However, you can also write to file directly without using the file component, you will need to specify fileDir folder path in order to save your blob in your machine.

from("azure-storage-blob://camelazure/container1?blobName=hello.txt&accountName=yourAccountName&accessKey=yourAccessKey&fileDir=/var/to/awesome/dir").
to("mock:results");

Also, the component supports batch consumer, hence you can consume multiple blobs with only specifying the container name, the consumer will return multiple exchanges depending on the number of the blobs in the container.

Example

from("azure-storage-blob://camelazure/container1?accountName=yourAccountName&accessKey=yourAccessKey&fileDir=/var/to/awesome/dir").
to("mock:results");

13.6.7. Producer Operations Examples

  • listBlobContainers
from("direct:start")
  .process(exchange -> {
    // set the header you want the producer to evaluate, refer to the previous
    // section to learn about the headers that can be set
    // e.g:
    exchange.getIn().setHeader(BlobConstants.LIST_BLOB_CONTAINERS_OPTIONS, new ListBlobContainersOptions().setMaxResultsPerPage(10));
  })
  .to("azure-storage-blob://camelazure?operation=listBlobContainers&client&serviceClient=#client")
  .to("mock:result");
  • createBlobContainer
from("direct:start")
  .process(exchange -> {
    // set the header you want the producer to evaluate, refer to the previous
    // section to learn about the headers that can be set
    // e.g:
    exchange.getIn().setHeader(BlobConstants.BLOB_CONTAINER_NAME, "newContainerName");
  })
  .to("azure-storage-blob://camelazure/container1?operation=createBlobContainer&serviceClient=#client")
  .to("mock:result");
  • deleteBlobContainer:
from("direct:start")
  .process(exchange -> {
    // set the header you want the producer to evaluate, refer to the previous
    // section to learn about the headers that can be set
    // e.g:
    exchange.getIn().setHeader(BlobConstants.BLOB_CONTAINER_NAME, "overridenName");
  })
  .to("azure-storage-blob://camelazure/container1?operation=deleteBlobContainer&serviceClient=#client")
  .to("mock:result");
  • listBlobs:
from("direct:start")
  .process(exchange -> {
    // set the header you want the producer to evaluate, refer to the previous
    // section to learn about the headers that can be set
    // e.g:
    exchange.getIn().setHeader(BlobConstants.BLOB_CONTAINER_NAME, "overridenName");
  })
  .to("azure-storage-blob://camelazure/container1?operation=listBlobs&serviceClient=#client")
  .to("mock:result");
  • getBlob:

We can either set an outputStream in the exchange body and write the data to it. E.g:

from("direct:start")
  .process(exchange -> {
    // set the header you want the producer to evaluate, refer to the previous
    // section to learn about the headers that can be set
    // e.g:
    exchange.getIn().setHeader(BlobConstants.BLOB_CONTAINER_NAME, "overridenName");

    // set our body
    exchange.getIn().setBody(outputStream);
  })
  .to("azure-storage-blob://camelazure/container1?blobName=blob&operation=getBlob&serviceClient=#client")
  .to("mock:result");

If we don’t set a body, then this operation will give us an InputStream instance which can proceeded further downstream:

from("direct:start")
  .to("azure-storage-blob://camelazure/container1?blobName=blob&operation=getBlob&serviceClient=#client")
  .process(exchange -> {
      InputStream inputStream = exchange.getMessage().getBody(InputStream.class);
      // We use Apache common IO for simplicity, but you are free to do whatever dealing
      // with inputStream
      System.out.println(IOUtils.toString(inputStream, StandardCharsets.UTF_8.name()));
  })
  .to("mock:result");
  • deleteBlob:
from("direct:start")
  .process(exchange -> {
    // set the header you want the producer to evaluate, refer to the previous
    // section to learn about the headers that can be set
    // e.g:
    exchange.getIn().setHeader(BlobConstants.BLOB_NAME, "overridenName");
  })
  .to("azure-storage-blob://camelazure/container1?blobName=blob&operation=deleteBlob&serviceClient=#client")
  .to("mock:result");
  • downloadBlobToFile:
from("direct:start")
  .process(exchange -> {
    // set the header you want the producer to evaluate, refer to the previous
    // section to learn about the headers that can be set
    // e.g:
    exchange.getIn().setHeader(BlobConstants.BLOB_NAME, "overridenName");
  })
  .to("azure-storage-blob://camelazure/container1?blobName=blob&operation=downloadBlobToFile&fileDir=/var/mydir&serviceClient=#client")
  .to("mock:result");
  • downloadLink
from("direct:start")
  .to("azure-storage-blob://camelazure/container1?blobName=blob&operation=downloadLink&serviceClient=#client")
  .process(exchange -> {
      String link = exchange.getMessage().getHeader(BlobConstants.DOWNLOAD_LINK, String.class);
      System.out.println("My link " + link);
  })
  .to("mock:result");
  • uploadBlockBlob
from("direct:start")
  .process(exchange -> {
    // set the header you want the producer to evaluate, refer to the previous
    // section to learn about the headers that can be set
    // e.g:
    exchange.getIn().setHeader(BlobConstants.BLOB_NAME, "overridenName");
    exchange.getIn().setBody("Block Blob");
  })
  .to("azure-storage-blob://camelazure/container1?blobName=blob&operation=uploadBlockBlob&serviceClient=#client")
  .to("mock:result");
  • stageBlockBlobList
from("direct:start")
  .process(exchange -> {
      final List<BlobBlock> blocks = new LinkedList<>();
      blocks.add(BlobBlock.createBlobBlock(new ByteArrayInputStream("Hello".getBytes())));
      blocks.add(BlobBlock.createBlobBlock(new ByteArrayInputStream("From".getBytes())));
      blocks.add(BlobBlock.createBlobBlock(new ByteArrayInputStream("Camel".getBytes())));

      exchange.getIn().setBody(blocks);
  })
  .to("azure-storage-blob://camelazure/container1?blobName=blob&operation=stageBlockBlobList&serviceClient=#client")
  .to("mock:result");
  • commitBlockBlobList
from("direct:start")
  .process(exchange -> {
      // We assume here you have the knowledge of these blocks you want to commit
      final List<Block> blocksIds = new LinkedList<>();
      blocksIds.add(new Block().setName("id-1"));
      blocksIds.add(new Block().setName("id-2"));
      blocksIds.add(new Block().setName("id-3"));

      exchange.getIn().setBody(blocksIds);
  })
  .to("azure-storage-blob://camelazure/container1?blobName=blob&operation=commitBlockBlobList&serviceClient=#client")
  .to("mock:result");
  • getBlobBlockList
from("direct:start")
  .to("azure-storage-blob://camelazure/container1?blobName=blob&operation=getBlobBlockList&serviceClient=#client")
  .log("${body}")
  .to("mock:result");
  • createAppendBlob
from("direct:start")
  .to("azure-storage-blob://camelazure/container1?blobName=blob&operation=createAppendBlob&serviceClient=#client")
  .to("mock:result");
  • commitAppendBlob
from("direct:start")
  .process(exchange -> {
    final String data = "Hello world from my awesome tests!";
    final InputStream dataStream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));

    exchange.getIn().setBody(dataStream);

    // of course you can set whatever headers you like, refer to the headers section to learn more
  })
  .to("azure-storage-blob://camelazure/container1?blobName=blob&operation=commitAppendBlob&serviceClient=#client")
  .to("mock:result");
  • createPageBlob
from("direct:start")
  .to("azure-storage-blob://camelazure/container1?blobName=blob&operation=createPageBlob&serviceClient=#client")
  .to("mock:result");
  • uploadPageBlob
from("direct:start")
  .process(exchange -> {
    byte[] dataBytes = new byte[512]; // we set range for the page from 0-511
    new Random().nextBytes(dataBytes);
    final InputStream dataStream = new ByteArrayInputStream(dataBytes);
    final PageRange pageRange = new PageRange().setStart(0).setEnd(511);

    exchange.getIn().setHeader(BlobConstants.PAGE_BLOB_RANGE, pageRange);
    exchange.getIn().setBody(dataStream);
  })
  .to("azure-storage-blob://camelazure/container1?blobName=blob&operation=uploadPageBlob&serviceClient=#client")
  .to("mock:result");
  • resizePageBlob
from("direct:start")
  .process(exchange -> {
    final PageRange pageRange = new PageRange().setStart(0).setEnd(511);

    exchange.getIn().setHeader(BlobConstants.PAGE_BLOB_RANGE, pageRange);
  })
  .to("azure-storage-blob://camelazure/container1?blobName=blob&operation=resizePageBlob&serviceClient=#client")
  .to("mock:result");
  • clearPageBlob
from("direct:start")
  .process(exchange -> {
    final PageRange pageRange = new PageRange().setStart(0).setEnd(511);

    exchange.getIn().setHeader(BlobConstants.PAGE_BLOB_RANGE, pageRange);
  })
  .to("azure-storage-blob://camelazure/container1?blobName=blob&operation=clearPageBlob&serviceClient=#client")
  .to("mock:result");
  • getPageBlobRanges
from("direct:start")
  .process(exchange -> {
    final PageRange pageRange = new PageRange().setStart(0).setEnd(511);

    exchange.getIn().setHeader(BlobConstants.PAGE_BLOB_RANGE, pageRange);
  })
  .to("azure-storage-blob://camelazure/container1?blobName=blob&operation=getPageBlobRanges&serviceClient=#client")
  .log("${body}")
  .to("mock:result");
  • copyBlob
from("direct:copyBlob")
  .process(exchange -> {
    exchange.getIn().setHeader(BlobConstants.BLOB_NAME, "file.txt");
    exchange.getMessage().setHeader(BlobConstants.SOURCE_BLOB_CONTAINER_NAME, "containerblob1");
    exchange.getMessage().setHeader(BlobConstants.SOURCE_BLOB_ACCOUNT_NAME, "account");
  })
  .to("azure-storage-blob://account/containerblob2?operation=copyBlob&sourceBlobAccessKey=RAW(accessKey)")
  .to("mock:result");

In this way the file.txt in the container containerblob1 of the account 'account', will be copied to the container containerblob2 of the same account.

13.6.8. SAS Token generation example

SAS Blob Container tokens can be generated programmatically or via Azure UI. To generate the token with java code, the following can be done:

BlobContainerClient blobClient = new BlobContainerClientBuilder()
            .endpoint(String.format("https://%s.blob.core.windows.net/%s", accountName, accessKey))
            .containerName(containerName)
            .credential(new StorageSharedKeyCredential(accountName, accessKey))
            .buildClient();

        // Create a SAS token that's valid for 1 day, as an example
        OffsetDateTime expiryTime = OffsetDateTime.now().plusDays(1);

        // Assign permissions to the SAS token
        BlobContainerSasPermission blobContainerSasPermission = new BlobContainerSasPermission()
            .setWritePermission(true)
            .setListPermission(true)
            .setCreatePermission(true)
            .setDeletePermission(true)
            .setAddPermission(true)
            .setReadPermission(true);

        BlobServiceSasSignatureValues sasSignatureValues = new BlobServiceSasSignatureValues(expiryTime, blobContainerSasPermission);

        return blobClient.generateSas(sasSignatureValues);

The generated SAS token can be then stored to an application.properties file so that it can be loaded by the camel route, for example:

camel.component.azure-storage-blob.sas-token=MY_TOKEN_HERE

from("direct:copyBlob")
  .to("azure-storage-blob://account/containerblob2?operation=uploadBlockBlob&credentialType=AZURE_SAS")

13.7. Spring Boot Auto-Configuration

The component supports 36 options, which are listed below.

NameDescriptionDefaultType

camel.component.azure-storage-blob.access-key

Access key for the associated azure account name to be used for authentication with azure blob services.

 

String

camel.component.azure-storage-blob.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.azure-storage-blob.blob-name

The blob name, to consume specific blob from a container. However on producer, is only required for the operations on the blob level.

 

String

camel.component.azure-storage-blob.blob-offset

Set the blob offset for the upload or download operations, default is 0.

0

Long

camel.component.azure-storage-blob.blob-sequence-number

A user-controlled value that you can use to track requests. The value of the sequence number must be between 0 and 263 - 1.The default value is 0.

0

Long

camel.component.azure-storage-blob.blob-type

The blob type in order to initiate the appropriate settings for each blob type.

 

BlobType

camel.component.azure-storage-blob.block-list-type

Specifies which type of blocks to return.

 

BlockListType

camel.component.azure-storage-blob.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.azure-storage-blob.change-feed-context

When using getChangeFeed producer operation, this gives additional context that is passed through the Http pipeline during the service call. The option is a com.azure.core.util.Context type.

 

Context

camel.component.azure-storage-blob.change-feed-end-time

When using getChangeFeed producer operation, this filters the results to return events approximately before the end time. Note: A few events belonging to the next hour can also be returned. A few events belonging to this hour can be missing; to ensure all events from the hour are returned, round the end time up by an hour. The option is a java.time.OffsetDateTime type.

 

OffsetDateTime

camel.component.azure-storage-blob.change-feed-start-time

When using getChangeFeed producer operation, this filters the results to return events approximately after the start time. Note: A few events belonging to the previous hour can also be returned. A few events belonging to this hour can be missing; to ensure all events from the hour are returned, round the start time down by an hour. The option is a java.time.OffsetDateTime type.

 

OffsetDateTime

camel.component.azure-storage-blob.close-stream-after-read

Close the stream after read or keep it open, default is true.

true

Boolean

camel.component.azure-storage-blob.close-stream-after-write

Close the stream after write or keep it open, default is true.

true

Boolean

camel.component.azure-storage-blob.commit-block-list-later

When is set to true, the staged blocks will not be committed directly.

true

Boolean

camel.component.azure-storage-blob.configuration

The component configurations. The option is a org.apache.camel.component.azure.storage.blob.BlobConfiguration type.

 

BlobConfiguration

camel.component.azure-storage-blob.create-append-blob

When is set to true, the append blocks will be created when committing append blocks.

true

Boolean

camel.component.azure-storage-blob.create-page-blob

When is set to true, the page blob will be created when uploading page blob.

true

Boolean

camel.component.azure-storage-blob.credential-type

Determines the credential strategy to adopt.

 

CredentialType

camel.component.azure-storage-blob.credentials

StorageSharedKeyCredential can be injected to create the azure client, this holds the important authentication information. The option is a com.azure.storage.common.StorageSharedKeyCredential type.

 

StorageSharedKeyCredential

camel.component.azure-storage-blob.data-count

How many bytes to include in the range. Must be greater than or equal to 0 if specified.

 

Long

camel.component.azure-storage-blob.download-link-expiration

Override the default expiration (millis) of URL download link.

 

Long

camel.component.azure-storage-blob.enabled

Whether to enable auto configuration of the azure-storage-blob component. This is enabled by default.

 

Boolean

camel.component.azure-storage-blob.file-dir

The file directory where the downloaded blobs will be saved to, this can be used in both, producer and consumer.

 

String

camel.component.azure-storage-blob.health-check-consumer-enabled

Used for enabling or disabling all consumer based health checks from this component.

true

Boolean

camel.component.azure-storage-blob.health-check-producer-enabled

Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true.

true

Boolean

camel.component.azure-storage-blob.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.azure-storage-blob.max-results-per-page

Specifies the maximum number of blobs to return, including all BlobPrefix elements. If the request does not specify maxResultsPerPage or specifies a value greater than 5,000, the server will return up to 5,000 items.

 

Integer

camel.component.azure-storage-blob.max-retry-requests

Specifies the maximum number of additional HTTP Get requests that will be made while reading the data from a response body.

0

Integer

camel.component.azure-storage-blob.operation

The blob operation that can be used with this component on the producer.

 

BlobOperationsDefinition

camel.component.azure-storage-blob.page-blob-size

Specifies the maximum size for the page blob, up to 8 TB. The page blob size must be aligned to a 512-byte boundary.

512

Long

camel.component.azure-storage-blob.prefix

Filters the results to return only blobs whose names begin with the specified prefix. May be null to return all blobs.

 

String

camel.component.azure-storage-blob.regex

Filters the results to return only blobs whose names match the specified regular expression. May be null to return all if both prefix and regex are set, regex takes the priority and prefix is ignored.

 

String

camel.component.azure-storage-blob.sas-token

Set a SAS Token in case of usage of Shared Access Signature

 

String

camel.component.azure-storage-blob.service-client

Client to a storage account. This client does not hold any state about a particular storage account but is instead a convenient way of sending off appropriate requests to the resource on the service. It may also be used to construct URLs to blobs and containers. This client contains operations on a service account. Operations on a container are available on BlobContainerClient through BlobServiceClient#getBlobContainerClient(String), and operations on a blob are available on BlobClient through BlobContainerClient#getBlobClient(String). The option is a com.azure.storage.blob.BlobServiceClient type.

 

BlobServiceClient

camel.component.azure-storage-blob.source-blob-access-key

Source Blob Access Key: for copyblob operation, sadly, we need to have an accessKey for the source blob we want to copy Passing an accessKey as header, it’s unsafe so we could set as key.

 

String

camel.component.azure-storage-blob.timeout

An optional timeout value beyond which a RuntimeException will be raised. The option is a java.time.Duration type.

 

Duration

Chapter 14. Azure Storage Queue Service

Both producer and consumer are supported

The Azure Storage Queue component supports storing and retrieving the messages to/from Azure Storage Queue service using Azure APIs v12. However in case of versions above v12, we will see if this component can adopt these changes depending on how much breaking changes can result.

Prerequisites

You must have a valid Windows Azure Storage account. More information is available at Azure Documentation Portal.

14.1. Dependencies

When using azure-storage-queue with Red Hat build of Camel Spring Boot, add the following Maven dependency to your pom.xml to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-azure-storage-queue-starter</artifactId>
</dependency>

14.2. URI Format

azure-storage-queue://accountName[/queueName][?options]

In case of consumer, accountName and queueName are required. In case of producer, it depends on the operation that being requested, for example if operation is on a service level, e.b: listQueues, only accountName is required, but in case of operation being requested on the queue level, for example, createQueue, sendMessage.. etc, both accountName and queueName are required.

The queue will be created if it does not already exist. You can append query options to the URI in the following format,

?options=value&option2=value&…

14.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

14.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

14.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

14.4. Component Options

The Azure Storage Queue Service component supports 15 options, which are listed below.

NameDescriptionDefaultType

configuration (common)

The component configurations.

 

QueueConfiguration

serviceClient (common)

Autowired Service client to a storage account to interact with the queue service. This client does not hold any state about a particular storage account but is instead a convenient way of sending off appropriate requests to the resource on the service. This client contains all the operations for interacting with a queue account in Azure Storage. Operations allowed by the client are creating, listing, and deleting queues, retrieving and updating properties of the account, and retrieving statistics of the account.

 

QueueServiceClient

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

createQueue (producer)

When is set to true, the queue will be automatically created when sending messages to the queue.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

operation (producer)

Queue service operation hint to the producer.

Enum values:

  • listQueues
  • createQueue
  • deleteQueue
  • clearQueue
  • sendMessage
  • deleteMessage
  • receiveMessages
  • peekMessages
  • updateMessage
 

QueueOperationDefinition

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

maxMessages (queue)

Maximum number of messages to get, if there are less messages exist in the queue than requested all the messages will be returned. If left empty only 1 message will be retrieved, the allowed range is 1 to 32 messages.

1

Integer

messageId (queue)

The ID of the message to be deleted or updated.

 

String

popReceipt (queue)

Unique identifier that must match for the message to be deleted or updated.

 

String

timeout (queue)

An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.

 

Duration

timeToLive (queue)

How long the message will stay alive in the queue. If unset the value will default to 7 days, if -1 is passed the message will not expire. The time to live must be -1 or any positive number. The format should be in this form: PnDTnHnMn.nS., e.g: PT20.345S — parses as 20.345 seconds, P2D — parses as 2 days However, in case you are using EndpointDsl/ComponentDsl, you can do something like Duration.ofSeconds() since these Java APIs are typesafe.

 

Duration

visibilityTimeout (queue)

The timeout period for how long the message is invisible in the queue. The timeout must be between 1 seconds and 7 days. The format should be in this form: PnDTnHnMn.nS., e.g: PT20.345S — parses as 20.345 seconds, P2D — parses as 2 days However, in case you are using EndpointDsl/ComponentDsl, you can do something like Duration.ofSeconds() since these Java APIs are typesafe.

 

Duration

accessKey (security)

Access key for the associated azure account name to be used for authentication with azure queue services.

 

String

credentials (security)

StorageSharedKeyCredential can be injected to create the azure client, this holds the important authentication information.

 

StorageSharedKeyCredential

14.5. Endpoint Options

The Azure Storage Queue Service endpoint is configured using URI syntax:

azure-storage-queue:accountName/queueName

with the following path and query parameters:

14.5.1. Path Parameters (2 parameters)

NameDescriptionDefaultType

accountName (common)

Azure account name to be used for authentication with azure queue services.

 

String

queueName (common)

The queue resource name.

 

String

14.5.2. Query Parameters (31 parameters)

NameDescriptionDefaultType

serviceClient (common)

Autowired Service client to a storage account to interact with the queue service. This client does not hold any state about a particular storage account but is instead a convenient way of sending off appropriate requests to the resource on the service. This client contains all the operations for interacting with a queue account in Azure Storage. Operations allowed by the client are creating, listing, and deleting queues, retrieving and updating properties of the account, and retrieving statistics of the account.

 

QueueServiceClient

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

sendEmptyMessageWhenIdle (consumer)

If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead.

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

pollStrategy (consumer (advanced))

A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel.

 

PollingConsumerPollStrategy

createQueue (producer)

When is set to true, the queue will be automatically created when sending messages to the queue.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

operation (producer)

Queue service operation hint to the producer.

Enum values:

  • listQueues
  • createQueue
  • deleteQueue
  • clearQueue
  • sendMessage
  • deleteMessage
  • receiveMessages
  • peekMessages
  • updateMessage
 

QueueOperationDefinition

maxMessages (queue)

Maximum number of messages to get, if there are less messages exist in the queue than requested all the messages will be returned. If left empty only 1 message will be retrieved, the allowed range is 1 to 32 messages.

1

Integer

messageId (queue)

The ID of the message to be deleted or updated.

 

String

popReceipt (queue)

Unique identifier that must match for the message to be deleted or updated.

 

String

timeout (queue)

An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown.

 

Duration

timeToLive (queue)

How long the message will stay alive in the queue. If unset the value will default to 7 days, if -1 is passed the message will not expire. The time to live must be -1 or any positive number. The format should be in this form: PnDTnHnMn.nS., e.g: PT20.345S — parses as 20.345 seconds, P2D — parses as 2 days However, in case you are using EndpointDsl/ComponentDsl, you can do something like Duration.ofSeconds() since these Java APIs are typesafe.

 

Duration

visibilityTimeout (queue)

The timeout period for how long the message is invisible in the queue. The timeout must be between 1 seconds and 7 days. The format should be in this form: PnDTnHnMn.nS., e.g: PT20.345S — parses as 20.345 seconds, P2D — parses as 2 days However, in case you are using EndpointDsl/ComponentDsl, you can do something like Duration.ofSeconds() since these Java APIs are typesafe.

 

Duration

backoffErrorThreshold (scheduler)

The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in.

 

int

backoffIdleThreshold (scheduler)

The number of subsequent idle polls that should happen before the backoffMultipler should kick-in.

 

int

backoffMultiplier (scheduler)

To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured.

 

int

delay (scheduler)

Milliseconds before the next poll.

500

long

greedy (scheduler)

If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages.

false

boolean

initialDelay (scheduler)

Milliseconds before the first poll starts.

1000

long

repeatCount (scheduler)

Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever.

0

long

runLoggingLevel (scheduler)

The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that.

Enum values:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • OFF

TRACE

LoggingLevel

scheduledExecutorService (scheduler)

Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool.

 

ScheduledExecutorService

scheduler (scheduler)

To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler.

none

Object

schedulerProperties (scheduler)

To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler.

 

Map

startScheduler (scheduler)

Whether the scheduler should be auto started.

true

boolean

timeUnit (scheduler)

Time unit for initialDelay and delay options.

Enum values:

  • NANOSECONDS
  • MICROSECONDS
  • MILLISECONDS
  • SECONDS
  • MINUTES
  • HOURS
  • DAYS

MILLISECONDS

TimeUnit

useFixedDelay (scheduler)

Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details.

true

boolean

accessKey (security)

Access key for the associated azure account name to be used for authentication with azure queue services.

 

String

credentials (security)

StorageSharedKeyCredential can be injected to create the azure client, this holds the important authentication information.

 

StorageSharedKeyCredential

Required information options

To use this component, you have 3 options in order to provide the required Azure authentication information:

  • Provide accountName and accessKey for your Azure account, this is the simplest way to get started. The accessKey can be generated through your Azure portal.
  • Provide a StorageSharedKeyCredential instance which can be provided into credentials option.
  • Provide a QueueServiceClient instance which can be provided into serviceClient. Note: You don’t need to create a specific client, e.g: QueueClient, the QueueServiceClient represents the upper level which can be used to retrieve lower level clients.

14.6. Usage

For example in order to get a message content from the queue messageQueue in the storageAccount storage account and, use the following snippet:

from("azure-storage-queue://storageAccount/messageQueue?accessKey=yourAccessKey").
to("file://queuedirectory");

14.6.1. Message headers evaluated by the component producer

HeaderVariable NameTypeOperationsDescription

CamelAzureStorageQueueSegmentOptions

QueueConstants.QUEUES_SEGMENT_OPTIONS

QueuesSegmentOptions

listQueues

Options for listing queues

CamelAzureStorageQueueTimeout

QueueConstants.TIMEOUT

Duration

All

An optional timeout value beyond which a \{@link RuntimeException} will be raised.

CamelAzureStorageQueueMetadata

QueueConstants.METADATA

Map<String,String>

createQueue

Metadata to associate with the queue

CamelAzureStorageQueueTimeToLive

QueueConstants.TIME_TO_LIVE

Duration

sendMessage

How long the message will stay alive in the queue. If unset the value will default to 7 days, if -1 is passed the message will not expire. The time to live must be -1 or any positive number.

CamelAzureStorageQueueVisibilityTimeout

QueueConstants.VISIBILITY_TIMEOUT

Duration

sendMessage, receiveMessages, updateMessage

The timeout period for how long the message is invisible in the queue. If unset the value will default to 0 and the message will be instantly visible. The timeout must be between 0 seconds and 7 days.

CamelAzureStorageQueueCreateQueue

QueueConstants.CREATE_QUEUE

boolean

sendMessage

When is set to true, the queue will be automatically created when sending messages to the queue.

CamelAzureStorageQueuePopReceipt

QueueConstants.POP_RECEIPT

String

deleteMessage, updateMessage

Unique identifier that must match for the message to be deleted or updated.

CamelAzureStorageQueueMessageId

QueueConstants.MESSAGE_ID

String

deleteMessage, updateMessage

The ID of the message to be deleted or updated.

CamelAzureStorageQueueMaxMessages

QueueConstants.MAX_MESSAGES

Integer

receiveMessages, peekMessages

Maximum number of messages to get, if there are less messages exist in the queue than requested all the messages will be returned. If left empty only 1 message will be retrieved, the allowed range is 1 to 32 messages.

CamelAzureStorageQueueOperation

QueueConstants.QUEUE_OPERATION

QueueOperationDefinition

All

Specify the producer operation to execute, please see the doc on this page related to producer operation.

CamelAzureStorageQueueName

QueueConstants.QUEUE_NAME

String

All

Override the queue name.

14.6.2. Message headers set by either component producer or consumer

HeaderVariable NameTypeDescription

CamelAzureStorageQueueMessageId

QueueConstants.MESSAGE_ID

String

The ID of message that being sent to the queue.

CamelAzureStorageQueueInsertionTime

QueueConstants.INSERTION_TIME

OffsetDateTime

The time the Message was inserted into the Queue.

CamelAzureStorageQueueExpirationTime

QueueConstants.EXPIRATION_TIME

OffsetDateTime

The time that the Message will expire and be automatically deleted.

CamelAzureStorageQueuePopReceipt

QueueConstants.POP_RECEIPT

String

This value is required to delete/update the Message. If deletion fails using this popreceipt then the message has been dequeued by another client.

CamelAzureStorageQueueTimeNextVisible

QueueConstants.TIME_NEXT_VISIBLE

OffsetDateTime

The time that the message will again become visible in the Queue.

CamelAzureStorageQueueDequeueCount

QueueConstants.DEQUEUE_COUNT

long

The number of times the message has been dequeued.

CamelAzureStorageQueueRawHttpHeaders

QueueConstants.RAW_HTTP_HEADERS

HttpHeaders

Returns non-parsed httpHeaders that can be used by the user.

14.6.3. Advanced Azure Storage Queue configuration

If your Camel Application is running behind a firewall or if you need to have more control over the QueueServiceClient instance configuration, you can create your own instance:

StorageSharedKeyCredential credential = new StorageSharedKeyCredential("yourAccountName", "yourAccessKey");
String uri = String.format("https://%s.queue.core.windows.net", "yourAccountName");

QueueServiceClient client = new QueueServiceClientBuilder()
                          .endpoint(uri)
                          .credential(credential)
                          .buildClient();
// This is camel context
context.getRegistry().bind("client", client);

Then refer to this instance in your Camel azure-storage-queue component configuration:

from("azure-storage-queue://cameldev/queue1?serviceClient=#client")
.to("file://outputFolder?fileName=output.txt&fileExist=Append");

14.6.4. Automatic detection of QueueServiceClient client in registry

The component is capable of detecting the presence of an QueueServiceClient bean into the registry. If it’s the only instance of that type it will be used as client and you won’t have to define it as uri parameter, like the example above. This may be really useful for smarter configuration of the endpoint.

14.6.5. Azure Storage Queue Producer operations

Camel Azure Storage Queue component provides wide range of operations on the producer side:

Operations on the service level

For these operations, accountName is required.

OperationDescription

listQueues

Lists the queues in the storage account that pass the filter starting at the specified marker.

Operations on the queue level

For these operations, accountName and queueName are required.

OperationDescription

createQueue

Creates a new queue.

deleteQueue

Permanently deletes the queue.

clearQueue

Deletes all messages in the queue..

sendMessage

Default Producer Operation Sends a message with a given time-to-live and a timeout period where the message is invisible in the queue. The message text is evaluated from the exchange message body. By default, if the queue doesn`t exist, it will create an empty queue first. If you want to disable this, set the config createQueue or header CamelAzureStorageQueueCreateQueue to false.

deleteMessage

Deletes the specified message in the queue.

receiveMessages

Retrieves up to the maximum number of messages from the queue and hides them from other operations for the timeout period. However it will not dequeue the message from the queue due to reliability reasons.

peekMessages

Peek messages from the front of the queue up to the maximum number of messages.

updateMessage

Updates the specific message in the queue with a new message and resets the visibility timeout. The message text is evaluated from the exchange message body.

Refer to the example section in this page to learn how to use these operations into your camel application.

14.6.6. Consumer Examples

To consume a queue into a file component with maximum 5 messages in one batch, this can be done like this:

from("azure-storage-queue://cameldev/queue1?serviceClient=#client&maxMessages=5")
.to("file://outputFolder?fileName=output.txt&fileExist=Append");

14.6.7. Producer Operations Examples

  • listQueues:
from("direct:start")
    .process(exchange -> {
      // set the header you want the producer to evaluate, refer to the previous
      // section to learn about the headers that can be set
      // e.g, to only returns list of queues with 'awesome' prefix:
      exchange.getIn().setHeader(QueueConstants.QUEUES_SEGMENT_OPTIONS, new QueuesSegmentOptions().setPrefix("awesome"));
     })
    .to("azure-storage-queue://cameldev?serviceClient=#client&operation=listQueues")
    .log("${body}")
    .to("mock:result");
  • createQueue:
from("direct:start")
    .process(exchange -> {
      // set the header you want the producer to evaluate, refer to the previous
      // section to learn about the headers that can be set
      // e.g:
      exchange.getIn().setHeader(QueueConstants.QUEUE_NAME, "overrideName");
     })
    .to("azure-storage-queue://cameldev/test?serviceClient=#client&operation=createQueue");
  • deleteQueue:
from("direct:start")
    .process(exchange -> {
      // set the header you want the producer to evaluate, refer to the previous
      // section to learn about the headers that can be set
      // e.g:
      exchange.getIn().setHeader(QueueConstants.QUEUE_NAME, "overrideName");
     })
    .to("azure-storage-queue://cameldev/test?serviceClient=#client&operation=deleteQueue");
  • clearQueue:
from("direct:start")
    .process(exchange -> {
      // set the header you want the producer to evaluate, refer to the previous
      // section to learn about the headers that can be set
      // e.g:
      exchange.getIn().setHeader(QueueConstants.QUEUE_NAME, "overrideName");
     })
    .to("azure-storage-queue://cameldev/test?serviceClient=#client&operation=clearQueue");
  • sendMessage:
from("direct:start")
    .process(exchange -> {
      // set the header you want the producer to evaluate, refer to the previous
      // section to learn about the headers that can be set
      // e.g:
      exchange.getIn().setBody("message to send");
      // we set a visibility of 1min
      exchange.getIn().setHeader(QueueConstants.VISIBILITY_TIMEOUT, Duration.ofMinutes(1));
     })
    .to("azure-storage-queue://cameldev/test?serviceClient=#client");
  • deleteMessage:
from("direct:start")
    .process(exchange -> {
      // set the header you want the producer to evaluate, refer to the previous
      // section to learn about the headers that can be set
      // e.g:
      // Mandatory header:
      exchange.getIn().setHeader(QueueConstants.MESSAGE_ID, "1");
      // Mandatory header:
      exchange.getIn().setHeader(QueueConstants.POP_RECEIPT, "PAAAAHEEERXXX-1");
     })
    .to("azure-storage-queue://cameldev/test?serviceClient=#client&operation=deleteMessage");
  • receiveMessages:
from("direct:start")
    .to("azure-storage-queue://cameldev/test?serviceClient=#client&operation=receiveMessages")
    .process(exchange -> {
        final List<QueueMessageItem> messageItems = exchange.getMessage().getBody(List.class);
        messageItems.forEach(messageItem -> System.out.println(messageItem.getMessageText()));
    })
   .to("mock:result");
  • peekMessages:
from("direct:start")
    .to("azure-storage-queue://cameldev/test?serviceClient=#client&operation=peekMessages")
    .process(exchange -> {
        final List<PeekedMessageItem> messageItems = exchange.getMessage().getBody(List.class);
        messageItems.forEach(messageItem -> System.out.println(messageItem.getMessageText()));
    })
   .to("mock:result");
  • updateMessage:
from("direct:start")
   .process(exchange -> {
       // set the header you want the producer to evaluate, refer to the previous
       // section to learn about the headers that can be set
       // e.g:
       exchange.getIn().setBody("new message text");
       // Mandatory header:
       exchange.getIn().setHeader(QueueConstants.MESSAGE_ID, "1");
       // Mandatory header:
       exchange.getIn().setHeader(QueueConstants.POP_RECEIPT, "PAAAAHEEERXXX-1");
       // Mandatory header:
       exchange.getIn().setHeader(QueueConstants.VISIBILITY_TIMEOUT, Duration.ofMinutes(1));
    })
    .to("azure-storage-queue://cameldev/test?serviceClient=#client&operation=updateMessage");

14.6.8. Development Notes (Important)

When developing on this component, you will need to obtain your Azure accessKey in order to run the integration tests. In addition to the mocked unit tests you will need to run the integration tests with every change you make or even client upgrade as the Azure client can break things even on minor versions upgrade. To run the integration tests, on this component directory, run the following maven command:

mvn verify -PfullTests -DaccountName=myacc -DaccessKey=mykey

Whereby accountName is your Azure account name and accessKey is the access key being generated from Azure portal.

14.7. Spring Boot Auto-Configuration

The component supports 16 options, which are listed below.

NameDescriptionDefaultType

camel.component.azure-storage-queue.access-key

Access key for the associated azure account name to be used for authentication with azure queue services.

 

String

camel.component.azure-storage-queue.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.azure-storage-queue.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.azure-storage-queue.configuration

The component configurations. The option is a org.apache.camel.component.azure.storage.queue.QueueConfiguration type.

 

QueueConfiguration

camel.component.azure-storage-queue.create-queue

When is set to true, the queue will be automatically created when sending messages to the queue.

false

Boolean

camel.component.azure-storage-queue.credentials

StorageSharedKeyCredential can be injected to create the azure client, this holds the important authentication information. The option is a com.azure.storage.common.StorageSharedKeyCredential type.

 

StorageSharedKeyCredential

camel.component.azure-storage-queue.enabled

Whether to enable auto configuration of the azure-storage-queue component. This is enabled by default.

 

Boolean

camel.component.azure-storage-queue.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.azure-storage-queue.max-messages

Maximum number of messages to get, if there are less messages exist in the queue than requested all the messages will be returned. If left empty only 1 message will be retrieved, the allowed range is 1 to 32 messages.

1

Integer

camel.component.azure-storage-queue.message-id

The ID of the message to be deleted or updated.

 

String

camel.component.azure-storage-queue.operation

Queue service operation hint to the producer.

 

QueueOperationDefinition

camel.component.azure-storage-queue.pop-receipt

Unique identifier that must match for the message to be deleted or updated.

 

String

camel.component.azure-storage-queue.service-client

Service client to a storage account to interact with the queue service. This client does not hold any state about a particular storage account but is instead a convenient way of sending off appropriate requests to the resource on the service. This client contains all the operations for interacting with a queue account in Azure Storage. Operations allowed by the client are creating, listing, and deleting queues, retrieving and updating properties of the account, and retrieving statistics of the account. The option is a com.azure.storage.queue.QueueServiceClient type.

 

QueueServiceClient

camel.component.azure-storage-queue.time-to-live

How long the message will stay alive in the queue. If unset the value will default to 7 days, if -1 is passed the message will not expire. The time to live must be -1 or any positive number. The format should be in this form: PnDTnHnMn.nS., e.g: PT20.345S — parses as 20.345 seconds, P2D — parses as 2 days However, in case you are using EndpointDsl/ComponentDsl, you can do something like Duration.ofSeconds() since these Java APIs are typesafe. The option is a java.time.Duration type.

 

Duration

camel.component.azure-storage-queue.timeout

An optional timeout applied to the operation. If a response is not returned before the timeout concludes a RuntimeException will be thrown. The option is a java.time.Duration type.

 

Duration

camel.component.azure-storage-queue.visibility-timeout

The timeout period for how long the message is invisible in the queue. The timeout must be between 1 seconds and 7 days. The format should be in this form: PnDTnHnMn.nS., e.g: PT20.345S — parses as 20.345 seconds, P2D — parses as 2 days However, in case you are using EndpointDsl/ComponentDsl, you can do something like Duration.ofSeconds() since these Java APIs are typesafe. The option is a java.time.Duration type.

 

Duration

Chapter 15. Bean

Only producer is supported

The Bean component binds beans to Camel message exchanges.

15.1. Dependencies

When using bean with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-bean-starter</artifactId>
</dependency>

15.2. URI format

bean:beanName[?options]

Where beanID can be any string which is used to look up the bean in the Registry

15.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

15.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

15.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

15.4. Component Options

The Bean component supports 4 options, which are listed below.

NameDescriptionDefaultType

cache (producer)

Deprecated Use singleton option instead.

true

Boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

scope (producer)

Scope of bean. When using singleton scope (default) the bean is created or looked up only once and reused for the lifetime of the endpoint. The bean should be thread-safe in case concurrent threads is calling the bean at the same time. When using request scope the bean is created or looked up once per request (exchange). This can be used if you want to store state on a bean while processing a request and you want to call the same bean instance multiple times while processing the request. The bean does not have to be thread-safe as the instance is only called from the same request. When using delegate scope, then the bean will be looked up or created per call. However in case of lookup then this is delegated to the bean registry such as Spring or CDI (if in use), which depends on their configuration can act as either singleton or prototype scope. so when using prototype then this depends on the delegated registry.

Enum values:

  • Singleton
  • Request
  • Prototype

Singleton

BeanScope

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

15.5. Endpoint Options

The Bean endpoint is configured using URI syntax:

bean:beanName

with the following path and query parameters:

15.5.1. Path Parameters (1 parameters)

NameDescriptionDefaultType

beanName (common)

Required Sets the name of the bean to invoke.

 

String

15.5.2. Query Parameters (5 parameters)

NameDescriptionDefaultType

cache (common)

Deprecated Use scope option instead.

 

Boolean

method (common)

Sets the name of the method to invoke on the bean.

 

String

scope (common)

Scope of bean. When using singleton scope (default) the bean is created or looked up only once and reused for the lifetime of the endpoint. The bean should be thread-safe in case concurrent threads is calling the bean at the same time. When using request scope the bean is created or looked up once per request (exchange). This can be used if you want to store state on a bean while processing a request and you want to call the same bean instance multiple times while processing the request. The bean does not have to be thread-safe as the instance is only called from the same request. When using prototype scope, then the bean will be looked up or created per call. However in case of lookup then this is delegated to the bean registry such as Spring or CDI (if in use), which depends on their configuration can act as either singleton or prototype scope. so when using prototype then this depends on the delegated registry.

Enum values:

  • Singleton
  • Request
  • Prototype

Singleton

BeanScope

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

parameters (advanced)

Used for configuring additional properties on the bean.

 

Map

15.6. Examples

The object instance that is used to consume messages must be explicitly registered with the Registry. For example, if you are using Spring you must define the bean in the Spring configuration XML file.

You can also register beans manually via Camel’s Registry with the bind method.

Once an endpoint has been registered, you can build Camel routes that use it to process exchanges.

A bean: endpoint cannot be defined as the input to the route; i.e. you cannot consume from it, you can only route from some inbound message Endpoint to the bean endpoint as output. So consider using a direct: or queue: endpoint as the input.

You can use the createProxy() methods on ProxyHelper to create a proxy that will generate exchanges and send them to any endpoint:

And the same route using XML DSL:

<route>
   <from uri="direct:hello"/>
   <to uri="bean:bye"/>
</route>

15.7. Bean as endpoint

Camel also supports invoking Bean as an Endpoint. What happens is that when the exchange is routed to the myBean Camel will use the Bean Binding to invoke the bean. The source for the bean is just a plain POJO.

Camel will use Bean Binding to invoke the sayHello method, by converting the Exchange’s In body to the String type and storing the output of the method on the Exchange Out body.

15.8. Java DSL bean syntax

Java DSL comes with syntactic sugar for the component. Instead of specifying the bean explicitly as the endpoint (i.e. to("bean:beanName")) you can use the following syntax:

// Send message to the bean endpoint
// and invoke method resolved using Bean Binding.
from("direct:start").bean("beanName");

// Send message to the bean endpoint
// and invoke given method.
from("direct:start").bean("beanName", "methodName");

Instead of passing name of the reference to the bean (so that Camel will lookup for it in the registry), you can specify the bean itself:

// Send message to the given bean instance.
from("direct:start").bean(new ExampleBean());

// Explicit selection of bean method to be invoked.
from("direct:start").bean(new ExampleBean(), "methodName");

// Camel will create the instance of bean and cache it for you.
from("direct:start").bean(ExampleBean.class);

15.9. Bean Binding

How bean methods to be invoked are chosen (if they are not specified explicitly through the method parameter) and how parameter values are constructed from the Message are all defined by the Bean Binding mechanism which is used throughout all of the various Bean Integration mechanisms in Camel.

15.10. Spring Boot Auto-Configuration

The component supports 13 options, which are listed below.

NameDescriptionDefaultType

camel.component.bean.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.bean.enabled

Whether to enable auto configuration of the bean component. This is enabled by default.

 

Boolean

camel.component.bean.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.bean.scope

Scope of bean. When using singleton scope (default) the bean is created or looked up only once and reused for the lifetime of the endpoint. The bean should be thread-safe in case concurrent threads is calling the bean at the same time. When using request scope the bean is created or looked up once per request (exchange). This can be used if you want to store state on a bean while processing a request and you want to call the same bean instance multiple times while processing the request. The bean does not have to be thread-safe as the instance is only called from the same request. When using delegate scope, then the bean will be looked up or created per call. However in case of lookup then this is delegated to the bean registry such as Spring or CDI (if in use), which depends on their configuration can act as either singleton or prototype scope. so when using prototype then this depends on the delegated registry.

 

BeanScope

camel.component.class.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.class.enabled

Whether to enable auto configuration of the class component. This is enabled by default.

 

Boolean

camel.component.class.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.class.scope

Scope of bean. When using singleton scope (default) the bean is created or looked up only once and reused for the lifetime of the endpoint. The bean should be thread-safe in case concurrent threads is calling the bean at the same time. When using request scope the bean is created or looked up once per request (exchange). This can be used if you want to store state on a bean while processing a request and you want to call the same bean instance multiple times while processing the request. The bean does not have to be thread-safe as the instance is only called from the same request. When using delegate scope, then the bean will be looked up or created per call. However in case of lookup then this is delegated to the bean registry such as Spring or CDI (if in use), which depends on their configuration can act as either singleton or prototype scope. so when using prototype then this depends on the delegated registry.

 

BeanScope

camel.language.bean.enabled

Whether to enable auto configuration of the bean language. This is enabled by default.

 

Boolean

camel.language.bean.scope

Scope of bean. When using singleton scope (default) the bean is created or looked up only once and reused for the lifetime of the endpoint. The bean should be thread-safe in case concurrent threads is calling the bean at the same time. When using request scope the bean is created or looked up once per request (exchange). This can be used if you want to store state on a bean while processing a request and you want to call the same bean instance multiple times while processing the request. The bean does not have to be thread-safe as the instance is only called from the same request. When using prototype scope, then the bean will be looked up or created per call. However in case of lookup then this is delegated to the bean registry such as Spring or CDI (if in use), which depends on their configuration can act as either singleton or prototype scope. So when using prototype scope then this depends on the bean registry implementation.

Singleton

String

camel.language.bean.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.component.bean.cache

Deprecated Use singleton option instead.

true

Boolean

camel.component.class.cache

Deprecated Use singleton option instead.

true

Boolean

Chapter 16. Bean Validator

Only producer is supported

The Validator component performs bean validation of the message body using the Java Bean Validation API (). Camel uses the reference implementation, which is Hibernate Validator.

16.1. Dependencies

When using bean-validator with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-bean-validator-starter</artifactId>
</dependency>

16.2. URI format

bean-validator:label[?options]

Where label is an arbitrary text value describing the endpoint. You can append query options to the URI in the following format,

?option=value&option=value&…​

16.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

16.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

16.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

16.4. Component Options

The Bean Validator component supports 8 options, which are listed below.

NameDescriptionDefaultType

ignoreXmlConfiguration (producer)

Whether to ignore data from the META-INF/validation.xml file.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

constraintValidatorFactory (advanced)

To use a custom ConstraintValidatorFactory.

 

ConstraintValidatorFactory

messageInterpolator (advanced)

To use a custom MessageInterpolator.

 

MessageInterpolator

traversableResolver (advanced)

To use a custom TraversableResolver.

 

TraversableResolver

validationProviderResolver (advanced)

To use a a custom ValidationProviderResolver.

 

ValidationProviderResolver

validatorFactory (advanced)

Autowired To use a custom ValidatorFactory.

 

ValidatorFactory

16.5. Endpoint Options

The Bean Validator endpoint is configured using URI syntax:

bean-validator:label

with the following path and query parameters:

16.5.1. Path Parameters (1 parameters)

NameDescriptionDefaultType

label (producer)

Required Where label is an arbitrary text value describing the endpoint.

 

String

16.5.2. Query Parameters (8 parameters)

NameDescriptionDefaultType

group (producer)

To use a custom validation group.

javax.validation.groups.Default

String

ignoreXmlConfiguration (producer)

Whether to ignore data from the META-INF/validation.xml file.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

constraintValidatorFactory (advanced)

To use a custom ConstraintValidatorFactory.

 

ConstraintValidatorFactory

messageInterpolator (advanced)

To use a custom MessageInterpolator.

 

MessageInterpolator

traversableResolver (advanced)

To use a custom TraversableResolver.

 

TraversableResolver

validationProviderResolver (advanced)

To use a a custom ValidationProviderResolver.

 

ValidationProviderResolver

validatorFactory (advanced)

To use a custom ValidatorFactory.

 

ValidatorFactory

16.6. OSGi deployment

To use Hibernate Validator in the OSGi environment use dedicated ValidationProviderResolver implementation, just as org.apache.camel.component.bean.validator.HibernateValidationProviderResolver. The snippet below demonstrates this approach. You can also use HibernateValidationProviderResolver.

Using HibernateValidationProviderResolver

from("direct:test").
  to("bean-validator://ValidationProviderResolverTest?validationProviderResolver=#myValidationProviderResolver");

<bean id="myValidationProviderResolver" class="org.apache.camel.component.bean.validator.HibernateValidationProviderResolver"/>

If no custom ValidationProviderResolver is defined and the validator component has been deployed into the OSGi environment, the HibernateValidationProviderResolver will be automatically used.

16.7. Example

Assumed we have a java bean with the following annotations

Car.java

public class Car {

    @NotNull
    private String manufacturer;

    @NotNull
    @Size(min = 5, max = 14, groups = OptionalChecks.class)
    private String licensePlate;

    // getter and setter
}

and an interface definition for our custom validation group

OptionalChecks.java

public interface OptionalChecks {
}

with the following Camel route, only the @NotNull constraints on the attributes manufacturer and licensePlate will be validated (Camel uses the default group javax.validation.groups.Default).

from("direct:start")
.to("bean-validator://x")
.to("mock:end")

If you want to check the constraints from the group OptionalChecks, you have to define the route like this

from("direct:start")
.to("bean-validator://x?group=OptionalChecks")
.to("mock:end")

If you want to check the constraints from both groups, you have to define a new interface first

AllChecks.java

@GroupSequence({Default.class, OptionalChecks.class})
public interface AllChecks {
}

and then your route definition should looks like this

from("direct:start")
.to("bean-validator://x?group=AllChecks")
.to("mock:end")

And if you have to provide your own message interpolator, traversable resolver and constraint validator factory, you have to write a route like this

<bean id="myMessageInterpolator" class="my.ConstraintValidatorFactory" />
<bean id="myTraversableResolver" class="my.TraversableResolver" />
<bean id="myConstraintValidatorFactory" class="my.ConstraintValidatorFactory" />
from("direct:start")
.to("bean-validator://x?group=AllChecks&messageInterpolator=#myMessageInterpolator
&traversableResolver=#myTraversableResolver&constraintValidatorFactory=#myConstraintValidatorFactory")
.to("mock:end")

It’s also possible to describe your constraints as XML and not as Java annotations. In this case, you have to provide the file META-INF/validation.xml which could looks like this

validation.xml

<validation-config
    xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration">

    <default-provider>org.hibernate.validator.HibernateValidator</default-provider>
    <message-interpolator>org.hibernate.validator.engine.ResourceBundleMessageInterpolator</message-interpolator>
    <traversable-resolver>org.hibernate.validator.engine.resolver.DefaultTraversableResolver</traversable-resolver>
    <constraint-validator-factory>org.hibernate.validator.engine.ConstraintValidatorFactoryImpl</constraint-validator-factory>
    <constraint-mapping>/constraints-car.xml</constraint-mapping>

</validation-config>

and the constraints-car.xml file

constraints-car.xml

<constraint-mappings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.0.xsd"
    xmlns="http://jboss.org/xml/ns/javax/validation/mapping">

    <default-package>org.apache.camel.component.bean.validator</default-package>

    <bean class="CarWithoutAnnotations" ignore-annotations="true">
        <field name="manufacturer">
            <constraint annotation="javax.validation.constraints.NotNull" />
        </field>

        <field name="licensePlate">
            <constraint annotation="javax.validation.constraints.NotNull" />

            <constraint annotation="javax.validation.constraints.Size">
                <groups>
                    <value>org.apache.camel.component.bean.validator.OptionalChecks</value>
                </groups>
                <element name="min">5</element>
                <element name="max">14</element>
            </constraint>
        </field>
    </bean>
</constraint-mappings>

Here is the XML syntax for the example route definition for OrderedChecks.

Note that the body should include an instance of a class to validate.

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="direct:start"/>
            <to uri="bean-validator://x?group=org.apache.camel.component.bean.validator.OrderedChecks"/>
        </route>
    </camelContext>
</beans>

16.8. Spring Boot Auto-Configuration

The component supports 9 options, which are listed below.

NameDescriptionDefaultType

camel.component.bean-validator.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.bean-validator.constraint-validator-factory

To use a custom ConstraintValidatorFactory. The option is a javax.validation.ConstraintValidatorFactory type.

 

ConstraintValidatorFactory

camel.component.bean-validator.enabled

Whether to enable auto configuration of the bean-validator component. This is enabled by default.

 

Boolean

camel.component.bean-validator.ignore-xml-configuration

Whether to ignore data from the META-INF/validation.xml file.

false

Boolean

camel.component.bean-validator.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.bean-validator.message-interpolator

To use a custom MessageInterpolator. The option is a javax.validation.MessageInterpolator type.

 

MessageInterpolator

camel.component.bean-validator.traversable-resolver

To use a custom TraversableResolver. The option is a javax.validation.TraversableResolver type.

 

TraversableResolver

camel.component.bean-validator.validation-provider-resolver

To use a a custom ValidationProviderResolver. The option is a javax.validation.ValidationProviderResolver type.

 

ValidationProviderResolver

camel.component.bean-validator.validator-factory

To use a custom ValidatorFactory. The option is a javax.validation.ValidatorFactory type.

 

ValidatorFactory

Chapter 17. Bindy

The goal of this component is to allow the parsing/binding of non-structured data (or to be more precise non-XML data) to/from Java Beans that have binding mappings defined with annotations. Using Bindy, you can bind data from sources such as :

  • CSV records,
  • Fixed-length records,
  • FIX messages,
  • or almost any other non-structured data

to one or many Plain Old Java Object (POJO). Bindy converts the data according to the type of the java property. POJOs can be linked together with one-to-many relationships available in some cases. Moreover, for data type like Date, Double, Float, Integer, Short, Long and BigDecimal, you can provide the pattern to apply during the formatting of the property.

For the BigDecimal numbers, you can also define the precision and the decimal or grouping separators.

TypeFormat TypePattern exampleLink

Date

DateFormat

dd-MM-yyyy

https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/text/SimpleDateFormat.html

Decimal*

DecimalFormat

##.###.###

https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/text/DecimalFormat.html

Where Decimal = Double, Integer, Float, Short, Long

Format supported

This first release only support comma separated values fields and key value pair fields (e.g. : FIX messages).

To work with camel-bindy, you must first define your model in a package (e.g. com.acme.model) and for each model class (e.g. Order, Client, Instrument, …​) add the required annotations (described hereafter) to the Class or field.

Multiple models

As you configure bindy using class names instead of package names you can put multiple models in the same package.

17.1. Dependencies

When using bindy-csv with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-bindy-starter</artifactId>
</dependency>

17.2. Options

The Bindy dataformat supports 5 options, which are listed below.

NameDefaultJava TypeDescription

type

 

Enum

Required Whether to use Csv, Fixed, or KeyValue.

Enum values:

  • Csv
  • Fixed
  • KeyValue

classType

 

String

Name of model class to use.

locale

 

String

To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default.

unwrapSingleInstance

 

Boolean

When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List.

allowEmptyStream

 

Boolean

Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided.

17.3. Annotations

The annotations created allow to map different concept of your model to the POJO like:

  • Type of record (CSV, key value pair (e.g. FIX message), fixed length …​),
  • Link (to link object in another object),
  • DataField and their properties (int, type, …​),
  • KeyValuePairField (for key = value format like we have in FIX financial messages),
  • Section (to identify header, body and footer section),
  • OneToMany,
  • BindyConverter,
  • FormatFactories

This section will describe them.

17.3.1. 1. CsvRecord

The CsvRecord annotation is used to identified the root class of the model. It represents a record = "a line of a CSV file" and can be linked to several children model classes.

Annotation nameRecord typeLevel

CsvRecord

CSV

Class

Parameter nameTypeRequiredDefault valueInfo

separator

String

 

Separator used to split a record in tokens (mandatory) - can be ',' or ';' or 'anything'. The only whitespace character supported is tab (\t). No other whitespace characters (spaces) are not supported. This value is interpreted as a regular expression. If you want to use a sign which has a special meaning in regular expressions, e.g. the '|' sign, then you have to mask it, like '|'.

allowEmptyStream

boolean

 

false

The allowEmptyStream parameter will allow to prcoess the unavaiable stream for CSV file.

autospanLine

boolean

 

false

Last record spans rest of line (optional) - if enabled then the last column is auto spanned to end of line, for example if its a comment, etc this allows the line to contain all characters, also the delimiter char.

crlf

String

 

WINDOWS

Character to be used to add a carriage return after each record (optional) - allow to define the carriage return character to use. If you specify a value other than the three listed before, the value you enter (custom) will be used as the CRLF character(s). Three values can be used : WINDOWS, UNIX, MAC, or custom.

endWithLineBreak

boolean

 

true

The endWithLineBreak parameter flags if the CSV file should end with a line break or not (optional)

generateHeaderColumns

boolean

 

false

The generateHeaderColumns parameter allow to add in the CSV generated the header containing names of the columns

isOrdered

boolean

 

false

Indicates if the message must be ordered in output

name

String

  

Name describing the record (optional)

quote

String

 

"

Whether to marshal columns with the given quote character (optional) - allow to specify a quote character of the fields when CSV is generated. This annotation is associated to the root class of the model and must be declared one time.

quoting

boolean

 

false

Indicate if the values (and headers) must be quoted when marshaling (optional)

quotingEscaped

boolean

 

false

Indicate if the values must be escaped when quoting (optional)

removeQuotes

boolean

 

true

The remove quotes parameter flags if unmarshalling should try to remove quotes for each field

skipField

boolean

 

false

The skipField parameter will allow to skip fields of a CSV file. If some fields are not necessary, they can be skipped.

skipFirstLine

boolean

 

false

The skipFirstLine parameter will allow to skip or not the first line of a CSV file. This line often contains columns definition

trimLine

boolean

 

true

Whether to trim each line (stand and end) before parsing the line into data fields.

case 1 : separator = ','

The separator used to segregate the fields in the CSV record is , :

10, J, Pauline, M, XD12345678, Fortis Dynamic 15/15, 2500, USD, 08-01-2009
@CsvRecord( separator = "," )
public Class Order {

}

case 2 : separator = ';'

Compare to the previous case, the separator here is ; instead of , :

10; J; Pauline; M; XD12345678; Fortis Dynamic 15/15; 2500; USD; 08-01-2009
@CsvRecord( separator = ";" )
public Class Order {

}

case 3 : separator = '|'

Compare to the previous case, the separator here is | instead of ; :

10| J| Pauline| M| XD12345678| Fortis Dynamic 15/15| 2500| USD| 08-01-2009
@CsvRecord( separator = "\\|" )
public Class Order {

}

case 4 : separator = '\",\"'

Applies for Camel 2.8.2 or older

When the field to be parsed of the CSV record contains , or ; which is also used as separator, we should find another strategy to tell camel bindy how to handle this case. To define the field containing the data with a comma, you will use single or double quotes as delimiter (e.g : '10', 'Street 10, NY', 'USA' or "10", "Street 10, NY", "USA").

Note

In this case, the first and last character of the line which are a single or double quotes will be removed by bindy.

"10","J","Pauline"," M","XD12345678","Fortis Dynamic 15,15","2500","USD","08-01-2009"
@CsvRecord( separator = "\",\"" )
public Class Order {

}

Bindy automatically detects if the record is enclosed with either single or double quotes and automatic remove those quotes when unmarshalling from CSV to Object. Therefore do not include the quotes in the separator, but simply do as below:

"10","J","Pauline"," M","XD12345678","Fortis Dynamic 15,15","2500","USD","08-01-2009"
@CsvRecord( separator = "," )
public Class Order {

}

Note that if you want to marshal from Object to CSV and use quotes, then you need to specify which quote character to use, using the quote attribute on the @CsvRecord as shown below:

@CsvRecord( separator = ",", quote = "\"" )
public Class Order {

}

case 5 : separator & skipFirstLine

The feature is interesting when the client wants to have in the first line of the file, the name of the data fields :

order id, client id, first name, last name, isin code, instrument name, quantity, currency, date

To inform bindy that this first line must be skipped during the parsing process, then we use the attribute :

@CsvRecord(separator = ",", skipFirstLine = true)
public Class Order {

}

case 6 : generateHeaderColumns

To add at the first line of the CSV generated, the attribute generateHeaderColumns must be set to true in the annotation like this :

@CsvRecord( generateHeaderColumns = true )
public Class Order {

}

As a result, Bindy during the unmarshaling process will generate CSV like this :

order id, client id, first name, last name, isin code, instrument name, quantity, currency, date
10, J, Pauline, M, XD12345678, Fortis Dynamic 15/15, 2500, USD, 08-01-2009

case 7 : carriage return

If the platform where camel-bindy will run is not Windows but Macintosh or Unix, then you can change the crlf property like this. Three values are available : WINDOWS, UNIX or MAC

@CsvRecord(separator = ",", crlf="MAC")
public Class Order {

}

Additionally, if for some reason you need to add a different line ending character, you can opt to specify it using the crlf parameter. In the following example, we can end the line with a comma followed by the newline character:

@CsvRecord(separator = ",", crlf=",\n")
public Class Order {

}

case 8 : isOrdered

Sometimes, the order to follow during the creation of the CSV record from the model is different from the order used during the parsing. Then, in this case, we can use the attribute isOrdered = true to indicate this in combination with attribute position of the DataField annotation.

@CsvRecord(isOrdered = true)
public Class Order {

   @DataField(pos = 1, position = 11)
   private int orderNr;

   @DataField(pos = 2, position = 10)
   private String clientNr;

}
Note

pos is used to parse the file stream, while position is used to generate the CSV.

17.3.3. 3. DataField

The DataField annotation defines the property of the field. Each datafield is identified by its position in the record, a type (string, int, date, …​) and optionally of a pattern.

Annotation nameRecord typeLevel

DataField

all

Property

Parameter nameTypeRequiredDefault valueInfo

pos

int

 

Position of the data in the input record, must start from 1 (mandatory). See the position parameter.

align

String

 

R

Align the text to the right or left. Use values <tt>R</tt> or <tt>L</tt>.

clip

boolean

 

false

Indicates to clip data in the field if it exceeds the allowed length when using fixed length.

columnName

String

  

Name of the header column (optional). Uses the name of the property as default. Only applicable when CsvRecord has generateHeaderColumns = true

decimalSeparator

String

  

Decimal Separator to be used with BigDecimal number

defaultValue

String

  

Field’s default value in case no value is set

delimiter

String

  

Optional delimiter to be used if the field has a variable length

groupingSeparator

String

  

Grouping Separator to be used with BigDecimal number when we would like to format/parse to number with grouping e.g. 123,456.789

impliedDecimalSeparator

boolean

 

false

Indicates if there is a decimal point implied at a specified location

length

int

 

0

Length of the data block (number of characters) if the record is set to a fixed length

lengthPos

int

 

0

Identifies a data field in the record that defines the expected fixed length for this field

method

String

  

Method name to call to apply such customization on DataField. This must be the method on the datafield itself or you must provide static fully qualified name of the class’s method e.g: see unit test org.apache.camel.dataformat.bindy.csv.BindySimpleCsvFunctionWithExternalMethodTest.replaceToBar

name

String

  

Name of the field (optional)

paddingChar

char

  

The char to pad with if the record is set to a fixed length

pattern

String

  

Pattern that the Java formatter (SimpleDateFormat by example) will use to transform the data (optional). If using pattern, then setting locale on bindy data format is recommended. Either set to a known locale such as "us" or use "default" to use platform default locale.

position

int

 

0

Position of the field in the output message generated (should start from 1). Must be used when the position of the field in the CSV generated (output message) must be different compare to input position (pos). See the pos parameter.

precision

int

 

0

precision of the \{@link java.math.BigDecimal} number to be created

required

boolean

 

false

Indicates if the field is mandatory

rounding

String

 

CEILING

Round mode to be used to round/scale a BigDecimal Values : UP, DOWN, CEILING, FLOOR, HALF_UP, HALF_DOWN,HALF_EVEN, UNNECESSARY e.g : Number = 123456.789, Precision = 2, Rounding = CEILING Result : 123456.79

timezone

String

  

Timezone to be used.

trim

boolean

 

false

Indicates if the value should be trimmed

case 1 : pos

This parameter/attribute represents the position of the field in the CSV record.

Position

@CsvRecord(separator = ",")
public class Order {

    @DataField(pos = 1)
    private int orderNr;

    @DataField(pos = 5)
    private String isinCode;

}

As you can see in this example the position starts at 1 but continues at 5 in the class Order. The numbers from 2 to 4 are defined in the class Client (see here after).

Position continues in another model class

public class Client {

    @DataField(pos = 2)
    private String clientNr;

    @DataField(pos = 3)
    private String firstName;

    @DataField(pos = 4)
    private String lastName;
}

case 2 : pattern

The pattern allows to enrich or validates the format of your data

Pattern

@CsvRecord(separator = ",")
public class Order {

    @DataField(pos = 1)
    private int orderNr;

    @DataField(pos = 5)
    private String isinCode;

    @DataField(name = "Name", pos = 6)
    private String instrumentName;

    @DataField(pos = 7, precision = 2)
    private BigDecimal amount;

    @DataField(pos = 8)
    private String currency;

    // pattern used during parsing or when the date is created
    @DataField(pos = 9, pattern = "dd-MM-yyyy")
    private Date orderDate;
}

case 3 : precision

The precision is helpful when you want to define the decimal part of your number.

Precision

@CsvRecord(separator = ",")
public class Order {

    @DataField(pos = 1)
    private int orderNr;

    @Link
    private Client client;

    @DataField(pos = 5)
    private String isinCode;

    @DataField(name = "Name", pos = 6)
    private String instrumentName;

    @DataField(pos = 7, precision = 2)
    private BigDecimal amount;

    @DataField(pos = 8)
    private String currency;

    @DataField(pos = 9, pattern = "dd-MM-yyyy")
    private Date orderDate;
}

case 4 : Position is different in output

The position attribute will inform bindy how to place the field in the CSV record generated. By default, the position used corresponds to the position defined with the attribute pos. If the position is different (that means that we have an asymetric processus comparing marshaling from unmarshaling) then we can use position to indicate this.

Here is an example:

Position is different in output

@CsvRecord(separator = ",", isOrdered = true)
public class Order {

    // Positions of the fields start from 1 and not from 0

    @DataField(pos = 1, position = 11)
    private int orderNr;

    @DataField(pos = 2, position = 10)
    private String clientNr;

    @DataField(pos = 3, position = 9)
    private String firstName;

    @DataField(pos = 4, position = 8)
    private String lastName;

    @DataField(pos = 5, position = 7)
    private String instrumentCode;

    @DataField(pos = 6, position = 6)
    private String instrumentNumber;
}

This attribute of the annotation @DataField must be used in combination with attribute isOrdered = true of the annotation @CsvRecord.

case 5 : required

If a field is mandatory, simply use the attribute required set to true.

Required

@CsvRecord(separator = ",")
public class Order {

    @DataField(pos = 1)
    private int orderNr;

    @DataField(pos = 2, required = true)
    private String clientNr;

    @DataField(pos = 3, required = true)
    private String firstName;

    @DataField(pos = 4, required = true)
    private String lastName;
}

If this field is not present in the record, then an error will be raised by the parser with the following information :

Some fields are missing (optional or mandatory), line :

case 6 : trim

If a field has leading and/or trailing spaces which should be removed before they are processed, simply use the attribute trim set to true.

Trim

@CsvRecord(separator = ",")
public class Order {

    @DataField(pos = 1, trim = true)
    private int orderNr;

    @DataField(pos = 2, trim = true)
    private Integer clientNr;

    @DataField(pos = 3, required = true)
    private String firstName;

    @DataField(pos = 4)
    private String lastName;
}

case 7 : defaultValue

If a field is not defined then uses the value indicated by the defaultValue attribute.

Default value

@CsvRecord(separator = ",")
public class Order {

    @DataField(pos = 1)
    private int orderNr;

    @DataField(pos = 2)
    private Integer clientNr;

    @DataField(pos = 3, required = true)
    private String firstName;

    @DataField(pos = 4, defaultValue = "Barin")
    private String lastName;
}

case 8 : columnName

Specifies the column name for the property only if @CsvRecord has annotation generateHeaderColumns = true.

Column Name

@CsvRecord(separator = ",", generateHeaderColumns = true)
public class Order {

    @DataField(pos = 1)
    private int orderNr;

    @DataField(pos = 5, columnName = "ISIN")
    private String isinCode;

    @DataField(name = "Name", pos = 6)
    private String instrumentName;
}

This attribute is only applicable to optional fields.

17.3.4. 4. FixedLengthRecord

The FixedLengthRecord annotation is used to identified the root class of the model. It represents a record = "a line of a file/message containing data fixed length (number of characters) formatted" and can be linked to several children model classes. This format is a bit particular because data of a field can be aligned to the right or to the left.

When the size of the data does not fill completely the length of the field, we can then add 'pad' characters.

Annotation nameRecord typeLevel

FixedLengthRecord

fixed

Class

Parameter nameTypeRequiredDefault valueInfo

countGrapheme

boolean

 

false

Indicates how chars are counted

crlf

String

 

WINDOWS

Character to be used to add a carriage return after each record (optional). Possible values: WINDOWS, UNIX, MAC, or custom. This option is used only during marshalling, whereas unmarshalling uses system default JDK provided line delimiter unless eol is customized.

eol

String

  

Character to be used to process considering end of line after each record while unmarshalling (optional - default: "", which help default JDK provided line delimiter to be used unless any other line delimiter provided) This option is used only during unmarshalling, where marshalling uses system default provided line delimiter as "WINDOWS" unless any other value is provided.

footer

Class

 

void

Indicates that the record(s) of this type may be followed by a single footer record at the end of the file

header

Class

 

void

Indicates that the record(s) of this type may be preceded by a single header record at the beginning of in the file

ignoreMissingChars

boolean

 

false

Indicates whether too short lines will be ignored

ignoreTrailingChars

boolean

 

false

Indicates that characters beyond the last mapped filed can be ignored when unmarshalling / parsing. This annotation is associated to the root class of the model and must be declared one time.

length

int

 

0

The fixed length of the record (number of characters). It means that the record will always be that long padded with \{#paddingChar()}'s

name

String

  

Name describing the record (optional)

paddingChar

char

  

The char to pad with.

skipFooter

boolean

 

false

Configures the data format to skip marshalling / unmarshalling of the footer record. Configure this parameter on the primary record (e.g., not the header or footer).

skipHeader

boolean

 

false

Configures the data format to skip marshalling / unmarshalling of the header record. Configure this parameter on the primary record (e.g., not the header or footer).

A record may not be both a header/footer and a primary fixed-length record.

case 1 : Simple fixed length record

This simple example shows how to design the model to parse/format a fixed message

10A9PaulineMISINXD12345678BUYShare2500.45USD01-08-2009

Fixed-simple

@FixedLengthRecord(length=54, paddingChar=' ')
public static class Order {

    @DataField(pos = 1, length=2)
    private int orderNr;

    @DataField(pos = 3, length=2)
    private String clientNr;

    @DataField(pos = 5, length=7)
    private String firstName;

    @DataField(pos = 12, length=1, align="L")
    private String lastName;

    @DataField(pos = 13, length=4)
    private String instrumentCode;

    @DataField(pos = 17, length=10)
    private String instrumentNumber;

    @DataField(pos = 27, length=3)
    private String orderType;

    @DataField(pos = 30, length=5)
    private String instrumentType;

    @DataField(pos = 35, precision = 2, length=7)
    private BigDecimal amount;

    @DataField(pos = 42, length=3)
    private String currency;

    @DataField(pos = 45, length=10, pattern = "dd-MM-yyyy")
    private Date orderDate;
}

case 2 : Fixed length record with alignment and padding

This more elaborated example show how to define the alignment for a field and how to assign a padding character which is ' ' here:

10A9 PaulineM ISINXD12345678BUYShare2500.45USD01-08-2009

Fixed-padding-align

@FixedLengthRecord(length=60, paddingChar=' ')
public static class Order {

    @DataField(pos = 1, length=2)
    private int orderNr;

    @DataField(pos = 3, length=2)
    private String clientNr;

    @DataField(pos = 5, length=9)
    private String firstName;

    @DataField(pos = 14, length=5, align="L")   // align text to the LEFT zone of the block
    private String lastName;

    @DataField(pos = 19, length=4)
    private String instrumentCode;

    @DataField(pos = 23, length=10)
    private String instrumentNumber;

    @DataField(pos = 33, length=3)
    private String orderType;

    @DataField(pos = 36, length=5)
    private String instrumentType;

    @DataField(pos = 41, precision = 2, length=7)
    private BigDecimal amount;

    @DataField(pos = 48, length=3)
    private String currency;

    @DataField(pos = 51, length=10, pattern = "dd-MM-yyyy")
    private Date orderDate;
}

case 3 : Field padding

Sometimes, the default padding defined for record cannnot be applied to the field as we have a number format where we would like to pad with '0' instead of ' '. In this case, you can use in the model the attribute paddingChar on @DataField to set this value.

10A9 PaulineM ISINXD12345678BUYShare000002500.45USD01-08-2009

Fixed-padding-field

@FixedLengthRecord(length = 65, paddingChar = ' ')
public static class Order {

    @DataField(pos = 1, length = 2)
    private int orderNr;

    @DataField(pos = 3, length = 2)
    private String clientNr;

    @DataField(pos = 5, length = 9)
    private String firstName;

    @DataField(pos = 14, length = 5, align = "L")
    private String lastName;

    @DataField(pos = 19, length = 4)
    private String instrumentCode;

    @DataField(pos = 23, length = 10)
    private String instrumentNumber;

    @DataField(pos = 33, length = 3)
    private String orderType;

    @DataField(pos = 36, length = 5)
    private String instrumentType;

    @DataField(pos = 41, precision = 2, length = 12, paddingChar = '0')
    private BigDecimal amount;

    @DataField(pos = 53, length = 3)
    private String currency;

    @DataField(pos = 56, length = 10, pattern = "dd-MM-yyyy")
    private Date orderDate;
}

case 4: Fixed length record with delimiter

Fixed-length records sometimes have delimited content within the record. The firstName and lastName fields are delimited with the ^ character in the following example:

10A9Pauline^M^ISINXD12345678BUYShare000002500.45USD01-08-2009

Fixed-delimited

@FixedLengthRecord
public static class Order {

    @DataField(pos = 1, length = 2)
    private int orderNr;

    @DataField(pos = 2, length = 2)
    private String clientNr;

    @DataField(pos = 3, delimiter = "^")
    private String firstName;

    @DataField(pos = 4, delimiter = "^")
    private String lastName;

    @DataField(pos = 5, length = 4)
    private String instrumentCode;

    @DataField(pos = 6, length = 10)
    private String instrumentNumber;

    @DataField(pos = 7, length = 3)
    private String orderType;

    @DataField(pos = 8, length = 5)
    private String instrumentType;

    @DataField(pos = 9, precision = 2, length = 12, paddingChar = '0')
    private BigDecimal amount;

    @DataField(pos = 10, length = 3)
    private String currency;

    @DataField(pos = 11, length = 10, pattern = "dd-MM-yyyy")
    private Date orderDate;
}

The pos value(s) in a fixed-length record may optionally be defined using ordinal, sequential values instead of precise column numbers.

case 5 : Fixed length record with record-defined field length

Occasionally a fixed-length record may contain a field that define the expected length of another field within the same record. In the following example the length of the instrumentNumber field value is defined by the value of instrumentNumberLen field in the record.

10A9Pauline^M^ISIN10XD12345678BUYShare000002500.45USD01-08-2009

Fixed-delimited

@FixedLengthRecord
public static class Order {

    @DataField(pos = 1, length = 2)
    private int orderNr;

    @DataField(pos = 2, length = 2)
    private String clientNr;

    @DataField(pos = 3, delimiter = "^")
    private String firstName;

    @DataField(pos = 4, delimiter = "^")
    private String lastName;

    @DataField(pos = 5, length = 4)
    private String instrumentCode;

    @DataField(pos = 6, length = 2, align = "R", paddingChar = '0')
    private int instrumentNumberLen;

    @DataField(pos = 7, lengthPos=6)
    private String instrumentNumber;

    @DataField(pos = 8, length = 3)
    private String orderType;

    @DataField(pos = 9, length = 5)
    private String instrumentType;

    @DataField(pos = 10, precision = 2, length = 12, paddingChar = '0')
    private BigDecimal amount;

    @DataField(pos = 11, length = 3)
    private String currency;

    @DataField(pos = 12, length = 10, pattern = "dd-MM-yyyy")
    private Date orderDate;
}

case 6 : Fixed length record with header and footer

Bindy will discover fixed-length header and footer records that are configured as part of the model – provided that the annotated classes exist either in the same package as the primary @FixedLengthRecord class, or within one of the configured scan packages. The following text illustrates two fixed-length records that are bracketed by a header record and footer record.

101-08-2009
10A9 PaulineM ISINXD12345678BUYShare000002500.45USD01-08-2009
10A9 RichN ISINXD12345678BUYShare000002700.45USD01-08-2009
9000000002

Fixed-header-and-footer-main-class

@FixedLengthRecord(header = OrderHeader.class, footer = OrderFooter.class)
public class Order {

    @DataField(pos = 1, length = 2)
    private int orderNr;

    @DataField(pos = 2, length = 2)
    private String clientNr;

    @DataField(pos = 3, length = 9)
    private String firstName;

    @DataField(pos = 4, length = 5, align = "L")
    private String lastName;

    @DataField(pos = 5, length = 4)
    private String instrumentCode;

    @DataField(pos = 6, length = 10)
    private String instrumentNumber;

    @DataField(pos = 7, length = 3)
    private String orderType;

    @DataField(pos = 8, length = 5)
    private String instrumentType;

    @DataField(pos = 9, precision = 2, length = 12, paddingChar = '0')
    private BigDecimal amount;

    @DataField(pos = 10, length = 3)
    private String currency;

    @DataField(pos = 11, length = 10, pattern = "dd-MM-yyyy")
    private Date orderDate;
}

@FixedLengthRecord
public  class OrderHeader {
    @DataField(pos = 1, length = 1)
    private int recordType = 1;

    @DataField(pos = 2, length = 10, pattern = "dd-MM-yyyy")
    private Date recordDate;
}

@FixedLengthRecord
public class OrderFooter {

    @DataField(pos = 1, length = 1)
    private int recordType = 9;

    @DataField(pos = 2, length = 9, align = "R", paddingChar = '0')
    private int numberOfRecordsInTheFile;
}

case 7 : Skipping content when parsing a fixed length record

It is common to integrate with systems that provide fixed-length records containing more information than needed for the target use case. It is useful in this situation to skip the declaration and parsing of those fields that we do not need. To accomodate this, Bindy will skip forward to the next mapped field within a record if the pos value of the next declared field is beyond the cursor position of the last parsed field. Using absolute pos locations for the fields of interest (instead of ordinal values) causes Bindy to skip content between two fields.

Similarly, it is possible that none of the content beyond some field is of interest. In this case, you can tell Bindy to skip parsing of everything beyond the last mapped field by setting the ignoreTrailingChars property on the @FixedLengthRecord declaration.

@FixedLengthRecord(ignoreTrailingChars = true)
public static class Order {

    @DataField(pos = 1, length = 2)
    private int orderNr;

    @DataField(pos = 3, length = 2)
    private String clientNr;

    // any characters that appear beyond the last mapped field will be ignored

}

17.3.5. 5. Message

The Message annotation is used to identified the class of your model who will contain key value pairs fields. This kind of format is used mainly in Financial Exchange Protocol Messages (FIX). Nevertheless, this annotation can be used for any other format where data are identified by keys. The key pair values are separated each other by a separator which can be a special character like a tab delimitor (unicode representation : \u0009) or a start of heading (unicode representation : \u0001)

Note

To work with FIX messages, the model must contain a Header and Trailer classes linked to the root message class which could be a Order class. This is not mandatory but will be very helpful when you will use camel-bindy in combination with camel-fix which is a Fix gateway based on quickFix project .

Annotation nameRecord typeLevel

Message

key value pair

Class

Parameter nameTypeRequiredDefault valueInfo

keyValuePairSeparator

String

 

Key value pair separator is used to split the values from their keys (mandatory). Can be '\u0001', '\u0009', '#', or 'anything'.

pairSeparator

String

 

Pair separator used to split the key value pairs in tokens (mandatory). Can be '=', ';', or 'anything'.

crlf

String

 

WINDOWS

Character to be used to add a carriage return after each record (optional). Possible values = WINDOWS, UNIX, MAC, or custom. If you specify a value other than the three listed before, the value you enter (custom) will be used as the CRLF character(s).

isOrdered

boolean

 

false

Indicates if the message must be ordered in output. This annotation is associated to the message class of the model and must be declared one time.

name

String

  

Name describing the message (optional)

type

String

 

FIX

type is used to define the type of the message (e.g. FIX, EMX, …​) (optional)

version

String

 

4.1

version defines the version of the message (e.g. 4.1, …​) (optional)

case 1 : separator = 'u0001'

The separator used to segregate the key value pair fields in a FIX message is the ASCII 01 character or in unicode format \u0001. This character must be escaped a second time to avoid a java runtime error. Here is an example :

8=FIX.4.1 9=20 34=1 35=0 49=INVMGR 56=BRKR 1=BE.CHM.001 11=CHM0001-01 22=4 ...

and how to use the annotation:

FIX - message

@Message(keyValuePairSeparator = "=", pairSeparator = "\u0001", type="FIX", version="4.1")
public class Order {

}

Look at test cases

The ASCII character like tab, …​ cannot be displayed in WIKI page. So, have a look to the test case of camel-bindy to see exactly how the FIX message looks like (https://github.com/apache/camel/blob/main/components/camel-bindy/src/test/data/fix/fix.txt) and the Order, Trailer, Header classes (https://github.com/apache/camel/blob/main/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/simple/Order.java).

17.3.6. 6. KeyValuePairField

The KeyValuePairField annotation defines the property of a key value pair field. Each KeyValuePairField is identified by a tag (= key) and its value associated, a type (string, int, date, …​), optionaly a pattern and if the field is required.

Annotation nameRecord typeLevel

KeyValuePairField

Key Value Pair - FIX

Property

Parameter nameTypeRequiredDefault valueInfo

tag

int

 

tag identifying the field in the message (mandatory) - must be unique

impliedDecimalSeparator

boolean

 

false

<b>Camel 2.11:</b> Indicates if there is a decimal point implied at a specified location

name

String

  

name of the field (optional)

pattern

String

  

pattern that the formater will use to transform the data (optional)

position

int

 

0

Position of the field in the message generated - must be used when the position of the key/tag in the FIX message must be different

precision

int

 

0

precision of the BigDecimal number to be created

required

boolean

 

false

Indicates if the field is mandatory

timezone

String

  

Timezone to be used.

case 1 : tag

This parameter represents the key of the field in the message:

FIX message - Tag

@Message(keyValuePairSeparator = "=", pairSeparator = "\u0001", type="FIX", version="4.1")
public class Order {

    @Link Header header;

    @Link Trailer trailer;

    @KeyValuePairField(tag = 1) // Client reference
    private String Account;

    @KeyValuePairField(tag = 11) // Order reference
    private String ClOrdId;

    @KeyValuePairField(tag = 22) // Fund ID type (Sedol, ISIN, ...)
    private String IDSource;

    @KeyValuePairField(tag = 48) // Fund code
    private String SecurityId;

    @KeyValuePairField(tag = 54) // Movement type ( 1 = Buy, 2 = sell)
    private String Side;

    @KeyValuePairField(tag = 58) // Free text
    private String Text;
}

case 2 : Different position in output

If the tags/keys that we will put in the FIX message must be sorted according to a predefine order, then use the attribute position of the annotation @KeyValuePairField.

FIX message - Tag - sort

@Message(keyValuePairSeparator = "=", pairSeparator = "\\u0001", type = "FIX", version = "4.1", isOrdered = true)
public class Order {

    @Link Header header;

    @Link Trailer trailer;

    @KeyValuePairField(tag = 1, position = 1) // Client reference
    private String account;

    @KeyValuePairField(tag = 11, position = 3) // Order reference
    private String clOrdId;
}

17.3.7. 7. Section

In FIX message of fixed length records, it is common to have different sections in the representation of the information : header, body and section. The purpose of the annotation @Section is to inform bindy about which class of the model represents the header (= section 1), body (= section 2) and footer (= section 3)

Only one attribute/parameter exists for this annotation.

Annotation nameRecord typeLevel

Section

FIX

Class

Parameter nameTypeRequiredDefault valueInfo

number

int

 

Number of the section

case 1 : Section

Definition of the header section:

FIX message - Section - Header

@Section(number = 1)
public class Header {

    @KeyValuePairField(tag = 8, position = 1) // Message Header
    private String beginString;

    @KeyValuePairField(tag = 9, position = 2) // Checksum
    private int bodyLength;
}

Definition of the body section:

FIX message - Section - Body

@Section(number = 2)
@Message(keyValuePairSeparator = "=", pairSeparator = "\\u0001", type = "FIX", version = "4.1", isOrdered = true)
public class Order {

    @Link Header header;

    @Link Trailer trailer;

    @KeyValuePairField(tag = 1, position = 1) // Client reference
    private String account;

    @KeyValuePairField(tag = 11, position = 3) // Order reference
    private String clOrdId;

Definition of the footer section:

FIX message - Section - Footer

@Section(number = 3)
public class Trailer {

    @KeyValuePairField(tag = 10, position = 1)
    // CheckSum
    private int checkSum;

    public int getCheckSum() {
        return checkSum;
    }

17.3.8. 8. OneToMany

The purpose of the annotation @OneToMany is to allow to work with a List<?> field defined a POJO class or from a record containing repetitive groups.

Note

Restrictions for OneToMany
Be careful, the one to many of bindy does not allow to handle repetitions defined on several levels of the hierarchy.

The relation OneToMany ONLY WORKS in the following cases :

  • Reading a FIX message containing repetitive groups (= group of tags/keys)
  • Generating a CSV with repetitive data
Annotation nameRecord typeLevel

OneToMany

all

Property

Parameter nameTypeRequiredDefault valueInfo

mappedTo

String

  

Class name associated to the type of the List<Type of the Class>

case 1 : Generating CSV with repetitive data

Here is the CSV output that we want :

Claus,Ibsen,Camel in Action 1,2010,35
Claus,Ibsen,Camel in Action 2,2012,35
Claus,Ibsen,Camel in Action 3,2013,35
Claus,Ibsen,Camel in Action 4,2014,35
Note

The repetitive data concern the title of the book and its publication date while first, last name and age are common and the classes used to modeling this. The Author class contains a List of Book.

Generate CSV with repetitive data

@CsvRecord(separator=",")
public class Author {

    @DataField(pos = 1)
    private String firstName;

    @DataField(pos = 2)
    private String lastName;

    @OneToMany
    private List<Book> books;

    @DataField(pos = 5)
    private String Age;
}

public class Book {

    @DataField(pos = 3)
    private String title;

    @DataField(pos = 4)
    private String year;
}

case 2 : Reading FIX message containing group of tags/keys

Here is the message that we would like to process in our model :

8=FIX 4.19=2034=135=049=INVMGR56=BRKR
1=BE.CHM.00111=CHM0001-0158=this is a camel - bindy test
22=448=BE000124567854=1
22=548=BE000987654354=2
22=648=BE000999999954=3
10=220

Tags 22, 48 and 54 are repeated.

And the code:

Reading FIX message containing group of tags/keys

public class Order {

    @Link Header header;

    @Link Trailer trailer;

    @KeyValuePairField(tag = 1) // Client reference
    private String account;

    @KeyValuePairField(tag = 11) // Order reference
    private String clOrdId;

    @KeyValuePairField(tag = 58) // Free text
    private String text;

    @OneToMany(mappedTo = "org.apache.camel.dataformat.bindy.model.fix.complex.onetomany.Security")
    List<Security> securities;
}

public class Security {

    @KeyValuePairField(tag = 22) // Fund ID type (Sedol, ISIN, ...)
    private String idSource;

    @KeyValuePairField(tag = 48) // Fund code
    private String securityCode;

    @KeyValuePairField(tag = 54) // Movement type ( 1 = Buy, 2 = sell)
    private String side;
}

17.3.9. 9. BindyConverter

The purpose of the annotation @BindyConverter is define a converter to be used on field level. The provided class must implement the Format interface.

@FixedLengthRecord(length = 10, paddingChar = ' ')
public static class DataModel {
    @DataField(pos =  1, length = 10, trim = true)
    @BindyConverter(CustomConverter.class)
    public String field1;
}

public static class CustomConverter implements Format<String> {
    @Override
    public String format(String object) throws Exception {
        return (new StringBuilder(object)).reverse().toString();
    }

    @Override
    public String parse(String string) throws Exception {
        return (new StringBuilder(string)).reverse().toString();
    }
}

17.3.10. 10. FormatFactories

The purpose of the annotation @FormatFactories is to define a set of converters at record-level. The provided classes must implement the FormatFactoryInterface interface.

@CsvRecord(separator = ",")
@FormatFactories({OrderNumberFormatFactory.class})
public static class Order {

    @DataField(pos = 1)
    private OrderNumber orderNr;

    @DataField(pos = 2)
    private String firstName;
}

public static class OrderNumber {
    private int orderNr;

    public static OrderNumber ofString(String orderNumber) {
        OrderNumber result = new OrderNumber();
        result.orderNr = Integer.valueOf(orderNumber);
        return result;
    }
}

public static class OrderNumberFormatFactory extends AbstractFormatFactory {

    {
        supportedClasses.add(OrderNumber.class);
    }

    @Override
    public Format<?> build(FormattingOptions formattingOptions) {
        return new Format<OrderNumber>() {
            @Override
            public String format(OrderNumber object) throws Exception {
                return String.valueOf(object.orderNr);
            }

            @Override
            public OrderNumber parse(String string) throws Exception {
                return OrderNumber.ofString(string);
            }
        };
    }
}

17.4. Supported Datatypes

The DefaultFormatFactory makes formatting of the following datatype available by returning an instance of the interface FormatFactoryInterface based on the provided FormattingOptions:

  • BigDecimal
  • BigInteger
  • Boolean
  • Byte
  • Character
  • Date
  • Double
  • Enums
  • Float
  • Integer
  • LocalDate
  • LocalDateTime
  • LocalTime
  • Long
  • Short
  • String

The DefaultFormatFactory can be overridden by providing an instance of FactoryRegistry in the registry in use (e.g. spring or JNDI).

17.5. Using the Java DSL

The next step instantiates the DataFormat bindy class associated with this record type and providing a class as a parameter.

For example the following uses the class BindyCsvDataFormat (which corresponds to the class associated with the CSV record type) which is configured with com.acme.model.MyModel.class to initialize the model objects configured in this package.

DataFormat bindy = new BindyCsvDataFormat(com.acme.model.MyModel.class);

17.5.1. Setting locale

Bindy supports configuring the locale on the dataformat, such as

BindyCsvDataFormat bindy = new BindyCsvDataFormat(com.acme.model.MyModel.class);

bindy.setLocale("us");

Or to use the platform default locale then use "default" as the locale name.

BindyCsvDataFormat bindy = new BindyCsvDataFormat(com.acme.model.MyModel.class);

bindy.setLocale("default");

17.5.2. Unmarshaling

from("file://inbox")
  .unmarshal(bindy)
  .to("direct:handleOrders");

Alternatively, you can use a named reference to a data format which can then be defined in your Registry e.g. your Spring XML file:

from("file://inbox")
  .unmarshal("myBindyDataFormat")
  .to("direct:handleOrders");

The Camel route will pick-up files in the inbox directory, unmarshall CSV records into a collection of model objects and send the collection
to the route referenced by handleOrders.

The collection returned is a List of Map objects. Each Map within the list contains the model objects that were marshalled out of each line of the CSV. The reason behind this is that each line can correspond to more than one object. This can be confusing when you simply expect one object to be returned per line.

Each object can be retrieve using its class name.

List<Map<String, Object>> unmarshaledModels = (List<Map<String, Object>>) exchange.getIn().getBody();

int modelCount = 0;
for (Map<String, Object> model : unmarshaledModels) {
  for (String className : model.keySet()) {
     Object obj = model.get(className);
     LOG.info("Count : " + modelCount + ", " + obj.toString());
  }
 modelCount++;
}

LOG.info("Total CSV records received by the csv bean : " + modelCount);

Assuming that you want to extract a single Order object from this map for processing in a route, you could use a combination of a Splitter and a Processor as per the following:

from("file://inbox")
    .unmarshal(bindy)
    .split(body())
        .process(new Processor() {
            public void process(Exchange exchange) throws Exception {
                Message in = exchange.getIn();
                Map<String, Object> modelMap = (Map<String, Object>) in.getBody();
                in.setBody(modelMap.get(Order.class.getCanonicalName()));
            }
        })
        .to("direct:handleSingleOrder")
    .end();

Take care of the fact that Bindy uses CHARSET_NAME property or the CHARSET_NAME header as define in the Exchange interface to do a characterset conversion of the inputstream received for unmarshalling. In some producers (e.g. file-endpoint) you can define a characterset. The characterset conversion can already been done by this producer. Sometimes you need to remove this property or header from the exchange before sending it to the unmarshal. If you don’t remove it the conversion might be done twice which might lead to unwanted results.

from("file://inbox?charset=Cp922")
  .removeProperty(Exchange.CHARSET_NAME)
  .unmarshal("myBindyDataFormat")
  .to("direct:handleOrders");

17.5.3. Marshaling

To generate CSV records from a collection of model objects, you create the following route :

from("direct:handleOrders")
   .marshal(bindy)
   .to("file://outbox")

17.6. Using Spring XML

This is really easy to use Spring as your favorite DSL language to declare the routes to be used for camel-bindy. The following example shows two routes where the first will pick-up records from files, unmarshal the content and bind it to their model. The result is then send to a pojo (doing nothing special) and place them into a queue.

The second route will extract the pojos from the queue and marshal the content to generate a file containing the CSV record.

Spring DSL

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://camel.apache.org/schema/spring
       http://camel.apache.org/schema/spring/camel-spring.xsd">

    <!-- Queuing engine - ActiveMq - work locally in mode virtual memory -->
    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="brokerURL" value="vm://localhost:61616"/>
    </bean>

    <camelContext xmlns="http://camel.apache.org/schema/spring">
        <dataFormats>
          <bindy id="bindyDataformat" type="Csv" classType="org.apache.camel.bindy.model.Order"/>
        </dataFormats>

        <route>
            <from uri="file://src/data/csv/?noop=true" />
            <unmarshal ref="bindyDataformat" />
            <to uri="bean:csv" />
            <to uri="activemq:queue:in" />
        </route>

        <route>
            <from uri="activemq:queue:in" />
            <marshal ref="bindyDataformat" />
            <to uri="file://src/data/csv/out/" />
        </route>
    </camelContext>
</beans>

Note

Please verify that your model classes implements serializable otherwise the queue manager will raise an error.

17.7. Dependencies

To use Bindy in your camel routes you need to add the a dependency on camel-bindy which implements this data format.

If you use maven you could just add the following to your pom.xml, substituting the version number for the latest & greatest release (see the download page for the latest versions).

<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-bindy</artifactId>
  <version>{CamelSBVersion}</version>
</dependency>

17.8. Spring Boot Auto-Configuration

The component supports 18 options, which are listed below.

NameDescriptionDefaultType

camel.dataformat.bindy-csv.allow-empty-stream

Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided.

false

Boolean

camel.dataformat.bindy-csv.class-type

Name of model class to use.

 

String

camel.dataformat.bindy-csv.enabled

Whether to enable auto configuration of the bindy-csv data format. This is enabled by default.

 

Boolean

camel.dataformat.bindy-csv.locale

To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default.

 

String

camel.dataformat.bindy-csv.type

Whether to use Csv, Fixed, or KeyValue.

 

String

camel.dataformat.bindy-csv.unwrap-single-instance

When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List.

true

Boolean

camel.dataformat.bindy-fixed.allow-empty-stream

Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided.

false

Boolean

camel.dataformat.bindy-fixed.class-type

Name of model class to use.

 

String

camel.dataformat.bindy-fixed.enabled

Whether to enable auto configuration of the bindy-fixed data format. This is enabled by default.

 

Boolean

camel.dataformat.bindy-fixed.locale

To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default.

 

String

camel.dataformat.bindy-fixed.type

Whether to use Csv, Fixed, or KeyValue.

 

String

camel.dataformat.bindy-fixed.unwrap-single-instance

When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List.

true

Boolean

camel.dataformat.bindy-kvp.allow-empty-stream

Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided.

false

Boolean

camel.dataformat.bindy-kvp.class-type

Name of model class to use.

 

String

camel.dataformat.bindy-kvp.enabled

Whether to enable auto configuration of the bindy-kvp data format. This is enabled by default.

 

Boolean

camel.dataformat.bindy-kvp.locale

To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default.

 

String

camel.dataformat.bindy-kvp.type

Whether to use Csv, Fixed, or KeyValue.

 

String

camel.dataformat.bindy-kvp.unwrap-single-instance

When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List.

true

Boolean

Chapter 18. Browse

Both producer and consumer are supported

The Browse component provides a simple BrowsableEndpoint which can be useful for testing, visualisation tools or debugging. The exchanges sent to the endpoint are all available to be browsed.

18.1. Dependencies

When using browse with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-browse-starter</artifactId>
</dependency>

18.2. URI format

browse:someName[?options]

Where someName can be any string to uniquely identify the endpoint.

18.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

18.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

18.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

18.4. Component Options

The Browse component supports 3 options, which are listed below.

NameDescriptionDefaultType

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

18.5. Endpoint Options

The Browse endpoint is configured using URI syntax:

browse:name

with the following path and query parameters:

18.5.1. Path Parameters (1 parameters)

NameDescriptionDefaultType

name (common)

Required A name which can be any string to uniquely identify the endpoint.

 

String

18.5.2. Query Parameters (4 parameters)

NameDescriptionDefaultType

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

18.6. Sample

In the route below, we insert a browse: component to be able to browse the Exchanges that are passing through:

from("activemq:order.in").to("browse:orderReceived").to("bean:processOrder");

We can now inspect the received exchanges from within the Java code:

private CamelContext context;

public void inspectReceivedOrders() {
    BrowsableEndpoint browse = context.getEndpoint("browse:orderReceived", BrowsableEndpoint.class);
    List<Exchange> exchanges = browse.getExchanges();

    // then we can inspect the list of received exchanges from Java
    for (Exchange exchange : exchanges) {
        String payload = exchange.getIn().getBody();
        // do something with payload
    }
}

18.7. Spring Boot Auto-Configuration

The component supports 4 options, which are listed below.

NameDescriptionDefaultType

camel.component.browse.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.browse.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.browse.enabled

Whether to enable auto configuration of the browse component. This is enabled by default.

 

Boolean

camel.component.browse.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

Chapter 19. Cassandra CQL

Both producer and consumer are supported

Apache Cassandra is an open source NoSQL database designed to handle large amounts on commodity hardware. Like Amazon’s DynamoDB, Cassandra has a peer-to-peer and master-less architecture to avoid single point of failure and garanty high availability. Like Google’s BigTable, Cassandra data is structured using column families which can be accessed through the Thrift RPC API or a SQL-like API called CQL.

Note

This component aims at integrating Cassandra 2.0+ using the CQL3 API (not the Thrift API). It’s based on Cassandra Java Driver provided by DataStax.

19.1. Dependencies

When using cql with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-cassandraql-starter</artifactId>
</dependency>

19.2. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

19.2.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

19.2.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

19.3. Component Options

The Cassandra CQL component supports 3 options, which are listed below.

NameDescriptionDefaultType

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

19.4. Endpoint Options

The Cassandra CQL endpoint is configured using URI syntax:

cql:beanRef:hosts:port/keyspace

with the following path and query parameters:

19.4.1. Path Parameters (4 parameters)

NameDescriptionDefaultType

beanRef (common)

beanRef is defined using bean:id.

 

String

hosts (common)

Hostname(s) Cassandra server(s). Multiple hosts can be separated by comma.

 

String

port (common)

Port number of Cassandra server(s).

 

Integer

keyspace (common)

Keyspace to use.

 

String

19.4.2. Query Parameters (30 parameters)

NameDescriptionDefaultType

clusterName (common)

Cluster name.

 

String

consistencyLevel (common)

Consistency level to use.

Enum values:

  • ANY
  • ONE
  • TWO
  • THREE
  • QUORUM
  • ALL
  • LOCAL_ONE
  • LOCAL_QUORUM
  • EACH_QUORUM
  • SERIAL
  • LOCAL_SERIAL
 

DefaultConsistencyLevel

cql (common)

CQL query to perform. Can be overridden with the message header with key CamelCqlQuery.

 

String

datacenter (common)

Datacenter to use.

datacenter1

String

loadBalancingPolicyClass (common)

To use a specific LoadBalancingPolicyClass.

 

String

password (common)

Password for session authentication.

 

String

prepareStatements (common)

Whether to use PreparedStatements or regular Statements.

true

boolean

resultSetConversionStrategy (common)

To use a custom class that implements logic for converting ResultSet into message body ALL, ONE, LIMIT_10, LIMIT_100…​

 

ResultSetConversionStrategy

session (common)

To use the Session instance (you would normally not use this option).

 

CqlSession

username (common)

Username for session authentication.

 

String

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

sendEmptyMessageWhenIdle (consumer)

If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead.

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

pollStrategy (consumer (advanced))

A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel.

 

PollingConsumerPollStrategy

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

backoffErrorThreshold (scheduler)

The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in.

 

int

backoffIdleThreshold (scheduler)

The number of subsequent idle polls that should happen before the backoffMultipler should kick-in.

 

int

backoffMultiplier (scheduler)

To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured.

 

int

delay (scheduler)

Milliseconds before the next poll.

500

long

greedy (scheduler)

If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages.

false

boolean

initialDelay (scheduler)

Milliseconds before the first poll starts.

1000

long

repeatCount (scheduler)

Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever.

0

long

runLoggingLevel (scheduler)

The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that.

Enum values:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • OFF

TRACE

LoggingLevel

scheduledExecutorService (scheduler)

Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool.

 

ScheduledExecutorService

scheduler (scheduler)

To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler.

none

Object

schedulerProperties (scheduler)

To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler.

 

Map

startScheduler (scheduler)

Whether the scheduler should be auto started.

true

boolean

timeUnit (scheduler)

Time unit for initialDelay and delay options.

Enum values:

  • NANOSECONDS
  • MICROSECONDS
  • MILLISECONDS
  • SECONDS
  • MINUTES
  • HOURS
  • DAYS

MILLISECONDS

TimeUnit

useFixedDelay (scheduler)

Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details.

true

boolean

19.5. Endpoint Connection Syntax

The endpoint can initiate the Cassandra connection or use an existing one.

URIDescription

cql:localhost/keyspace

Single host, default port, usual for testing

cql:host1,host2/keyspace

Multi host, default port

cql:host1,host2:9042/keyspace

Multi host, custom port

cql:host1,host2

Default port and keyspace

cql:bean:sessionRef

Provided Session reference

cql:bean:clusterRef/keyspace

Provided Cluster reference

To fine tune the Cassandra connection (SSL options, pooling options, load balancing policy, retry policy, reconnection policy…​), create your own Cluster instance and give it to the Camel endpoint.

19.6. Messages

19.6.1. Incoming Message

The Camel Cassandra endpoint expects a bunch of simple objects (Object or Object[] or Collection<Object>) which will be bound to the CQL statement as query parameters. If message body is null or empty, then CQL query will be executed without binding parameters.

Headers

  • CamelCqlQuery (optional, String or RegularStatement)

    CQL query either as a plain String or built using the QueryBuilder.

19.6.2. Outgoing Message

The Camel Cassandra endpoint produces one or many a Cassandra Row objects depending on the resultSetConversionStrategy:

  • List<Row> if resultSetConversionStrategy is ALL or LIMIT_[0-9]+
  • Single` Row` if resultSetConversionStrategy is ONE
  • Anything else, if resultSetConversionStrategy is a custom implementation of the ResultSetConversionStrategy

19.7. Repositories

Cassandra can be used to store message keys or messages for the idempotent and aggregation EIP.

Cassandra might not be the best tool for queuing use cases yet, read Cassandra anti-patterns queues and queue like datasets. It’s advised to use LeveledCompaction and a small GC grace setting for these tables to allow tombstoned rows to be removed quickly.

19.8. Idempotent repository

The NamedCassandraIdempotentRepository stores messages keys in a Cassandra table like this:

CAMEL_IDEMPOTENT.cql

CREATE TABLE CAMEL_IDEMPOTENT (
  NAME varchar,   -- Repository name
  KEY varchar,    -- Message key
  PRIMARY KEY (NAME, KEY)
) WITH compaction = {'class':'LeveledCompactionStrategy'}
  AND gc_grace_seconds = 86400;

This repository implementation uses lightweight transactions (also known as Compare and Set) and requires Cassandra 2.0.7+.

Alternatively, the CassandraIdempotentRepository does not have a NAME column and can be extended to use a different data model.

OptionDefaultDescription

table

CAMEL_IDEMPOTENT

Table name

pkColumns

NAME,` KEY`

Primary key columns

name

 

Repository name, value used for NAME column

ttl

 

Key time to live

writeConsistencyLevel

 

Consistency level used to insert/delete key: ANY, ONE, TWO, QUORUM, LOCAL_QUORUM

readConsistencyLevel

 

Consistency level used to read/check key: ONE, TWO, QUORUM, LOCAL_QUORUM

19.9. Aggregation repository

The NamedCassandraAggregationRepository stores exchanges by correlation key in a Cassandra table like this:

CAMEL_AGGREGATION.cql

CREATE TABLE CAMEL_AGGREGATION (
  NAME varchar,        -- Repository name
  KEY varchar,         -- Correlation id
  EXCHANGE_ID varchar, -- Exchange id
  EXCHANGE blob,       -- Serialized exchange
  PRIMARY KEY (NAME, KEY)
) WITH compaction = {'class':'LeveledCompactionStrategy'}
  AND gc_grace_seconds = 86400;

Alternatively, the CassandraAggregationRepository does not have a NAME column and can be extended to use a different data model.

OptionDefaultDescription

table

CAMEL_AGGREGATION

Table name

pkColumns

NAME,KEY

Primary key columns

exchangeIdColumn

EXCHANGE_ID

Exchange Id column

exchangeColumn

EXCHANGE

Exchange content column

name

 

Repository name, value used for NAME column

ttl

 

Exchange time to live

writeConsistencyLevel

 

Consistency level used to insert/delete exchange: ANY, ONE, TWO, QUORUM, LOCAL_QUORUM

readConsistencyLevel

 

Consistency level used to read/check exchange: ONE, TWO, QUORUM, LOCAL_QUORUM

19.10. Examples

To insert something on a table you can use the following code:

String CQL = "insert into camel_user(login, first_name, last_name) values (?, ?, ?)";
from("direct:input")
    .to("cql://localhost/camel_ks?cql=" + CQL);

At this point you should be able to insert data by using a list as body

Arrays.asList("davsclaus", "Claus", "Ibsen")

The same approach can be used for updating or querying the table.

19.11. Spring Boot Auto-Configuration

The component supports 4 options, which are listed below.

NameDescriptionDefaultType

camel.component.cql.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.cql.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.cql.enabled

Whether to enable auto configuration of the cql component. This is enabled by default.

 

Boolean

camel.component.cql.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

Chapter 20. CICS

Since Camel 4.4-redhat

Only producer is supported.

This component allows you to interact with the IBM CICS® general-purpose transaction processing subsystem.

Note

Only synchronous mode call are supported.

20.1. Dependencies

When using camel-cics with Red Hat build of Camel Spring Boot, add the following Maven dependency to your pom.xml to have support for auto configuration:

<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-cics-starter</artifactId>
</dependency>

You must also declare the ctgclient.jar dependency when working with camel-cics starer.

<dependency>
    <artifactId>com.ibm</artifactId>
    <groupId>ctgclient</groupId>
    <scope>system</scope>
    <systemPath>${basedir}/lib/ctgclient.jar</systemPath>
</dependency>

This JAR is provided by IBM and is included in the cics system.

20.2. URI format

cics://[interfaceType]/[dataExchangeType][?options]

Where interfaceType is the CICS set of the external API that the camel-cics invokes. At the moment, only ECI (External Call Interface) is supported. This component communicates with the CICS server using two kinds of dataExchangeType.

  • commarea is a block of storage, limited to 32763 bytes, allocated by the program.
  • channel is the new mechanism for exchanging data, analogous to a parameter list.

By default, if dataExchangeType is not specified, this component uses commarea:

cics://eci?host=xxx&port=xxx...

To use the channel and the container you must specify it explicitly in the URI

cics://eci/channel?host=xxx&port=xxx...

20.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

20.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

20.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

20.4. Component Options

The CICS component supports 17 options, which are listed below.

NameDescriptionDefaultType

ctgDebug

Enable debug mode on the underlying IBM CGT client.

false

java.lang.Boolean

eciBinding

The Binding instance to transform a Camel Exchange to EciRequest and vice versa

 

com.redhat.camel.component.cics.CICSEciBinding

eciTimeout

The ECI timeout value associated with this ECIRequest object. An ECI timeout value of zero indicates that this ECIRequest will not be timed out by CICS Transaction Gateway. An ECI timeout value greater than zero indicates that the ECIRequest may be timed out by CICS Transaction Gateway. ECI timeout can expire before a response is received from CICS. This means that the client does not receive the confirmation from CICS that a unit of work has been backed out or committed.

0

short

encoding

The transfer encoding of the message.

Cp1145

java.lang.String

gatewayFactory

The connection factory to be used

 

com.redhat.camel.component.cics.pool.CICSGatewayFactory

host

The address of the CICS Transaction Gateway that this instance connects to

 

java.lang.String

lazyStartProducer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

 

boolean

port

The port of the CICS Transaction Gateway that this instance connects to.

2006

int

protocol

the protocol that this component will use to connect to the CICS Transaction Gateway.

tcp

java.lang.String

server

The address of the CICS server that this instance connects to.

 

java.lang.String

sslKeyring

The full classname of the SSL key ring class or keystore file to be used for the client encrypted connection.

 

java.lang.String

sslPassword

The password for the encrypted key ring class or keystore

 

java.lang.String

configuration

To use a shared CICS configuration

 

com.redhat.camel.component.cics.CICSConfiguration

socketConnectionTimeout

The socket connection timeout

 

int

password

Password to use for authentication

 

java.lang.String

userId

User ID to use for authentication

 

java.lang.String

20.5. Endpoint Options

The CICS endpoint is configured using URI syntax:

cics://[interfaceType]/[dataExchangeType][?options]

With the following path and query parameters:

20.5.1. Path Parameters (2 parameters)

NameDescriptionDefaultType

interfaceType

The interface type, can be eci, esi or epi. at the moment only eci is supported.

eci

java.lang.String

dataExchangeType

The kind of data exchange to use Enum value:

  • commarea
  • channel

commarea

com.redhat.camel.component.cics.support.CICSDataExchangeType

20.5.2. Query Parameters (15 parameters)

NameDescriptionDefaultType

ctgDebug

Enable debug mode on the underlying IBM CGT client.

false

java.lang.Boolean

eciBinding

The Binding instance to transform a Camel Exchange to EciRequest and vice versa

 

com.redhat.camel.component.cics.CICSEciBinding

eciTimeout

The ECI timeout value associated with this ECIRequest object. An ECI timeout value of zero indicates that this ECIRequest will not be timed out by CICS Transaction Gateway. An ECI timeout value greater than zero indicates that the ECIRequest may be timed out by CICS Transaction Gateway. ECI timeout can expire before a response is received from CICS. This means that the client does not receive the confirmation from CICS that a unit of work has been backed out or committed.

0

short

encoding

Encoding to convert COMMAREA data to before sending.

Cp1145

java.lang.String

gatewayFactory

The connection factory to use

 

com.redhat.camel.component.cics.pool.CICSGatewayFactory

host

The address of the CICS Transaction Gateway that this instance connects to

localhost

java.lang.String

port

The port of the CICS Transaction Gateway that this instance connects to.

2006

int

protocol

the protocol that this component will use to connect to the CICS Transaction Gateway.

tcp

java.lang.String

server

The address of the CICS server that this instance connects to

 

java.lang.String

lazyStartProducer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

 

boolean

sslKeyring

The full class name of the SSL key ring class or keystore file to be used for the client encrypted connection

 

java.lang.String

sslPassword

The password for the encrypted key ring class or keystore

 

java.lang.String

socketConnectionTimeout

The socket connection timeout

 

int

password

Password to use for authentication

 

java.lang.String

userId

User ID to use for authentication

 

java.lang.String

20.6. Message Headers

The CICS component supports 15 message header(s), which is/are listed below:

NameDescriptionDefaultType

CICS_RETURN_CODE
Constant: com.redhat.camel.component.cics.CICSConstants#CICS_RETURN_CODE_HEADER

Return code from this flow operation.

 

int

CICS_RETURN_CODE_STRING
Constant: com.redhat.camel.component.cics.CICSConstants#CICS_RETURN_CODE_STRING_HEADER

The CICS return code as a String. The String is the name of the appropriate Java constant, for example, if this header is ECI_NO_ERROR, then the String returned will be ECI_NO_ERROR. If this header is unknown then the String returned will be ECI_UNKNOWN_CICS_RC.

Note

For CICS return codes that may have more than one meaning the String returned is a concatenation of the return codes. The only concatenated String is: ECI_ERR_REQUEST_TIMEOUT_OR_ERR_NO_REPLY.

 

java.ang.String

CICS_EXTEND_MODE
Constant: com.redhat.camel.component.cics.CICSConstants#CICS_EXTEND_MODE_HEADER

Extend mode of request. The default value is ECI_NO_EXTEND.

 

int

CICS_LUW_TOKEN
Constant: com.redhat.camel.component.cics.CICSConstants#CICS_LUW_TOKEN_HEADER

Extended Logical Unit of Work token. The default value is ECI_LUW_NEW.

 

int

CICS_PROGRAM_NAME
Constant: com.redhat.camel.component.cics.CICSConstants#CICS_PROGRAM_NAME_HEADER

Program to invoke on CICS server.

 

java.lang.String

CICS_TRANSACTION_ID
Constant: com.redhat.camel.component.cics.CICSConstants#CICS_TRANSACTION_ID_HEADER

Transaction ID to run CICS program under.

 

java.lang.String

CICS_COMM_AREA_SIZE
Constant: com.redhat.camel.component.cics.CICSConstants#CICS_COMM_AREA_SIZE_HEADER

Length of COMMAREA. The default value is 0.

 

int

CICS_CHANNEL_NAME
Constant: com.redhat.camel.component.cics.CICSConstants#CICS_CHANNEL_NAME_HEADER

The name of the channel to create com.redhat.camel.component.cics.CICSConstants#CICS_CHANNEL_NAME_HEADER

 

java.lang.String

CICS_CONTAINER_NAME
Constant: com.redhat.camel.component.cics.CICSConstants#CICS_CONTAINER_NAME_HEADER

The name of the container to create.

 

java.lang.String

CICS_CHANNEL_CCSID
Constant: com.redhat.camel.component.cics.CICSConstants#CICS_CHANNEL_CCSID_HEADER

The CCSID the channel should set as its default.

 

int

CICS_SERVER
Constant: com.redhat.camel.component.cics.CICSConstants#CICS_SERVER_HEADER

CICS server to direct request to. This header overrides the value configured in the endpoint.

 

java.lang.String

CICS_USER_ID
Constant: com.redhat.camel.component.cics.CICSConstants#CICS_USER_ID_HEADER

User ID for CICS server. This header overrides the value configured in the endpoint.

 

java.lang.String

CICS_PASSWORD
Constant: com.redhat.camel.component.cics.CICSConstants#CICS_PASSWORD_HEADER

Password or password phrase for CICS server. This header overrides the value configured in the endpoint.

 

java.lang.String

CICS_ABEND_CODE
Constant: com.redhat.camel.component.cics.CICSConstants#CICS_ABEND_CODE_HEADER

CICS transaction abend code.

 

java.lang.String

CICS_ECI_REQUEST_TIMEOUT
Constant: com.redhat.camel.component.cics.CICSConstants#CICS_ECI_REQUEST_TIMEOUT_HEADER

The value, in seconds, of the ECI timeout for the current ECIRequest. A value of zero indicates that this ECIRequest will not be timed out by CICS Transaction Gateway

0

short

CICS_ENCODING
Constant: com.redhat.camel.component.cics.CICSConstants#CICS_ENCODING_HEADER

Encoding to convert COMMAREA data to before sending.

 

String

20.7. Samples

20.7.1. Using Commarea

Following sample show how to configure a route that runs a program on a CICS server using COMMAREA. The COMMAREA size has to be defined in CICS_COMM_AREA_SIZE header, while the COMMAREA input data is defined in the Camel Exchange body.

Note

You must create a COMMAREA that is large enough to contain all the information to be sent to the server and large enough to contain all the information that can be returned from the server.

//.....
import static com.redhat.camel.component.cics.CICSConstants.CICS_PROGRAM_NAME_HEADER;
import static com.redhat.camel.component.cics.CICSConstants.CICS_COMM_AREA_SIZE_HEADER;
//....

from("direct:run").
   setHeader(CICS_PROGRAM_NAME_HEADER, "ECIREADY").
   setHeader(CICS_COMM_AREA_SIZE_HEADER, 18).
   setBody(constant("My input data")).
   to("cics:eci/commarea?host=192.168.0.23&port=2006&protocol=tcp&userId=foo&password=bar");

The Outcome of the CICS program invocation is mapped to Camel Exchange in this way:

  • The numeric value of return code is stored in the CICS_RETURN_CODE header
  • The COMMAREA output data is stored in the Camel Exchange Body.

20.7.2. Using Channel with a single input container

Following sample shows how to use a channel with a single container to run a CICS program. The channel name and the container name are taken from headers, and the container value from the body:

//.....
import static com.redhat.camel.component.cics.CICSConstants.CICS_PROGRAM_NAME_HEADER;
import static com.redhat.camel.component.cics.CICSConstants.CICS_CHANNEL_NAME_HEADER;
import static com.redhat.camel.component.cics.CICSConstants.CICS_CONTAINER_NAME_HEADER;

//...
from("direct:run").
  setHeader(CICS_PROGRAM_NAME_HEADER, "EC03").
  setHeader(CICS_CHANNEL_NAME_HEADER, "SAMPLECHANNEL").
  setHeader(CICS_CONTAINER_NAME_HEADER, "INPUTDATA").
  setBody(constant("My input data")).
  to("cics:eci/channel?host=192.168.0.23&port=2006&protocol=tcp&userId=foo&password=bar");

The container(s) returned is stored in an java.util.Map<String,Object>, the key is the container name and the value is the output data of the container.

20.7.3. Using Channel with multiple input container

If you need to run a CICS program that takes multiple container as input, you can create a java.util.Map<String,Object> where the keys are the container names and the values are the input data. In this case the CICS_CONTAINER_NAME header is ignored.

//.....
import static com.redhat.camel.component.cics.CICSConstants.CICS_PROGRAM_NAME_HEADER;
import static com.redhat.camel.component.cics.CICSConstants.CICS_CHANNEL_NAME_HEADER;

//...
from("direct:run").
  setHeader(CICS_PROGRAM_NAME_HEADER, "EC03").
  setHeader(CICS_CHANNEL_NAME_HEADER, "SAMPLECHANNEL").
  process(exchange->{
    byte[] thirdContainerData = HexFormat.of().parseHex("e04fd020ea3a6910a2d808002b30309d");
    Map<String,Object> containers = Map.of(
           "firstContainerName", "firstContainerData",
           "secondContainerName", "secondContainerData",
           "thirdContainerName", thirdContainerData
    );
    exchange.getMessage().setBody(containers);
  }).
  to("cics:eci/channel?host=192.168.0.23&port=2006&protocol=tcp&userId=foo&password=bar");

20.8. Spring Boot Auto-Configuration

The component supports 17 options, which are listed below.

NameDescriptionDefaultType

camel.component.cics.binding

The Binding instance to transform a Camel Exchange to EciRequest and vice versa.

 

com.redhat.camel.component.cics.CICSEciBinding

camel.component.cics.configuration

Configuration.

 

com.redhat.camel.component.cics.CICSConfiguration

camel.component.cics.ctg-debug

Enable debug mode on the underlying IBM CGT client.

 

java.lang.Boolean

camel.component.cics.eci-timeout

The ECI timeout value associated with this ECIRequest object. An ECI timeout value of zero indicates that this ECIRequest will not be timed out by CICS Transaction Gateway. An ECI timeout value greater than zero indicates that the ECIRequest may be timed out by CICS Transaction Gateway. ECI timeout can expire before a response is received from CICS. This means that the client does not receive the confirmation from CICS that a unit of work has been backed out or committed.

 

java.lang.Short

camel.component.cics.enabled

Whether to enable auto configuration of the cics component. This is enabled by default.

 

java.lang.Boolean

camel.component.cics.encoding

The transfer encoding of the message.

Cp1145

java.lang.String

camel.component.cics.gateway-factory

The connection factory to be use. The option is a com.redhat.camel.component.cics.pool.CICSGatewayFactory type.

 

com.redhat.camel.component.cics.pool.CICSGatewayFactory

camel.component.cics.host

The address of the CICS Transaction Gateway that this instance connects to

 

java.lang.String

camel.component.cics.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

 

java.lang.Boolean

camel.component.cics.password

Password to use for authentication

 

java.lang.String

camel.component.cics.port

The port of the CICS Transaction Gateway that this instance connects to.

2006

java.lang.Integer

camel.component.cics.protocol

the protocol that this component will use to connect to the CICS Transaction Gateway.

tcp

java.lang.String

camel.component.cics.server

The address of the CICS server that this instance connects to

 

java.lang.String

camel.component.cics.socket-connection-timeout

The socket connection timeout

 

java.lang.Integer

camel.component.cics.ssl-keyring

The full classname of the SSL key ring class or keystore file to be used for the client encrypted connection

 

java.lang.String

camel.component.cics.ssl-password

The password for the encrypted key ring class or keystore

 

java.lang.String

camel.component.cics.user-id

User ID to use for authentication

 

java.lang.String

Chapter 21. Constant

The Constant Expression Language is really just a way to use a constant value or object.

Note

This is a fixed constant value (or object) that is only set once during starting up the route, do not use this if you want dynamic values during routing.

21.1. Dependencies

When using constant with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-core-starter</artifactId>
</dependency>

21.2. Constant Options

The Constant language supports 2 options, which are listed below.

NameDefaultJava TypeDescription

resultType

 

String

Sets the class name of the constant type.

trim

 

Boolean

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

21.3. Example

The setHeader EIP can utilize a constant expression like:

<route>
  <from uri="seda:a"/>
  <setHeader name="theHeader">
    <constant>the value</constant>
  </setHeader>
  <to uri="mock:b"/>
</route>

in this case, the message coming from the seda:a endpoint will have the header with key theHeader set its value as the value (string type).

And the same example using Java DSL:

from("seda:a")
  .setHeader("theHeader", constant("the value"))
  .to("mock:b");

21.3.1. Specifying type of value

The option resultType can be used to specify the type of the value, when the value is given as a String value, which happens when using XML or YAML DSL:

For example to set a header with int type you can do:

<route>
  <from uri="seda:a"/>
  <setHeader name="zipCode">
    <constant resultType="int">90210</constant>
  </setHeader>
  <to uri="mock:b"/>
</route>

21.4. Loading constant from external resource

You can externalize the constant and have Camel load it from a resource such as "classpath:", "file:", or "http:".
This is done using the following syntax: "resource:scheme:location", eg to refer to a file on the classpath you can do:

.setHeader("myHeader").constant("resource:classpath:constant.txt")

21.5. Dependencies

The Constant language is part of camel-core.

21.6. Spring Boot Auto-Configuration

The component supports 147 options, which are listed below.

NameDescriptionDefaultType

camel.cloud.consul.service-discovery.acl-token

Sets the ACL token to be used with Consul.

 

String

camel.cloud.consul.service-discovery.block-seconds

The seconds to wait for a watch event, default 10 seconds.

10

Integer

camel.cloud.consul.service-discovery.configurations

Define additional configuration definitions.

 

Map

camel.cloud.consul.service-discovery.connect-timeout-millis

Connect timeout for OkHttpClient.

 

Long

camel.cloud.consul.service-discovery.datacenter

The data center.

 

String

camel.cloud.consul.service-discovery.enabled

Enable the component.

true

Boolean

camel.cloud.consul.service-discovery.password

Sets the password to be used for basic authentication.

 

String

camel.cloud.consul.service-discovery.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.consul.service-discovery.read-timeout-millis

Read timeout for OkHttpClient.

 

Long

camel.cloud.consul.service-discovery.url

The Consul agent URL.

 

String

camel.cloud.consul.service-discovery.user-name

Sets the username to be used for basic authentication.

 

String

camel.cloud.consul.service-discovery.write-timeout-millis

Write timeout for OkHttpClient.

 

Long

camel.cloud.dns.service-discovery.configurations

Define additional configuration definitions.

 

Map

camel.cloud.dns.service-discovery.domain

The domain name;.

 

String

camel.cloud.dns.service-discovery.enabled

Enable the component.

true

Boolean

camel.cloud.dns.service-discovery.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.dns.service-discovery.proto

The transport protocol of the desired service.

_tcp

String

camel.cloud.etcd.service-discovery.configurations

Define additional configuration definitions.

 

Map

camel.cloud.etcd.service-discovery.enabled

Enable the component.

true

Boolean

camel.cloud.etcd.service-discovery.password

The password to use for basic authentication.

 

String

camel.cloud.etcd.service-discovery.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.etcd.service-discovery.service-path

The path to look for for service discovery.

/services/

String

camel.cloud.etcd.service-discovery.timeout

To set the maximum time an action could take to complete.

 

Long

camel.cloud.etcd.service-discovery.type

To set the discovery type, valid values are on-demand and watch.

on-demand

String

camel.cloud.etcd.service-discovery.uris

The URIs the client can connect to.

 

String

camel.cloud.etcd.service-discovery.user-name

The user name to use for basic authentication.

 

String

camel.cloud.kubernetes.service-discovery.api-version

Sets the API version when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.ca-cert-data

Sets the Certificate Authority data when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.ca-cert-file

Sets the Certificate Authority data that are loaded from the file when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-cert-data

Sets the Client Certificate data when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-cert-file

Sets the Client Certificate data that are loaded from the file when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-key-algo

Sets the Client Keystore algorithm, such as RSA when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-key-data

Sets the Client Keystore data when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-key-file

Sets the Client Keystore data that are loaded from the file when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-key-passphrase

Sets the Client Keystore passphrase when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.configurations

Define additional configuration definitions.

 

Map

camel.cloud.kubernetes.service-discovery.dns-domain

Sets the DNS domain to use for DNS lookup.

 

String

camel.cloud.kubernetes.service-discovery.enabled

Enable the component.

true

Boolean

camel.cloud.kubernetes.service-discovery.lookup

How to perform service lookup. Possible values: client, dns, environment. When using client, then the client queries the kubernetes master to obtain a list of active pods that provides the service, and then random (or round robin) select a pod. When using dns the service name is resolved as name.namespace.svc.dnsDomain. When using dnssrv the service name is resolved with SRV query for .…​svc…​ When using environment then environment variables are used to lookup the service. By default environment is used.

environment

String

camel.cloud.kubernetes.service-discovery.master-url

Sets the URL to the master when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.namespace

Sets the namespace to use. Will by default use namespace from the ENV variable KUBERNETES_MASTER.

 

String

camel.cloud.kubernetes.service-discovery.oauth-token

Sets the OAUTH token for authentication (instead of username/password) when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.password

Sets the password for authentication when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.port-name

Sets the Port Name to use for DNS/DNSSRV lookup.

 

String

camel.cloud.kubernetes.service-discovery.port-protocol

Sets the Port Protocol to use for DNS/DNSSRV lookup.

 

String

camel.cloud.kubernetes.service-discovery.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.kubernetes.service-discovery.trust-certs

Sets whether to turn on trust certificate check when using client lookup.

false

Boolean

camel.cloud.kubernetes.service-discovery.username

Sets the username for authentication when using client lookup.

 

String

camel.cloud.ribbon.load-balancer.client-name

Sets the Ribbon client name.

 

String

camel.cloud.ribbon.load-balancer.configurations

Define additional configuration definitions.

 

Map

camel.cloud.ribbon.load-balancer.enabled

Enable the component.

true

Boolean

camel.cloud.ribbon.load-balancer.namespace

The namespace.

 

String

camel.cloud.ribbon.load-balancer.password

The password.

 

String

camel.cloud.ribbon.load-balancer.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.ribbon.load-balancer.username

The username.

 

String

camel.hystrix.allow-maximum-size-to-diverge-from-core-size

Allows the configuration for maximumSize to take effect. That value can then be equal to, or higher, than coreSize.

false

Boolean

camel.hystrix.circuit-breaker-enabled

Whether to use a HystrixCircuitBreaker or not. If false no circuit-breaker logic will be used and all requests permitted. This is similar in effect to circuitBreakerForceClosed() except that continues tracking metrics and knowing whether it should be open/closed, this property results in not even instantiating a circuit-breaker.

true

Boolean

camel.hystrix.circuit-breaker-error-threshold-percentage

Error percentage threshold (as whole number such as 50) at which point the circuit breaker will trip open and reject requests. It will stay tripped for the duration defined in circuitBreakerSleepWindowInMilliseconds; The error percentage this is compared against comes from HystrixCommandMetrics.getHealthCounts().

50

Integer

camel.hystrix.circuit-breaker-force-closed

If true the HystrixCircuitBreaker#allowRequest() will always return true to allow requests regardless of the error percentage from HystrixCommandMetrics.getHealthCounts(). The circuitBreakerForceOpen() property takes precedence so if it set to true this property does nothing.

false

Boolean

camel.hystrix.circuit-breaker-force-open

If true the HystrixCircuitBreaker.allowRequest() will always return false, causing the circuit to be open (tripped) and reject all requests. This property takes precedence over circuitBreakerForceClosed();.

false

Boolean

camel.hystrix.circuit-breaker-request-volume-threshold

Minimum number of requests in the metricsRollingStatisticalWindowInMilliseconds() that must exist before the HystrixCircuitBreaker will trip. If below this number the circuit will not trip regardless of error percentage.

20

Integer

camel.hystrix.circuit-breaker-sleep-window-in-milliseconds

The time in milliseconds after a HystrixCircuitBreaker trips open that it should wait before trying requests again.

5000

Integer

camel.hystrix.configurations

Define additional configuration definitions.

 

Map

camel.hystrix.core-pool-size

Core thread-pool size that gets passed to java.util.concurrent.ThreadPoolExecutor#setCorePoolSize(int).

10

Integer

camel.hystrix.enabled

Enable the component.

true

Boolean

camel.hystrix.execution-isolation-semaphore-max-concurrent-requests

Number of concurrent requests permitted to HystrixCommand.run(). Requests beyond the concurrent limit will be rejected. Applicable only when executionIsolationStrategy == SEMAPHORE.

20

Integer

camel.hystrix.execution-isolation-strategy

What isolation strategy HystrixCommand.run() will be executed with. If THREAD then it will be executed on a separate thread and concurrent requests limited by the number of threads in the thread-pool. If SEMAPHORE then it will be executed on the calling thread and concurrent requests limited by the semaphore count.

THREAD

String

camel.hystrix.execution-isolation-thread-interrupt-on-timeout

Whether the execution thread should attempt an interrupt (using Future#cancel ) when a thread times out. Applicable only when executionIsolationStrategy() == THREAD.

true

Boolean

camel.hystrix.execution-timeout-enabled

Whether the timeout mechanism is enabled for this command.

true

Boolean

camel.hystrix.execution-timeout-in-milliseconds

Time in milliseconds at which point the command will timeout and halt execution. If executionIsolationThreadInterruptOnTimeout == true and the command is thread-isolated, the executing thread will be interrupted. If the command is semaphore-isolated and a HystrixObservableCommand, that command will get unsubscribed.

1000

Integer

camel.hystrix.fallback-enabled

Whether HystrixCommand.getFallback() should be attempted when failure occurs.

true

Boolean

camel.hystrix.fallback-isolation-semaphore-max-concurrent-requests

Number of concurrent requests permitted to HystrixCommand.getFallback(). Requests beyond the concurrent limit will fail-fast and not attempt retrieving a fallback.

10

Integer

camel.hystrix.group-key

Sets the group key to use. The default value is CamelHystrix.

CamelHystrix

String

camel.hystrix.keep-alive-time

Keep-alive time in minutes that gets passed to ThreadPoolExecutor#setKeepAliveTime(long,TimeUnit).

1

Integer

camel.hystrix.max-queue-size

Max queue size that gets passed to BlockingQueue in HystrixConcurrencyStrategy.getBlockingQueue(int) This should only affect the instantiation of a threadpool - it is not eliglible to change a queue size on the fly. For that, use queueSizeRejectionThreshold().

-1

Integer

camel.hystrix.maximum-size

Maximum thread-pool size that gets passed to ThreadPoolExecutor#setMaximumPoolSize(int) . This is the maximum amount of concurrency that can be supported without starting to reject HystrixCommands. Please note that this setting only takes effect if you also set allowMaximumSizeToDivergeFromCoreSize.

10

Integer

camel.hystrix.metrics-health-snapshot-interval-in-milliseconds

Time in milliseconds to wait between allowing health snapshots to be taken that calculate success and error percentages and affect HystrixCircuitBreaker.isOpen() status. On high-volume circuits the continual calculation of error percentage can become CPU intensive thus this controls how often it is calculated.

500

Integer

camel.hystrix.metrics-rolling-percentile-bucket-size

Maximum number of values stored in each bucket of the rolling percentile. This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.

10

Integer

camel.hystrix.metrics-rolling-percentile-enabled

Whether percentile metrics should be captured using HystrixRollingPercentile inside HystrixCommandMetrics.

true

Boolean

camel.hystrix.metrics-rolling-percentile-window-buckets

Number of buckets the rolling percentile window is broken into. This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.

6

Integer

camel.hystrix.metrics-rolling-percentile-window-in-milliseconds

Duration of percentile rolling window in milliseconds. This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.

10000

Integer

camel.hystrix.metrics-rolling-statistical-window-buckets

Number of buckets the rolling statistical window is broken into. This is passed into HystrixRollingNumber inside HystrixCommandMetrics.

10

Integer

camel.hystrix.metrics-rolling-statistical-window-in-milliseconds

This property sets the duration of the statistical rolling window, in milliseconds. This is how long metrics are kept for the thread pool. The window is divided into buckets and rolls by those increments.

10000

Integer

camel.hystrix.queue-size-rejection-threshold

Queue size rejection threshold is an artificial max size at which rejections will occur even if maxQueueSize has not been reached. This is done because the maxQueueSize of a BlockingQueue can not be dynamically changed and we want to support dynamically changing the queue size that affects rejections. This is used by HystrixCommand when queuing a thread for execution.

5

Integer

camel.hystrix.request-log-enabled

Whether HystrixCommand execution and events should be logged to HystrixRequestLog.

true

Boolean

camel.hystrix.thread-pool-key

Sets the thread pool key to use. Will by default use the same value as groupKey has been configured to use.

CamelHystrix

String

camel.hystrix.thread-pool-rolling-number-statistical-window-buckets

Number of buckets the rolling statistical window is broken into. This is passed into HystrixRollingNumber inside each HystrixThreadPoolMetrics instance.

10

Integer

camel.hystrix.thread-pool-rolling-number-statistical-window-in-milliseconds

Duration of statistical rolling window in milliseconds. This is passed into HystrixRollingNumber inside each HystrixThreadPoolMetrics instance.

10000

Integer

camel.language.constant.enabled

Whether to enable auto configuration of the constant language. This is enabled by default.

 

Boolean

camel.language.constant.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.csimple.enabled

Whether to enable auto configuration of the csimple language. This is enabled by default.

 

Boolean

camel.language.csimple.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.exchangeproperty.enabled

Whether to enable auto configuration of the exchangeProperty language. This is enabled by default.

 

Boolean

camel.language.exchangeproperty.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.file.enabled

Whether to enable auto configuration of the file language. This is enabled by default.

 

Boolean

camel.language.file.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.header.enabled

Whether to enable auto configuration of the header language. This is enabled by default.

 

Boolean

camel.language.header.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.ref.enabled

Whether to enable auto configuration of the ref language. This is enabled by default.

 

Boolean

camel.language.ref.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.simple.enabled

Whether to enable auto configuration of the simple language. This is enabled by default.

 

Boolean

camel.language.simple.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.tokenize.enabled

Whether to enable auto configuration of the tokenize language. This is enabled by default.

 

Boolean

camel.language.tokenize.group-delimiter

Sets the delimiter to use when grouping. If this has not been set then token will be used as the delimiter.

 

String

camel.language.tokenize.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.resilience4j.automatic-transition-from-open-to-half-open-enabled

Enables automatic transition from OPEN to HALF_OPEN state once the waitDurationInOpenState has passed.

false

Boolean

camel.resilience4j.circuit-breaker-ref

Refers to an existing io.github.resilience4j.circuitbreaker.CircuitBreaker instance to lookup and use from the registry. When using this, then any other circuit breaker options are not in use.

 

String

camel.resilience4j.config-ref

Refers to an existing io.github.resilience4j.circuitbreaker.CircuitBreakerConfig instance to lookup and use from the registry.

 

String

camel.resilience4j.configurations

Define additional configuration definitions.

 

Map

camel.resilience4j.enabled

Enable the component.

true

Boolean

camel.resilience4j.failure-rate-threshold

Configures the failure rate threshold in percentage. If the failure rate is equal or greater than the threshold the CircuitBreaker transitions to open and starts short-circuiting calls. The threshold must be greater than 0 and not greater than 100. Default value is 50 percentage.

 

Float

camel.resilience4j.minimum-number-of-calls

Configures the minimum number of calls which are required (per sliding window period) before the CircuitBreaker can calculate the error rate. For example, if minimumNumberOfCalls is 10, then at least 10 calls must be recorded, before the failure rate can be calculated. If only 9 calls have been recorded the CircuitBreaker will not transition to open even if all 9 calls have failed. Default minimumNumberOfCalls is 100.

100

Integer

camel.resilience4j.permitted-number-of-calls-in-half-open-state

Configures the number of permitted calls when the CircuitBreaker is half open. The size must be greater than 0. Default size is 10.

10

Integer

camel.resilience4j.sliding-window-size

Configures the size of the sliding window which is used to record the outcome of calls when the CircuitBreaker is closed. slidingWindowSize configures the size of the sliding window. Sliding window can either be count-based or time-based. If slidingWindowType is COUNT_BASED, the last slidingWindowSize calls are recorded and aggregated. If slidingWindowType is TIME_BASED, the calls of the last slidingWindowSize seconds are recorded and aggregated. The slidingWindowSize must be greater than 0. The minimumNumberOfCalls must be greater than 0. If the slidingWindowType is COUNT_BASED, the minimumNumberOfCalls cannot be greater than slidingWindowSize . If the slidingWindowType is TIME_BASED, you can pick whatever you want. Default slidingWindowSize is 100.

100

Integer

camel.resilience4j.sliding-window-type

Configures the type of the sliding window which is used to record the outcome of calls when the CircuitBreaker is closed. Sliding window can either be count-based or time-based. If slidingWindowType is COUNT_BASED, the last slidingWindowSize calls are recorded and aggregated. If slidingWindowType is TIME_BASED, the calls of the last slidingWindowSize seconds are recorded and aggregated. Default slidingWindowType is COUNT_BASED.

COUNT_BASED

String

camel.resilience4j.slow-call-duration-threshold

Configures the duration threshold (seconds) above which calls are considered as slow and increase the slow calls percentage. Default value is 60 seconds.

60

Integer

camel.resilience4j.slow-call-rate-threshold

Configures a threshold in percentage. The CircuitBreaker considers a call as slow when the call duration is greater than slowCallDurationThreshold Duration. When the percentage of slow calls is equal or greater the threshold, the CircuitBreaker transitions to open and starts short-circuiting calls. The threshold must be greater than 0 and not greater than 100. Default value is 100 percentage which means that all recorded calls must be slower than slowCallDurationThreshold.

 

Float

camel.resilience4j.wait-duration-in-open-state

Configures the wait duration (in seconds) which specifies how long the CircuitBreaker should stay open, before it switches to half open. Default value is 60 seconds.

60

Integer

camel.resilience4j.writable-stack-trace-enabled

Enables writable stack traces. When set to false, Exception.getStackTrace returns a zero length array. This may be used to reduce log spam when the circuit breaker is open as the cause of the exceptions is already known (the circuit breaker is short-circuiting calls).

true

Boolean

camel.rest.api-component

The name of the Camel component to use as the REST API (such as swagger) If no API Component has been explicit configured, then Camel will lookup if there is a Camel component responsible for servicing and generating the REST API documentation, or if a org.apache.camel.spi.RestApiProcessorFactory is registered in the registry. If either one is found, then that is being used.

 

String

camel.rest.api-context-path

Sets a leading API context-path the REST API services will be using. This can be used when using components such as camel-servlet where the deployed web application is deployed using a context-path.

 

String

camel.rest.api-context-route-id

Sets the route id to use for the route that services the REST API. The route will by default use an auto assigned route id.

 

String

camel.rest.api-host

To use an specific hostname for the API documentation (eg swagger) This can be used to override the generated host with this configured hostname.

 

String

camel.rest.api-property

Allows to configure as many additional properties for the api documentation (swagger). For example set property api.title to my cool stuff.

 

Map

camel.rest.api-vendor-extension

Whether vendor extension is enabled in the Rest APIs. If enabled then Camel will include additional information as vendor extension (eg keys starting with x-) such as route ids, class names etc. Not all 3rd party API gateways and tools supports vendor-extensions when importing your API docs.

false

Boolean

camel.rest.binding-mode

Sets the binding mode to use. The default value is off.

 

RestBindingMode

camel.rest.client-request-validation

Whether to enable validation of the client request to check whether the Content-Type and Accept headers from the client is supported by the Rest-DSL configuration of its consumes/produces settings. This can be turned on, to enable this check. In case of validation error, then HTTP Status codes 415 or 406 is returned. The default value is false.

false

Boolean

camel.rest.component

The Camel Rest component to use for the REST transport (consumer), such as netty-http, jetty, servlet, undertow. If no component has been explicit configured, then Camel will lookup if there is a Camel component that integrates with the Rest DSL, or if a org.apache.camel.spi.RestConsumerFactory is registered in the registry. If either one is found, then that is being used.

 

String

camel.rest.component-property

Allows to configure as many additional properties for the rest component in use.

 

Map

camel.rest.consumer-property

Allows to configure as many additional properties for the rest consumer in use.

 

Map

camel.rest.context-path

Sets a leading context-path the REST services will be using. This can be used when using components such as camel-servlet where the deployed web application is deployed using a context-path. Or for components such as camel-jetty or camel-netty-http that includes a HTTP server.

 

String

camel.rest.cors-headers

Allows to configure custom CORS headers.

 

Map

camel.rest.data-format-property

Allows to configure as many additional properties for the data formats in use. For example set property prettyPrint to true to have json outputted in pretty mode. The properties can be prefixed to denote the option is only for either JSON or XML and for either the IN or the OUT. The prefixes are: json.in. json.out. xml.in. xml.out. For example a key with value xml.out.mustBeJAXBElement is only for the XML data format for the outgoing. A key without a prefix is a common key for all situations.

 

Map

camel.rest.enable-cors

Whether to enable CORS headers in the HTTP response. The default value is false.

false

Boolean

camel.rest.endpoint-property

Allows to configure as many additional properties for the rest endpoint in use.

 

Map

camel.rest.host

The hostname to use for exposing the REST service.

 

String

camel.rest.host-name-resolver

If no hostname has been explicit configured, then this resolver is used to compute the hostname the REST service will be using.

 

RestHostNameResolver

camel.rest.json-data-format

Name of specific json data format to use. By default json-jackson will be used. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance.

 

String

camel.rest.port

The port number to use for exposing the REST service. Notice if you use servlet component then the port number configured here does not apply, as the port number in use is the actual port number the servlet component is using. eg if using Apache Tomcat its the tomcat http port, if using Apache Karaf its the HTTP service in Karaf that uses port 8181 by default etc. Though in those situations setting the port number here, allows tooling and JMX to know the port number, so its recommended to set the port number to the number that the servlet engine uses.

 

String

camel.rest.producer-api-doc

Sets the location of the api document (swagger api) the REST producer will use to validate the REST uri and query parameters are valid accordingly to the api document. This requires adding camel-swagger-java to the classpath, and any miss configuration will let Camel fail on startup and report the error(s). The location of the api document is loaded from classpath by default, but you can use file: or http: to refer to resources to load from file or http url.

 

String

camel.rest.producer-component

Sets the name of the Camel component to use as the REST producer.

 

String

camel.rest.scheme

The scheme to use for exposing the REST service. Usually http or https is supported. The default value is http.

 

String

camel.rest.skip-binding-on-error-code

Whether to skip binding on output if there is a custom HTTP error code header. This allows to build custom error messages that do not bind to json / xml etc, as success messages otherwise will do.

false

Boolean

camel.rest.use-x-forward-headers

Whether to use X-Forward headers for Host and related setting. The default value is true.

true

Boolean

camel.rest.xml-data-format

Name of specific XML data format to use. By default jaxb will be used. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance.

 

String

camel.rest.api-context-id-pattern

Deprecated Sets an CamelContext id pattern to only allow Rest APIs from rest services within CamelContext’s which name matches the pattern. The pattern name refers to the CamelContext name, to match on the current CamelContext only. For any other value, the pattern uses the rules from PatternHelper#matchPattern(String,String).

 

String

camel.rest.api-context-listing

Deprecated Sets whether listing of all available CamelContext’s with REST services in the JVM is enabled. If enabled it allows to discover these contexts, if false then only the current CamelContext is in use.

false

Boolean

Chapter 22. Control Bus

Only producer is supported

The Control Bus from the EIP patterns allows for the integration system to be monitored and managed from within the framework.

Use a Control Bus to manage an enterprise integration system. The Control Bus uses the same messaging mechanism used by the application data, but uses separate channels to transmit data that is relevant to the management of components involved in the message flow.

In Camel you can manage and monitor using JMX, or by using a Java API from the CamelContext, or from the org.apache.camel.api.management package, or use the event notifier which has an example here.

The ControlBus component provides easy management of Camel applications based on the Control Bus EIP pattern. For example, by sending a message to an Endpoint you can control the lifecycle of routes, or gather performance statistics.

controlbus:command[?options]

Where command can be any string to identify which type of command to use.

22.1. Commands

CommandDescription

route

To control routes using the routeId and action parameter.

language

Allows you to specify a to use for evaluating the message body. If there is any result from the evaluation, then the result is put in the message body.

22.2. Dependencies

When using controlbus with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-controlbus-starter</artifactId>
</dependency>

22.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

22.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

22.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

22.4. Component Options

The Control Bus component supports 2 options, which are listed below.

NameDescriptionDefaultType

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

22.5. Endpoint Options

The Control Bus endpoint is configured using URI syntax:

controlbus:command:language

with the following path and query parameters:

22.5.1. Path Parameters (2 parameters)

NameDescriptionDefaultType

command (producer)

Required Command can be either route or language.

Enum values:

  • route
  • language
 

String

language (producer)

Allows you to specify the name of a Language to use for evaluating the message body. If there is any result from the evaluation, then the result is put in the message body.

Enum values:

  • bean
  • constant
  • el
  • exchangeProperty
  • file
  • groovy
  • header
  • jsonpath
  • mvel
  • ognl
  • ref
  • simple
  • spel
  • sql
  • terser
  • tokenize
  • xpath
  • xquery
  • xtokenize
 

Language

22.5.1.1. Query Parameters (6 parameters)
NameDescriptionDefaultType

action (producer)

To denote an action that can be either: start, stop, or status. To either start or stop a route, or to get the status of the route as output in the message body. You can use suspend and resume from Camel 2.11.1 onwards to either suspend or resume a route. And from Camel 2.11.1 onwards you can use stats to get performance statics returned in XML format; the routeId option can be used to define which route to get the performance stats for, if routeId is not defined, then you get statistics for the entire CamelContext. The restart action will restart the route.

Enum values:

  • start
  • stop
  • suspend
  • resume
  • restart
  • status
  • stats
 

String

async (producer)

Whether to execute the control bus task asynchronously. Important: If this option is enabled, then any result from the task is not set on the Exchange. This is only possible if executing tasks synchronously.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

loggingLevel (producer)

Logging level used for logging when task is done, or if any exceptions occurred during processing the task.

Enum values:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • OFF

INFO

LoggingLevel

restartDelay (producer)

The delay in millis to use when restarting a route.

1000

int

routeId (producer)

To specify a route by its id. The special keyword current indicates the current route.

 

String

22.6. Using route command

The route command allows you to do common tasks on a given route very easily, for example to start a route, you can send an empty message to this endpoint:

template.sendBody("controlbus:route?routeId=foo&action=start", null);

To get the status of the route, you can do:

String status = template.requestBody("controlbus:route?routeId=foo&action=status", null, String.class);

22.7. Getting performance statistics

This requires JMX to be enabled (is by default) then you can get the performance statistics per route, or for the CamelContext. For example to get the statistics for a route named foo, we can do:

String xml = template.requestBody("controlbus:route?routeId=foo&action=stats", null, String.class);

The returned statistics is in XML format. Its the same data you can get from JMX with the dumpRouteStatsAsXml operation on the ManagedRouteMBean.

To get statistics for the entire CamelContext you just omit the routeId parameter as shown below:

String xml = template.requestBody("controlbus:route?action=stats", null, String.class);

22.8. Using Simple language

You can use the Simple language with the control bus, for example to stop a specific route, you can send a message to the "controlbus:language:simple" endpoint containing the following message:

template.sendBody("controlbus:language:simple", "${camelContext.getRouteController().stopRoute('myRoute')}");

As this is a void operation, no result is returned. However, if you want the route status you can do:

String status = template.requestBody("controlbus:language:simple", "${camelContext.getRouteStatus('myRoute')}", String.class);

It’s easier to use the route command to control lifecycle of routes. The language command allows you to execute a language script that has stronger powers such as Groovy or to some extend the Simple language.

For example to shutdown Camel itself you can do:

template.sendBody("controlbus:language:simple?async=true", "${camelContext.stop()}");

We use async=true to stop Camel asynchronously as otherwise we would be trying to stop Camel while it was in-flight processing the message we sent to the control bus component.

Note

You can also use other languages such as Groovy, etc.

22.9. Spring Boot Auto-Configuration

The component supports 3 options, which are listed below.

NameDescriptionDefaultType

camel.component.controlbus.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.controlbus.enabled

Whether to enable auto configuration of the controlbus component. This is enabled by default.

 

Boolean

camel.component.controlbus.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

Chapter 23. Cron

Only consumer is supported

The Cron component is a generic interface component that allows triggering events at specific time interval specified using the Unix cron syntax (e.g. 0/2 * * * * ? to trigger an event every two seconds).

Being an interface component, the Cron component does not contain a default implementation, instead it requires that the users plug the implementation of their choice.

The following standard Camel components support the Cron endpoints:

  • Camel-quartz
  • Camel-spring

The Cron component is also supported in Camel K, which can use the Kubernetes scheduler to trigger the routes when required by the cron expression. Camel K does not require additional libraries to be plugged when using cron expressions compatible with Kubernetes cron syntax.

23.1. Dependencies

When using cron with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-cron-starter</artifactId>
</dependency>

Additional libraries may be needed in order to plug a specific implementation.

23.2. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

23.2.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

23.2.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

23.3. Component Options

The Cron component supports 3 options, which are listed below.

NameDescriptionDefaultType

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

cronService (advanced)

The id of the CamelCronService to use when multiple implementations are provided.

 

String

23.4. Endpoint Options

The Cron endpoint is configured using URI syntax:

cron:name

with the following path and query parameters:

23.4.1. Path Parameters (1 parameters)

NameDescriptionDefaultType

name (consumer)

Required The name of the cron trigger.

 

String

23.4.2. Query Parameters (4 parameters)

NameDescriptionDefaultType

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

schedule (consumer)

Required A cron expression that will be used to generate events.

 

String

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

23.5. Usage

The component can be used to trigger events at specified times, as in the following example:

from("cron:tab?schedule=0/1+*+*+*+*+?")
.setBody().constant("event")
.log("${body}");

The schedule expression 0/3+10+*+? can be also written as 0/3 10 * * * ? and triggers an event every three seconds only in the tenth minute of each hour.

Parts in the schedule expression means (in order):

  • Seconds (optional)
  • Minutes
  • Hours
  • Day of month
  • Month
  • Day of week
  • Year (optional)

Schedule expressions can be made of 5 to 7 parts. When expressions are composed of 6 parts, the first items is the "seconds" part (and year is considered missing).

Other valid examples of schedule expressions are:

  • 0/2 * * * ? (5 parts, an event every two minutes)
  • 0 0/2 * * * MON-FRI 2030 (7 parts, an event every two minutes only in year 2030)

Routes can also be written using the XML DSL.

<route>
    <from uri="cron:tab?schedule=0/1+*+*+*+*+?"/>
    <setBody>
      <constant>event</constant>
    </setBody>
    <to uri="log:info"/>
</route>

23.6. Spring Boot Auto-Configuration

The component supports 4 options, which are listed below.

NameDescriptionDefaultType

camel.component.cron.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.cron.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.cron.cron-service

The id of the CamelCronService to use when multiple implementations are provided.

 

String

camel.component.cron.enabled

Whether to enable auto configuration of the cron component. This is enabled by default.

 

Boolean

Chapter 24. Crypto (JCE)

Since Camel 2.3

Only producer is supported

With Camel cryptographic endpoints and Java Cryptographic extension, it is easy to create Digital Signatures for Exchanges. Camel provides a pair of flexible endpoints which get used in concert to create a signature for an exchange in one part of the exchange workflow and then verify the signature in a later part of the workflow.

24.1. Dependencies

When using crypto with Red Hat build of Camel Spring Boot ensure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-crypto-starter</artifactId>
</dependency>

24.2. Introduction

Digital signatures make use of Asymmetric Cryptographic techniques to sign messages. From a high level, the algorithms use pairs of complimentary keys with the special property that data encrypted with one key can only be decrypted with the other. The private key, is closely guarded and used to 'sign' the message while the other, public key, is shared around to anyone interested in verifying the signed messages. Messages are signed by using the private key to encrypting a digest of the message. This encrypted digest is transmitted along with the message. On the other side the verifier recalculates the message digest and uses the public key to decrypt the digest in the signature. If both digests match, the verifier knows only the holder of the private key could have created the signature.

Camel uses the Signature service from the Java Cryptographic Extension to do all the heavy cryptographic lifting required to create exchange signatures. The following are the resources for explaining the mechanics of Cryptography, Message digests and Digital Signatures and how to leverage them with the JCE.

  • Bruce Schneier’s Applied Cryptography
  • Beginning Cryptography with Java by David Hook
  • The ever insightful Wikipedia Digital_signatures

24.3. URI format

Camel provides a pair of crypto endpoints to create and verify signatures

crypto:sign:name[?options]
crypto:verify:name[?options]
  • crypto:sign creates the signature and stores it in the Header keyed by the constant org.apache.camel.component.crypto.DigitalSignatureConstants.SIGNATURE, that is, "CamelDigitalSignature".
  • crypto:verify reads in the contents of this header and do the verification calculation.

To function, the sign and verify process needs a pair of keys to be shared, signing requiring a PrivateKey and verifying a PublicKey (or a Certificate containing one). Using the JCE, it is very simple to generate these key pairs but it is usually most secure to use a KeyStore to house and share your keys. The DSL is very flexible about how keys are supplied and provides a number of mechanisms.

A crypto:sign endpoint is typically defined in one route and the complimentary crypto:verify in another, though for simplicity in the examples they appear one after the other. Both signing and verifying should be configured identically.

24.4. Configuring Options

Camel components are configured on two separate levels:

  • component level
  • endpoint level

24.4.1. Configuring Component Options

The component level is the highest level which holds general and common configurations that are inherited by the endpoints. For example a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

Configuring components can be done with the Component DSL, in a configuration file (application.properties|yaml), or directly with Java code.

24.4.2. Configuring Endpoint Options

Endpoints have many options, which allows you to configure what you need the endpoint to do. The options are also categorized into whether the endpoint is used as consumer (from) or as a producer (to), or used for both.

Configuring endpoints is done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

Use Property Placeholders to configure options that allows to not hardcode urls, port numbers, sensitive information, and other settings. In other words placeholders allows to externalize the configuration from your code, and gives more flexibility and reuse.

The following two sections lists all the options, firstly for the component followed by the endpoint.

24.5. Component Options

The Crypto (JCE) component supports 21 options that are listed below.

NameDescriptionDefaultType

algorithm (producer)

Sets the JCE name of the Algorithm that should be used for the signer.

SHA256withRSA

String

alias (producer)

Sets the alias used to query the KeyStore for keys and \\{link java.security.cert.Certificate Certificates} to be used in signing and verifying exchanges. This value can be provided at runtime via the message header org.apache.camel.component.crypto.DigitalSignatureConstants#KEYSTORE_ALIAS.

 

String

certificateName (producer)

Sets the reference name for a PrivateKey that can be found in the registry.

 

String

keystore (producer)

Sets the KeyStore that can contain keys and Certificates for use in signing and verifying exchanges. A KeyStore is typically used with an alias, either one supplied in the Route definition or dynamically via the message header CamelSignatureKeyStoreAlias. If no alias is supplied and there is only a single entry in the Keystore, then this single entry will be used.

 

KeyStore

keystoreName (producer)

Sets the reference name for a Keystore that can be found in the registry.

 

String

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

privateKey* (producer)

Set the PrivateKey that should be used to sign the exchange.

 

PrivateKey

privateKeyName (producer)

Sets the reference name for a PrivateKey that can be found in the registry.

 

String

provider (producer)

Set the id of the security provider that provides the configured Signature algorithm.

 

String

publicKeyName (producer)

references that should be resolved when the context changes.

 

String

secureRandomName (producer)

Sets the reference name for a SecureRandom that can be found in the registry.

 

String

signatureHeaderName (producer)

Set the name of the message header that should be used to store the base64 encoded signature. This defaults to 'CamelDigitalSignature'.

 

String

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

bufferSize (advanced)

Set the size of the buffer used to read in the Exchange payload data.

2048

Integer

certificate (advanced)

Set the Certificate that should be used to verify the signature in the exchange based on its payload.

 

Certificate

clearHeaders (advanced)

Determines if the Signature specific headers be cleared after signing and verification. Defaults to true, and should only be made otherwise at your extreme peril as vital private information such as Keys and passwords may escape if unset.

true

boolean

configuration (advanced)

To use the shared DigitalSignatureConfiguration as configuration.

 

DigitalSignatureConfiguration

keyStoreParameters (advanced)

Sets the KeyStore that can contain keys and Certficates for use in signing and verifying exchanges based on the given KeyStoreParameters. A KeyStore is typically used with an alias, either one supplied in the Route definition or dynamically via the message header CamelSignatureKeyStoreAlias. If no alias is supplied and there is only a single entry in the Keystore, then this single entry will be used.

 

KeyStoreParameters

publicKey (advanced)

Set the PublicKey that should be used to verify the signature in the exchange.

 

PublicKey

secureRandom (advanced)

Set the SecureRandom used to initialize the Signature service.

 

SecureRandom

password (security)

Sets the password used to access an aliased PrivateKey in the KeyStore.

 

String

24.6. Endpoint Options

The Crypto (JCE) endpoint is configured using URI syntax:

crypto:cryptoOperation:name

The following are the path and query parameters:

24.6.1. Path Parameters (2 parameters)

NameDescriptionDefaultType

cryptoOperation (producer)

Required Set the Crypto operation from that supplied after the crypto scheme in the endpoint uri e.g. crypto:sign sets sign as the operation.

Enum values:

* sign

* verify

 

CryptoOperation

name (producer)

Required The logical name of this operation.

 

String

24.6.2. Query Parameters (19 parameters)

NameDescriptionDefaultType

algorithm (producer)

Sets the JCE name of the Algorithm that should be used for the signer.

SHA256withRSA

String

alias (producer)

Sets the alias used to query the KeyStore for keys and \\{link java.security.cert.Certificate Certificates} to be used in signing and verifying exchanges. This value can be provided at runtime via the message header org.apache.camel.component.crypto.DigitalSignatureConstants#KEYSTORE_ALIAS.

 

String

certificateName (producer)

Sets the reference name for a PrivateKey that can be found in the registry.

 

String

keystore (producer)

Sets the KeyStore that can contain keys and Certficates for use in signing and verifying exchanges. A KeyStore is typically used with an alias, either one supplied in the Route definition or dynamically via the message header CamelSignatureKeyStoreAlias. If no alias is supplied and there is only a single entry in the Keystore, then this single entry will be used.

 

KeyStore

keystoreName (producer)

Sets the reference name for a Keystore that can be found in the registry.

 

String

privateKey (producer)

Set the PrivateKey that should be used to sign the exchange.

 

PrivateKey

privateKeyName (producer)

Sets the reference name for a PrivateKey that can be found in the registry.

 

String

provider (producer)

Set the id of the security provider that provides the configured Signature algorithm.

 

String

publicKeyName (producer)

references that should be resolved when the context changes.

 

String

secureRandomName (producer)

Sets the reference name for a SecureRandom that can be found in the registry.

 

String

signatureHeaderName (producer)

Set the name of the message header that should be used to store the base64 encoded signature. This defaults to 'CamelDigitalSignature'.

 

String

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages using Camel routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time.

false

boolean

bufferSize (advanced)

Set the size of the buffer used to read in the Exchange payload data.

2048

Integer

certificate (advanced)

Set the Certificate that should be used to verify the signature in the exchange based on its payload.

 

Certificate

clearHeaders (advanced)

Determines if the Signature specific headers be cleared after signing and verification. Defaults to true, and should only be made otherwise at your extreme peril as vital private information such as Keys and passwords may escape if unset.

true

boolean

keyStoreParameters (advanced)

Sets the KeyStore that can contain keys and Certficates for use in signing and verifying exchanges based on the given KeyStoreParameters. A KeyStore is typically used with an alias, either one supplied in the Route definition or dynamically via the message header CamelSignatureKeyStoreAlias. If no alias is supplied and there is only a single entry in the Keystore, then this single entry will be used.

 

KeyStoreParameters

publicKey (advanced)

Set the PublicKey that should be used to verify the signature in the exchange.

 

PublicKey

secureRandom (advanced)

Set the SecureRandom used to initialize the Signature service.

 

SecureRandom

password (security)

Sets the password used to access an aliased PrivateKey in the KeyStore.

 

String

24.7. Message Headers

The Crypto (JCE) component supports 4 message headers that are listed below.

NameDescriptionDefaultType

[CamelSignaturePrivateKey (producer)

Constant: SIGNATURE_PRIVATE_KEY

The PrivateKey that should be used to sign the message.

 

PrivateKey

[CamelSignaturePublicKeyOrCert (producer)

Constant: SIGNATURE_PUBLIC_KEY_OR_CERT

The Certificate or PublicKey that should be used to verify the signature.

 

Certificate or PublicKey

CamelSignatureKeyStoreAlias (producer)

Constant: KEYSTORE_ALIAS

The alias used to query the KeyStore for keys and Certificates to be used in signing and verifying exchanges.

 

String

CamelSignatureKeyStorePassword (producer)

Constant: KEYSTORE_PASSWORD

The password used to access an aliased PrivateKey in the KeyStore.

 

char[]

24.8. Using

24.8.1. Raw keys

The most basic way to sign and verify an exchange is with a KeyPair as follows.

KeyPair keyPair = KeyGenerator.getInstance("RSA").generateKeyPair();

from("direct:sign")
    .setHeader(DigitalSignatureConstants.SIGNATURE_PRIVATE_KEY, constant(keys.getPrivate()))
    .to("crypto:sign:message")
    .to("direct:verify");

from("direct:verify")
    .setHeader(DigitalSignatureConstants.SIGNATURE_PUBLIC_KEY_OR_CERT, constant(keys.getPublic()))
    .to("crypto:verify:check");

The same can be achieved with the Spring XML Extensions using references to keys.

24.8.2. KeyStores and Aliases.

The JCE provides a very versatile keystore concept for housing pairs of private keys and certificates, keeping them encrypted and password protected. They can be retrieved by applying an alias to the retrieval APIs. There are a number of ways to get keys and Certificates into a keystore, most often this is done with the external 'keytool' application.

The following command will create a keystore containing a key and certificate aliased by bob, which can be used in the following examples. The password for the keystore and the key is letmein.

keytool -genkey -keyalg RSA -keysize 2048 -keystore keystore.jks -storepass letmein -alias bob -dname "CN=Bob,OU=IT,O=Camel" -noprompt

The following route first signs an exchange using Bob’s alias from the KeyStore bound into the Camel Registry, and then verifies it using the same alias.

from("direct:sign")
    .to("crypto:sign:keystoreSign?alias=bob&keystoreName=myKeystore&password=letmein")
    .log("Signature: ${header.CamelDigitalSignature}")
    .to("crypto:verify:keystoreVerify?alias=bob&keystoreName=myKeystore&password=letmein")
    .log("Verified: ${body}");

The following code shows how to load the keystore created using the above keytool command and bind it into the registry with the name myKeystore for use in the above route. The example makes use of the @Configuration and @BindToRegistry annotations introduced in Camel 3 to instantiate the KeyStore and register it with the name myKeyStore.

@Configuration
public class KeystoreConfig {

    @BindToRegistry
    public KeyStore myKeystore() throws Exception {
        KeyStore store = KeyStore.getInstance("JKS");
        try (FileInputStream fis = new FileInputStream("keystore.jks")) {
            store.load(fis, "letmein".toCharArray());
        }
        return store;
    }
}

Again in Spring a ref is used to lookup an actual keystore instance.

24.8.3. Changing JCE Provider and Algorithm

Changing the Signature algorithm or the Security provider is a simple matter of specifying their names. You will need to also use Keys that are compatible with the algorithm you choose.

24.8.4. Changing the Signature Message Header

It may be desirable to change the message header used to store the signature. A different header name can be specified in the route definition as follows

from("direct:sign")
    .to("crypto:sign:keystoreSign?alias=bob&keystoreName=myKeystore&password=letmein&signatureHeaderName=mySignature")
    .log("Signature: ${header.mySignature}")
    .to("crypto:verify:keystoreVerify?alias=bob&keystoreName=myKeystore&password=letmein&signatureHeaderName=mySignature");

===Changing the bufferSize

In case you need to update the size of the buffer.

24.8.5. Supplying Keys dynamically.

When using a Recipient list or similar EIP, the recipient of an exchange can vary dynamically. Using the same key across all recipients may be neither feasible nor desirable. It would be useful to be able to specify signature keys dynamically on a per-exchange basis. The exchange could then be dynamically enriched with the key of its target recipient prior to signing. To facilitate this the signature mechanisms allow for keys to be supplied dynamically via the message headers below.

  • DigitalSignatureConstants.SIGNATURE_PRIVATE_KEY, "CamelSignaturePrivateKey"
  • DigitalSignatureConstants.SIGNATURE_PUBLIC_KEY_OR_CERT, "CamelSignaturePublicKeyOrCert"

Even better would be to dynamically supply a keystore alias. Again the alias can be supplied in a message header

  • DigitalSignatureConstants.KEYSTORE_ALIAS, "CamelSignatureKeyStoreAlias"

The header would be set as follows:

Exchange unsigned = getMandatoryEndpoint("direct:alias-sign").createExchange();
unsigned.getIn().setBody(payload);
unsigned.getIn().setHeader(DigitalSignatureConstants.KEYSTORE_ALIAS, "bob");
unsigned.getIn().setHeader(DigitalSignatureConstants.KEYSTORE_PASSWORD, "letmein".toCharArray());
template.send("direct:alias-sign", unsigned);
Exchange signed = getMandatoryEndpoint("direct:alias-sign").createExchange();
signed.getIn().copyFrom(unsigned.getMessage());
signed.getIn().setHeader(DigitalSignatureConstants.KEYSTORE_ALIAS, "bob");
template.send("direct:alias-verify", signed);

24.9. Spring Boot Auto-Configuration

The component supports 47 options that are listed below.

NameDescriptionDefaultType

camel.component.crypto.algorithm

Sets the JCE name of the Algorithm that should be used for the signer.

SHA256withRSA

String

camel.component.crypto.alias

Sets the alias used to query the KeyStore for keys and {link java.security.cert.Certificate Certificates} to be used in signing and verifying exchanges. This value can be provided at runtime via the message header org.apache.camel.component.crypto.DigitalSignatureConstants#KEYSTORE_ALIAS.

 

String

camel.component.crypto.autowired-enabled

Whether auto-wiring is enabled. This is used for automatic auto-wiring options (the option must be marked as auto-wired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.crypto.buffer-size

Set the size of the buffer used to read in the Exchange payload data.

2048

Integer

camel.component.crypto.certificate

Set the Certificate that should be used to verify the signature in the exchange based on its payload. The option is a java.security.cert.Certificate type.

 

Certificate

camel.component.crypto.certificate-name

Sets the reference name for a PrivateKey that can be found in the registry.

 

String

camel.component.crypto.clear-headers

Determines if the Signature specific headers be cleared after signing and verification. Defaults to true, and should only be made otherwise at your extreme peril as vital private information such as Keys and passwords may escape if unset.

true

Boolean

camel.component.crypto.configuration

To use the shared DigitalSignatureConfiguration as configuration. The option is a org.apache.camel.component.crypto.DigitalSignatureConfiguration type.

 

DigitalSignatureConfiguration

camel.component.crypto.enabled

Whether to enable auto configuration of the crypto component. This is enabled by default.

 

Boolean

camel.component.crypto.key-store-parameters

Sets the KeyStore that can contain keys and Certficates for use in signing and verifying exchanges based on the given KeyStoreParameters. A KeyStore is typically used with an alias, either one supplied in the Route definition or dynamically via the message header CamelSignatureKeyStoreAlias. If no alias is supplied and there is only a single entry in the Keystore, then this single entry will be used. The option is a org.apache.camel.support.jsse.KeyStoreParameters type.

 

KeyStoreParameters

camel.component.crypto.keystore

Sets the KeyStore that can contain keys and Certficates for use in signing and verifying exchanges. A KeyStore is typically used with an alias, either one supplied in the Route definition or dynamically via the message header CamelSignatureKeyStoreAlias. If no alias is supplied and there is only a single entry in the Keystore, then this single entry will be used. The option is a java.security.KeyStore type.

 

KeyStore

camel.component.crypto.keystore-name

Sets the reference name for a Keystore that can be found in the registry.

 

String

camel.component.crypto.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.crypto.password

Sets the password used to access an aliased PrivateKey in the KeyStore.

 

String

camel.component.crypto.private-key

Set the PrivateKey that should be used to sign the exchange. The option is a java.security.PrivateKey type.

 

PrivateKey

camel.component.crypto.private-key-name

Sets the reference name for a PrivateKey that can be found in the registry.

 

String

camel.component.crypto.provider

Set the id of the security provider that provides the configured Signature algorithm.

 

String

camel.component.crypto.public-key

Set the PublicKey that should be used to verify the signature in the exchange. The option is a java.security.PublicKey type.

 

PublicKey

camel.component.crypto.public-key-name

references that should be resolved when the context changes.

 

String

camel.component.crypto.secure-random

Set the SecureRandom used to initialize the Signature service. The option is a java.security.SecureRandom type.

 

SecureRandom

camel.component.crypto.secure-random-name

Sets the reference name for a SecureRandom that can be found in the registry.

 

String

camel.component.crypto.signature-header-name

Set the name of the message header that should be used to store the base64 encoded signature. This defaults to 'CamelDigitalSignature'.

 

String

camel.dataformat.crypto.algorithm

The JCE algorithm name indicating the cryptographic algorithm that will be used.

 

String

camel.dataformat.crypto.algorithm-parameter-ref

A JCE AlgorithmParameterSpec used to initialize the Cipher. Will lookup the type using the given name as a java.security.spec.AlgorithmParameterSpec type.

 

String

camel.dataformat.crypto.buffer-size

The size of the buffer used in the signature process.

4096

Integer

camel.dataformat.crypto.crypto-provider

The name of the JCE Security Provider that should be used.

 

String

camel.dataformat.crypto.enabled

Whether to enable auto configuration of the crypto data format. This is enabled by default.

 

Boolean

camel.dataformat.crypto.init-vector-ref

Refers to a byte array containing the Initialization Vector that will be used to initialize the Cipher.

 

String

camel.dataformat.crypto.inline

Flag indicating that the configured IV should be inlined into the encrypted data stream. Is by default false.

false

Boolean

camel.dataformat.crypto.key-ref

Refers to the secret key to lookup from the register to use.

 

String

camel.dataformat.crypto.mac-algorithm

The JCE algorithm name indicating the Message Authentication algorithm.

HmacSHA1

String

camel.dataformat.crypto.should-append-h-m-a-c

Flag indicating that a Message Authentication Code should be calculated and appended to the encrypted data.

true

Boolean

camel.dataformat.pgp.algorithm

Symmetric key encryption algorithm; possible values are defined in org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags; for example 2 (= TRIPLE DES), 3 (= CAST5), 4 (= BLOWFISH), 6 (= DES), 7 (= AES_128). Only relevant for encrypting.

 

Integer

camel.dataformat.pgp.armored

This option will cause PGP to base64 encode the encrypted text, making it available for copy/paste, etc.

false

Boolean

camel.dataformat.pgp.compression-algorithm

Compression algorithm; possible values are defined in org.bouncycastle.bcpg.CompressionAlgorithmTags; for example 0 (= UNCOMPRESSED), 1 (= ZIP), 2 (= ZLIB), 3 (= BZIP2). Only relevant for encrypting.

 

Integer

camel.dataformat.pgp.enabled

Whether to enable auto configuration of the pgp data format. This is enabled by default.

 

Boolean

camel.dataformat.pgp.hash-algorithm

Signature hash algorithm; possible values are defined in org.bouncycastle.bcpg.HashAlgorithmTags; for example 2 (= SHA1), 8 (= SHA256), 9 (= SHA384), 10 (= SHA512), 11 (=SHA224). Only relevant for signing.

 

Integer

camel.dataformat.pgp.integrity

Adds an integrity check/sign into the encryption file. The default value is true.

true

Boolean

camel.dataformat.pgp.key-file-name

Filename of the keyring; must be accessible as a classpath resource (but you can specify a location in the file system by using the file: prefix).

 

String

camel.dataformat.pgp.key-userid

The user ID of the key in the PGP keyring used during encryption. Can also be only a part of a user ID. For example, if the user ID is Test User then you can use the part Test User or to address the user ID.

 

String

camel.dataformat.pgp.password

Password used when opening the private key (not used for encryption).

 

String

camel.dataformat.pgp.provider

Java Cryptography Extension (JCE) provider, default is Bouncy Castle (BC). Alternatively you can use, for example, the IAIK JCE provider; in this case the provider must be registered beforehand and the Bouncy Castle provider must not be registered beforehand. The Sun JCE provider does not work.

 

String

camel.dataformat.pgp.signature-key-file-name

Filename of the keyring to use for signing (during encryption) or for signature verification (during decryption); must be accessible as a classpath resource (but you can specify a location in the file system by using the file: prefix).

 

String

camel.dataformat.pgp.signature-key-ring

Keyring used for signing/verifying as byte array. You can not set the signatureKeyFileName and signatureKeyRing at the same time.

 

String

camel.dataformat.pgp.signature-key-userid

User ID of the key in the PGP keyring used for signing (during encryption) or signature verification (during decryption). During the signature verification process the specified User ID restricts the public keys from the public keyring which can be used for the verification. If no User ID is specified for the signature verification then any public key in the public keyring can be used for the verification. Can also be only a part of a user ID. For example, if the user ID is Test User then you can use the part Test User or to address the User ID.

 

String

camel.dataformat.pgp.signature-password

Password used when opening the private key used for signing (during encryption).

 

String

camel.dataformat.pgp.signature-verification-option

Controls the behavior for verifying the signature during un-marshaling. There are 4 values possible: optional: The PGP message may or may not contain signatures; if it does contain signatures, then a signature verification is executed. required: The PGP message must contain at least one signature; if this is not the case an exception (PGPException) is thrown. A signature verification is executed. ignore: Contained signatures in the PGP message are ignored; no signature verification is executed. no_signature_allowed: The PGP message must not contain a signature; otherwise an exception (PGPException) is thrown.

 

String

Chapter 25. CSimple

The CSimple language is compiled Simple language.

25.1. Dependencies

When using csimple with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-core-starter</artifactId>
</dependency>

25.2. Different between CSimple and Simple

The simple language is a dynamic expression language which is runtime parsed into a set of Camel Expressions or Predicates.

The csimple language is parsed into regular Java source code and compiled together with all the other source code, or compiled once during bootstrap via the camel-csimple-joor module.

The simple language is generally very lightweight and fast, however for some use-cases with dynamic method calls via OGNL paths, then the simple language does runtime introspection and reflection calls. This has an overhead on performance, and was one of the reasons why csimple was created.

The csimple language requires to be typesafe and method calls via OGNL paths requires to know the type during parsing. This means for csimple languages expressions you would need to provide the class type in the script, whereas simple introspects this at runtime.

In other words the simple language is using duck typing (if it looks like a duck, and quacks like a duck, then it is a duck) and csimple is using Java type (typesafety). If there is a type error then simple will report this at runtime, and with csimple there will be a Java compilation error.

25.2.1. Additional CSimple functions

The csimple language includes some additional functions to support common use-cases working with Collection, Map or array types. The following functions bodyAsIndex, headerAsIndex, and exchangePropertyAsIndex is used for these use-cases as they are typed.

FunctionTypeDescription

bodyAsIndex(type, index)

Type

To be used for collecting the body from an existing Collection, Map or array (lookup by the index) and then converting the body to the given type determined by its classname. The converted body can be null.

mandatoryBodyAsIndex(type, index)

Type

To be used for collecting the body from an existing Collection, Map or array (lookup by the index) and then converting the body to the given type determined by its classname. Expects the body to be not null.

headerAsIndex(key, type, index)

Type

To be used for collecting a header from an existing Collection, Map or array (lookup by the index) and then converting the header value to the given type determined by its classname. The converted header can be null.

mandatoryHeaderAsIndex(key, type, index)

Type

To be used for collecting a header from an existing Collection, Map or array (lookup by the index) and then converting the header value to the given type determined by its classname. Expects the header to be not null.

exchangePropertyAsIndex(key, type, index)

Type

To be used for collecting an exchange property from an existing Collection, Map or array (lookup by the index) and then converting the exchange property to the given type determined by its classname. The converted exchange property can be null.

mandatoryExchangePropertyAsIndex(key, type, index)

Type

To be used for collecting an exchange property from an existing Collection, Map or array (lookup by the index) and then converting the exchange property to the given type determined by its classname. Expects the exchange property to be not null.

For example given the following simple expression:

Hello $\{body[0].name}

This script has no type information, and the simple language will resolve this at runtime, by introspecting the message body and if it’s a collection based then lookup the first element, and then invoke a method named getName via reflection.

In csimple (compiled) we want to pre compile this and therefore the end user must provide type information with the bodyAsIndex function:

Hello $\{bodyAsIndex(com.foo.MyUser, 0).name}

25.3. Compilation

The csimple language is parsed into regular Java source code and compiled together with all the other source code, or it can be compiled once during bootstrap via the camel-csimple-joor module.

There are two ways to compile csimple

  • using the camel-csimple-maven-plugin generating source code at built time.
  • using camel-csimple-joor which does runtime in-memory compilation during bootstrap of Camel.

25.3.1. Using camel-csimple-maven-plugin

The camel-csimple-maven-plugin Maven plugin is used for discovering all the csimple scripts from the source code, and then automatic generate source code in the src/generated/java folder, which then gets compiled together with all the other sources.

The maven plugin will do source code scanning of .java and .xml files (Java and XML DSL). The scanner limits to detect certain code patterns, and it may miss discovering some csimple scripts if they are being used in unusual/rare ways.

The runtime compilation using camel-csimple-joor does not have this limitation.

The benefit is all the csimple scripts will be compiled using the regular Java compiler and therefore everything is included out of the box as .class files in the application JAR file, and no additional dependencies is required at runtime.

To use camel-csimple-maven-plugin you need to add it to your pom.xml file as shown:

<plugins>
    <!-- generate source code for csimple languages -->
    <plugin>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-csimple-maven-plugin</artifactId>
        <version>${camel.version}</version>
        <executions>
            <execution>
                <id>generate</id>
                <goals>
                    <goal>generate</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    <!-- include source code generated to maven sources paths -->
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
            <execution>
                <phase>generate-sources</phase>
                <goals>
                    <goal>add-source</goal>
                    <goal>add-resource</goal>
                </goals>
                <configuration>
                    <sources>
                        <source>src/generated/java</source>
                    </sources>
                    <resources>
                        <resource>
                            <directory>src/generated/resources</directory>
                        </resource>
                    </resources>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

And then you must also add the build-helper-maven-plugin Maven plugin to include src/generated to the list of source folders for the Java compiler, to ensure the generated source code is compiled and included in the application JAR file.

See the camel-example-csimple example at Camel Examples which uses the maven plugin.

25.3.2. Using camel-csimple-joor

The jOOR library integrates with the Java compiler and performs runtime compilation of Java code.

The supported runtime when using camel-simple-joor is intended for Java standalone, Spring Boot, Camel Quarkus and other microservices runtimes. It is not supported in OSGi, Camel Karaf or any kind of Java Application Server runtime.

jOOR does not support runtime compilation with Spring Boot using fat jar packaging (https://github.com/jOOQ/jOOR/issues/69), it works with exploded classpath.

To use camel-simple-joor you simply just add it as dependency to the classpath:

<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-csimple-joor</artifactId>
  <version>{CamelSBProjectVersion}</version>
</dependency>

There is no need for adding Maven plugins to the pom.xml file.

See the camel-example-csimple-joor example at Camel Examples which uses the jOOR compiler.

25.4. CSimple Language options

The CSimple language supports 2 options, which are listed below.

NameDefaultJava TypeDescription

resultType

 

String

Sets the class name of the result type (type from output).

trim

 

Boolean

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

25.5. Limitations

Currently, the csimple language does not support:

  • nested functions (aka functions inside functions)
  • the null safe operator (?).

For example the following scripts cannot compile:

  Hello ${bean:greeter(${body}, ${header.counter})}
  ${bodyAs(MyUser)?.address?.zip} > 10000

25.6. Auto imports

The csimple language will automatically import from:

import java.util.*;
import java.util.concurrent.*;
import java.util.stream.*;
import org.apache.camel.*;
import org.apache.camel.util.*;

25.7. Configuration file

You can configure the csimple language in the camel-csimple.properties file which is loaded from the root classpath.

For example you can add additional imports in the camel-csimple.properties file by adding:

import com.foo.MyUser;
import com.bar.*;
import static com.foo.MyHelper.*;

You can also add aliases (key=value) where an alias will be used as a shorthand replacement in the code.

echo()=${bodyAs(String)} ${bodyAs(String)}

Which allows to use echo() in the csimple language script such as:

from("direct:hello")
    .transform(csimple("Hello echo()"))
    .log("You said ${body}");

The echo() alias will be replaced with its value resulting in a script as:

    .transform(csimple("Hello ${bodyAs(String)} ${bodyAs(String)}"))

25.8. See Also

See the Simple language as csimple has the same set of functions as simple language.

25.9. Spring Boot Auto-Configuration

The component supports 147 options, which are listed below.

NameDescriptionDefaultType

camel.cloud.consul.service-discovery.acl-token

Sets the ACL token to be used with Consul.

 

String

camel.cloud.consul.service-discovery.block-seconds

The seconds to wait for a watch event, default 10 seconds.

10

Integer

camel.cloud.consul.service-discovery.configurations

Define additional configuration definitions.

 

Map

camel.cloud.consul.service-discovery.connect-timeout-millis

Connect timeout for OkHttpClient.

 

Long

camel.cloud.consul.service-discovery.datacenter

The data center.

 

String

camel.cloud.consul.service-discovery.enabled

Enable the component.

true

Boolean

camel.cloud.consul.service-discovery.password

Sets the password to be used for basic authentication.

 

String

camel.cloud.consul.service-discovery.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.consul.service-discovery.read-timeout-millis

Read timeout for OkHttpClient.

 

Long

camel.cloud.consul.service-discovery.url

The Consul agent URL.

 

String

camel.cloud.consul.service-discovery.user-name

Sets the username to be used for basic authentication.

 

String

camel.cloud.consul.service-discovery.write-timeout-millis

Write timeout for OkHttpClient.

 

Long

camel.cloud.dns.service-discovery.configurations

Define additional configuration definitions.

 

Map

camel.cloud.dns.service-discovery.domain

The domain name;.

 

String

camel.cloud.dns.service-discovery.enabled

Enable the component.

true

Boolean

camel.cloud.dns.service-discovery.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.dns.service-discovery.proto

The transport protocol of the desired service.

_tcp

String

camel.cloud.etcd.service-discovery.configurations

Define additional configuration definitions.

 

Map

camel.cloud.etcd.service-discovery.enabled

Enable the component.

true

Boolean

camel.cloud.etcd.service-discovery.password

The password to use for basic authentication.

 

String

camel.cloud.etcd.service-discovery.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.etcd.service-discovery.service-path

The path to look for for service discovery.

/services/

String

camel.cloud.etcd.service-discovery.timeout

To set the maximum time an action could take to complete.

 

Long

camel.cloud.etcd.service-discovery.type

To set the discovery type, valid values are on-demand and watch.

on-demand

String

camel.cloud.etcd.service-discovery.uris

The URIs the client can connect to.

 

String

camel.cloud.etcd.service-discovery.user-name

The user name to use for basic authentication.

 

String

camel.cloud.kubernetes.service-discovery.api-version

Sets the API version when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.ca-cert-data

Sets the Certificate Authority data when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.ca-cert-file

Sets the Certificate Authority data that are loaded from the file when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-cert-data

Sets the Client Certificate data when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-cert-file

Sets the Client Certificate data that are loaded from the file when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-key-algo

Sets the Client Keystore algorithm, such as RSA when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-key-data

Sets the Client Keystore data when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-key-file

Sets the Client Keystore data that are loaded from the file when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-key-passphrase

Sets the Client Keystore passphrase when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.configurations

Define additional configuration definitions.

 

Map

camel.cloud.kubernetes.service-discovery.dns-domain

Sets the DNS domain to use for DNS lookup.

 

String

camel.cloud.kubernetes.service-discovery.enabled

Enable the component.

true

Boolean

camel.cloud.kubernetes.service-discovery.lookup

How to perform service lookup. Possible values: client, dns, environment. When using client, then the client queries the kubernetes master to obtain a list of active pods that provides the service, and then random (or round robin) select a pod. When using dns the service name is resolved as name.namespace.svc.dnsDomain. When using dnssrv the service name is resolved with SRV query for .…​svc…​ When using environment then environment variables are used to lookup the service. By default environment is used.

environment

String

camel.cloud.kubernetes.service-discovery.master-url

Sets the URL to the master when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.namespace

Sets the namespace to use. Will by default use namespace from the ENV variable KUBERNETES_MASTER.

 

String

camel.cloud.kubernetes.service-discovery.oauth-token

Sets the OAUTH token for authentication (instead of username/password) when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.password

Sets the password for authentication when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.port-name

Sets the Port Name to use for DNS/DNSSRV lookup.

 

String

camel.cloud.kubernetes.service-discovery.port-protocol

Sets the Port Protocol to use for DNS/DNSSRV lookup.

 

String

camel.cloud.kubernetes.service-discovery.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.kubernetes.service-discovery.trust-certs

Sets whether to turn on trust certificate check when using client lookup.

false

Boolean

camel.cloud.kubernetes.service-discovery.username

Sets the username for authentication when using client lookup.

 

String

camel.cloud.ribbon.load-balancer.client-name

Sets the Ribbon client name.

 

String

camel.cloud.ribbon.load-balancer.configurations

Define additional configuration definitions.

 

Map

camel.cloud.ribbon.load-balancer.enabled

Enable the component.

true

Boolean

camel.cloud.ribbon.load-balancer.namespace

The namespace.

 

String

camel.cloud.ribbon.load-balancer.password

The password.

 

String

camel.cloud.ribbon.load-balancer.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.ribbon.load-balancer.username

The username.

 

String

camel.hystrix.allow-maximum-size-to-diverge-from-core-size

Allows the configuration for maximumSize to take effect. That value can then be equal to, or higher, than coreSize.

false

Boolean

camel.hystrix.circuit-breaker-enabled

Whether to use a HystrixCircuitBreaker or not. If false no circuit-breaker logic will be used and all requests permitted. This is similar in effect to circuitBreakerForceClosed() except that continues tracking metrics and knowing whether it should be open/closed, this property results in not even instantiating a circuit-breaker.

true

Boolean

camel.hystrix.circuit-breaker-error-threshold-percentage

Error percentage threshold (as whole number such as 50) at which point the circuit breaker will trip open and reject requests. It will stay tripped for the duration defined in circuitBreakerSleepWindowInMilliseconds; The error percentage this is compared against comes from HystrixCommandMetrics.getHealthCounts().

50

Integer

camel.hystrix.circuit-breaker-force-closed

If true the HystrixCircuitBreaker#allowRequest() will always return true to allow requests regardless of the error percentage from HystrixCommandMetrics.getHealthCounts(). The circuitBreakerForceOpen() property takes precedence so if it set to true this property does nothing.

false

Boolean

camel.hystrix.circuit-breaker-force-open

If true the HystrixCircuitBreaker.allowRequest() will always return false, causing the circuit to be open (tripped) and reject all requests. This property takes precedence over circuitBreakerForceClosed();.

false

Boolean

camel.hystrix.circuit-breaker-request-volume-threshold

Minimum number of requests in the metricsRollingStatisticalWindowInMilliseconds() that must exist before the HystrixCircuitBreaker will trip. If below this number the circuit will not trip regardless of error percentage.

20

Integer

camel.hystrix.circuit-breaker-sleep-window-in-milliseconds

The time in milliseconds after a HystrixCircuitBreaker trips open that it should wait before trying requests again.

5000

Integer

camel.hystrix.configurations

Define additional configuration definitions.

 

Map

camel.hystrix.core-pool-size

Core thread-pool size that gets passed to java.util.concurrent.ThreadPoolExecutor#setCorePoolSize(int).

10

Integer

camel.hystrix.enabled

Enable the component.

true

Boolean

camel.hystrix.execution-isolation-semaphore-max-concurrent-requests

Number of concurrent requests permitted to HystrixCommand.run(). Requests beyond the concurrent limit will be rejected. Applicable only when executionIsolationStrategy == SEMAPHORE.

20

Integer

camel.hystrix.execution-isolation-strategy

What isolation strategy HystrixCommand.run() will be executed with. If THREAD then it will be executed on a separate thread and concurrent requests limited by the number of threads in the thread-pool. If SEMAPHORE then it will be executed on the calling thread and concurrent requests limited by the semaphore count.

THREAD

String

camel.hystrix.execution-isolation-thread-interrupt-on-timeout

Whether the execution thread should attempt an interrupt (using Future#cancel ) when a thread times out. Applicable only when executionIsolationStrategy() == THREAD.

true

Boolean

camel.hystrix.execution-timeout-enabled

Whether the timeout mechanism is enabled for this command.

true

Boolean

camel.hystrix.execution-timeout-in-milliseconds

Time in milliseconds at which point the command will timeout and halt execution. If executionIsolationThreadInterruptOnTimeout == true and the command is thread-isolated, the executing thread will be interrupted. If the command is semaphore-isolated and a HystrixObservableCommand, that command will get unsubscribed.

1000

Integer

camel.hystrix.fallback-enabled

Whether HystrixCommand.getFallback() should be attempted when failure occurs.

true

Boolean

camel.hystrix.fallback-isolation-semaphore-max-concurrent-requests

Number of concurrent requests permitted to HystrixCommand.getFallback(). Requests beyond the concurrent limit will fail-fast and not attempt retrieving a fallback.

10

Integer

camel.hystrix.group-key

Sets the group key to use. The default value is CamelHystrix.

CamelHystrix

String

camel.hystrix.keep-alive-time

Keep-alive time in minutes that gets passed to ThreadPoolExecutor#setKeepAliveTime(long,TimeUnit).

1

Integer

camel.hystrix.max-queue-size

Max queue size that gets passed to BlockingQueue in HystrixConcurrencyStrategy.getBlockingQueue(int) This should only affect the instantiation of a threadpool - it is not eliglible to change a queue size on the fly. For that, use queueSizeRejectionThreshold().

-1

Integer

camel.hystrix.maximum-size

Maximum thread-pool size that gets passed to ThreadPoolExecutor#setMaximumPoolSize(int) . This is the maximum amount of concurrency that can be supported without starting to reject HystrixCommands. Please note that this setting only takes effect if you also set allowMaximumSizeToDivergeFromCoreSize.

10

Integer

camel.hystrix.metrics-health-snapshot-interval-in-milliseconds

Time in milliseconds to wait between allowing health snapshots to be taken that calculate success and error percentages and affect HystrixCircuitBreaker.isOpen() status. On high-volume circuits the continual calculation of error percentage can become CPU intensive thus this controls how often it is calculated.

500

Integer

camel.hystrix.metrics-rolling-percentile-bucket-size

Maximum number of values stored in each bucket of the rolling percentile. This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.

10

Integer

camel.hystrix.metrics-rolling-percentile-enabled

Whether percentile metrics should be captured using HystrixRollingPercentile inside HystrixCommandMetrics.

true

Boolean

camel.hystrix.metrics-rolling-percentile-window-buckets

Number of buckets the rolling percentile window is broken into. This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.

6

Integer

camel.hystrix.metrics-rolling-percentile-window-in-milliseconds

Duration of percentile rolling window in milliseconds. This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.

10000

Integer

camel.hystrix.metrics-rolling-statistical-window-buckets

Number of buckets the rolling statistical window is broken into. This is passed into HystrixRollingNumber inside HystrixCommandMetrics.

10

Integer

camel.hystrix.metrics-rolling-statistical-window-in-milliseconds

This property sets the duration of the statistical rolling window, in milliseconds. This is how long metrics are kept for the thread pool. The window is divided into buckets and rolls by those increments.

10000

Integer

camel.hystrix.queue-size-rejection-threshold

Queue size rejection threshold is an artificial max size at which rejections will occur even if maxQueueSize has not been reached. This is done because the maxQueueSize of a BlockingQueue can not be dynamically changed and we want to support dynamically changing the queue size that affects rejections. This is used by HystrixCommand when queuing a thread for execution.

5

Integer

camel.hystrix.request-log-enabled

Whether HystrixCommand execution and events should be logged to HystrixRequestLog.

true

Boolean

camel.hystrix.thread-pool-key

Sets the thread pool key to use. Will by default use the same value as groupKey has been configured to use.

CamelHystrix

String

camel.hystrix.thread-pool-rolling-number-statistical-window-buckets

Number of buckets the rolling statistical window is broken into. This is passed into HystrixRollingNumber inside each HystrixThreadPoolMetrics instance.

10

Integer

camel.hystrix.thread-pool-rolling-number-statistical-window-in-milliseconds

Duration of statistical rolling window in milliseconds. This is passed into HystrixRollingNumber inside each HystrixThreadPoolMetrics instance.

10000

Integer

camel.language.constant.enabled

Whether to enable auto configuration of the constant language. This is enabled by default.

 

Boolean

camel.language.constant.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.csimple.enabled

Whether to enable auto configuration of the csimple language. This is enabled by default.

 

Boolean

camel.language.csimple.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.exchangeproperty.enabled

Whether to enable auto configuration of the exchangeProperty language. This is enabled by default.

 

Boolean

camel.language.exchangeproperty.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.file.enabled

Whether to enable auto configuration of the file language. This is enabled by default.

 

Boolean

camel.language.file.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.header.enabled

Whether to enable auto configuration of the header language. This is enabled by default.

 

Boolean

camel.language.header.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.ref.enabled

Whether to enable auto configuration of the ref language. This is enabled by default.

 

Boolean

camel.language.ref.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.simple.enabled

Whether to enable auto configuration of the simple language. This is enabled by default.

 

Boolean

camel.language.simple.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.tokenize.enabled

Whether to enable auto configuration of the tokenize language. This is enabled by default.

 

Boolean

camel.language.tokenize.group-delimiter

Sets the delimiter to use when grouping. If this has not been set then token will be used as the delimiter.

 

String

camel.language.tokenize.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.resilience4j.automatic-transition-from-open-to-half-open-enabled

Enables automatic transition from OPEN to HALF_OPEN state once the waitDurationInOpenState has passed.

false

Boolean

camel.resilience4j.circuit-breaker-ref

Refers to an existing io.github.resilience4j.circuitbreaker.CircuitBreaker instance to lookup and use from the registry. When using this, then any other circuit breaker options are not in use.

 

String

camel.resilience4j.config-ref

Refers to an existing io.github.resilience4j.circuitbreaker.CircuitBreakerConfig instance to lookup and use from the registry.

 

String

camel.resilience4j.configurations

Define additional configuration definitions.

 

Map

camel.resilience4j.enabled

Enable the component.

true

Boolean

camel.resilience4j.failure-rate-threshold

Configures the failure rate threshold in percentage. If the failure rate is equal or greater than the threshold the CircuitBreaker transitions to open and starts short-circuiting calls. The threshold must be greater than 0 and not greater than 100. Default value is 50 percentage.

 

Float

camel.resilience4j.minimum-number-of-calls

Configures the minimum number of calls which are required (per sliding window period) before the CircuitBreaker can calculate the error rate. For example, if minimumNumberOfCalls is 10, then at least 10 calls must be recorded, before the failure rate can be calculated. If only 9 calls have been recorded the CircuitBreaker will not transition to open even if all 9 calls have failed. Default minimumNumberOfCalls is 100.

100

Integer

camel.resilience4j.permitted-number-of-calls-in-half-open-state

Configures the number of permitted calls when the CircuitBreaker is half open. The size must be greater than 0. Default size is 10.

10

Integer

camel.resilience4j.sliding-window-size

Configures the size of the sliding window which is used to record the outcome of calls when the CircuitBreaker is closed. slidingWindowSize configures the size of the sliding window. Sliding window can either be count-based or time-based. If slidingWindowType is COUNT_BASED, the last slidingWindowSize calls are recorded and aggregated. If slidingWindowType is TIME_BASED, the calls of the last slidingWindowSize seconds are recorded and aggregated. The slidingWindowSize must be greater than 0. The minimumNumberOfCalls must be greater than 0. If the slidingWindowType is COUNT_BASED, the minimumNumberOfCalls cannot be greater than slidingWindowSize . If the slidingWindowType is TIME_BASED, you can pick whatever you want. Default slidingWindowSize is 100.

100

Integer

camel.resilience4j.sliding-window-type

Configures the type of the sliding window which is used to record the outcome of calls when the CircuitBreaker is closed. Sliding window can either be count-based or time-based. If slidingWindowType is COUNT_BASED, the last slidingWindowSize calls are recorded and aggregated. If slidingWindowType is TIME_BASED, the calls of the last slidingWindowSize seconds are recorded and aggregated. Default slidingWindowType is COUNT_BASED.

COUNT_BASED

String

camel.resilience4j.slow-call-duration-threshold

Configures the duration threshold (seconds) above which calls are considered as slow and increase the slow calls percentage. Default value is 60 seconds.

60

Integer

camel.resilience4j.slow-call-rate-threshold

Configures a threshold in percentage. The CircuitBreaker considers a call as slow when the call duration is greater than slowCallDurationThreshold Duration. When the percentage of slow calls is equal or greater the threshold, the CircuitBreaker transitions to open and starts short-circuiting calls. The threshold must be greater than 0 and not greater than 100. Default value is 100 percentage which means that all recorded calls must be slower than slowCallDurationThreshold.

 

Float

camel.resilience4j.wait-duration-in-open-state

Configures the wait duration (in seconds) which specifies how long the CircuitBreaker should stay open, before it switches to half open. Default value is 60 seconds.

60

Integer

camel.resilience4j.writable-stack-trace-enabled

Enables writable stack traces. When set to false, Exception.getStackTrace returns a zero length array. This may be used to reduce log spam when the circuit breaker is open as the cause of the exceptions is already known (the circuit breaker is short-circuiting calls).

true

Boolean

camel.rest.api-component

The name of the Camel component to use as the REST API (such as swagger) If no API Component has been explicit configured, then Camel will lookup if there is a Camel component responsible for servicing and generating the REST API documentation, or if a org.apache.camel.spi.RestApiProcessorFactory is registered in the registry. If either one is found, then that is being used.

 

String

camel.rest.api-context-path

Sets a leading API context-path the REST API services will be using. This can be used when using components such as camel-servlet where the deployed web application is deployed using a context-path.

 

String

camel.rest.api-context-route-id

Sets the route id to use for the route that services the REST API. The route will by default use an auto assigned route id.

 

String

camel.rest.api-host

To use an specific hostname for the API documentation (eg swagger) This can be used to override the generated host with this configured hostname.

 

String

camel.rest.api-property

Allows to configure as many additional properties for the api documentation (swagger). For example set property api.title to my cool stuff.

 

Map

camel.rest.api-vendor-extension

Whether vendor extension is enabled in the Rest APIs. If enabled then Camel will include additional information as vendor extension (eg keys starting with x-) such as route ids, class names etc. Not all 3rd party API gateways and tools supports vendor-extensions when importing your API docs.

false

Boolean

camel.rest.binding-mode

Sets the binding mode to use. The default value is off.

 

RestBindingMode

camel.rest.client-request-validation

Whether to enable validation of the client request to check whether the Content-Type and Accept headers from the client is supported by the Rest-DSL configuration of its consumes/produces settings. This can be turned on, to enable this check. In case of validation error, then HTTP Status codes 415 or 406 is returned. The default value is false.

false

Boolean

camel.rest.component

The Camel Rest component to use for the REST transport (consumer), such as netty-http, jetty, servlet, undertow. If no component has been explicit configured, then Camel will lookup if there is a Camel component that integrates with the Rest DSL, or if a org.apache.camel.spi.RestConsumerFactory is registered in the registry. If either one is found, then that is being used.

 

String

camel.rest.component-property

Allows to configure as many additional properties for the rest component in use.

 

Map

camel.rest.consumer-property

Allows to configure as many additional properties for the rest consumer in use.

 

Map

camel.rest.context-path

Sets a leading context-path the REST services will be using. This can be used when using components such as camel-servlet where the deployed web application is deployed using a context-path. Or for components such as camel-jetty or camel-netty-http that includes a HTTP server.

 

String

camel.rest.cors-headers

Allows to configure custom CORS headers.

 

Map

camel.rest.data-format-property

Allows to configure as many additional properties for the data formats in use. For example set property prettyPrint to true to have json outputted in pretty mode. The properties can be prefixed to denote the option is only for either JSON or XML and for either the IN or the OUT. The prefixes are: json.in. json.out. xml.in. xml.out. For example a key with value xml.out.mustBeJAXBElement is only for the XML data format for the outgoing. A key without a prefix is a common key for all situations.

 

Map

camel.rest.enable-cors

Whether to enable CORS headers in the HTTP response. The default value is false.

false

Boolean

camel.rest.endpoint-property

Allows to configure as many additional properties for the rest endpoint in use.

 

Map

camel.rest.host

The hostname to use for exposing the REST service.

 

String

camel.rest.host-name-resolver

If no hostname has been explicit configured, then this resolver is used to compute the hostname the REST service will be using.

 

RestHostNameResolver

camel.rest.json-data-format

Name of specific json data format to use. By default json-jackson will be used. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance.

 

String

camel.rest.port

The port number to use for exposing the REST service. Notice if you use servlet component then the port number configured here does not apply, as the port number in use is the actual port number the servlet component is using. eg if using Apache Tomcat its the tomcat http port, if using Apache Karaf its the HTTP service in Karaf that uses port 8181 by default etc. Though in those situations setting the port number here, allows tooling and JMX to know the port number, so its recommended to set the port number to the number that the servlet engine uses.

 

String

camel.rest.producer-api-doc

Sets the location of the api document (swagger api) the REST producer will use to validate the REST uri and query parameters are valid accordingly to the api document. This requires adding camel-swagger-java to the classpath, and any miss configuration will let Camel fail on startup and report the error(s). The location of the api document is loaded from classpath by default, but you can use file: or http: to refer to resources to load from file or http url.

 

String

camel.rest.producer-component

Sets the name of the Camel component to use as the REST producer.

 

String

camel.rest.scheme

The scheme to use for exposing the REST service. Usually http or https is supported. The default value is http.

 

String

camel.rest.skip-binding-on-error-code

Whether to skip binding on output if there is a custom HTTP error code header. This allows to build custom error messages that do not bind to json / xml etc, as success messages otherwise will do.

false

Boolean

camel.rest.use-x-forward-headers

Whether to use X-Forward headers for Host and related setting. The default value is true.

true

Boolean

camel.rest.xml-data-format

Name of specific XML data format to use. By default jaxb will be used. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance.

 

String

camel.rest.api-context-id-pattern

Deprecated Sets an CamelContext id pattern to only allow Rest APIs from rest services within CamelContext’s which name matches the pattern. The pattern name refers to the CamelContext name, to match on the current CamelContext only. For any other value, the pattern uses the rules from PatternHelper#matchPattern(String,String).

 

String

camel.rest.api-context-listing

Deprecated Sets whether listing of all available CamelContext’s with REST services in the JVM is enabled. If enabled it allows to discover these contexts, if false then only the current CamelContext is in use.

false

Boolean

Chapter 26. CXF

Both producer and consumer are supported

The CXF component provides integration with Apache CXF for connecting to JAX-WS services hosted in CXF.

Tip

When using CXF in streaming modes (see DataFormat option), then also read about Stream caching.

26.1. Dependencies

When using cxf with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-cxf-soap-starter</artifactId>
</dependency>

26.2. URI format

There are two URI formats for this endpoint: cxfEndpoint and someAddress.

cxf:bean:cxfEndpoint[?options]

Where cxfEndpoint represents a bean ID that references a bean in the Spring bean registry. With this URI format, most of the endpoint details are specified in the bean definition.

cxf://someAddress[?options]

Where someAddress specifies the CXF endpoint’s address. With this URI format, most of the endpoint details are specified using options.

For either style above, you can append options to the URI as follows:

cxf:bean:cxfEndpoint?wsdlURL=wsdl/hello_world.wsdl&dataFormat=PAYLOAD

26.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

26.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

26.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

26.4. Component Options

The CXF component supports 6 options, which are listed below.

NameDescriptionDefaultType

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

allowStreaming (advanced)

This option controls whether the CXF component, when running in PAYLOAD mode, will DOM parse the incoming messages into DOM Elements or keep the payload as a javax.xml.transform.Source object that would allow streaming in some cases.

 

Boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

headerFilterStrategy (filter)

To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message.

 

HeaderFilterStrategy

useGlobalSslContextParameters (security)

Enable usage of global SSL context parameters.

false

boolean

26.5. Endpoint Options

The CXF endpoint is configured using URI syntax:

cxf:beanId:address

with the following path and query parameters:

26.5.1. Path Parameters (2 parameters)

NameDescriptionDefaultType

beanId (common)

To lookup an existing configured CxfEndpoint. Must used bean: as prefix.

 

String

address (service)

The service publish address.

 

String

26.5.2. Query Parameters (35 parameters)

NameDescriptionDefaultType

dataFormat (common)

The data type messages supported by the CXF endpoint.

Enum values:

  • PAYLOAD
  • RAW
  • MESSAGE
  • CXF_MESSAGE
  • POJO

POJO

DataFormat

wrappedStyle (common)

The WSDL style that describes how parameters are represented in the SOAP body. If the value is false, CXF will chose the document-literal unwrapped style, If the value is true, CXF will chose the document-literal wrapped style.

 

Boolean

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

cookieHandler (producer)

Configure a cookie handler to maintain a HTTP session.

 

CookieHandler

defaultOperationName (producer)

This option will set the default operationName that will be used by the CxfProducer which invokes the remote service.

 

String

defaultOperationNamespace (producer)

This option will set the default operationNamespace that will be used by the CxfProducer which invokes the remote service.

 

String

hostnameVerifier (producer)

The hostname verifier to be used. Use the # notation to reference a HostnameVerifier from the registry.

 

HostnameVerifier

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

sslContextParameters (producer)

The Camel SSL setting reference. Use the # notation to reference the SSL Context.

 

SSLContextParameters

wrapped (producer)

Which kind of operation that CXF endpoint producer will invoke.

false

boolean

synchronous (producer (advanced))

Sets whether synchronous processing should be strictly used.

false

boolean

allowStreaming (advanced)

This option controls whether the CXF component, when running in PAYLOAD mode, will DOM parse the incoming messages into DOM Elements or keep the payload as a javax.xml.transform.Source object that would allow streaming in some cases.

 

Boolean

bus (advanced)

To use a custom configured CXF Bus.

 

Bus

continuationTimeout (advanced)

This option is used to set the CXF continuation timeout which could be used in CxfConsumer by default when the CXF server is using Jetty or Servlet transport.

30000

long

cxfBinding (advanced)

To use a custom CxfBinding to control the binding between Camel Message and CXF Message.

 

CxfBinding

cxfConfigurer (advanced)

This option could apply the implementation of org.apache.camel.component.cxf.CxfEndpointConfigurer which supports to configure the CXF endpoint in programmatic way. User can configure the CXF server and client by implementing configure{ServerClient} method of CxfEndpointConfigurer.

 

CxfConfigurer

defaultBus (advanced)

Will set the default bus when CXF endpoint create a bus by itself.

false

boolean

headerFilterStrategy (advanced)

To use a custom HeaderFilterStrategy to filter header to and from Camel message.

 

HeaderFilterStrategy

mergeProtocolHeaders (advanced)

Whether to merge protocol headers. If enabled then propagating headers between Camel and CXF becomes more consistent and similar. For more details see CAMEL-6393.

false

boolean

mtomEnabled (advanced)

To enable MTOM (attachments). This requires to use POJO or PAYLOAD data format mode.

false

boolean

properties (advanced)

To set additional CXF options using the key/value pairs from the Map. For example to turn on stacktraces in SOAP faults, properties.faultStackTraceEnabled=true.

 

Map

skipPayloadMessagePartCheck (advanced)

Sets whether SOAP message validation should be disabled.

false

boolean

loggingFeatureEnabled (logging)

This option enables CXF Logging Feature which writes inbound and outbound SOAP messages to log.

false

boolean

loggingSizeLimit (logging)

To limit the total size of number of bytes the logger will output when logging feature has been enabled and -1 for no limit.

49152

int

skipFaultLogging (logging)

This option controls whether the PhaseInterceptorChain skips logging the Fault that it catches.

false

boolean

password (security)

This option is used to set the basic authentication information of password for the CXF client.

 

String

username (security)

This option is used to set the basic authentication information of username for the CXF client.

 

String

bindingId (service)

The bindingId for the service model to use.

 

String

portName (service)

The endpoint name this service is implementing, it maps to the wsdl:portname. In the format of ns:PORT_NAME where ns is a namespace prefix valid at this scope.

 

String

publishedEndpointUrl (service)

This option can override the endpointUrl that published from the WSDL which can be accessed with service address url plus wsd.

 

String

serviceClass (service)

The class name of the SEI (Service Endpoint Interface) class which could have JSR181 annotation or not.

 

Class

serviceName (service)

The service name this service is implementing, it maps to the wsdl:servicename.

 

String

wsdlURL (service)

The location of the WSDL. Can be on the classpath, file system, or be hosted remotely.

 

String

The serviceName and portName are QNames, so if you provide them be sure to prefix them with their {namespace} as shown in the examples above.

26.5.3. Descriptions of the dataformats

In Apache Camel, the Camel CXF component is the key to integrating routes with Web services. You can use the Camel CXF component to create a CXF endpoint, which can be used in either of the following ways:

  • Consumer — (at the start of a route) represents a Web service instance, which integrates with the route. The type of payload injected into the route depends on the value of the endpoint’s dataFormat option.
  • Producer — (at other points in the route) represents a WS client proxy, which converts the current exchange object into an operation invocation on a remote Web service. The format of the current exchange must match the endpoint’s dataFormat setting.
DataFormatDescription

POJO

POJOs (Plain old Java objects) are the Java parameters to the method being invoked on the target server. Both Protocol and Logical JAX-WS handlers are supported.

PAYLOAD

PAYLOAD is the message payload (the contents of the soap:body) after message configuration in the CXF endpoint is applied. Only Protocol JAX-WS handler is supported. Logical JAX-WS handler is not supported.

RAW

RAW mode provides the raw message stream that is received from the transport layer. It is not possible to touch or change the stream, some of the CXF interceptors will be removed if you are using this kind of DataFormat, so you can’t see any soap headers after the camel-cxf consumer. JAX-WS handler is not supported.

CXF_MESSAGE

CXF_MESSAGE allows for invoking the full capabilities of CXF interceptors by converting the message from the transport layer into a raw SOAP message

You can determine the data format mode of an exchange by retrieving the exchange property, CamelCXFDataFormat. The exchange key constant is defined in org.apache.camel.component.cxf.common.message.CxfConstants.DATA_FORMAT_PROPERTY.

26.5.4. How to enable CXF’s LoggingOutInterceptor in RAW mode

CXF’s LoggingOutInterceptor outputs outbound message that goes on the wire to logging system (Java Util Logging). Since the LoggingOutInterceptor is in PRE_STREAM phase (but PRE_STREAM phase is removed in RAW mode), you have to configure LoggingOutInterceptor to be run during the WRITE phase. The following is an example.

@Bean
public CxfEndpoint serviceEndpoint(LoggingOutInterceptor loggingOutInterceptor) {
    CxfSpringEndpoint cxfEndpoint = new CxfSpringEndpoint();
    cxfEndpoint.setAddress("http://localhost:" + port
                            + "/services" + SERVICE_ADDRESS);
    cxfEndpoint.setServiceClass(org.apache.camel.component.cxf.HelloService.class);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("dataFormat", "RAW");
    cxfEndpoint.setProperties(properties);
    cxfEndpoint.getOutInterceptors().add(loggingOutInterceptor);
    return cxfEndpoint;
}


@Bean
public LoggingOutInterceptor loggingOutInterceptor() {
    LoggingOutInterceptor logger = new LoggingOutInterceptor("write");
    return logger;
}

26.5.5. Description of relayHeaders option

There are in-band and out-of-band on-the-wire headers from the perspective of a JAXWS WSDL-first developer.

The in-band headers are headers that are explicitly defined as part of the WSDL binding contract for an endpoint such as SOAP headers.

The out-of-band headers are headers that are serialized over the wire, but are not explicitly part of the WSDL binding contract.

Headers relaying/filtering is bi-directional.

When a route has a CXF endpoint and the developer needs to have on-the-wire headers, such as SOAP headers, be relayed along the route to be consumed say by another JAXWS endpoint, then relayHeaders should be set to true, which is the default value.

26.5.6. Available only in POJO mode

The relayHeaders=true expresses an intent to relay the headers. The actual decision on whether a given header is relayed is delegated to a pluggable instance that implements the MessageHeadersRelay interface. A concrete implementation of MessageHeadersRelay will be consulted to decide if a header needs to be relayed or not. There is already an implementation of SoapMessageHeadersRelay which binds itself to well-known SOAP name spaces. Currently only out-of-band headers are filtered, and in-band headers will always be relayed when relayHeaders=true. If there is a header on the wire whose name space is unknown to the runtime, then a fall back DefaultMessageHeadersRelay will be used, which simply allows all headers to be relayed.

The relayHeaders=false setting specifies that all headers in-band and out-of-band should be dropped.

You can plugin your own MessageHeadersRelay implementations overriding or adding additional ones to the list of relays. In order to override a preloaded relay instance just make sure that your MessageHeadersRelay implementation services the same name spaces as the one you looking to override. Also note, that the overriding relay has to service all of the name spaces as the one you looking to override, or else a runtime exception on route start up will be thrown as this would introduce an ambiguity in name spaces to relay instance mappings.

<cxf:cxfEndpoint ...>
   <cxf:properties>
     <entry key="org.apache.camel.cxf.message.headers.relays">
       <list>
         <ref bean="customHeadersRelay"/>
       </list>
     </entry>
   </cxf:properties>
 </cxf:cxfEndpoint>
 <bean id="customHeadersRelay" class="org.apache.camel.component.cxf.soap.headers.CustomHeadersRelay"/>

Take a look at the tests that show how you’d be able to relay/drop headers here:

https://github.com/apache/camel/blob/main/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/soap/headers/CxfMessageHeadersRelayTest.java

  • POJO and PAYLOAD modes are supported. In POJO mode, only out-of-band message headers are available for filtering as the in-band headers have been processed and removed from header list by CXF. The in-band headers are incorporated into the MessageContentList in POJO mode. The camel-cxf component does make any attempt to remove the in-band headers from the MessageContentList. If filtering of in-band headers is required, please use PAYLOAD mode or plug in a (pretty straightforward) CXF interceptor/JAXWS Handler to the CXF endpoint.
  • The Message Header Relay mechanism has been merged into CxfHeaderFilterStrategy. The relayHeaders option, its semantics, and default value remain the same, but it is a property of CxfHeaderFilterStrategy. Here is an example of configuring it.
@Bean
public HeaderFilterStrategy dropAllMessageHeadersStrategy() {
    CxfHeaderFilterStrategy headerFilterStrategy = new CxfHeaderFilterStrategy();
    headerFilterStrategy.setRelayHeaders(false);
    return headerFilterStrategy;
}

Then, your endpoint can reference the CxfHeaderFilterStrategy.

@Bean
public CxfEndpoint routerNoRelayEndpoint(HeaderFilterStrategy dropAllMessageHeadersStrategy) {
    CxfSpringEndpoint cxfEndpoint = new CxfSpringEndpoint();
    cxfEndpoint.setServiceClass(org.apache.camel.component.cxf.soap.headers.HeaderTester.class);
    cxfEndpoint.setAddress("/CxfMessageHeadersRelayTest/HeaderService/routerNoRelayEndpoint");
    cxfEndpoint.setWsdlURL("soap_header.wsdl");
    cxfEndpoint.setEndpointNameAsQName(
        QName.valueOf("{http://apache.org/camel/component/cxf/soap/headers}SoapPortNoRelay"));
    cxfEndpoint.setServiceNameAsQName(SERVICENAME);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("dataFormat", "PAYLOAD");
    cxfEndpoint.setProperties(properties);
    cxfEndpoint.setHeaderFilterStrategy(dropAllMessageHeadersStrategy);
    return cxfEndpoint;
}

@Bean
public CxfEndpoint serviceNoRelayEndpoint(HeaderFilterStrategy dropAllMessageHeadersStrategy) {
    CxfSpringEndpoint cxfEndpoint = new CxfSpringEndpoint();
    cxfEndpoint.setServiceClass(org.apache.camel.component.cxf.soap.headers.HeaderTester.class);
    cxfEndpoint.setAddress("http://localhost:" + port + "/services/CxfMessageHeadersRelayTest/HeaderService/routerNoRelayEndpointBackend");
    cxfEndpoint.setWsdlURL("soap_header.wsdl");
    cxfEndpoint.setEndpointNameAsQName(
        QName.valueOf("{http://apache.org/camel/component/cxf/soap/headers}SoapPortNoRelay"));
    cxfEndpoint.setServiceNameAsQName(SERVICENAME);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("dataFormat", "PAYLOAD");
    cxfEndpoint.setProperties(properties);
    cxfEndpoint.setHeaderFilterStrategy(dropAllMessageHeadersStrategy);
    return cxfEndpoint;
}

Then configure the route as follows:

rom("cxf:bean:routerNoRelayEndpoint")
    .to("cxf:bean:serviceNoRelayEndpoint");
  • The MessageHeadersRelay interface has changed slightly and has been renamed to MessageHeaderFilter. It is a property of CxfHeaderFilterStrategy. Here is an example of configuring user defined Message Header Filters:
@Bean
public HeaderFilterStrategy customMessageFilterStrategy() {
    CxfHeaderFilterStrategy headerFilterStrategy = new CxfHeaderFilterStrategy();
    List<MessageHeaderFilter> headerFilterList = new ArrayList<MessageHeaderFilter>();
    headerFilterList.add(new SoapMessageHeaderFilter());
    headerFilterList.add(new CustomHeaderFilter());
    headerFilterStrategy.setMessageHeaderFilters(headerFilterList);
    return headerFilterStrategy;
}
  • In addition to relayHeaders, the following properties can be configured in CxfHeaderFilterStrategy.
NameRequiredDescription

relayHeaders

No

All message headers will be processed by Message Header Filters Type: boolean Default: true

relayAllMessageHeaders

No

All message headers will be propagated (without processing by Message Header Filters) Type: booleanDefault: false

allowFilterNamespaceClash

No

If two filters overlap in activation namespace, the property control how it should be handled. If the value is true, last one wins. If the value is false, it will throw an exception Type: boolean Default: false

26.6. Configure the CXF endpoints with Spring

You can configure the CXF endpoint with the Spring configuration file shown below, and you can also embed the endpoint into the camelContext tags. When you are invoking the service endpoint, you can set the operationName and operationNamespace headers to explicitly state which operation you are calling.

<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:cxf="http://camel.apache.org/schema/cxf/jaxws"
        xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://camel.apache.org/schema/cxf/jaxws http://camel.apache.org/schema/cxf/jaxws/camel-cxf.xsd
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
     <cxf:cxfEndpoint id="routerEndpoint" address="http://localhost:9003/CamelContext/RouterPort"
            serviceClass="org.apache.hello_world_soap_http.GreeterImpl"/>
     <cxf:cxfEndpoint id="serviceEndpoint" address="http://localhost:9000/SoapContext/SoapPort"
            wsdlURL="testutils/hello_world.wsdl"
            serviceClass="org.apache.hello_world_soap_http.Greeter"
            endpointName="s:SoapPort"
            serviceName="s:SOAPService"
        xmlns:s="http://apache.org/hello_world_soap_http" />
     <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
       <route>
         <from uri="cxf:bean:routerEndpoint" />
         <to uri="cxf:bean:serviceEndpoint" />
       </route>
    </camelContext>
  </beans>

Be sure to include the JAX-WS schemaLocation attribute specified on the root beans element. This allows CXF to validate the file and is required. Also note the namespace declarations at the end of the <cxf:cxfEndpoint/> tag. These declarations are required because the combined {namespace}localName syntax is presently not supported for this tag’s attribute values.

The cxf:cxfEndpoint element supports many additional attributes:

NameValue

PortName

The endpoint name this service is implementing, it maps to the wsdl:port@name. In the format of ns:PORT_NAME where ns is a namespace prefix valid at this scope.

serviceName

The service name this service is implementing, it maps to the wsdl:service@name. In the format of ns:SERVICE_NAME where ns is a namespace prefix valid at this scope.

wsdlURL

The location of the WSDL. Can be on the classpath, file system, or be hosted remotely.

bindingId

The bindingId for the service model to use.

address

The service publish address.

bus

The bus name that will be used in the JAX-WS endpoint.

serviceClass

The class name of the SEI (Service Endpoint Interface) class which could have JSR181 annotation or not.

It also supports many child elements:

NameValue

cxf:inInterceptors

The incoming interceptors for this endpoint. A list of <bean> or <ref>.

cxf:inFaultInterceptors

The incoming fault interceptors for this endpoint. A list of <bean> or <ref>.

cxf:outInterceptors

The outgoing interceptors for this endpoint. A list of <bean> or <ref>.

cxf:outFaultInterceptors

The outgoing fault interceptors for this endpoint. A list of <bean> or <ref>.

cxf:properties

A properties map which should be supplied to the JAX-WS endpoint. See below.

cxf:handlers

A JAX-WS handler list which should be supplied to the JAX-WS endpoint. See below.

cxf:dataBinding

You can specify the which DataBinding will be use in the endpoint. This can be supplied using the Spring <bean class="MyDataBinding"/> syntax.

cxf:binding

You can specify the BindingFactory for this endpoint to use. This can be supplied using the Spring <bean class="MyBindingFactory"/> syntax.

cxf:features

The features that hold the interceptors for this endpoint. A list of beans or refs

cxf:schemaLocations

The schema locations for endpoint to use. A list of schemaLocations

cxf:serviceFactory

The service factory for this endpoint to use. This can be supplied using the Spring <bean class="MyServiceFactory"/> syntax

You can find more advanced examples that show how to provide interceptors, properties and handlers on the CXF JAX-WS Configuration page.

Note

You can use cxf:properties to set the camel-cxf endpoint’s dataFormat and setDefaultBus properties from spring configuration file.

<cxf:cxfEndpoint id="testEndpoint" address="http://localhost:9000/router"
     serviceClass="org.apache.camel.component.cxf.HelloService"
     endpointName="s:PortName"
     serviceName="s:ServiceName"
     xmlns:s="http://www.example.com/test">
     <cxf:properties>
       <entry key="dataFormat" value="RAW"/>
       <entry key="setDefaultBus" value="true"/>
     </cxf:properties>
   </cxf:cxfEndpoint>
Note

In SpringBoot, you can use Spring XML files to configure camel-cxf and use code similar to the following example to create XML configured beans:

@ImportResource({
		"classpath:spring-configuration.xml"
})

However, the use of Java code configured beans (as shown in other examples) is best practice in SpringBoot.

26.7. How to make the camel-cxf component use log4j instead of java.util.logging

CXF’s default logger is java.util.logging. If you want to change it to log4j, proceed as follows. Create a file, in the classpath, named META-INF/cxf/org.apache.cxf.logger. This file should contain the fully-qualified name of the class, org.apache.cxf.common.logging.Log4jLogger, with no comments, on a single line.

26.8. How to let camel-cxf response start with xml processing instruction

If you are using some SOAP client such as PHP, you will get this kind of error, because CXF doesn’t add the XML processing instruction <?xml version="1.0" encoding="utf-8"?>:

Error:sendSms: SoapFault exception: [Client] looks like we got no XML document in [...]

To resolve this issue, you just need to tell StaxOutInterceptor to write the XML start document for you, as in the WriteXmlDeclarationInterceptor below:

public class WriteXmlDeclarationInterceptor extends AbstractPhaseInterceptor<SoapMessage> {
    public WriteXmlDeclarationInterceptor() {
        super(Phase.PRE_STREAM);
        addBefore(StaxOutInterceptor.class.getName());
    }

    public void handleMessage(SoapMessage message) throws Fault {
        message.put("org.apache.cxf.stax.force-start-document", Boolean.TRUE);
    }

}

As an alternative you can add a message header for it as demonstrated in CxfConsumerTest:

 // set up the response context which force start document
 Map<String, Object> map = new HashMap<String, Object>();
 map.put("org.apache.cxf.stax.force-start-document", Boolean.TRUE);
 exchange.getOut().setHeader(Client.RESPONSE_CONTEXT, map);

26.9. How to override the CXF producer address from message header

The camel-cxf producer supports to override the target service address by setting a message header CamelDestinationOverrideUrl.

 // set up the service address from the message header to override the setting of CXF endpoint
 exchange.getIn().setHeader(Exchange.DESTINATION_OVERRIDE_URL, constant(getServiceAddress()));

26.10. How to consume a message from a camel-cxf endpoint in POJO data format

The camel-cxf endpoint consumer POJO data format is based on the CXF invoker, so the message header has a property with the name of CxfConstants.OPERATION_NAME and the message body is a list of the SEI method parameters.

Consider the PersonProcessor example code:

public class PersonProcessor implements Processor {

    private static final Logger LOG = LoggerFactory.getLogger(PersonProcessor.class);

    @Override
    @SuppressWarnings("unchecked")
    public void process(Exchange exchange) throws Exception {
        LOG.info("processing exchange in camel");

        BindingOperationInfo boi = (BindingOperationInfo) exchange.getProperty(BindingOperationInfo.class.getName());
        if (boi != null) {
            LOG.info("boi.isUnwrapped" + boi.isUnwrapped());
        }
        // Get the parameters list which element is the holder.
        MessageContentsList msgList = (MessageContentsList) exchange.getIn().getBody();
        Holder<String> personId = (Holder<String>) msgList.get(0);
        Holder<String> ssn = (Holder<String>) msgList.get(1);
        Holder<String> name = (Holder<String>) msgList.get(2);

        if (personId.value == null || personId.value.length() == 0) {
            LOG.info("person id 123, so throwing exception");
            // Try to throw out the soap fault message
            org.apache.camel.wsdl_first.types.UnknownPersonFault personFault
                    = new org.apache.camel.wsdl_first.types.UnknownPersonFault();
            personFault.setPersonId("");
            org.apache.camel.wsdl_first.UnknownPersonFault fault
                    = new org.apache.camel.wsdl_first.UnknownPersonFault("Get the null value of person name", personFault);
            exchange.getMessage().setBody(fault);
            return;
        }

        name.value = "Bonjour";
        ssn.value = "123";
        LOG.info("setting Bonjour as the response");
        // Set the response message, first element is the return value of the operation,
        // the others are the holders of method parameters
        exchange.getMessage().setBody(new Object[] { null, personId, ssn, name });
    }

}

26.11. How to prepare the message for the camel-cxf endpoint in POJO data format

The camel-cxf endpoint producer is based on the CXF client API. First you need to specify the operation name in the message header, then add the method parameters to a list, and initialize the message with this parameter list. The response message’s body is a messageContentsList, you can get the result from that list.

If you don’t specify the operation name in the message header, CxfProducer will try to use the defaultOperationName from CxfEndpoint, if there is no defaultOperationName set on CxfEndpoint, it will pick up the first operationName from the Operation list.

If you want to get the object array from the message body, you can get the body using message.getBody(Object[].class), as shown in CxfProducerRouterTest.testInvokingSimpleServerWithParams:

Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut);
final List<String> params = new ArrayList<>();
// Prepare the request message for the camel-cxf procedure
params.add(TEST_MESSAGE);
senderExchange.getIn().setBody(params);
senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, ECHO_OPERATION);

Exchange exchange = template.send("direct:EndpointA", senderExchange);

org.apache.camel.Message out = exchange.getMessage();
// The response message's body is an MessageContentsList which first element is the return value of the operation,
// If there are some holder parameters, the holder parameter will be filled in the reset of List.
// The result will be extract from the MessageContentsList with the String class type
MessageContentsList result = (MessageContentsList) out.getBody();
LOG.info("Received output text: " + result.get(0));
Map<String, Object> responseContext = CastUtils.cast((Map<?, ?>) out.getHeader(Client.RESPONSE_CONTEXT));
assertNotNull(responseContext);
assertEquals("UTF-8", responseContext.get(org.apache.cxf.message.Message.ENCODING),
        "We should get the response context here");
assertEquals("echo " + TEST_MESSAGE, result.get(0), "Reply body on Camel is wrong");

26.12. How to deal with the message for a camel-cxf endpoint in PAYLOAD data format

PAYLOAD means that you process the payload from the SOAP envelope as a native CxfPayload. Message.getBody() will return a org.apache.camel.component.cxf.CxfPayload object, with getters for SOAP message headers and the SOAP body.

See CxfConsumerPayloadTest:

protected RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {
        public void configure() {
            from(simpleEndpointURI + "&dataFormat=PAYLOAD").to("log:info").process(new Processor() {
                @SuppressWarnings("unchecked")
                public void process(final Exchange exchange) throws Exception {
                    CxfPayload<SoapHeader> requestPayload = exchange.getIn().getBody(CxfPayload.class);
                    List<Source> inElements = requestPayload.getBodySources();
                    List<Source> outElements = new ArrayList<>();
                    // You can use a customer toStringConverter to turn a CxfPayLoad message into String as you want
                    String request = exchange.getIn().getBody(String.class);
                    XmlConverter converter = new XmlConverter();
                    String documentString = ECHO_RESPONSE;

                    Element in = new XmlConverter().toDOMElement(inElements.get(0));
                    // Just check the element namespace
                    if (!in.getNamespaceURI().equals(ELEMENT_NAMESPACE)) {
                        throw new IllegalArgumentException("Wrong element namespace");
                    }
                    if (in.getLocalName().equals("echoBoolean")) {
                        documentString = ECHO_BOOLEAN_RESPONSE;
                        checkRequest("ECHO_BOOLEAN_REQUEST", request);
                    } else {
                        documentString = ECHO_RESPONSE;
                        checkRequest("ECHO_REQUEST", request);
                    }
                    Document outDocument = converter.toDOMDocument(documentString, exchange);
                    outElements.add(new DOMSource(outDocument.getDocumentElement()));
                    // set the payload header with null
                    CxfPayload<SoapHeader> responsePayload = new CxfPayload<>(null, outElements, null);
                    exchange.getMessage().setBody(responsePayload);
                }
            });
        }
    };
}

26.13. How to get and set SOAP headers in POJO mode

POJO means that the data format is a "list of Java objects" when the camel-cxf endpoint produces or consumes Camel exchanges. Even though Camel exposes the message body as POJOs in this mode, camel-cxf still provides access to read and write SOAP headers. However, since CXF interceptors remove in-band SOAP headers from the header list after they have been processed, only out-of-band SOAP headers are available to camel-cxf in POJO mode.

The following example illustrates how to get/set SOAP headers. Suppose we have a route that forwards from one Camel-cxf endpoint to another. That is, SOAP Client → Camel → CXF service. We can attach two processors to obtain/insert SOAP headers at (1) before a request goes out to the CXF service and (2) before the response comes back to the SOAP Client. Processor (1) and (2) in this example are InsertRequestOutHeaderProcessor and InsertResponseOutHeaderProcessor. Our route looks like this:

from("cxf:bean:routerRelayEndpointWithInsertion")
    .process(new InsertRequestOutHeaderProcessor())
    .to("cxf:bean:serviceRelayEndpointWithInsertion")
    .process(new InsertResponseOutHeaderProcessor());

The Bean routerRelayEndpointWithInsertion and serviceRelayEndpointWithInsertion are defined as follows:

@Bean
public CxfEndpoint routerRelayEndpointWithInsertion() {
    CxfSpringEndpoint cxfEndpoint = new CxfSpringEndpoint();
    cxfEndpoint.setServiceClass(org.apache.camel.component.cxf.soap.headers.HeaderTester.class);
    cxfEndpoint.setAddress("/CxfMessageHeadersRelayTest/HeaderService/routerRelayEndpointWithInsertion");
    cxfEndpoint.setWsdlURL("soap_header.wsdl");
    cxfEndpoint.setEndpointNameAsQName(
        QName.valueOf("{http://apache.org/camel/component/cxf/soap/headers}SoapPortRelayWithInsertion"));
    cxfEndpoint.setServiceNameAsQName(SERVICENAME);
    cxfEndpoint.getFeatures().add(new LoggingFeature());
    return cxfEndpoint;
}

@Bean
public CxfEndpoint serviceRelayEndpointWithInsertion() {
    CxfSpringEndpoint cxfEndpoint = new CxfSpringEndpoint();
    cxfEndpoint.setServiceClass(org.apache.camel.component.cxf.soap.headers.HeaderTester.class);
    cxfEndpoint.setAddress("http://localhost:" + port + "/services/CxfMessageHeadersRelayTest/HeaderService/routerRelayEndpointWithInsertionBackend");
    cxfEndpoint.setWsdlURL("soap_header.wsdl");
    cxfEndpoint.setEndpointNameAsQName(
        QName.valueOf("{http://apache.org/camel/component/cxf/soap/headers}SoapPortRelayWithInsertion"));
    cxfEndpoint.setServiceNameAsQName(SERVICENAME);
    cxfEndpoint.getFeatures().add(new LoggingFeature());
    return cxfEndpoint;
}

SOAP headers are propagated to and from Camel Message headers. The Camel message header name is "org.apache.cxf.headers.Header.list" which is a constant defined in CXF (org.apache.cxf.headers.Header.HEADER_LIST). The header value is a List of CXF SoapHeader objects (org.apache.cxf.binding.soap.SoapHeader). The following snippet is the InsertResponseOutHeaderProcessor (that insert a new SOAP header in the response message). The way to access SOAP headers in both InsertResponseOutHeaderProcessor and InsertRequestOutHeaderProcessor are actually the same. The only difference between the two processors is setting the direction of the inserted SOAP header.

You can find the InsertResponseOutHeaderProcessor example in CxfMessageHeadersRelayTest:

public static class InsertResponseOutHeaderProcessor implements Processor {

    public void process(Exchange exchange) throws Exception {
        List<SoapHeader> soapHeaders = CastUtils.cast((List<?>)exchange.getIn().getHeader(Header.HEADER_LIST));

        // Insert a new header
        String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><outofbandHeader "
            + "xmlns=\"http://cxf.apache.org/outofband/Header\" hdrAttribute=\"testHdrAttribute\" "
            + "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" soap:mustUnderstand=\"1\">"
            + "<name>New_testOobHeader</name><value>New_testOobHeaderValue</value></outofbandHeader>";
        SoapHeader newHeader = new SoapHeader(soapHeaders.get(0).getName(),
                       DOMUtils.readXml(new StringReader(xml)).getDocumentElement());
        // make sure direction is OUT since it is a response message.
        newHeader.setDirection(Direction.DIRECTION_OUT);
        //newHeader.setMustUnderstand(false);
        soapHeaders.add(newHeader);

    }

}

26.14. How to get and set SOAP headers in PAYLOAD mode

We’ve already shown how to access the SOAP message as CxfPayload object in PAYLOAD mode inm the section How to deal with the message for a camel-cxf endpoint in PAYLOAD data format.

Once you obtain a CxfPayload object, you can invoke the CxfPayload.getHeaders() method that returns a List of DOM Elements (SOAP headers).

For an example see CxfPayLoadSoapHeaderTest:

from(getRouterEndpointURI()).process(new Processor() {
    @SuppressWarnings("unchecked")
    public void process(Exchange exchange) throws Exception {
        CxfPayload<SoapHeader> payload = exchange.getIn().getBody(CxfPayload.class);
        List<Source> elements = payload.getBodySources();
        assertNotNull(elements, "We should get the elements here");
        assertEquals(1, elements.size(), "Get the wrong elements size");

        Element el = new XmlConverter().toDOMElement(elements.get(0));
        elements.set(0, new DOMSource(el));
        assertEquals("http://camel.apache.org/pizza/types",
                el.getNamespaceURI(), "Get the wrong namespace URI");

        List<SoapHeader> headers = payload.getHeaders();
        assertNotNull(headers, "We should get the headers here");
        assertEquals(1, headers.size(), "Get the wrong headers size");
        assertEquals("http://camel.apache.org/pizza/types",
                ((Element) (headers.get(0).getObject())).getNamespaceURI(), "Get the wrong namespace URI");
        // alternatively you can also get the SOAP header via the camel header:
        headers = exchange.getIn().getHeader(Header.HEADER_LIST, List.class);
        assertNotNull(headers, "We should get the headers here");
        assertEquals(1, headers.size(), "Get the wrong headers size");
        assertEquals("http://camel.apache.org/pizza/types",
                ((Element) (headers.get(0).getObject())).getNamespaceURI(), "Get the wrong namespace URI");

    }

})
.to(getServiceEndpointURI());

You can also use the same way as described in sub-chapter "How to get and set SOAP headers in POJO mode" to set or get the SOAP headers. So, you can use the header "org.apache.cxf.headers.Header.list" to get and set a list of SOAP headers.This does also mean that if you have a route that forwards from one Camel-cxf endpoint to another (SOAP Client → Camel → CXF service), now also the SOAP headers sent by the SOAP client are forwarded to the CXF service. If you do not want that these headers are forwarded you have to remove them in the Camel header "org.apache.cxf.headers.Header.list".

26.15. SOAP headers are not available in RAW mode

SOAP headers are not available in RAW mode as SOAP processing is skipped.

26.16. How to throw a SOAP Fault from Camel

If you are using a camel-cxf endpoint to consume the SOAP request, you may need to throw the SOAP Fault from the camel context.
Basically, you can use the throwFault DSL to do that; it works for POJO, PAYLOAD and MESSAGE data format.
You can define the soap fault as shown in CxfCustomizedExceptionTest:

SOAP_FAULT = new SoapFault(EXCEPTION_MESSAGE, SoapFault.FAULT_CODE_CLIENT);
Element detail = SOAP_FAULT.getOrCreateDetail();
Document doc = detail.getOwnerDocument();
Text tn = doc.createTextNode(DETAIL_TEXT);
detail.appendChild(tn);

Then throw it as you like

from(routerEndpointURI).setFaultBody(constant(SOAP_FAULT));

If your CXF endpoint is working in the MESSAGE data format, you could set the SOAP Fault message in the message body and set the response code in the message header as demonstrated by CxfMessageStreamExceptionTest

from(routerEndpointURI).process(new Processor() {

    public void process(Exchange exchange) throws Exception {
        Message out = exchange.getOut();
        // Set the message body with the
        out.setBody(this.getClass().getResourceAsStream("SoapFaultMessage.xml"));
        // Set the response code here
        out.setHeader(org.apache.cxf.message.Message.RESPONSE_CODE, new Integer(500));
    }

});

Same for using POJO data format. You can set the SOAPFault on the out body.

26.17. How to propagate a camel-cxf endpoint’s request and response context

CXF client API provides a way to invoke the operation with request and response context. If you are using a camel-cxf endpoint producer to invoke the outside web service, you can set the request context and get response context with the following code:

        CxfExchange exchange = (CxfExchange)template.send(getJaxwsEndpointUri(), new Processor() {
             public void process(final Exchange exchange) {
                 final List<String> params = new ArrayList<String>();
                 params.add(TEST_MESSAGE);
                 // Set the request context to the inMessage
                 Map<String, Object> requestContext = new HashMap<String, Object>();
                 requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, JAXWS_SERVER_ADDRESS);
                 exchange.getIn().setBody(params);
                 exchange.getIn().setHeader(Client.REQUEST_CONTEXT , requestContext);
                 exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, GREET_ME_OPERATION);
             }
         });
         org.apache.camel.Message out = exchange.getOut();
         // The output is an object array, the first element of the array is the return value
         Object\[\] output = out.getBody(Object\[\].class);
         LOG.info("Received output text: " + output\[0\]);
         // Get the response context form outMessage
         Map<String, Object> responseContext = CastUtils.cast((Map)out.getHeader(Client.RESPONSE_CONTEXT));
         assertNotNull(responseContext);
         assertEquals("Get the wrong wsdl operation name", "{http://apache.org/hello_world_soap_http}greetMe",
                      responseContext.get("javax.xml.ws.wsdl.operation").toString());

26.18. Attachment Support

POJO Mode: Both SOAP with Attachment and MTOM are supported (see example in Payload Mode for enabling MTOM). However, SOAP with Attachment is not tested. Since attachments are marshalled and unmarshalled into POJOs, users typically do not need to deal with the attachment themself. Attachments are propagated to Camel message’s attachments if the MTOM is not enabled. So, it is possible to retrieve attachments by Camel Message API

DataHandler Message.getAttachment(String id)

Payload Mode: MTOM is supported by the component. Attachments can be retrieved by Camel Message APIs mentioned above. SOAP with Attachment (SwA) is supported and attachments can be retrieved. SwA is the default (same as setting the CXF endpoint property "mtom-enabled" to false).

To enable MTOM, set the CXF endpoint property "mtom-enabled" to true.

@Bean
public CxfEndpoint routerEndpoint() {
    CxfSpringEndpoint cxfEndpoint = new CxfSpringEndpoint();
    cxfEndpoint.setServiceNameAsQName(SERVICE_QNAME);
    cxfEndpoint.setEndpointNameAsQName(PORT_QNAME);
    cxfEndpoint.setAddress("/" + getClass().getSimpleName()+ "/jaxws-mtom/hello");
    cxfEndpoint.setWsdlURL("mtom.wsdl");
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("dataFormat", "PAYLOAD");
    properties.put("mtom-enabled", true);
    cxfEndpoint.setProperties(properties);
    return cxfEndpoint;
}

You can produce a Camel message with attachment to send to a CXF endpoint in Payload mode.

Exchange exchange = context.createProducerTemplate().send("direct:testEndpoint", new Processor() {

    public void process(Exchange exchange) throws Exception {
        exchange.setPattern(ExchangePattern.InOut);
        List<Source> elements = new ArrayList<Source>();
        elements.add(new DOMSource(DOMUtils.readXml(new StringReader(MtomTestHelper.REQ_MESSAGE)).getDocumentElement()));
        CxfPayload<SoapHeader> body = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(),
            elements, null);
        exchange.getIn().setBody(body);
        exchange.getIn().addAttachment(MtomTestHelper.REQ_PHOTO_CID,
            new DataHandler(new ByteArrayDataSource(MtomTestHelper.REQ_PHOTO_DATA, "application/octet-stream")));

        exchange.getIn().addAttachment(MtomTestHelper.REQ_IMAGE_CID,
            new DataHandler(new ByteArrayDataSource(MtomTestHelper.requestJpeg, "image/jpeg")));

    }

});

// process response

CxfPayload<SoapHeader> out = exchange.getOut().getBody(CxfPayload.class);
Assert.assertEquals(1, out.getBody().size());

Map<String, String> ns = new HashMap<String, String>();
ns.put("ns", MtomTestHelper.SERVICE_TYPES_NS);
ns.put("xop", MtomTestHelper.XOP_NS);

XPathUtils xu = new XPathUtils(ns);
Element oute = new XmlConverter().toDOMElement(out.getBody().get(0));
Element ele = (Element)xu.getValue("//ns:DetailResponse/ns:photo/xop:Include", oute,
                                   XPathConstants.NODE);
String photoId = ele.getAttribute("href").substring(4); // skip "cid:"

ele = (Element)xu.getValue("//ns:DetailResponse/ns:image/xop:Include", oute,
                                   XPathConstants.NODE);
String imageId = ele.getAttribute("href").substring(4); // skip "cid:"

DataHandler dr = exchange.getOut().getAttachment(photoId);
Assert.assertEquals("application/octet-stream", dr.getContentType());
MtomTestHelper.assertEquals(MtomTestHelper.RESP_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream()));

dr = exchange.getOut().getAttachment(imageId);
Assert.assertEquals("image/jpeg", dr.getContentType());

BufferedImage image = ImageIO.read(dr.getInputStream());
Assert.assertEquals(560, image.getWidth());
Assert.assertEquals(300, image.getHeight());

You can also consume a Camel message received from a CXF endpoint in Payload mode. The CxfMtomConsumerPayloadModeTest illustrates how this works:

public static class MyProcessor implements Processor {

    @SuppressWarnings("unchecked")
    public void process(Exchange exchange) throws Exception {
        CxfPayload<SoapHeader> in = exchange.getIn().getBody(CxfPayload.class);

        // verify request
        Assert.assertEquals(1, in.getBody().size());

        Map<String, String> ns = new HashMap<String, String>();
        ns.put("ns", MtomTestHelper.SERVICE_TYPES_NS);
        ns.put("xop", MtomTestHelper.XOP_NS);

        XPathUtils xu = new XPathUtils(ns);
        Element body = new XmlConverter().toDOMElement(in.getBody().get(0));
        Element ele = (Element)xu.getValue("//ns:Detail/ns:photo/xop:Include", body,
                                           XPathConstants.NODE);
        String photoId = ele.getAttribute("href").substring(4); // skip "cid:"
        Assert.assertEquals(MtomTestHelper.REQ_PHOTO_CID, photoId);

        ele = (Element)xu.getValue("//ns:Detail/ns:image/xop:Include", body,
                                           XPathConstants.NODE);
        String imageId = ele.getAttribute("href").substring(4); // skip "cid:"
        Assert.assertEquals(MtomTestHelper.REQ_IMAGE_CID, imageId);

        DataHandler dr = exchange.getIn().getAttachment(photoId);
        Assert.assertEquals("application/octet-stream", dr.getContentType());
        MtomTestHelper.assertEquals(MtomTestHelper.REQ_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream()));

        dr = exchange.getIn().getAttachment(imageId);
        Assert.assertEquals("image/jpeg", dr.getContentType());
        MtomTestHelper.assertEquals(MtomTestHelper.requestJpeg, IOUtils.readBytesFromStream(dr.getInputStream()));

        // create response
        List<Source> elements = new ArrayList<Source>();
        elements.add(new DOMSource(DOMUtils.readXml(new StringReader(MtomTestHelper.RESP_MESSAGE)).getDocumentElement()));
        CxfPayload<SoapHeader> sbody = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(),
            elements, null);
        exchange.getOut().setBody(sbody);
        exchange.getOut().addAttachment(MtomTestHelper.RESP_PHOTO_CID,
            new DataHandler(new ByteArrayDataSource(MtomTestHelper.RESP_PHOTO_DATA, "application/octet-stream")));

        exchange.getOut().addAttachment(MtomTestHelper.RESP_IMAGE_CID,
            new DataHandler(new ByteArrayDataSource(MtomTestHelper.responseJpeg, "image/jpeg")));

    }
}

Raw Mode: Attachments are not supported as it does not process the message at all.

CXF_RAW Mode: MTOM is supported, and Attachments can be retrieved by Camel Message APIs mentioned above. Note that when receiving a multipart (i.e. MTOM) message the default SOAPMessage to String converter will provide the complete multipart payload on the body. If you require just the SOAP XML as a String, you can set the message body with message.getSOAPPart(), and Camel convert can do the rest of work for you.

26.19. Streaming Support in PAYLOAD mode

The camel-cxf component now supports streaming of incoming messages when using PAYLOAD mode. Previously, the incoming messages would have been completely DOM parsed. For large messages, this is time consuming and uses a significant amount of memory. The incoming messages can remain as a javax.xml.transform.Source while being routed and, if nothing modifies the payload, can then be directly streamed out to the target destination. For common "simple proxy" use cases (example: from("cxf:…​").to("cxf:…​")), this can provide very significant performance increases as well as significantly lowered memory requirements.

However, there are cases where streaming may not be appropriate or desired. Due to the streaming nature, invalid incoming XML may not be caught until later in the processing chain. Also, certain actions may require the message to be DOM parsed anyway (like WS-Security or message tracing and such) in which case the advantages of the streaming is limited. At this point, there are two ways to control the streaming:

  • Endpoint property: you can add "allowStreaming=false" as an endpoint property to turn the streaming on/off.
  • Component property: the CxfComponent object also has an allowStreaming property that can set the default for endpoints created from that component.

Global system property: you can add a system property of "org.apache.camel.component.cxf.streaming" to "false" to turn it off. That sets the global default, but setting the endpoint property above will override this value for that endpoint.

26.20. Using the generic CXF Dispatch mode

The camel-cxf component supports the generic CXF dispatch mode that can transport messages of arbitrary structures (i.e., not bound to a specific XML schema). To use this mode, you simply omit specifying the wsdlURL and serviceClass attributes of the CXF endpoint.

<cxf:cxfEndpoint id="testEndpoint" address="http://localhost:9000/SoapContext/SoapAnyPort">
     <cxf:properties>
       <entry key="dataFormat" value="PAYLOAD"/>
     </cxf:properties>
   </cxf:cxfEndpoint>

It is noted that the default CXF dispatch client does not send a specific SOAPAction header. Therefore, when the target service requires a specific SOAPAction value, it is supplied in the Camel header using the key SOAPAction (case-insensitive).

26.21. Spring Boot Auto-Configuration

The component supports 13 options, which are listed below.

NameDescriptionDefaultType

camel.component.cxf.allow-streaming

This option controls whether the CXF component, when running in PAYLOAD mode, will DOM parse the incoming messages into DOM Elements or keep the payload as a javax.xml.transform.Source object that would allow streaming in some cases.

 

Boolean

camel.component.cxf.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.cxf.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.cxf.enabled

Whether to enable auto configuration of the cxf component. This is enabled by default.

 

Boolean

camel.component.cxf.header-filter-strategy

To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message. The option is a org.apache.camel.spi.HeaderFilterStrategy type.

 

HeaderFilterStrategy

camel.component.cxf.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.cxf.use-global-ssl-context-parameters

Enable usage of global SSL context parameters.

false

Boolean

camel.component.cxfrs.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.cxfrs.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.cxfrs.enabled

Whether to enable auto configuration of the cxfrs component. This is enabled by default.

 

Boolean

camel.component.cxfrs.header-filter-strategy

To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message. The option is a org.apache.camel.spi.HeaderFilterStrategy type.

 

HeaderFilterStrategy

camel.component.cxfrs.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.cxfrs.use-global-ssl-context-parameters

Enable usage of global SSL context parameters.

false

Boolean

Chapter 27. CXF-RS

Both producer and consumer are supported

The CXFRS component provides integration with Apache CXF for connecting to JAX-RS 1.1 and 2.0 services hosted in CXF.

27.1. Dependencies

When using camel-cxf-rest with Red Hat build of Camel Spring Boot, add the following Maven dependency to your pom.xml to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-cxf-rest-starter</artifactId>
</dependency>

27.2. URI format

cxfrs://address?options

Where the address represents the address of the CXF endpoint.

cxfrs:bean:rsEndpoint

Where the rsEndpoint represents the name of the spring bean, which presents the CXFRS client or server.

For the formats above, you can append options to the URI as follows:

cxfrs:bean:cxfEndpoint?resourceClasses=org.apache.camel.rs.Example

27.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

27.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

27.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

27.4. Component Options

The CXF-RS component supports 5 options, which are listed below.

NameDescriptionDefaultType

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

headerFilterStrategy (filter)

To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message.

 

HeaderFilterStrategy

useGlobalSslContextParameters (security)

Enable usage of global SSL context parameters.

false

boolean

27.5. Endpoint Options

The CXF-RS endpoint is configured using URI syntax:

cxfrs:beanId:address

With the following path and query parameters:

27.5.1. Path Parameters (2 parameters)

NameDescriptionDefaultType

beanId (common)

To lookup an existing configured CxfRsEndpoint. Must use bean: as prefix.

 

String

address (common)

The service publish address.

 

String

27.5.2. Query Parameters (31 parameters)

NameDescriptionDefaultType

features (common)

Set the feature list to the CxfRs endpoint.

 

List

loggingFeatureEnabled (common)

This option enables CXF Logging Feature which writes inbound and outbound REST messages to log.

false

boolean

loggingSizeLimit (common)

To limit the total size of number of bytes the logger will output when logging feature has been enabled.

 

int

modelRef (common)

This option is used to specify the model file which is useful for the resource class without annotation. When using this option, then the service class can be omitted, to emulate document-only endpoints.

 

String

providers (common)

Set custom JAX-RS provider(s) list to the CxfRs endpoint. You can specify a string with a list of providers to lookup in the registy separated by comma.

 

String

resourceClasses (common)

The resource classes which you want to export as REST service. Multiple classes can be separated by comma.

 

List

schemaLocations (common)

Sets the locations of the schema(s) which can be used to validate the incoming XML or JAXB-driven JSON.

 

List

skipFaultLogging (common)

This option controls whether the PhaseInterceptorChain skips logging the Fault that it catches.

false

boolean

bindingStyle (consumer)

Sets how requests and responses will be mapped to/from Camel. Two values are possible: SimpleConsumer: This binding style processes request parameters, multiparts, etc. and maps them to IN headers, IN attachments and to the message body. It aims to eliminate low-level processing of org.apache.cxf.message.MessageContentsList. It also also adds more flexibility and simplicity to the response mapping. Only available for consumers. Default: The default style. For consumers this passes on a MessageContentsList to the route, requiring low-level processing in the route. This is the traditional binding style, which simply dumps the org.apache.cxf.message.MessageContentsList coming in from the CXF stack onto the IN message body. The user is then responsible for processing it according to the contract defined by the JAX-RS method signature. Custom: allows you to specify a custom binding through the binding option.

Enum values:

  • SimpleConsumer
  • Default
  • Custom

Default

BindingStyle

publishedEndpointUrl (consumer)

This option can override the endpointUrl that published from the WADL which can be accessed with resource address url plus _wadl.

 

String

bridgeErrorHandler (consumer (advanced))

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
 

ExchangePattern

serviceBeans (consumer (advanced))

The service beans (the bean ids to lookup in the registry) which you want to export as REST service. Multiple beans can be separated by comma.

 

String

cookieHandler (producer)

Configure a cookie handler to maintain a HTTP session.

 

CookieHandler

hostnameVerifier (producer)

The hostname verifier to be used. Use the # notation to reference a HostnameVerifier from the registry.

 

HostnameVerifier

sslContextParameters (producer)

The Camel SSL setting reference. Use the # notation to reference the SSL Context.

 

SSLContextParameters

throwExceptionOnFailure (producer)

This option tells the CxfRsProducer to inspect return codes and will generate an Exception if the return code is larger than 207.

true

boolean

httpClientAPI (producer (advanced))

If it is true, the CxfRsProducer will use the HttpClientAPI to invoke the service. If it is false, the CxfRsProducer will use the ProxyClientAPI to invoke the service.

true

boolean

ignoreDeleteMethodMessageBody (producer (advanced))

This option is used to tell CxfRsProducer to ignore the message body of the DELETE method when using HTTP API.

false

boolean

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

maxClientCacheSize (producer (advanced))

This option allows you to configure the maximum size of the cache. The implementation caches CXF clients or ClientFactoryBean in CxfProvider and CxfRsProvider.

10

int

synchronous (producer (advanced))

Sets whether synchronous processing should be strictly used.

false

boolean

binding (advanced)

To use a custom CxfBinding to control the binding between Camel Message and CXF Message.

 

CxfRsBinding

bus (advanced)

To use a custom configured CXF Bus.

 

Bus

continuationTimeout (advanced)

This option is used to set the CXF continuation timeout which could be used in CxfConsumer by default when the CXF server is using Jetty or Servlet transport.

30000

long

cxfRsConfigurer (advanced)

This option could apply the implementation of org.apache.camel.component.cxf.jaxrs.CxfRsEndpointConfigurer which supports to configure the CXF endpoint in programmatic way. User can configure the CXF server and client by implementing configure\\{Server/Client} method of CxfEndpointConfigurer.

 

CxfRsConfigurer

defaultBus (advanced)

Will set the default bus when CXF endpoint create a bus by itself.

false

boolean

headerFilterStrategy (advanced)

To use a custom HeaderFilterStrategy to filter header to and from Camel message.

 

HeaderFilterStrategy

performInvocation (advanced)

When the option is true, Camel will perform the invocation of the resource class instance and put the response object into the exchange for further processing.

false

boolean

propagateContexts (advanced)

When the option is true, JAXRS UriInfo, HttpHeaders, Request and SecurityContext contexts will be available to custom CXFRS processors as typed Camel exchange properties. These contexts can be used to analyze the current requests using JAX-RS API.

false

boolean

27.6. Message Headers

The CXF-RS component supports 16 message header(s), which is/are listed below:

NameDescriptionDefaultType

operationName (common)

Constant: OPERATION_NAME

The name of the operation.

 

String

CamelAuthentication (common)

Constant: AUTHENTICATION

The authentication.

 

Subject

CamelHttpMethod (common)

Constant: HTTP_METHOD

The http method to use.

 

String

CamelHttpPath (common)

Constant: HTTP_PATH

The http path.

 

String

Content-Type (common)

Constant: CONTENT_TYPE

The content type.

 

String

CamelHttpQuery (common)

Constant: HTTP_QUERY

The http query.

 

String

CamelHttpResponseCode (common)

Constant: HTTP_RESPONSE_CODE

The http response code.

 

Integer

Content-Encoding (common)

Constant: CONTENT_ENCODING

The content encoding.

 

String

org.apache.cxf.message.Message.PROTOCOL_HEADERS (common)

Constant: PROTOCOL_HEADERS

The protocol headers.

 

Map

CamelCxfMessage (common)

Constant: CAMEL_CXF_MESSAGE

The CXF message.

 

Message

CamelCxfRsUsingHttpAPI (common)

Constant: CAMEL_CXF_RS_USING_HTTP_API

If it is true, the CxfRsProducer will use the HttpClientAPI to invoke the service. If it is false, the CxfRsProducer will use the ProxyClientAPI to invoke the service.

 

Boolean

CamelCxfRsVarValues (common)

Constant: CAMEL_CXF_RS_VAR_VALUES

The path values.

 

Object[]

CamelCxfRsResponseClass (common)

Constant: CAMEL_CXF_RS_RESPONSE_CLASS

The response class.

 

Class

CamelCxfRsResponseGenericType (common)

Constant: CAMEL_CXF_RS_RESPONSE_GENERIC_TYPE

The response generic type.

 

Type

CamelCxfRsQueryMap (common)

Constant: CAMEL_CXF_RS_QUERY_MAP

The query map.

 

Map

CamelCxfRsOperationResourceInfoStack (common)

Constant: CAMEL_CXF_RS_OPERATION_RESOURCE_INFO_STACK

The stack of MethodInvocationInfo representing resources path when JAX-RS invocation looks for target.

 

OperationResourceInfoStack

You can also configure the CXF REST endpoint through the spring configuration.

Note

Avoid creating your own HTTP server instances in a Camel Spring Boot application by using either of the cxf-rt-transports-jetty, cxf-rt-transports-netty-server, cxf-rt-transports-undertow libraries. It is recommended to use the Spring Boot embedded HTTP server stack which is created when you use the spring-boot-starter-web, cxf-spring-boot-starter-jaxrs, or cxf-spring-boot-starter-jaxws dependencies.

Note

Since there are lots of differences between the CXF REST client and CXF REST Server, we provide different configuration for them.

+ Please check the following files for more details:

27.7. How to configure the REST endpoint in Camel

In the camel-cxf schema file, there are two elements for the REST endpoint definition:

  • cxf:rsServer for REST consumer
  • cxf:rsClient for REST producer.

You can find a Camel REST service route configuration example there.

27.8. How to override the CXF producer address from message header

The camel-cxfrs producer supports overriding the service address by setting the message with the key of CamelDestinationOverrideUrl.

 // set up the service address from the message header to override the setting of CXF endpoint
 exchange.getIn().setHeader(Exchange.DESTINATION_OVERRIDE_URL, constant(getServiceAddress()));

27.9. Consuming a REST Request - Simple Binding Style

Since Camel 2.11

The Default binding style is rather low-level, requiring the user to manually process the MessageContentsList object coming into the route. Thus, it tightly couples the route logic with the method signature and parameter indices of the JAX-RS operation which is somewhat inelegant, difficult and error-prone.

In contrast, the SimpleConsumer binding style performs the following mappings, to make the request data more accessible to you within the Camel Message:

  • JAX-RS Parameters (@HeaderParam, @QueryParam, etc.) are injected as IN message headers. The header name matches the value of the annotation.
  • The request entity (POJO or another type) becomes the IN message body. If a single entity cannot be identified in the JAX-RS method signature, it falls back to the original MessageContentsList.
  • Binary @Multipart body parts become IN message attachments, supporting DataHandler, InputStream, DataSource and CXF’s Attachment class.
  • Non-binary @Multipart body parts are mapped as IN message headers. The header name matches the Body Part name.

Additionally, the following rules apply to the Response mapping:

  • If the message body type is different to javax.ws.rs.core.Response (user-built response), a new Response is created and the message body is set as the entity (so long it’s not null). The response status code is taken from the Exchange.HTTP_RESPONSE_CODE header, or defaults to 200 OK if not present.
  • If the message body type is equal to javax.ws.rs.core.Response, it means that the user has built a custom response, and therefore it is respected, and it becomes the final response.
  • In all cases, Camel headers permitted by custom or default HeaderFilterStrategy are added to the HTTP response.

27.9.1. Enabling the Simple Binding Style

This binding style can be activated by setting the bindingStyle parameter in the consumer endpoint to value SimpleConsumer:

  from("cxfrs:bean:rsServer?bindingStyle=SimpleConsumer")
    .to("log:TEST?showAll=true");

27.9.2. Examples of request binding with different method signatures

Below is a list of method signatures along with the expected result from the simple binding:

  • public Response doAction(BusinessObject request);: the request payload is placed in tbe IN message body, replacing the original MessageContentsList.
  • public Response doAction(BusinessObject request, @HeaderParam("abcd") String abcd, @QueryParam("defg") String defg);: the request payload is placed in the IN message body, replacing the original MessageContentsList. Both request parameters are mapped as IN message headers with names "abcd" and "defg".
  • public Response doAction(@HeaderParam("abcd") String abcd, @QueryParam("defg") String defg);: both request parameters are mapped as the IN message headers with names "abcd" and "defg". The original MessageContentsList is preserved, even though it only contains the two parameters.
  • public Response doAction(@Multipart(value="body1") BusinessObject request, @Multipart(value="body2") BusinessObject request2);: the first parameter is transferred as a header with name "body1", and the second one is mapped as header "body2". The original MessageContentsList is preserved as the IN message body.
  • public Response doAction(InputStream abcd);: the InputStream is unwrapped from the MessageContentsList and preserved as the IN message body.
  • public Response doAction(DataHandler abcd);: the DataHandler is unwrapped from the MessageContentsList and preserved as the IN message body.

27.9.3. Examples of the Simple Binding Style

Given a JAX-RS resource class with this method:

@POST @Path("/customers/{type}")
public Response newCustomer(Customer customer, @PathParam("type") String type, @QueryParam("active") @DefaultValue("true") boolean active) {
    return null;
}

Serviced by the following route:

from("cxfrs:bean:rsServer?bindingStyle=SimpleConsumer")
    .recipientList(simple("direct:${header.operationName}"));

from("direct:newCustomer")
    .log("Request: type=${header.type}, active=${header.active}, customerData=${body}");

The following HTTP request with XML payload (given that the Customer DTO is JAXB-annotated):

POST /customers/gold?active=true

Payload:
<Customer>
  <fullName>Raul Kripalani</fullName>
  <country>Spain</country>
  <project>Apache Camel</project>
</Customer>

Will print the message:

Request: type=gold, active=true, customerData=<Customer.toString() representation>
NOTE
More examples on how to process requests and write responses can be found here .

27.10. Consuming a REST Request - Default Binding Style

The CXF JAXRS front end implements the JAX-RS (JSR-311) API, so we can export the resource classes as a REST service. We leverage the CXF Invoker API to turn a REST request into a normal Java object method invocation.There is no need to specify the URI template within your endpoint. The CXF takes care of the REST request URI to resource class method mapping according to the JSR-311 specification. All you need to do in Camel is delegate this method request to the right processor or endpoint.

CXFRS route example

private static final String CXF_RS_ENDPOINT_URI =
        "cxfrs://http://localhost:" + CXT + "/rest?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceResource";
private static final String CXF_RS_ENDPOINT_URI2 =
        "cxfrs://http://localhost:" + CXT + "/rest2?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerService";
private static final String CXF_RS_ENDPOINT_URI3 =
        "cxfrs://http://localhost:" + CXT + "/rest3?"
        + "resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceNoAnnotations&"
        + "modelRef=classpath:/org/apache/camel/component/cxf/jaxrs/CustomerServiceModel.xml";
private static final String CXF_RS_ENDPOINT_URI4 =
        "cxfrs://http://localhost:" + CXT + "/rest4?"
        + "modelRef=classpath:/org/apache/camel/component/cxf/jaxrs/CustomerServiceDefaultHandlerModel.xml";
private static final String CXF_RS_ENDPOINT_URI5 =
        "cxfrs://http://localhost:" + CXT + "/rest5?"
        + "propagateContexts=true&"
        + "modelRef=classpath:/org/apache/camel/component/cxf/jaxrs/CustomerServiceDefaultHandlerModel.xml";
protected RouteBuilder createRouteBuilder() throws Exception {
    final Processor testProcessor = new TestProcessor();
    final Processor testProcessor2 = new TestProcessor2();
    final Processor testProcessor3 = new TestProcessor3();
    return new RouteBuilder() {
        public void configure() {
            errorHandler(new NoErrorHandlerBuilder());
            from(CXF_RS_ENDPOINT_URI).process(testProcessor);
            from(CXF_RS_ENDPOINT_URI2).process(testProcessor);
            from(CXF_RS_ENDPOINT_URI3).process(testProcessor);
            from(CXF_RS_ENDPOINT_URI4).process(testProcessor2);
            from(CXF_RS_ENDPOINT_URI5).process(testProcessor3);
        }
    };
}

And the corresponding resource class is used to configure the endpoint.

NOTE
By default, JAX-RS resource classes are only used to configure JAX-RS properties. Methods will not be executed during routing of messages to the endpoint. Instead, it is the responsibility of the route to do all processing.

It is sufficient to provide an interface only as opposed to a no-op service implementation class for the default mode.

If a performInvocation option is enabled, the service implementation will be invoked first, the response will be set on the Camel exchange, and the route execution will continue as usual. This can be useful for integrating the existing JAX-RS implementations into Camel routes and for post-processing JAX-RS Responses in custom processors.

@Path("/customerservice/")
public interface CustomerServiceResource {

    @GET
    @Path("/customers/{id}/")
    Customer getCustomer(@PathParam("id") String id);

    @PUT
    @Path("/customers/")
    Response updateCustomer(Customer customer);

    @Path("/{id}")
    @PUT()
    @Consumes({ "application/xml", "text/plain",
                    "application/json" })
    @Produces({ "application/xml", "text/plain",
                    "application/json" })
    Object invoke(@PathParam("id") String id,
                    String payload);
}

27.11. How to invoke the REST service through camel-cxfrs producer

The CXF JAXRS front end implements a proxy-based client API. With this API you can invoke the remote REST service through a proxy. The camel-cxfrs producer is based on this proxy API. You can specify the operation name in the message header and prepare the parameter in the message body, the camel-cxfrs producer will generate the right REST request for you.

Example

Exchange exchange = template.send("direct://proxy", new Processor() {
    public void process(Exchange exchange) throws Exception {
        exchange.setPattern(ExchangePattern.InOut);
        Message inMessage = exchange.getIn();
        // set the operation name
        inMessage.setHeader(CxfConstants.OPERATION_NAME, "getCustomer");
        // using the proxy client API
        inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.FALSE);
        // set a customer header
        inMessage.setHeader("key", "value");
        // set up the accepted content type
        inMessage.setHeader(Exchange.ACCEPT_CONTENT_TYPE, "application/json");
        // set the parameters, if you just have one parameter,
        // camel will put this object into an Object[] itself
        inMessage.setBody("123");
    }
});

// get the response message
Customer response = (Customer) exchange.getMessage().getBody();

assertNotNull(response, "The response should not be null");
assertEquals(123, response.getId(), "Get a wrong customer id");
assertEquals("John", response.getName(), "Get a wrong customer name");
assertEquals(200, exchange.getMessage().getHeader(Exchange.HTTP_RESPONSE_CODE), "Get a wrong response code");
assertEquals("value", exchange.getMessage().getHeader("key"), "Get a wrong header value");

The CXF JAXRS front end also provides an HTTP centric client API. You can also invoke this API from camel-cxfrs producer. You need to specify the HTTP_PATH and the HTTP_METHOD and let the producer use the http centric client API by using the URI option httpClientAPI or by setting the message header CxfConstants.CAMEL_CXF_RS_USING_HTTP_API. You can turn the response object to the type class specified with the message header CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS.

Exchange exchange = template.send("direct://http", new Processor() {
    public void process(Exchange exchange) throws Exception {
        exchange.setPattern(ExchangePattern.InOut)
        Message inMessage = exchange.getIn();
        // using the http central client API
        inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.TRUE);
        // set the Http method
        inMessage.setHeader(Exchange.HTTP_METHOD, "GET");
        // set the relative path
        inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/123");
        // Specify the response class, cxfrs will use InputStream as the response object type
        inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
        // set a customer header
        inMessage.setHeader("key", "value");
        // since we use the Get method, so we don't need to set the message body
        inMessage.setBody(null);
    }
});

You can also specify the query parameters from cxfrs URI for the CXFRS http centric client.

Exchange exchange = template.send("cxfrs://http://localhost:9003/testQuery?httpClientAPI=true&q1=12&q2=13"

To support the Dynamical routing, you can override the URI’s query parameters by using the CxfConstants.CAMEL_CXF_RS_QUERY_MAP header to set the parameter map for it.

Map<String, String> queryMap = new LinkedHashMap<>();
queryMap.put("q1", "new");
queryMap.put("q2", "world");
inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_QUERY_MAP, queryMap);

27.12. Spring Boot Auto-Configuration

The component supports 6 options, which are listed below.

NameDescriptionDefaultType

camel.component.cxfrs.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.cxfrs.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.cxfrs.enabled

Whether to enable auto configuration of the cxfrs component. This is enabled by default.

 

Boolean

camel.component.cxfrs.header-filter-strategy

To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message. The option is a org.apache.camel.spi.HeaderFilterStrategy type.

 

HeaderFilterStrategy

camel.component.cxfrs.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.cxfrs.use-global-ssl-context-parameters

Enable usage of global SSL context parameters.

false

Boolean

Chapter 28. Data Format

Only producer is supported

The Dataformat component allows to use the Data Format as a Camel Component.

28.1. Dependencies

When using dataformat with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-dataformat-starter</artifactId>
</dependency>

28.2. URI format

dataformat:name:(marshal|unmarshal)[?options]

Where name is the name of the Data Format. And then followed by the operation which must either be marshal or unmarshal. The options is used for configuring the Data Format in use. See the Data Format documentation for which options it support.

28.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

28.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

28.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

28.4. Component Options

The Data Format component supports 2 options, which are listed below.

NameDescriptionDefaultType

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

28.5. Endpoint Options

The Data Format endpoint is configured using URI syntax:

dataformat:name:operation

with the following path and query parameters:

28.5.1. Path Parameters (2 parameters)

NameDescriptionDefaultType

name (producer)

Required Name of data format.

 

String

operation (producer)

Required Operation to use either marshal or unmarshal.

Enum values:

  • marshal
  • unmarshal
 

String

28.5.2. Query Parameters (1 parameters)

NameDescriptionDefaultType

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

28.6. Samples

For example to use the JAXB Data Format we can do as follows:

from("activemq:My.Queue").
  to("dataformat:jaxb:unmarshal?contextPath=com.acme.model").
  to("mqseries:Another.Queue");

And in XML DSL you do:

<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
  <route>
    <from uri="activemq:My.Queue"/>
    <to uri="dataformat:jaxb:unmarshal?contextPath=com.acme.model"/>
    <to uri="mqseries:Another.Queue"/>
  </route>
</camelContext>

28.7. Spring Boot Auto-Configuration

The component supports 3 options, which are listed below.

NameDescriptionDefaultType

camel.component.dataformat.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.dataformat.enabled

Whether to enable auto configuration of the dataformat component. This is enabled by default.

 

Boolean

camel.component.dataformat.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

Chapter 29. Dataset

Both producer and consumer are supported

Testing of distributed and asynchronous processing is notoriously difficult. The Mock, Test and DataSet endpoints work great with the Camel Testing Framework to simplify your unit and integration testing using Enterprise Integration Patterns and Camel’s large range of Components together with the powerful Bean Integration.

The DataSet component provides a mechanism to easily perform load & soak testing of your system. It works by allowing you to create DataSet instances both as a source of messages and as a way to assert that the data set is received.

Camel will use the throughput logger when sending datasets.

29.1. Dependencies

When using dataset with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-dataset-starter</artifactId>
</dependency>

29.2. URI format

dataset:name[?options]

Where name is used to find the DataSet instance in the Registry

Camel ships with a support implementation of org.apache.camel.component.dataset.DataSet, the org.apache.camel.component.dataset.DataSetSupport class, that can be used as a base for implementing your own DataSet. Camel also ships with some implementations that can be used for testing: org.apache.camel.component.dataset.SimpleDataSet, org.apache.camel.component.dataset.ListDataSet and org.apache.camel.component.dataset.FileDataSet, all of which extend DataSetSupport.

29.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

29.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

29.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

29.4. Component Options

The Dataset component supports 5 options, which are listed below.

NameDescriptionDefaultType

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

log (producer)

To turn on logging when the mock receives an incoming message. This will log only one time at INFO level for the incoming message. For more detailed logging then set the logger to DEBUG level for the org.apache.camel.component.mock.MockEndpoint class.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

exchangeFormatter (advanced)

Autowired Sets a custom ExchangeFormatter to convert the Exchange to a String suitable for logging. If not specified, we default to DefaultExchangeFormatter.

 

ExchangeFormatter

29.5. Endpoint Options

The Dataset endpoint is configured using URI syntax:

dataset:name

with the following path and query parameters:

29.5.1. Path Parameters (1 parameters)

NameDescriptionDefaultType

name (common)

Required Name of DataSet to lookup in the registry.

 

DataSet

29.5.2. Query Parameters (21 parameters)

NameDescriptionDefaultType

dataSetIndex (common)

Controls the behaviour of the CamelDataSetIndex header. For Consumers: - off = the header will not be set - strict/lenient = the header will be set For Producers: - off = the header value will not be verified, and will not be set if it is not present = strict = the header value must be present and will be verified = lenient = the header value will be verified if it is present, and will be set if it is not present.

Enum values:

  • strict
  • lenient
  • off

lenient

String

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

initialDelay (consumer)

Time period in millis to wait before starting sending messages.

1000

long

minRate (consumer)

Wait until the DataSet contains at least this number of messages.

0

int

preloadSize (consumer)

Sets how many messages should be preloaded (sent) before the route completes its initialization.

0

long

produceDelay (consumer)

Allows a delay to be specified which causes a delay when a message is sent by the consumer (to simulate slow processing).

3

long

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

assertPeriod (producer)

Sets a grace period after which the mock endpoint will re-assert to ensure the preliminary assertion is still valid. This is used for example to assert that exactly a number of messages arrives. For example if expectedMessageCount(int) was set to 5, then the assertion is satisfied when 5 or more message arrives. To ensure that exactly 5 messages arrives, then you would need to wait a little period to ensure no further message arrives. This is what you can use this method for. By default this period is disabled.

 

long

consumeDelay (producer)

Allows a delay to be specified which causes a delay when a message is consumed by the producer (to simulate slow processing).

0

long

expectedCount (producer)

Specifies the expected number of message exchanges that should be received by this endpoint. Beware: If you want to expect that 0 messages, then take extra care, as 0 matches when the tests starts, so you need to set a assert period time to let the test run for a while to make sure there are still no messages arrived; for that use setAssertPeriod(long). An alternative is to use NotifyBuilder, and use the notifier to know when Camel is done routing some messages, before you call the assertIsSatisfied() method on the mocks. This allows you to not use a fixed assert period, to speedup testing times. If you want to assert that exactly n’th message arrives to this mock endpoint, then see also the setAssertPeriod(long) method for further details.

-1

int

failFast (producer)

Sets whether assertIsSatisfied() should fail fast at the first detected failed expectation while it may otherwise wait for all expected messages to arrive before performing expectations verifications. Is by default true. Set to false to use behavior as in Camel 2.x.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

log (producer)

To turn on logging when the mock receives an incoming message. This will log only one time at INFO level for the incoming message. For more detailed logging then set the logger to DEBUG level for the org.apache.camel.component.mock.MockEndpoint class.

false

boolean

reportGroup (producer)

A number that is used to turn on throughput logging based on groups of the size.

 

int

resultMinimumWaitTime (producer)

Sets the minimum expected amount of time (in millis) the assertIsSatisfied() will wait on a latch until it is satisfied.

 

long

resultWaitTime (producer)

Sets the maximum amount of time (in millis) the assertIsSatisfied() will wait on a latch until it is satisfied.

 

long

retainFirst (producer)

Specifies to only retain the first n’th number of received Exchanges. This is used when testing with big data, to reduce memory consumption by not storing copies of every Exchange this mock endpoint receives. Important: When using this limitation, then the getReceivedCounter() will still return the actual number of received Exchanges. For example if we have received 5000 Exchanges, and have configured to only retain the first 10 Exchanges, then the getReceivedCounter() will still return 5000 but there is only the first 10 Exchanges in the getExchanges() and getReceivedExchanges() methods. When using this method, then some of the other expectation methods is not supported, for example the expectedBodiesReceived(Object…​) sets a expectation on the first number of bodies received. You can configure both setRetainFirst(int) and setRetainLast(int) methods, to limit both the first and last received.

-1

int

retainLast (producer)

Specifies to only retain the last n’th number of received Exchanges. This is used when testing with big data, to reduce memory consumption by not storing copies of every Exchange this mock endpoint receives. Important: When using this limitation, then the getReceivedCounter() will still return the actual number of received Exchanges. For example if we have received 5000 Exchanges, and have configured to only retain the last 20 Exchanges, then the getReceivedCounter() will still return 5000 but there is only the last 20 Exchanges in the getExchanges() and getReceivedExchanges() methods. When using this method, then some of the other expectation methods is not supported, for example the expectedBodiesReceived(Object…​) sets a expectation on the first number of bodies received. You can configure both setRetainFirst(int) and setRetainLast(int) methods, to limit both the first and last received.

-1

int

sleepForEmptyTest (producer)

Allows a sleep to be specified to wait to check that this endpoint really is empty when expectedMessageCount(int) is called with zero.

 

long

copyOnExchange (producer (advanced))

Sets whether to make a deep copy of the incoming Exchange when received at this mock endpoint. Is by default true.

true

boolean

29.6. Configuring DataSet

Camel will lookup in the Registry for a bean implementing the DataSet interface. So you can register your own DataSet as:

<bean id="myDataSet" class="com.mycompany.MyDataSet">
  <property name="size" value="100"/>
</bean>

29.7. Example

For example, to test that a set of messages are sent to a queue and then consumed from the queue without losing any messages:

// send the dataset to a queue
from("dataset:foo").to("activemq:SomeQueue");

// now lets test that the messages are consumed correctly
from("activemq:SomeQueue").to("dataset:foo");

The above would look in the Registry to find the foo DataSet instance which is used to create the messages.

Then you create a DataSet implementation, such as using the SimpleDataSet as described below, configuring things like how big the data set is and what the messages look like etc.

29.8. DataSetSupport (abstract class)

The DataSetSupport abstract class is a nice starting point for new DataSets, and provides some useful features to derived classes.

29.8.1. Properties on DataSetSupport

PropertyTypeDefaultDescription

defaultHeaders

Map<String,Object>

null

Specifies the default message body. For SimpleDataSet it is a constant payload; though if you want to create custom payloads per message, create your own derivation of DataSetSupport.

outputTransformer

org.apache.camel.Processor

null

 

size

long

10

Specifies how many messages to send/consume.

reportCount

long

-1

Specifies the number of messages to be received before reporting progress. Useful for showing progress of a large load test. If < 0, then size / 5, if is 0 then size, else set to reportCount value.

29.9. SimpleDataSet

The SimpleDataSet extends DataSetSupport, and adds a default body.

29.9.1. Additional Properties on SimpleDataSet

PropertyTypeDefaultDescription

defaultBody

Object

<hello>world!</hello>

Specifies the default message body. By default, the SimpleDataSet produces the same constant payload for each exchange. If you want to customize the payload for each exchange, create a Camel Processor and configure the SimpleDataSet to use it by setting the outputTransformer property.

29.10. ListDataSet

The List`DataSet` extends DataSetSupport, and adds a list of default bodies.

29.10.1. Additional Properties on ListDataSet

PropertyTypeDefaultDescription

defaultBodies

List<Object>

empty LinkedList<Object>

Specifies the default message body. By default, the ListDataSet selects a constant payload from the list of defaultBodies using the CamelDataSetIndex. If you want to customize the payload, create a Camel Processor and configure the ListDataSet to use it by setting the outputTransformer property.

size

long

the size of the defaultBodies list

Specifies how many messages to send/consume. This value can be different from the size of the defaultBodies list. If the value is less than the size of the defaultBodies list, some of the list elements will not be used. If the value is greater than the size of the defaultBodies list, the payload for the exchange will be selected using the modulus of the CamelDataSetIndex and the size of the defaultBodies list (i.e. CamelDataSetIndex % defaultBodies.size() )

29.11. FileDataSet

The FileDataSet extends ListDataSet, and adds support for loading the bodies from a file.

29.11.1. Additional Properties on FileDataSet

PropertyTypeDefaultDescription

sourceFile

File

null

Specifies the source file for payloads

delimiter

String

\z

Specifies the delimiter pattern used by a java.util.Scanner to split the file into multiple payloads.

29.12. Spring Boot Auto-Configuration

The component supports 11 options, which are listed below.

NameDescriptionDefaultType

camel.component.dataset-test.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.dataset-test.enabled

Whether to enable auto configuration of the dataset-test component. This is enabled by default.

 

Boolean

camel.component.dataset-test.exchange-formatter

Sets a custom ExchangeFormatter to convert the Exchange to a String suitable for logging. If not specified, we default to DefaultExchangeFormatter. The option is a org.apache.camel.spi.ExchangeFormatter type.

 

ExchangeFormatter

camel.component.dataset-test.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.dataset-test.log

To turn on logging when the mock receives an incoming message. This will log only one time at INFO level for the incoming message. For more detailed logging then set the logger to DEBUG level for the org.apache.camel.component.mock.MockEndpoint class.

false

Boolean

camel.component.dataset.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.dataset.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.dataset.enabled

Whether to enable auto configuration of the dataset component. This is enabled by default.

 

Boolean

camel.component.dataset.exchange-formatter

Sets a custom ExchangeFormatter to convert the Exchange to a String suitable for logging. If not specified, we default to DefaultExchangeFormatter. The option is a org.apache.camel.spi.ExchangeFormatter type.

 

ExchangeFormatter

camel.component.dataset.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.dataset.log

To turn on logging when the mock receives an incoming message. This will log only one time at INFO level for the incoming message. For more detailed logging then set the logger to DEBUG level for the org.apache.camel.component.mock.MockEndpoint class.

false

Boolean

Chapter 30. Direct

Both producer and consumer are supported

The Direct component provides direct, synchronous invocation of any consumers when a producer sends a message exchange.
This endpoint can be used to connect existing routes in the same camel context.

Note

Asynchronous
The SEDA component provides asynchronous invocation of any consumers when a producer sends a message exchange.

30.1. Dependencies

When using direct with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-direct-starter</artifactId>
</dependency>

30.2. URI format

direct:someName[?options]

Where someName can be any string to uniquely identify the endpoint

30.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

30.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

30.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

30.4. Component Options

The Direct component supports 5 options, which are listed below.

NameDescriptionDefaultType

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

block (producer)

If sending a message to a direct endpoint which has no active consumer, then we can tell the producer to block and wait for the consumer to become active.

true

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

timeout (producer)

The timeout value to use if block is enabled.

30000

long

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

30.5. Endpoint Options

The Direct endpoint is configured using URI syntax:

direct:name

with the following path and query parameters:

30.5.1. Path Parameters (1 parameters)

NameDescriptionDefaultType

name (common)

Required Name of direct endpoint.

 

String

30.5.2. Query Parameters (8 parameters)

NameDescriptionDefaultType

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

block (producer)

If sending a message to a direct endpoint which has no active consumer, then we can tell the producer to block and wait for the consumer to become active.

true

boolean

failIfNoConsumers (producer)

Whether the producer should fail by throwing an exception, when sending to a DIRECT endpoint with no active consumers.

true

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

timeout (producer)

The timeout value to use if block is enabled.

30000

long

synchronous (advanced)

Whether synchronous processing is forced. If enabled then the producer thread, will be forced to wait until the message has been completed before the same thread will continue processing. If disabled (default) then the producer thread may be freed and can do other work while the message is continued processed by other threads (reactive).

false

boolean

30.6. Samples

In the route below we use the direct component to link the two routes together:

from("activemq:queue:order.in")
    .to("bean:orderServer?method=validate")
    .to("direct:processOrder");

from("direct:processOrder")
    .to("bean:orderService?method=process")
    .to("activemq:queue:order.out");

And the sample using spring DSL:

<route>
 <from uri="activemq:queue:order.in"/>
 <to uri="bean:orderService?method=validate"/>
 <to uri="direct:processOrder"/>
</route>

<route>
 <from uri="direct:processOrder"/>
 <to uri="bean:orderService?method=process"/>
 <to uri="activemq:queue:order.out"/>
</route>

See also samples from the SEDA component, how they can be used together.

30.7. Spring Boot Auto-Configuration

The component supports 6 options, which are listed below.

NameDescriptionDefaultType

camel.component.direct.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.direct.block

If sending a message to a direct endpoint which has no active consumer, then we can tell the producer to block and wait for the consumer to become active.

true

Boolean

camel.component.direct.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.direct.enabled

Whether to enable auto configuration of the direct component. This is enabled by default.

 

Boolean

camel.component.direct.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.direct.timeout

The timeout value to use if block is enabled.

30000

Long

Chapter 31. Elasticsearch

Since Camel 3.18.3

Only producer is supported

The ElasticSearch component allows you to interface with an ElasticSearch 8.x API using the Java API Client library.

31.1. Dependencies

When using elasticsearch with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-elasticsearch-starter</artifactId>
</dependency>

31.2. URI format

elasticsearch://clusterName[?options]

31.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

31.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

31.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

31.4. Component Options

The Elasticsearch component supports 14 options, which are listed below.

NameDescriptionDefaultType

connectionTimeout (producer)

The time in ms to wait before connection will timeout.

30000

int

hostAddresses (producer)

Comma separated list with ip:port formatted remote transport addresses to use. The ip and port options must be left blank for hostAddresses to be considered instead.

 

String

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

maxRetryTimeout (producer)

The time in ms before retry.

30000

int

socketTimeout (producer)

The timeout in ms to wait before the socket will timeout.

30000

int

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

client (advanced)

Autowired To use an existing configured Elasticsearch client, instead of creating a client per endpoint. This allow to customize the client with specific settings.

 

RestClient

enableSniffer (advanced)

Enable automatically discover nodes from a running Elasticsearch cluster. If this option is used in conjunction with Spring Boot then it’s managed by the Spring Boot configuration (see: Disable Sniffer in Spring Boot).

false

boolean

sniffAfterFailureDelay (advanced)

The delay of a sniff execution scheduled after a failure (in milliseconds).

60000

int

snifferInterval (advanced)

The interval between consecutive ordinary sniff executions in milliseconds. Will be honoured when sniffOnFailure is disabled or when there are no failures between consecutive sniff executions.

300000

int

certificatePath (security)

The path of the self-signed certificate to use to access to Elasticsearch.

 

String

enableSSL (security)

Enable SSL.

false

boolean

password (security)

Password for authenticate.

 

String

user (security)

Basic authenticate user.

 

String

31.5. Endpoint Options

The Elasticsearch endpoint is configured using URI syntax:

elasticsearch:clusterName

with the following path and query parameters:

31.5.1. Path Parameters (1 parameters)

NameDescriptionDefaultType

clusterName (producer)

Required Name of the cluster.

 

String

31.5.2. Query Parameters (19 parameters)

NameDescriptionDefaultType

connectionTimeout (producer)

The time in ms to wait before connection will timeout.

30000

int

disconnect (producer)

Disconnect after it finish calling the producer.

false

boolean

from (producer)

Starting index of the response.

 

Integer

hostAddresses (producer)

Comma separated list with ip:port formatted remote transport addresses to use.

 

String

indexName (producer)

The name of the index to act against.

 

String

maxRetryTimeout (producer)

The time in ms before retry.

30000

int

operation (producer)

What operation to perform.

Enum values:

  • Index
  • Update
  • Bulk
  • GetById
  • MultiGet
  • MultiSearch
  • Delete
  • DeleteIndex
  • Search
  • Exists
  • Ping
 

ElasticsearchOperation

scrollKeepAliveMs (producer)

Time in ms during which elasticsearch will keep search context alive.

60000

int

size (producer)

Size of the response.

 

Integer

socketTimeout (producer)

The timeout in ms to wait before the socket will timeout.

30000

int

useScroll (producer)

Enable scroll usage.

false

boolean

waitForActiveShards (producer)

Index creation waits for the write consistency number of shards to be available.

1

int

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

documentClass (advanced)

The class to use when deserializing the documents.

ObjectNode

Class

enableSniffer (advanced)

Enable automatically discover nodes from a running Elasticsearch cluster. If this option is used in conjunction with Spring Boot then it’s managed by the Spring Boot configuration (see: Disable Sniffer in Spring Boot).

false

boolean

sniffAfterFailureDelay (advanced)

The delay of a sniff execution scheduled after a failure (in milliseconds).

60000

int

snifferInterval (advanced)

The interval between consecutive ordinary sniff executions in milliseconds. Will be honoured when sniffOnFailure is disabled or when there are no failures between consecutive sniff executions.

300000

int

certificatePath (security)

The path of the self-signed certificate to use to access to Elasticsearch.

 

String

enableSSL (security)

Enable SSL.

false

boolean

31.6. Message Headers

The Elasticsearch component supports 9 message header(s), which is/are listed below:

NameDescriptionDefaultType

operation (producer)

Constant: PARAM_OPERATION

The operation to perform.

Enum values:

  • Index
  • Update
  • Bulk
  • GetById
  • MultiGet
  • MultiSearch
  • Delete
  • DeleteIndex
  • Search
  • Exists
  • Ping
 

ElasticsearchOperation

indexId (producer)

Constant: PARAM_INDEX_ID

The id of the indexed document.

 

String

indexName (producer)

Constant: PARAM_INDEX_NAME

The name of the index to act against.

 

String

documentClass (producer)

Constant: PARAM_DOCUMENT_CLASS

The full qualified name of the class of the document to unmarshall.

ObjectNode

Class

waitForActiveShards (producer)

Constant: PARAM_WAIT_FOR_ACTIVE_SHARDS

The index creation waits for the write consistency number of shards to be available.

 

Integer

scrollKeepAliveMs (producer)

Constant: PARAM_SCROLL_KEEP_ALIVE_MS

The starting index of the response.

 

Integer

useScroll (producer)

Constant: PARAM_SCROLL

Set to true to enable scroll usage.

 

Boolean

size (producer)

Constant: PARAM_SIZE

The size of the response.

 

Integer

from (producer)

Constant: PARAM_FROM

The starting index of the response.

 

Integer

31.7. Message Operations

The following ElasticSearch operations are currently supported. Simply set an endpoint URI option or exchange header with a key of "operation" and a value set to one of the following. Some operations also require other parameters or the message body to be set.

operationmessage bodydescription

Index

Map, String, byte[], Reader, InputStream or IndexRequest.Builder content to index

Adds content to an index and returns the content’s indexId in the body. You can set the name of the target index by setting the message header with the key "indexName". You can set the indexId by setting the message header with the key "indexId".

GetById

String or GetRequest.Builder index id of content to retrieve

Retrieves the document corresponding to the given index id and returns a GetResponse object in the body. You can set the name of the target index by setting the message header with the key "indexName". You can set the type of document by setting the message header with the key "documentClass".

Delete

String or DeleteRequest.Builder index id of content to delete

Deletes the specified indexName and returns a Result object in the body. You can set the name of the target index by setting the message header with the key "indexName".

DeleteIndex

String or DeleteIndexRequest.Builder index name of the index to delete

Deletes the specified indexName and returns a status code in the body. You can set the name of the target index by setting the message header with the key "indexName".

Bulk

Iterable or BulkRequest.Builder of any type that is already accepted (DeleteOperation.Builder for delete operation, UpdateOperation.Builder for update operation, CreateOperation.Builder for create operation, byte[], InputStream, String, Reader, Map or any document type for index operation)

Adds/Updates/Deletes content from/to an index and returns a List<BulkResponseItem> object in the body You can set the name of the target index by setting the message header with the key "indexName".

Search

Map, String or SearchRequest.Builder

Search the content with the map of query string. You can set the name of the target index by setting the message header with the key "indexName". You can set the number of hits to return by setting the message header with the key "size". You can set the starting document offset by setting the message header with the key "from".

MultiSearch

MsearchRequest.Builder

Multiple search in one

MultiGet

Iterable<String> or MgetRequest.Builder the id of the document to retrieve

Multiple get in one

You can set the name of the target index by setting the message header with the key "indexName".

Exists

None

Checks whether the index exists or not and returns a Boolean flag in the body.

You must set the name of the target index by setting the message header with the key "indexName".

Update

byte[], InputStream, String, Reader, Map or any document type content to update

Updates content to an index and returns the content’s indexId in the body. You can set the name of the target index by setting the message header with the key "indexName". You can set the indexId by setting the message header with the key "indexId".

Ping

None

Pings the Elasticsearch cluster and returns true if the ping succeeded, false otherwise

31.8. Configure the component and enable basic authentication

To use the Elasticsearch component it has to be configured with a minimum configuration.

ElasticsearchComponent elasticsearchComponent = new ElasticsearchComponent();
elasticsearchComponent.setHostAddresses("myelkhost:9200");
camelContext.addComponent("elasticsearch", elasticsearchComponent);

For basic authentication with elasticsearch or using reverse http proxy in front of the elasticsearch cluster, simply setup basic authentication and SSL on the component like the example below

ElasticsearchComponent elasticsearchComponent = new ElasticsearchComponent();
elasticsearchComponent.setHostAddresses("myelkhost:9200");
elasticsearchComponent.setUser("elkuser");
elasticsearchComponent.setPassword("secure!!");
elasticsearchComponent.setEnableSSL(true);
elasticsearchComponent.setCertificatePath(certPath);

camelContext.addComponent("elasticsearch", elasticsearchComponent);

31.9. Index Example

Below is a simple INDEX example

from("direct:index")
  .to("elasticsearch://elasticsearch?operation=Index&indexName=twitter");
<route>
    <from uri="direct:index"/>
    <to uri="elasticsearch://elasticsearch?operation=Index&amp;indexName=twitter"/>
</route>

For this operation you need to specify a indexId header.

A client would simply need to pass a body message containing a Map to the route. The result body contains the indexId created.

Map<String, String> map = new HashMap<String, String>();
map.put("content", "test");
String indexId = template.requestBody("direct:index", map, String.class);

31.10. Search Example

Searching on specific field(s) and value use the Operation ´Search´. Pass in the query JSON String or the Map

from("direct:search")
  .to("elasticsearch://elasticsearch?operation=Search&indexName=twitter");
<route>
    <from uri="direct:search"/>
    <to uri="elasticsearch://elasticsearch?operation=Search&amp;indexName=twitter"/>
</route>
String query = "{\"query\":{\"match\":{\"doc.content\":\"new release of ApacheCamel\"}}}";
HitsMetadata<?> response = template.requestBody("direct:search", query, HitsMetadata.class);

Search on specific field(s) using Map.

Map<String, Object> actualQuery = new HashMap<>();
actualQuery.put("doc.content", "new release of ApacheCamel");

Map<String, Object> match = new HashMap<>();
match.put("match", actualQuery);

Map<String, Object> query = new HashMap<>();
query.put("query", match);
HitsMetadata<?> response = template.requestBody("direct:search", query, HitsMetadata.class);

Search using Elasticsearch scroll api in order to fetch all results.

from("direct:search")
  .to("elasticsearch://elasticsearch?operation=Search&indexName=twitter&useScroll=true&scrollKeepAliveMs=30000");
<route>
    <from uri="direct:search"/>
    <to uri="elasticsearch://elasticsearch?operation=Search&amp;indexName=twitter&amp;useScroll=true&amp;scrollKeepAliveMs=30000"/>
</route>
String query = "{\"query\":{\"match\":{\"doc.content\":\"new release of ApacheCamel\"}}}";
try (ElasticsearchScrollRequestIterator response = template.requestBody("direct:search", query, ElasticsearchScrollRequestIterator.class)) {
    // do something smart with results
}

can also be used.

from("direct:search")
  .to("elasticsearch://elasticsearch?operation=Search&indexName=twitter&useScroll=true&scrollKeepAliveMs=30000")
  .split()
  .body()
  .streaming()
  .to("mock:output")
  .end();

31.11. MultiSearch Example

MultiSearching on specific field(s) and value use the Operation ´MultiSearch´. Pass in the MultiSearchRequest instance

from("direct:multiSearch")
  .to("elasticsearch://elasticsearch?operation=MultiSearch");
<route>
    <from uri="direct:multiSearch"/>
    <to uri="elasticsearch://elasticsearch?operation=MultiSearch"/>
</route>

MultiSearch on specific field(s)

MsearchRequest.Builder builder = new MsearchRequest.Builder().index("twitter").searches(
        new RequestItem.Builder().header(new MultisearchHeader.Builder().build())
                .body(new MultisearchBody.Builder().query(b -> b.matchAll(x -> x)).build()).build(),
        new RequestItem.Builder().header(new MultisearchHeader.Builder().build())
                .body(new MultisearchBody.Builder().query(b -> b.matchAll(x -> x)).build()).build());
List<MultiSearchResponseItem<?>> response = template.requestBody("direct:multiSearch", builder, List.class);

31.12. Document type

For all the search operations, it is possible to indicate the type of document to retrieve in order to get the result already unmarshalled with the expected type.

The document type can be set using the header "documentClass" or via the uri parameter of the same name.

31.13. Using Camel Elasticsearch with Spring Boot

When you use camel-elasticsearch-starter with Spring Boot v2, then you must declare the following dependency in your own pom.xml.

<dependency>
  <groupId>jakarta.json</groupId>
  <artifactId>jakarta.json-api</artifactId>
  <version>2.0.2</version>
</dependency>

This is needed because Spring Boot v2 provides jakarta.json-api:1.1.6, and Elasticsearch requires to use json-api v2.

31.13.1. Use RestClient provided by Spring Boot

By default Spring Boot will auto configure an Elasticsearch RestClient that will be used by camel, it is possible to customize the client with the following basic properties:

spring.elasticsearch.uris=myelkhost:9200
spring.elasticsearch.username=elkuser
spring.elasticsearch.password=secure!!

More information can be found in application-properties.data.spring.elasticsearch.connection-timeout.

31.13.2. Disable Sniffer when using Spring Boot

When Spring Boot is on the classpath the Sniffer client for Elasticsearch is enabled by default. This option can be disabled in the Spring Boot Configuration:

spring:
  autoconfigure:
    exclude: org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAutoConfiguration

31.14. Spring Boot Auto-Configuration

The component supports 15 options, which are listed below.

NameDescriptionDefaultType

camel.component.elasticsearch.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.elasticsearch.certificate-path

The path of the self-signed certificate to use to access to Elasticsearch.

 

String

camel.component.elasticsearch.client

To use an existing configured Elasticsearch client, instead of creating a client per endpoint. This allow to customize the client with specific settings. The option is a org.elasticsearch.client.RestClient type.

 

RestClient

camel.component.elasticsearch.connection-timeout

The time in ms to wait before connection will timeout.

30000

Integer

camel.component.elasticsearch.enable-s-s-l

Enable SSL.

false

Boolean

camel.component.elasticsearch.enable-sniffer

Enable automatically discover nodes from a running Elasticsearch cluster. If this option is used in conjunction with Spring Boot then it’s managed by the Spring Boot configuration (see: Disable Sniffer in Spring Boot).

false

Boolean

camel.component.elasticsearch.enabled

Whether to enable auto configuration of the elasticsearch component. This is enabled by default.

 

Boolean

camel.component.elasticsearch.host-addresses

Comma separated list with ip:port formatted remote transport addresses to use. The ip and port options must be left blank for hostAddresses to be considered instead.

 

String

camel.component.elasticsearch.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.elasticsearch.max-retry-timeout

The time in ms before retry.

30000

Integer

camel.component.elasticsearch.password

Password for authenticate.

 

String

camel.component.elasticsearch.sniff-after-failure-delay

The delay of a sniff execution scheduled after a failure (in milliseconds).

60000

Integer

camel.component.elasticsearch.sniffer-interval

The interval between consecutive ordinary sniff executions in milliseconds. Will be honoured when sniffOnFailure is disabled or when there are no failures between consecutive sniff executions.

300000

Integer

camel.component.elasticsearch.socket-timeout

The timeout in ms to wait before the socket will timeout.

30000

Integer

camel.component.elasticsearch.user

Basic authenticate user.

 

String

Chapter 32. ExchangeProperty

The ExchangeProperty Expression Language allows you to extract values of named exchange properties.

32.1. Dependencies

The ExchangeProperty language is part of camel-core.

When using exchangeProperty with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-core-starter</artifactId>
</dependency>

32.2. Exchange Property Options

The ExchangeProperty language supports 1 options, which are listed below.

NameDefaultJava TypeDescription

trim

 

Boolean

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

32.3. Example

The recipientList EIP can utilize a exchangeProperty like:

<route>
  <from uri="direct:a" />
  <recipientList>
    <exchangeProperty>myProperty</exchangeProperty>
  </recipientList>
</route>

In this case, the list of recipients are contained in the property 'myProperty'.

And the same example in Java DSL:

from("direct:a").recipientList(exchangeProperty("myProperty"));

32.4. Spring Boot Auto-Configuration

The component supports 147 options, which are listed below.

NameDescriptionDefaultType

camel.cloud.consul.service-discovery.acl-token

Sets the ACL token to be used with Consul.

 

String

camel.cloud.consul.service-discovery.block-seconds

The seconds to wait for a watch event, default 10 seconds.

10

Integer

camel.cloud.consul.service-discovery.configurations

Define additional configuration definitions.

 

Map

camel.cloud.consul.service-discovery.connect-timeout-millis

Connect timeout for OkHttpClient.

 

Long

camel.cloud.consul.service-discovery.datacenter

The data center.

 

String

camel.cloud.consul.service-discovery.enabled

Enable the component.

true

Boolean

camel.cloud.consul.service-discovery.password

Sets the password to be used for basic authentication.

 

String

camel.cloud.consul.service-discovery.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.consul.service-discovery.read-timeout-millis

Read timeout for OkHttpClient.

 

Long

camel.cloud.consul.service-discovery.url

The Consul agent URL.

 

String

camel.cloud.consul.service-discovery.user-name

Sets the username to be used for basic authentication.

 

String

camel.cloud.consul.service-discovery.write-timeout-millis

Write timeout for OkHttpClient.

 

Long

camel.cloud.dns.service-discovery.configurations

Define additional configuration definitions.

 

Map

camel.cloud.dns.service-discovery.domain

The domain name;.

 

String

camel.cloud.dns.service-discovery.enabled

Enable the component.

true

Boolean

camel.cloud.dns.service-discovery.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.dns.service-discovery.proto

The transport protocol of the desired service.

_tcp

String

camel.cloud.etcd.service-discovery.configurations

Define additional configuration definitions.

 

Map

camel.cloud.etcd.service-discovery.enabled

Enable the component.

true

Boolean

camel.cloud.etcd.service-discovery.password

The password to use for basic authentication.

 

String

camel.cloud.etcd.service-discovery.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.etcd.service-discovery.service-path

The path to look for for service discovery.

/services/

String

camel.cloud.etcd.service-discovery.timeout

To set the maximum time an action could take to complete.

 

Long

camel.cloud.etcd.service-discovery.type

To set the discovery type, valid values are on-demand and watch.

on-demand

String

camel.cloud.etcd.service-discovery.uris

The URIs the client can connect to.

 

String

camel.cloud.etcd.service-discovery.user-name

The user name to use for basic authentication.

 

String

camel.cloud.kubernetes.service-discovery.api-version

Sets the API version when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.ca-cert-data

Sets the Certificate Authority data when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.ca-cert-file

Sets the Certificate Authority data that are loaded from the file when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-cert-data

Sets the Client Certificate data when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-cert-file

Sets the Client Certificate data that are loaded from the file when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-key-algo

Sets the Client Keystore algorithm, such as RSA when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-key-data

Sets the Client Keystore data when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-key-file

Sets the Client Keystore data that are loaded from the file when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-key-passphrase

Sets the Client Keystore passphrase when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.configurations

Define additional configuration definitions.

 

Map

camel.cloud.kubernetes.service-discovery.dns-domain

Sets the DNS domain to use for DNS lookup.

 

String

camel.cloud.kubernetes.service-discovery.enabled

Enable the component.

true

Boolean

camel.cloud.kubernetes.service-discovery.lookup

How to perform service lookup. Possible values: client, dns, environment. When using client, then the client queries the kubernetes master to obtain a list of active pods that provides the service, and then random (or round robin) select a pod. When using dns the service name is resolved as name.namespace.svc.dnsDomain. When using dnssrv the service name is resolved with SRV query for .…​svc…​ When using environment then environment variables are used to lookup the service. By default environment is used.

environment

String

camel.cloud.kubernetes.service-discovery.master-url

Sets the URL to the master when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.namespace

Sets the namespace to use. Will by default use namespace from the ENV variable KUBERNETES_MASTER.

 

String

camel.cloud.kubernetes.service-discovery.oauth-token

Sets the OAUTH token for authentication (instead of username/password) when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.password

Sets the password for authentication when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.port-name

Sets the Port Name to use for DNS/DNSSRV lookup.

 

String

camel.cloud.kubernetes.service-discovery.port-protocol

Sets the Port Protocol to use for DNS/DNSSRV lookup.

 

String

camel.cloud.kubernetes.service-discovery.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.kubernetes.service-discovery.trust-certs

Sets whether to turn on trust certificate check when using client lookup.

false

Boolean

camel.cloud.kubernetes.service-discovery.username

Sets the username for authentication when using client lookup.

 

String

camel.cloud.ribbon.load-balancer.client-name

Sets the Ribbon client name.

 

String

camel.cloud.ribbon.load-balancer.configurations

Define additional configuration definitions.

 

Map

camel.cloud.ribbon.load-balancer.enabled

Enable the component.

true

Boolean

camel.cloud.ribbon.load-balancer.namespace

The namespace.

 

String

camel.cloud.ribbon.load-balancer.password

The password.

 

String

camel.cloud.ribbon.load-balancer.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.ribbon.load-balancer.username

The username.

 

String

camel.hystrix.allow-maximum-size-to-diverge-from-core-size

Allows the configuration for maximumSize to take effect. That value can then be equal to, or higher, than coreSize.

false

Boolean

camel.hystrix.circuit-breaker-enabled

Whether to use a HystrixCircuitBreaker or not. If false no circuit-breaker logic will be used and all requests permitted. This is similar in effect to circuitBreakerForceClosed() except that continues tracking metrics and knowing whether it should be open/closed, this property results in not even instantiating a circuit-breaker.

true

Boolean

camel.hystrix.circuit-breaker-error-threshold-percentage

Error percentage threshold (as whole number such as 50) at which point the circuit breaker will trip open and reject requests. It will stay tripped for the duration defined in circuitBreakerSleepWindowInMilliseconds; The error percentage this is compared against comes from HystrixCommandMetrics.getHealthCounts().

50

Integer

camel.hystrix.circuit-breaker-force-closed

If true the HystrixCircuitBreaker#allowRequest() will always return true to allow requests regardless of the error percentage from HystrixCommandMetrics.getHealthCounts(). The circuitBreakerForceOpen() property takes precedence so if it set to true this property does nothing.

false

Boolean

camel.hystrix.circuit-breaker-force-open

If true the HystrixCircuitBreaker.allowRequest() will always return false, causing the circuit to be open (tripped) and reject all requests. This property takes precedence over circuitBreakerForceClosed();.

false

Boolean

camel.hystrix.circuit-breaker-request-volume-threshold

Minimum number of requests in the metricsRollingStatisticalWindowInMilliseconds() that must exist before the HystrixCircuitBreaker will trip. If below this number the circuit will not trip regardless of error percentage.

20

Integer

camel.hystrix.circuit-breaker-sleep-window-in-milliseconds

The time in milliseconds after a HystrixCircuitBreaker trips open that it should wait before trying requests again.

5000

Integer

camel.hystrix.configurations

Define additional configuration definitions.

 

Map

camel.hystrix.core-pool-size

Core thread-pool size that gets passed to java.util.concurrent.ThreadPoolExecutor#setCorePoolSize(int).

10

Integer

camel.hystrix.enabled

Enable the component.

true

Boolean

camel.hystrix.execution-isolation-semaphore-max-concurrent-requests

Number of concurrent requests permitted to HystrixCommand.run(). Requests beyond the concurrent limit will be rejected. Applicable only when executionIsolationStrategy == SEMAPHORE.

20

Integer

camel.hystrix.execution-isolation-strategy

What isolation strategy HystrixCommand.run() will be executed with. If THREAD then it will be executed on a separate thread and concurrent requests limited by the number of threads in the thread-pool. If SEMAPHORE then it will be executed on the calling thread and concurrent requests limited by the semaphore count.

THREAD

String

camel.hystrix.execution-isolation-thread-interrupt-on-timeout

Whether the execution thread should attempt an interrupt (using Future#cancel ) when a thread times out. Applicable only when executionIsolationStrategy() == THREAD.

true

Boolean

camel.hystrix.execution-timeout-enabled

Whether the timeout mechanism is enabled for this command.

true

Boolean

camel.hystrix.execution-timeout-in-milliseconds

Time in milliseconds at which point the command will timeout and halt execution. If executionIsolationThreadInterruptOnTimeout == true and the command is thread-isolated, the executing thread will be interrupted. If the command is semaphore-isolated and a HystrixObservableCommand, that command will get unsubscribed.

1000

Integer

camel.hystrix.fallback-enabled

Whether HystrixCommand.getFallback() should be attempted when failure occurs.

true

Boolean

camel.hystrix.fallback-isolation-semaphore-max-concurrent-requests

Number of concurrent requests permitted to HystrixCommand.getFallback(). Requests beyond the concurrent limit will fail-fast and not attempt retrieving a fallback.

10

Integer

camel.hystrix.group-key

Sets the group key to use. The default value is CamelHystrix.

CamelHystrix

String

camel.hystrix.keep-alive-time

Keep-alive time in minutes that gets passed to ThreadPoolExecutor#setKeepAliveTime(long,TimeUnit).

1

Integer

camel.hystrix.max-queue-size

Max queue size that gets passed to BlockingQueue in HystrixConcurrencyStrategy.getBlockingQueue(int) This should only affect the instantiation of a threadpool - it is not eliglible to change a queue size on the fly. For that, use queueSizeRejectionThreshold().

-1

Integer

camel.hystrix.maximum-size

Maximum thread-pool size that gets passed to ThreadPoolExecutor#setMaximumPoolSize(int) . This is the maximum amount of concurrency that can be supported without starting to reject HystrixCommands. Please note that this setting only takes effect if you also set allowMaximumSizeToDivergeFromCoreSize.

10

Integer

camel.hystrix.metrics-health-snapshot-interval-in-milliseconds

Time in milliseconds to wait between allowing health snapshots to be taken that calculate success and error percentages and affect HystrixCircuitBreaker.isOpen() status. On high-volume circuits the continual calculation of error percentage can become CPU intensive thus this controls how often it is calculated.

500

Integer

camel.hystrix.metrics-rolling-percentile-bucket-size

Maximum number of values stored in each bucket of the rolling percentile. This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.

10

Integer

camel.hystrix.metrics-rolling-percentile-enabled

Whether percentile metrics should be captured using HystrixRollingPercentile inside HystrixCommandMetrics.

true

Boolean

camel.hystrix.metrics-rolling-percentile-window-buckets

Number of buckets the rolling percentile window is broken into. This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.

6

Integer

camel.hystrix.metrics-rolling-percentile-window-in-milliseconds

Duration of percentile rolling window in milliseconds. This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.

10000

Integer

camel.hystrix.metrics-rolling-statistical-window-buckets

Number of buckets the rolling statistical window is broken into. This is passed into HystrixRollingNumber inside HystrixCommandMetrics.

10

Integer

camel.hystrix.metrics-rolling-statistical-window-in-milliseconds

This property sets the duration of the statistical rolling window, in milliseconds. This is how long metrics are kept for the thread pool. The window is divided into buckets and rolls by those increments.

10000

Integer

camel.hystrix.queue-size-rejection-threshold

Queue size rejection threshold is an artificial max size at which rejections will occur even if maxQueueSize has not been reached. This is done because the maxQueueSize of a BlockingQueue can not be dynamically changed and we want to support dynamically changing the queue size that affects rejections. This is used by HystrixCommand when queuing a thread for execution.

5

Integer

camel.hystrix.request-log-enabled

Whether HystrixCommand execution and events should be logged to HystrixRequestLog.

true

Boolean

camel.hystrix.thread-pool-key

Sets the thread pool key to use. Will by default use the same value as groupKey has been configured to use.

CamelHystrix

String

camel.hystrix.thread-pool-rolling-number-statistical-window-buckets

Number of buckets the rolling statistical window is broken into. This is passed into HystrixRollingNumber inside each HystrixThreadPoolMetrics instance.

10

Integer

camel.hystrix.thread-pool-rolling-number-statistical-window-in-milliseconds

Duration of statistical rolling window in milliseconds. This is passed into HystrixRollingNumber inside each HystrixThreadPoolMetrics instance.

10000

Integer

camel.language.constant.enabled

Whether to enable auto configuration of the constant language. This is enabled by default.

 

Boolean

camel.language.constant.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.csimple.enabled

Whether to enable auto configuration of the csimple language. This is enabled by default.

 

Boolean

camel.language.csimple.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.exchangeproperty.enabled

Whether to enable auto configuration of the exchangeProperty language. This is enabled by default.

 

Boolean

camel.language.exchangeproperty.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.file.enabled

Whether to enable auto configuration of the file language. This is enabled by default.

 

Boolean

camel.language.file.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.header.enabled

Whether to enable auto configuration of the header language. This is enabled by default.

 

Boolean

camel.language.header.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.ref.enabled

Whether to enable auto configuration of the ref language. This is enabled by default.

 

Boolean

camel.language.ref.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.simple.enabled

Whether to enable auto configuration of the simple language. This is enabled by default.

 

Boolean

camel.language.simple.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.tokenize.enabled

Whether to enable auto configuration of the tokenize language. This is enabled by default.

 

Boolean

camel.language.tokenize.group-delimiter

Sets the delimiter to use when grouping. If this has not been set then token will be used as the delimiter.

 

String

camel.language.tokenize.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.resilience4j.automatic-transition-from-open-to-half-open-enabled

Enables automatic transition from OPEN to HALF_OPEN state once the waitDurationInOpenState has passed.

false

Boolean

camel.resilience4j.circuit-breaker-ref

Refers to an existing io.github.resilience4j.circuitbreaker.CircuitBreaker instance to lookup and use from the registry. When using this, then any other circuit breaker options are not in use.

 

String

camel.resilience4j.config-ref

Refers to an existing io.github.resilience4j.circuitbreaker.CircuitBreakerConfig instance to lookup and use from the registry.

 

String

camel.resilience4j.configurations

Define additional configuration definitions.

 

Map

camel.resilience4j.enabled

Enable the component.

true

Boolean

camel.resilience4j.failure-rate-threshold

Configures the failure rate threshold in percentage. If the failure rate is equal or greater than the threshold the CircuitBreaker transitions to open and starts short-circuiting calls. The threshold must be greater than 0 and not greater than 100. Default value is 50 percentage.

 

Float

camel.resilience4j.minimum-number-of-calls

Configures the minimum number of calls which are required (per sliding window period) before the CircuitBreaker can calculate the error rate. For example, if minimumNumberOfCalls is 10, then at least 10 calls must be recorded, before the failure rate can be calculated. If only 9 calls have been recorded the CircuitBreaker will not transition to open even if all 9 calls have failed. Default minimumNumberOfCalls is 100.

100

Integer

camel.resilience4j.permitted-number-of-calls-in-half-open-state

Configures the number of permitted calls when the CircuitBreaker is half open. The size must be greater than 0. Default size is 10.

10

Integer

camel.resilience4j.sliding-window-size

Configures the size of the sliding window which is used to record the outcome of calls when the CircuitBreaker is closed. slidingWindowSize configures the size of the sliding window. Sliding window can either be count-based or time-based. If slidingWindowType is COUNT_BASED, the last slidingWindowSize calls are recorded and aggregated. If slidingWindowType is TIME_BASED, the calls of the last slidingWindowSize seconds are recorded and aggregated. The slidingWindowSize must be greater than 0. The minimumNumberOfCalls must be greater than 0. If the slidingWindowType is COUNT_BASED, the minimumNumberOfCalls cannot be greater than slidingWindowSize . If the slidingWindowType is TIME_BASED, you can pick whatever you want. Default slidingWindowSize is 100.

100

Integer

camel.resilience4j.sliding-window-type

Configures the type of the sliding window which is used to record the outcome of calls when the CircuitBreaker is closed. Sliding window can either be count-based or time-based. If slidingWindowType is COUNT_BASED, the last slidingWindowSize calls are recorded and aggregated. If slidingWindowType is TIME_BASED, the calls of the last slidingWindowSize seconds are recorded and aggregated. Default slidingWindowType is COUNT_BASED.

COUNT_BASED

String

camel.resilience4j.slow-call-duration-threshold

Configures the duration threshold (seconds) above which calls are considered as slow and increase the slow calls percentage. Default value is 60 seconds.

60

Integer

camel.resilience4j.slow-call-rate-threshold

Configures a threshold in percentage. The CircuitBreaker considers a call as slow when the call duration is greater than slowCallDurationThreshold Duration. When the percentage of slow calls is equal or greater the threshold, the CircuitBreaker transitions to open and starts short-circuiting calls. The threshold must be greater than 0 and not greater than 100. Default value is 100 percentage which means that all recorded calls must be slower than slowCallDurationThreshold.

 

Float

camel.resilience4j.wait-duration-in-open-state

Configures the wait duration (in seconds) which specifies how long the CircuitBreaker should stay open, before it switches to half open. Default value is 60 seconds.

60

Integer

camel.resilience4j.writable-stack-trace-enabled

Enables writable stack traces. When set to false, Exception.getStackTrace returns a zero length array. This may be used to reduce log spam when the circuit breaker is open as the cause of the exceptions is already known (the circuit breaker is short-circuiting calls).

true

Boolean

camel.rest.api-component

The name of the Camel component to use as the REST API (such as swagger) If no API Component has been explicit configured, then Camel will lookup if there is a Camel component responsible for servicing and generating the REST API documentation, or if a org.apache.camel.spi.RestApiProcessorFactory is registered in the registry. If either one is found, then that is being used.

 

String

camel.rest.api-context-path

Sets a leading API context-path the REST API services will be using. This can be used when using components such as camel-servlet where the deployed web application is deployed using a context-path.

 

String

camel.rest.api-context-route-id

Sets the route id to use for the route that services the REST API. The route will by default use an auto assigned route id.

 

String

camel.rest.api-host

To use an specific hostname for the API documentation (eg swagger) This can be used to override the generated host with this configured hostname.

 

String

camel.rest.api-property

Allows to configure as many additional properties for the api documentation (swagger). For example set property api.title to my cool stuff.

 

Map

camel.rest.api-vendor-extension

Whether vendor extension is enabled in the Rest APIs. If enabled then Camel will include additional information as vendor extension (eg keys starting with x-) such as route ids, class names etc. Not all 3rd party API gateways and tools supports vendor-extensions when importing your API docs.

false

Boolean

camel.rest.binding-mode

Sets the binding mode to use. The default value is off.

 

RestBindingMode

camel.rest.client-request-validation

Whether to enable validation of the client request to check whether the Content-Type and Accept headers from the client is supported by the Rest-DSL configuration of its consumes/produces settings. This can be turned on, to enable this check. In case of validation error, then HTTP Status codes 415 or 406 is returned. The default value is false.

false

Boolean

camel.rest.component

The Camel Rest component to use for the REST transport (consumer), such as netty-http, jetty, servlet, undertow. If no component has been explicit configured, then Camel will lookup if there is a Camel component that integrates with the Rest DSL, or if a org.apache.camel.spi.RestConsumerFactory is registered in the registry. If either one is found, then that is being used.

 

String

camel.rest.component-property

Allows to configure as many additional properties for the rest component in use.

 

Map

camel.rest.consumer-property

Allows to configure as many additional properties for the rest consumer in use.

 

Map

camel.rest.context-path

Sets a leading context-path the REST services will be using. This can be used when using components such as camel-servlet where the deployed web application is deployed using a context-path. Or for components such as camel-jetty or camel-netty-http that includes a HTTP server.

 

String

camel.rest.cors-headers

Allows to configure custom CORS headers.

 

Map

camel.rest.data-format-property

Allows to configure as many additional properties for the data formats in use. For example set property prettyPrint to true to have json outputted in pretty mode. The properties can be prefixed to denote the option is only for either JSON or XML and for either the IN or the OUT. The prefixes are: json.in. json.out. xml.in. xml.out. For example a key with value xml.out.mustBeJAXBElement is only for the XML data format for the outgoing. A key without a prefix is a common key for all situations.

 

Map

camel.rest.enable-cors

Whether to enable CORS headers in the HTTP response. The default value is false.

false

Boolean

camel.rest.endpoint-property

Allows to configure as many additional properties for the rest endpoint in use.

 

Map

camel.rest.host

The hostname to use for exposing the REST service.

 

String

camel.rest.host-name-resolver

If no hostname has been explicit configured, then this resolver is used to compute the hostname the REST service will be using.

 

RestHostNameResolver

camel.rest.json-data-format

Name of specific json data format to use. By default json-jackson will be used. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance.

 

String

camel.rest.port

The port number to use for exposing the REST service. Notice if you use servlet component then the port number configured here does not apply, as the port number in use is the actual port number the servlet component is using. eg if using Apache Tomcat its the tomcat http port, if using Apache Karaf its the HTTP service in Karaf that uses port 8181 by default etc. Though in those situations setting the port number here, allows tooling and JMX to know the port number, so its recommended to set the port number to the number that the servlet engine uses.

 

String

camel.rest.producer-api-doc

Sets the location of the api document (swagger api) the REST producer will use to validate the REST uri and query parameters are valid accordingly to the api document. This requires adding camel-swagger-java to the classpath, and any miss configuration will let Camel fail on startup and report the error(s). The location of the api document is loaded from classpath by default, but you can use file: or http: to refer to resources to load from file or http url.

 

String

camel.rest.producer-component

Sets the name of the Camel component to use as the REST producer.

 

String

camel.rest.scheme

The scheme to use for exposing the REST service. Usually http or https is supported. The default value is http.

 

String

camel.rest.skip-binding-on-error-code

Whether to skip binding on output if there is a custom HTTP error code header. This allows to build custom error messages that do not bind to json / xml etc, as success messages otherwise will do.

false

Boolean

camel.rest.use-x-forward-headers

Whether to use X-Forward headers for Host and related setting. The default value is true.

true

Boolean

camel.rest.xml-data-format

Name of specific XML data format to use. By default jaxb will be used. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance.

 

String

camel.rest.api-context-id-pattern

Deprecated Sets an CamelContext id pattern to only allow Rest APIs from rest services within CamelContext’s which name matches the pattern. The pattern name refers to the CamelContext name, to match on the current CamelContext only. For any other value, the pattern uses the rules from PatternHelper#matchPattern(String,String).

 

String

camel.rest.api-context-listing

Deprecated Sets whether listing of all available CamelContext’s with REST services in the JVM is enabled. If enabled it allows to discover these contexts, if false then only the current CamelContext is in use.

false

Boolean

Chapter 33. FHIR

Both producer and consumer are supported

The FHIR component integrates with the HAPI-FHIR library which is an open-source implementation of the FHIR (Fast Healthcare Interoperability Resources) specification in Java.

33.1. Dependencies

When using fhir with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-fhir-starter</artifactId>
</dependency>

33.2. URI Format

The FHIR Component uses the following URI format:

fhir://endpoint-prefix/endpoint?[options]

Endpoint prefix can be one of:

  • capabilities
  • create
  • delete
  • history
  • load-page
  • meta
  • operation
  • patch
  • read
  • search
  • transaction
  • update
  • validate

33.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

33.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

33.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

33.4. Component Options

The FHIR component supports 27 options, which are listed below.

NameDescriptionDefaultType

encoding (common)

Encoding to use for all request.

Enum values:

  • JSON
  • XML
 

String

fhirVersion (common)

The FHIR Version to use.

Enum values:

  • DSTU2
  • DSTU2_HL7ORG
  • DSTU2_1
  • DSTU3
  • R4
  • R5

R4

String

log (common)

Will log every requests and responses.

false

boolean

prettyPrint (common)

Pretty print all request.

false

boolean

serverUrl (common)

The FHIR server base URL.

 

String

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

client (advanced)

To use the custom client.

 

IGenericClient

clientFactory (advanced)

To use the custom client factory.

 

IRestfulClientFactory

compress (advanced)

Compresses outgoing (POST/PUT) contents to the GZIP format.

false

boolean

configuration (advanced)

To use the shared configuration.

 

FhirConfiguration

connectionTimeout (advanced)

How long to try and establish the initial TCP connection (in ms).

10000

Integer

deferModelScanning (advanced)

When this option is set, model classes will not be scanned for children until the child list for the given type is actually accessed.

false

boolean

fhirContext (advanced)

FhirContext is an expensive object to create. To avoid creating multiple instances, it can be set directly.

 

FhirContext

forceConformanceCheck (advanced)

Force conformance check.

false

boolean

sessionCookie (advanced)

HTTP session cookie to add to every request.

 

String

socketTimeout (advanced)

How long to block for individual read/write operations (in ms).

10000

Integer

summary (advanced)

Request that the server modify the response using the _summary param.

Enum values:

  • COUNT
  • TEXT
  • DATA
  • TRUE
  • FALSE
 

String

validationMode (advanced)

When should Camel validate the FHIR Server’s conformance statement.

Enum values:

  • NEVER
  • ONCE

ONCE

String

proxyHost (proxy)

The proxy host.

 

String

proxyPassword (proxy)

The proxy password.

 

String

proxyPort (proxy)

The proxy port.

 

Integer

proxyUser (proxy)

The proxy username.

 

String

accessToken (security)

OAuth access token.

 

String

password (security)

Username to use for basic authentication.

 

String

username (security)

Username to use for basic authentication.

 

String

33.5. Endpoint Options

The FHIR endpoint is configured using URI syntax:

fhir:apiName/methodName

with the following path and query parameters:

33.5.1. Path Parameters (2 parameters)

NameDescriptionDefaultType

apiName (common)

Required What kind of operation to perform.

Enum values:

  • CAPABILITIES
  • CREATE
  • DELETE
  • HISTORY
  • LOAD_PAGE
  • META
  • OPERATION
  • PATCH
  • READ
  • SEARCH
  • TRANSACTION
  • UPDATE
  • VALIDATE
 

FhirApiName

methodName (common)

Required What sub operation to use for the selected operation.

 

String

33.5.2. Query Parameters (44 parameters)

NameDescriptionDefaultType

encoding (common)

Encoding to use for all request.

Enum values:

  • JSON
  • XML
 

String

fhirVersion (common)

The FHIR Version to use.

Enum values:

  • DSTU2
  • DSTU2_HL7ORG
  • DSTU2_1
  • DSTU3
  • R4
  • R5

R4

String

inBody (common)

Sets the name of a parameter to be passed in the exchange In Body.

 

String

log (common)

Will log every requests and responses.

false

boolean

prettyPrint (common)

Pretty print all request.

false

boolean

serverUrl (common)

The FHIR server base URL.

 

String

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

sendEmptyMessageWhenIdle (consumer)

If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead.

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

pollStrategy (consumer (advanced))

A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel.

 

PollingConsumerPollStrategy

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

client (advanced)

To use the custom client.

 

IGenericClient

clientFactory (advanced)

To use the custom client factory.

 

IRestfulClientFactory

compress (advanced)

Compresses outgoing (POST/PUT) contents to the GZIP format.

false

boolean

connectionTimeout (advanced)

How long to try and establish the initial TCP connection (in ms).

10000

Integer

deferModelScanning (advanced)

When this option is set, model classes will not be scanned for children until the child list for the given type is actually accessed.

false

boolean

fhirContext (advanced)

FhirContext is an expensive object to create. To avoid creating multiple instances, it can be set directly.

 

FhirContext

forceConformanceCheck (advanced)

Force conformance check.

false

boolean

sessionCookie (advanced)

HTTP session cookie to add to every request.

 

String

socketTimeout (advanced)

How long to block for individual read/write operations (in ms).

10000

Integer

summary (advanced)

Request that the server modify the response using the _summary param.

Enum values:

  • COUNT
  • TEXT
  • DATA
  • TRUE
  • FALSE
 

String

validationMode (advanced)

When should Camel validate the FHIR Server’s conformance statement.

Enum values:

  • NEVER
  • ONCE

ONCE

String

proxyHost (proxy)

The proxy host.

 

String

proxyPassword (proxy)

The proxy password.

 

String

proxyPort (proxy)

The proxy port.

 

Integer

proxyUser (proxy)

The proxy username.

 

String

backoffErrorThreshold (scheduler)

The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in.

 

int

backoffIdleThreshold (scheduler)

The number of subsequent idle polls that should happen before the backoffMultipler should kick-in.

 

int

backoffMultiplier (scheduler)

To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured.

 

int

delay (scheduler)

Milliseconds before the next poll.

500

long

greedy (scheduler)

If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages.

false

boolean

initialDelay (scheduler)

Milliseconds before the first poll starts.

1000

long

repeatCount (scheduler)

Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever.

0

long

runLoggingLevel (scheduler)

The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that.

Enum values:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • OFF

TRACE

LoggingLevel

scheduledExecutorService (scheduler)

Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool.

 

ScheduledExecutorService

scheduler (scheduler)

To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler.

none

Object

schedulerProperties (scheduler)

To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler.

 

Map

startScheduler (scheduler)

Whether the scheduler should be auto started.

true

boolean

timeUnit (scheduler)

Time unit for initialDelay and delay options.

Enum values:

  • NANOSECONDS
  • MICROSECONDS
  • MILLISECONDS
  • SECONDS
  • MINUTES
  • HOURS
  • DAYS

MILLISECONDS

TimeUnit

useFixedDelay (scheduler)

Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details.

true

boolean

accessToken (security)

OAuth access token.

 

String

password (security)

Username to use for basic authentication.

 

String

username (security)

Username to use for basic authentication.

 

String

33.6. API Parameters (13 APIs)

The @FHIR endpoint is an API based component and has additional parameters based on which API name and API method is used. The API name and API method is located in the endpoint URI as the apiName/methodName path parameters:

fhir:apiName/methodName

There are 13 API names as listed in the table below:

API NameTypeDescription

capabilities

Both

API to Fetch the capability statement for the server

create

Both

API for the create operation, which creates a new resource instance on the server

delete

Both

API for the delete operation, which performs a logical delete on a server resource

history

Both

API for the history method

load-page

Both

API that Loads the previous/next bundle of resources from a paged set, using the link specified in the link type=next tag within the atom bundle

meta

Both

API for the meta operations, which can be used to get, add and remove tags and other Meta elements from a resource or across the server

operation

Both

API for extended FHIR operations

patch

Both

API for the patch operation, which performs a logical patch on a server resource

read

Both

API method for read operations

search

Both

API to search for resources matching a given set of criteria

transaction

Both

API for sending a transaction (collection of resources) to the server to be executed as a single unit

update

Both

API for the update operation, which performs a logical delete on a server resource

validate

Both

API for validating resources

Each API is documented in the following sections to come.

33.6.1. API: capabilities

Both producer and consumer are supported

The capabilities API is defined in the syntax as follows:

fhir:capabilities/methodName?[parameters]

The method is listed in the table below, followed by detailed syntax for each method. (API methods can have a shorthand alias name which can be used in the syntax instead of the name)

MethodDescription

ofType

Retrieve the conformance statement using the given model type

33.6.1.1. Method ofType

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseConformance ofType(Class<org.hl7.fhir.instance.model.api.IBaseConformance> type, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/ofType API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

type

The model type

Class

In addition to the parameters above, the fhir API can also use any of the Query Parameters.

Any of the parameters can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format CamelFhir.parameter. The inBody parameter overrides message header, i.e. the endpoint parameter inBody=myParameterNameHere would override a CamelFhir.myParameterNameHere header.

33.6.2. API: create

Both producer and consumer are supported

The create API is defined in the syntax as follows:

fhir:create/methodName?[parameters]

The 1 method(s) is listed in the table below, followed by detailed syntax for each method. (API methods can have a shorthand alias name which can be used in the syntax instead of the name)

MethodDescription

resource

Creates a IBaseResource on the server

33.6.2.1. Method resource

Signatures:

  • ca.uhn.fhir.rest.api.MethodOutcome resource(String resourceAsString, String url, ca.uhn.fhir.rest.api.PreferReturnEnum preferReturn, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);
  • ca.uhn.fhir.rest.api.MethodOutcome resource(org.hl7.fhir.instance.model.api.IBaseResource resource, String url, ca.uhn.fhir.rest.api.PreferReturnEnum preferReturn, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/resource API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

preferReturn

Add a Prefer header to the request, which requests that the server include or suppress the resource body as a part of the result. If a resource is returned by the server it will be parsed an accessible to the client via MethodOutcome#getResource() , may be null

PreferReturnEnum

resource

The resource to create

IBaseResource

resourceAsString

The resource to create

String

url

The search URL to use. The format of this URL should be of the form ResourceTypeParameters, for example: Patientname=Smith&identifier=13.2.4.11.4%7C847366, may be null

String

In addition to the parameters above, the fhir API can also use any of the Query Parameters.

Any of the parameters can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format CamelFhir.parameter. The inBody parameter overrides message header, i.e. the endpoint parameter inBody=myParameterNameHere would override a CamelFhir.myParameterNameHere header.

33.6.3. API: delete

Both producer and consumer are supported

The delete API is defined in the syntax as follows:

fhir:delete/methodName?[parameters]

The 3 method(s) is listed in the table below, followed by detailed syntax for each method. (API methods can have a shorthand alias name which can be used in the syntax instead of the name)

MethodDescription

resource

Deletes the given resource

resourceById

Deletes the resource by resource type e

resourceConditionalByUrl

Specifies that the delete should be performed as a conditional delete against a given search URL

33.6.3.1. Method resource

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseOperationOutcome resource(org.hl7.fhir.instance.model.api.IBaseResource resource, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/resource API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

resource

The IBaseResource to delete

IBaseResource

33.6.3.2. Method resourceById

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseOperationOutcome resourceById(String type, String stringId, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);
  • org.hl7.fhir.instance.model.api.IBaseOperationOutcome resourceById(org.hl7.fhir.instance.model.api.IIdType id, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/resourceById API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

id

The IIdType referencing the resource

IIdType

stringId

It’s id

String

type

The resource type e.g Patient

String

33.6.3.3. Method resourceConditionalByUrl

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseOperationOutcome resourceConditionalByUrl(String url, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/resourceConditionalByUrl API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

url

The search URL to use. The format of this URL should be of the form ResourceTypeParameters, for example: Patientname=Smith&identifier=13.2.4.11.4%7C847366

String

In addition to the parameters above, the fhir API can also use any of the Query Parameters.

Any of the parameters can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format CamelFhir.parameter. The inBody parameter overrides message header, i.e. the endpoint parameter inBody=myParameterNameHere would override a CamelFhir.myParameterNameHere header.

33.6.4. API: history

Both producer and consumer are supported

The history API is defined in the syntax as follows:

fhir:history/methodName?[parameters]

The 3 method(s) is listed in the table below, followed by detailed syntax for each method. (API methods can have a shorthand alias name which can be used in the syntax instead of the name)

MethodDescription

onInstance

Perform the operation across all versions of a specific resource (by ID and type) on the server

onServer

Perform the operation across all versions of all resources of all types on the server

onType

Perform the operation across all versions of all resources of the given type on the server

33.6.4.1. Method onInstance

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseBundle onInstance(org.hl7.fhir.instance.model.api.IIdType id, Class<org.hl7.fhir.instance.model.api.IBaseBundle> returnType, Integer count, java.util.Date cutoff, org.hl7.fhir.instance.model.api.IPrimitiveType<java.util.Date> iCutoff, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/onInstance API method has the parameters listed in the table below:

ParameterDescriptionType

count

Request that the server return only up to theCount number of resources, may be NULL

Integer

cutoff

Request that the server return only resource versions that were created at or after the given time (inclusive), may be NULL

Date

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

iCutoff

Request that the server return only resource versions that were created at or after the given time (inclusive), may be NULL

IPrimitiveType

id

The IIdType which must be populated with both a resource type and a resource ID at

IIdType

returnType

Request that the method return a Bundle resource (such as ca.uhn.fhir.model.dstu2.resource.Bundle). Use this method if you are accessing a DSTU2 server.

Class

33.6.4.2. Method onServer

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseBundle onServer(Class<org.hl7.fhir.instance.model.api.IBaseBundle> returnType, Integer count, java.util.Date cutoff, org.hl7.fhir.instance.model.api.IPrimitiveType<java.util.Date> iCutoff, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/onServer API method has the parameters listed in the table below:

ParameterDescriptionType

count

Request that the server return only up to theCount number of resources, may be NULL

Integer

cutoff

Request that the server return only resource versions that were created at or after the given time (inclusive), may be NULL

Date

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

iCutoff

Request that the server return only resource versions that were created at or after the given time (inclusive), may be NULL

IPrimitiveType

returnType

Request that the method return a Bundle resource (such as ca.uhn.fhir.model.dstu2.resource.Bundle). Use this method if you are accessing a DSTU2 server.

Class

33.6.4.3. Method onType

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseBundle onType(Class<org.hl7.fhir.instance.model.api.IBaseResource> resourceType, Class<org.hl7.fhir.instance.model.api.IBaseBundle> returnType, Integer count, java.util.Date cutoff, org.hl7.fhir.instance.model.api.IPrimitiveType<java.util.Date> iCutoff, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/onType API method has the parameters listed in the table below:

ParameterDescriptionType

count

Request that the server return only up to theCount number of resources, may be NULL

Integer

cutoff

Request that the server return only resource versions that were created at or after the given time (inclusive), may be NULL

Date

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

iCutoff

Request that the server return only resource versions that were created at or after the given time (inclusive), may be NULL

IPrimitiveType

resourceType

The resource type to search for

Class

returnType

Request that the method return a Bundle resource (such as ca.uhn.fhir.model.dstu2.resource.Bundle). Use this method if you are accessing a DSTU2 server.

Class

In addition to the parameters above, the fhir API can also use any of the Query Parameters.

Any of the parameters can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format CamelFhir.parameter. The inBody parameter overrides message header, i.e. the endpoint parameter inBody=myParameterNameHere would override a CamelFhir.myParameterNameHere header.

33.6.5. API: load-page

Both producer and consumer are supported

The load-page API is defined in the syntax as follows:

fhir:load-page/methodName?[parameters]

The 3 method(s) is listed in the table below, followed by detailed syntax for each method. (API methods can have a shorthand alias name which can be used in the syntax instead of the name)

MethodDescription

byUrl

Load a page of results using the given URL and bundle type and return a DSTU1 Atom bundle

next

Load the next page of results using the link with relation next in the bundle

previous

Load the previous page of results using the link with relation prev in the bundle

33.6.5.1. Method byUrl

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseBundle byUrl(String url, Class<org.hl7.fhir.instance.model.api.IBaseBundle> returnType, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/byUrl API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

returnType

The return type

Class

url

The search url

String

33.6.5.2. Method next

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseBundle next(org.hl7.fhir.instance.model.api.IBaseBundle bundle, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/next API method has the parameters listed in the table below:

ParameterDescriptionType

bundle

The IBaseBundle

IBaseBundle

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

33.6.5.3. Method previous

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseBundle previous(org.hl7.fhir.instance.model.api.IBaseBundle bundle, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/previous API method has the parameters listed in the table below:

ParameterDescriptionType

bundle

The IBaseBundle

IBaseBundle

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

In addition to the parameters above, the fhir API can also use any of the Query Parameters.

Any of the parameters can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format CamelFhir.parameter. The inBody parameter overrides message header, i.e. the endpoint parameter inBody=myParameterNameHere would override a CamelFhir.myParameterNameHere header.

33.6.6. API: meta

Both producer and consumer are supported

The meta API is defined in the syntax as follows:

fhir:meta/methodName?[parameters]

The 5 method(s) is listed in the table below, followed by detailed syntax for each method. (API methods can have a shorthand alias name which can be used in the syntax instead of the name)

MethodDescription

add

Add the elements in the given metadata to the already existing set (do not remove any)

delete

Delete the elements in the given metadata from the given id

getFromResource

Fetch the current metadata from a specific resource

getFromServer

Fetch the current metadata from the whole Server

getFromType

Fetch the current metadata from a specific type

33.6.6.1. Method add

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseMetaType add(org.hl7.fhir.instance.model.api.IBaseMetaType meta, org.hl7.fhir.instance.model.api.IIdType id, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/add API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

id

The id

IIdType

meta

The IBaseMetaType class

IBaseMetaType

33.6.6.2. Method delete

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseMetaType delete(org.hl7.fhir.instance.model.api.IBaseMetaType meta, org.hl7.fhir.instance.model.api.IIdType id, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/delete API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

id

The id

IIdType

meta

The IBaseMetaType class

IBaseMetaType

33.6.6.3. Method getFromResource

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseMetaType getFromResource(Class<org.hl7.fhir.instance.model.api.IBaseMetaType> metaType, org.hl7.fhir.instance.model.api.IIdType id, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/getFromResource API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

id

The id

IIdType

metaType

The IBaseMetaType class

Class

33.6.6.4. Method getFromServer

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseMetaType getFromServer(Class<org.hl7.fhir.instance.model.api.IBaseMetaType> metaType, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/getFromServer API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

metaType

The type of the meta datatype for the given FHIR model version (should be MetaDt.class or MetaType.class)

Class

33.6.6.5. Method getFromType

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseMetaType getFromType(Class<org.hl7.fhir.instance.model.api.IBaseMetaType> metaType, String resourceType, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/getFromType API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

metaType

The IBaseMetaType class

Class

resourceType

The resource type e.g Patient

String

In addition to the parameters above, the fhir API can also use any of the Query Parameters.

Any of the parameters can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format CamelFhir.parameter. The inBody parameter overrides message header, i.e. the endpoint parameter inBody=myParameterNameHere would override a CamelFhir.myParameterNameHere header.

33.6.7. API: operation

Both producer and consumer are supported

The operation API is defined in the syntax as follows:

fhir:operation/methodName?[parameters]

The 5 method(s) is listed in the table below, followed by detailed syntax for each method. (API methods can have a shorthand alias name which can be used in the syntax instead of the name)

MethodDescription

onInstance

Perform the operation across all versions of a specific resource (by ID and type) on the server

onInstanceVersion

This operation operates on a specific version of a resource

onServer

Perform the operation across all versions of all resources of all types on the server

onType

Perform the operation across all versions of all resources of the given type on the server

processMessage

This operation is called $process-message as defined by the FHIR specification

33.6.7.1. Method onInstance

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseResource onInstance(org.hl7.fhir.instance.model.api.IIdType id, String name, org.hl7.fhir.instance.model.api.IBaseParameters parameters, Class<org.hl7.fhir.instance.model.api.IBaseParameters> outputParameterType, boolean useHttpGet, Class<org.hl7.fhir.instance.model.api.IBaseResource> returnType, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/onInstance API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

id

Resource (version will be stripped)

IIdType

name

Operation name

String

outputParameterType

The type to use for the output parameters (this should be set to Parameters.class drawn from the version of the FHIR structures you are using), may be NULL

Class

parameters

The parameters to use as input. May also be null if the operation does not require any input parameters.

IBaseParameters

returnType

If this operation returns a single resource body as its return type instead of a Parameters resource, use this method to specify that resource type. This is useful for certain operations (e.g. Patient/NNN/$everything) which return a bundle instead of a Parameters resource, may be NULL

Class

useHttpGet

Use HTTP GET verb

Boolean

33.6.7.2. Method onInstanceVersion

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseResource onInstanceVersion(org.hl7.fhir.instance.model.api.IIdType id, String name, org.hl7.fhir.instance.model.api.IBaseParameters parameters, Class<org.hl7.fhir.instance.model.api.IBaseParameters> outputParameterType, boolean useHttpGet, Class<org.hl7.fhir.instance.model.api.IBaseResource> returnType, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/onInstanceVersion API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

id

Resource version

IIdType

name

Operation name

String

outputParameterType

The type to use for the output parameters (this should be set to Parameters.class drawn from the version of the FHIR structures you are using), may be NULL

Class

parameters

The parameters to use as input. May also be null if the operation does not require any input parameters.

IBaseParameters

returnType

If this operation returns a single resource body as its return type instead of a Parameters resource, use this method to specify that resource type. This is useful for certain operations (e.g. Patient/NNN/$everything) which return a bundle instead of a Parameters resource, may be NULL

Class

useHttpGet

Use HTTP GET verb

Boolean

33.6.7.3. Method onServer

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseResource onServer(String name, org.hl7.fhir.instance.model.api.IBaseParameters parameters, Class<org.hl7.fhir.instance.model.api.IBaseParameters> outputParameterType, boolean useHttpGet, Class<org.hl7.fhir.instance.model.api.IBaseResource> returnType, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/onServer API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

name

Operation name

String

outputParameterType

The type to use for the output parameters (this should be set to Parameters.class drawn from the version of the FHIR structures you are using), may be NULL

Class

parameters

The parameters to use as input. May also be null if the operation does not require any input parameters.

IBaseParameters

returnType

If this operation returns a single resource body as its return type instead of a Parameters resource, use this method to specify that resource type. This is useful for certain operations (e.g. Patient/NNN/$everything) which return a bundle instead of a Parameters resource, may be NULL

Class

useHttpGet

Use HTTP GET verb

Boolean

33.6.7.4. Method onType

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseResource onType(Class<org.hl7.fhir.instance.model.api.IBaseResource> resourceType, String name, org.hl7.fhir.instance.model.api.IBaseParameters parameters, Class<org.hl7.fhir.instance.model.api.IBaseParameters> outputParameterType, boolean useHttpGet, Class<org.hl7.fhir.instance.model.api.IBaseResource> returnType, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/onType API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

name

Operation name

String

outputParameterType

The type to use for the output parameters (this should be set to Parameters.class drawn from the version of the FHIR structures you are using), may be NULL

Class

parameters

The parameters to use as input. May also be null if the operation does not require any input parameters.

IBaseParameters

resourceType

The resource type to operate on

Class

returnType

If this operation returns a single resource body as its return type instead of a Parameters resource, use this method to specify that resource type. This is useful for certain operations (e.g. Patient/NNN/$everything) which return a bundle instead of a Parameters resource, may be NULL

Class

useHttpGet

Use HTTP GET verb

Boolean

33.6.7.5. Method processMessage

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseBundle processMessage(String respondToUri, org.hl7.fhir.instance.model.api.IBaseBundle msgBundle, boolean asynchronous, Class<org.hl7.fhir.instance.model.api.IBaseBundle> responseClass, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/processMessage API method has the parameters listed in the table below:

ParameterDescriptionType

asynchronous

Whether to process the message asynchronously or synchronously, defaults to synchronous.

Boolean

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

msgBundle

Set the Message Bundle to POST to the messaging server

IBaseBundle

respondToUri

An optional query parameter indicating that responses from the receiving server should be sent to this URI, may be NULL

String

responseClass

The response class

Class

In addition to the parameters above, the fhir API can also use any of the Query Parameters.

Any of the parameters can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format CamelFhir.parameter. The inBody parameter overrides message header, i.e. the endpoint parameter inBody=myParameterNameHere would override a CamelFhir.myParameterNameHere header.

33.6.8. API: patch

Both producer and consumer are supported

The patch API is defined in the syntax as follows:

fhir:patch/methodName?[parameters]

The 2 method(s) is listed in the table below, followed by detailed syntax for each method. (API methods can have a shorthand alias name which can be used in the syntax instead of the name)

MethodDescription

patchById

Applies the patch to the given resource ID

patchByUrl

Specifies that the update should be performed as a conditional create against a given search URL

33.6.8.1. Method patchById

Signatures:

  • ca.uhn.fhir.rest.api.MethodOutcome patchById(String patchBody, String stringId, ca.uhn.fhir.rest.api.PreferReturnEnum preferReturn, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);
  • ca.uhn.fhir.rest.api.MethodOutcome patchById(String patchBody, org.hl7.fhir.instance.model.api.IIdType id, ca.uhn.fhir.rest.api.PreferReturnEnum preferReturn, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/patchById API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

id

The resource ID to patch

IIdType

patchBody

The body of the patch document serialized in either XML or JSON which conforms to

String

preferReturn

Add a Prefer header to the request, which requests that the server include or suppress the resource body as a part of the result. If a resource is returned by the server it will be parsed an accessible to the client via MethodOutcome#getResource()

PreferReturnEnum

stringId

The resource ID to patch

String

33.6.8.2. Method patchByUrl

Signatures:

  • ca.uhn.fhir.rest.api.MethodOutcome patchByUrl(String patchBody, String url, ca.uhn.fhir.rest.api.PreferReturnEnum preferReturn, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/patchByUrl API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

patchBody

The body of the patch document serialized in either XML or JSON which conforms to

String

preferReturn

Add a Prefer header to the request, which requests that the server include or suppress the resource body as a part of the result. If a resource is returned by the server it will be parsed an accessible to the client via MethodOutcome#getResource()

PreferReturnEnum

url

The search URL to use. The format of this URL should be of the form ResourceTypeParameters, for example: Patientname=Smith&identifier=13.2.4.11.4%7C847366

String

In addition to the parameters above, the fhir API can also use any of the Query Parameters.

Any of the parameters can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format CamelFhir.parameter. The inBody parameter overrides message header, i.e. the endpoint parameter inBody=myParameterNameHere would override a CamelFhir.myParameterNameHere header.

33.6.9. API: read

Both producer and consumer are supported

The read API is defined in the syntax as follows:

fhir:read/methodName?[parameters]

The 2 method(s) is listed in the table below, followed by detailed syntax for each method. (API methods can have a shorthand alias name which can be used in the syntax instead of the name)

MethodDescription

resourceById

Reads a IBaseResource on the server by id

resourceByUrl

Reads a IBaseResource on the server by url

33.6.9.1. Method resourceById

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseResource resourceById(Class<org.hl7.fhir.instance.model.api.IBaseResource> resource, Long longId, String ifVersionMatches, Boolean returnNull, org.hl7.fhir.instance.model.api.IBaseResource returnResource, Boolean throwError, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);
  • org.hl7.fhir.instance.model.api.IBaseResource resourceById(Class<org.hl7.fhir.instance.model.api.IBaseResource> resource, String stringId, String version, String ifVersionMatches, Boolean returnNull, org.hl7.fhir.instance.model.api.IBaseResource returnResource, Boolean throwError, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);
  • org.hl7.fhir.instance.model.api.IBaseResource resourceById(Class<org.hl7.fhir.instance.model.api.IBaseResource> resource, org.hl7.fhir.instance.model.api.IIdType id, String ifVersionMatches, Boolean returnNull, org.hl7.fhir.instance.model.api.IBaseResource returnResource, Boolean throwError, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);
  • org.hl7.fhir.instance.model.api.IBaseResource resourceById(String resourceClass, Long longId, String ifVersionMatches, Boolean returnNull, org.hl7.fhir.instance.model.api.IBaseResource returnResource, Boolean throwError, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);
  • org.hl7.fhir.instance.model.api.IBaseResource resourceById(String resourceClass, String stringId, String ifVersionMatches, String version, Boolean returnNull, org.hl7.fhir.instance.model.api.IBaseResource returnResource, Boolean throwError, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);
  • org.hl7.fhir.instance.model.api.IBaseResource resourceById(String resourceClass, org.hl7.fhir.instance.model.api.IIdType id, String ifVersionMatches, Boolean returnNull, org.hl7.fhir.instance.model.api.IBaseResource returnResource, Boolean throwError, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/resourceById API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

id

The IIdType referencing the resource

IIdType

ifVersionMatches

A version to match against the newest version on the server

String

longId

The resource ID

Long

resource

The resource to read (e.g. Patient)

Class

resourceClass

The resource to read (e.g. Patient)

String

returnNull

Return null if version matches

Boolean

returnResource

Return the resource if version matches

IBaseResource

stringId

The resource ID

String

throwError

Throw error if the version matches

Boolean

version

The resource version

String

33.6.9.2. Method resourceByUrl

Signatures:

  • org.hl7.fhir.instance.model.api.IBaseResource resourceByUrl(Class<org.hl7.fhir.instance.model.api.IBaseResource> resource, String url, String ifVersionMatches, Boolean returnNull, org.hl7.fhir.instance.model.api.IBaseResource returnResource, Boolean throwError, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);
  • org.hl7.fhir.instance.model.api.IBaseResource resourceByUrl(Class<org.hl7.fhir.instance.model.api.IBaseResource> resource, org.hl7.fhir.instance.model.api.IIdType iUrl, String ifVersionMatches, Boolean returnNull, org.hl7.fhir.instance.model.api.IBaseResource returnResource, Boolean throwError, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);
  • org.hl7.fhir.instance.model.api.IBaseResource resourceByUrl(String resourceClass, String url, String ifVersionMatches, Boolean returnNull, org.hl7.fhir.instance.model.api.IBaseResource returnResource, Boolean throwError, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);
  • org.hl7.fhir.instance.model.api.IBaseResource resourceByUrl(String resourceClass, org.hl7.fhir.instance.model.api.IIdType iUrl, String ifVersionMatches, Boolean returnNull, org.hl7.fhir.instance.model.api.IBaseResource returnResource, Boolean throwError, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/resourceByUrl API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

iUrl

The IIdType referencing the resource by absolute url

IIdType

ifVersionMatches

A version to match against the newest version on the server

String

resource

The resource to read (e.g. Patient)

Class

resourceClass

The resource to read (e.g. Patient.class)

String

returnNull

Return null if version matches

Boolean

returnResource

Return the resource if version matches

IBaseResource

throwError

Throw error if the version matches

Boolean

url

Referencing the resource by absolute url

String

In addition to the parameters above, the fhir API can also use any of the Query Parameters.

Any of the parameters can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format CamelFhir.parameter. The inBody parameter overrides message header, i.e. the endpoint parameter inBody=myParameterNameHere would override a CamelFhir.myParameterNameHere header.

33.6.11. API: transaction

Both producer and consumer are supported

The transaction API is defined in the syntax as follows:

fhir:transaction/methodName?[parameters]

The 2 method(s) is listed in the table below, followed by detailed syntax for each method. (API methods can have a shorthand alias name which can be used in the syntax instead of the name)

MethodDescription

withBundle

Use the given raw text (should be a Bundle resource) as the transaction input

withResources

Use a list of resources as the transaction input

33.6.11.1. Method withBundle

Signatures:

  • String withBundle(String stringBundle, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);
  • org.hl7.fhir.instance.model.api.IBaseBundle withBundle(org.hl7.fhir.instance.model.api.IBaseBundle bundle, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/withBundle API method has the parameters listed in the table below:

ParameterDescriptionType

bundle

Bundle to use in the transaction

IBaseBundle

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

stringBundle

Bundle to use in the transaction

String

33.6.11.2. Method withResources

Signatures:

  • java.util.List<org.hl7.fhir.instance.model.api.IBaseResource> withResources(java.util.List<org.hl7.fhir.instance.model.api.IBaseResource> resources, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/withResources API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

resources

Resources to use in the transaction

List

In addition to the parameters above, the fhir API can also use any of the Query Parameters.

Any of the parameters can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format CamelFhir.parameter. The inBody parameter overrides message header, i.e. the endpoint parameter inBody=myParameterNameHere would override a CamelFhir.myParameterNameHere header.

33.6.12. API: update

Both producer and consumer are supported

The update API is defined in the syntax as follows:

fhir:update/methodName?[parameters]

The 2 method(s) is listed in the table below, followed by detailed syntax for each method. (API methods can have a shorthand alias name which can be used in the syntax instead of the name)

MethodDescription

resource

Updates a IBaseResource on the server by id

resourceBySearchUrl

Updates a IBaseResource on the server by search url

33.6.12.1. Method resource

Signatures:

  • ca.uhn.fhir.rest.api.MethodOutcome resource(String resourceAsString, String stringId, ca.uhn.fhir.rest.api.PreferReturnEnum preferReturn, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);
  • ca.uhn.fhir.rest.api.MethodOutcome resource(String resourceAsString, org.hl7.fhir.instance.model.api.IIdType id, ca.uhn.fhir.rest.api.PreferReturnEnum preferReturn, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);
  • ca.uhn.fhir.rest.api.MethodOutcome resource(org.hl7.fhir.instance.model.api.IBaseResource resource, String stringId, ca.uhn.fhir.rest.api.PreferReturnEnum preferReturn, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);
  • ca.uhn.fhir.rest.api.MethodOutcome resource(org.hl7.fhir.instance.model.api.IBaseResource resource, org.hl7.fhir.instance.model.api.IIdType id, ca.uhn.fhir.rest.api.PreferReturnEnum preferReturn, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/resource API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

id

The IIdType referencing the resource

IIdType

preferReturn

Whether the server include or suppress the resource body as a part of the result

PreferReturnEnum

resource

The resource to update (e.g. Patient)

IBaseResource

resourceAsString

The resource body to update

String

stringId

The ID referencing the resource

String

33.6.12.2. Method resourceBySearchUrl

Signatures:

  • ca.uhn.fhir.rest.api.MethodOutcome resourceBySearchUrl(String resourceAsString, String url, ca.uhn.fhir.rest.api.PreferReturnEnum preferReturn, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);
  • ca.uhn.fhir.rest.api.MethodOutcome resourceBySearchUrl(org.hl7.fhir.instance.model.api.IBaseResource resource, String url, ca.uhn.fhir.rest.api.PreferReturnEnum preferReturn, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/resourceBySearchUrl API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

preferReturn

Whether the server include or suppress the resource body as a part of the result

PreferReturnEnum

resource

The resource to update (e.g. Patient)

IBaseResource

resourceAsString

The resource body to update

String

url

Specifies that the update should be performed as a conditional create against a given search URL

String

In addition to the parameters above, the fhir API can also use any of the Query Parameters.

Any of the parameters can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format CamelFhir.parameter. The inBody parameter overrides message header, i.e. the endpoint parameter inBody=myParameterNameHere would override a CamelFhir.myParameterNameHere header.

33.6.13. API: validate

Both producer and consumer are supported

The validate API is defined in the syntax as follows:

fhir:validate/methodName?[parameters]

The 1 method(s) is listed in the table below, followed by detailed syntax for each method. (API methods can have a shorthand alias name which can be used in the syntax instead of the name)

MethodDescription

resource

Validates the resource

33.6.13.1. Method resource

Signatures:

  • ca.uhn.fhir.rest.api.MethodOutcome resource(String resourceAsString, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);
  • ca.uhn.fhir.rest.api.MethodOutcome resource(org.hl7.fhir.instance.model.api.IBaseResource resource, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters, Object> extraParameters);

The fhir/resource API method has the parameters listed in the table below:

ParameterDescriptionType

extraParameters

See ExtraParameters for a full list of parameters that can be passed, may be NULL

Map

resource

The IBaseResource to validate

IBaseResource

resourceAsString

Raw resource to validate

String

In addition to the parameters above, the fhir API can also use any of the Query Parameters.

Any of the parameters can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format CamelFhir.parameter. The inBody parameter overrides message header, i.e. the endpoint parameter inBody=myParameterNameHere would override a CamelFhir.myParameterNameHere header.

33.7. Spring Boot Auto-Configuration

The component supports 56 options, which are listed below.

NameDescriptionDefaultType

camel.component.fhir.access-token

OAuth access token.

 

String

camel.component.fhir.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.fhir.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.fhir.client

To use the custom client. The option is a ca.uhn.fhir.rest.client.api.IGenericClient type.

 

IGenericClient

camel.component.fhir.client-factory

To use the custom client factory. The option is a ca.uhn.fhir.rest.client.api.IRestfulClientFactory type.

 

IRestfulClientFactory

camel.component.fhir.compress

Compresses outgoing (POST/PUT) contents to the GZIP format.

false

Boolean

camel.component.fhir.configuration

To use the shared configuration. The option is a org.apache.camel.component.fhir.FhirConfiguration type.

 

FhirConfiguration

camel.component.fhir.connection-timeout

How long to try and establish the initial TCP connection (in ms).

10000

Integer

camel.component.fhir.defer-model-scanning

When this option is set, model classes will not be scanned for children until the child list for the given type is actually accessed.

false

Boolean

camel.component.fhir.enabled

Whether to enable auto configuration of the fhir component. This is enabled by default.

 

Boolean

camel.component.fhir.encoding

Encoding to use for all request.

 

String

camel.component.fhir.fhir-context

FhirContext is an expensive object to create. To avoid creating multiple instances, it can be set directly. The option is a ca.uhn.fhir.context.FhirContext type.

 

FhirContext

camel.component.fhir.fhir-version

The FHIR Version to use.

R4

String

camel.component.fhir.force-conformance-check

Force conformance check.

false

Boolean

camel.component.fhir.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.fhir.log

Will log every requests and responses.

false

Boolean

camel.component.fhir.password

Username to use for basic authentication.

 

String

camel.component.fhir.pretty-print

Pretty print all request.

false

Boolean

camel.component.fhir.proxy-host

The proxy host.

 

String

camel.component.fhir.proxy-password

The proxy password.

 

String

camel.component.fhir.proxy-port

The proxy port.

 

Integer

camel.component.fhir.proxy-user

The proxy username.

 

String

camel.component.fhir.server-url

The FHIR server base URL.

 

String

camel.component.fhir.session-cookie

HTTP session cookie to add to every request.

 

String

camel.component.fhir.socket-timeout

How long to block for individual read/write operations (in ms).

10000

Integer

camel.component.fhir.summary

Request that the server modify the response using the _summary param.

 

String

camel.component.fhir.username

Username to use for basic authentication.

 

String

camel.component.fhir.validation-mode

When should Camel validate the FHIR Server’s conformance statement.

ONCE

String

camel.dataformat.fhirjson.content-type-header

Whether the data format should set the Content-Type header with the type from the data format. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON.

true

Boolean

camel.dataformat.fhirjson.dont-encode-elements

If provided, specifies the elements which should NOT be encoded. Valid values for this field would include: Patient - Don’t encode patient and all its children Patient.name - Don’t encode the patient’s name Patient.name.family - Don’t encode the patient’s family name .text - Don’t encode the text element on any resource (only the very first position may contain a wildcard) DSTU2 note: Note that values including meta, such as Patient.meta will work for DSTU2 parsers, but values with subelements on meta such as Patient.meta.lastUpdated will only work in DSTU3 mode.

 

Set

camel.dataformat.fhirjson.dont-strip-versions-from-references-at-paths

If supplied value(s), any resource references at the specified paths will have their resource versions encoded instead of being automatically stripped during the encoding process. This setting has no effect on the parsing process. This method provides a finer-grained level of control than setStripVersionsFromReferences(String) and any paths specified by this method will be encoded even if setStripVersionsFromReferences(String) has been set to true (which is the default).

 

List

camel.dataformat.fhirjson.enabled

Whether to enable auto configuration of the fhirJson data format. This is enabled by default.

 

Boolean

camel.dataformat.fhirjson.encode-elements

If provided, specifies the elements which should be encoded, to the exclusion of all others. Valid values for this field would include: Patient - Encode patient and all its children Patient.name - Encode only the patient’s name Patient.name.family - Encode only the patient’s family name .text - Encode the text element on any resource (only the very first position may contain a wildcard) .(mandatory) - This is a special case which causes any mandatory fields (min 0) to be encoded.

 

Set

camel.dataformat.fhirjson.encode-elements-applies-to-child-resources-only

If set to true (default is false), the values supplied to setEncodeElements(Set) will not be applied to the root resource (typically a Bundle), but will be applied to any sub-resources contained within it (i.e. search result resources in that bundle).

false

Boolean

camel.dataformat.fhirjson.fhir-version

The version of FHIR to use. Possible values are: DSTU2,DSTU2_HL7ORG,DSTU2_1,DSTU3,R4.

DSTU3

String

camel.dataformat.fhirjson.omit-resource-id

If set to true (default is false) the ID of any resources being encoded will not be included in the output. Note that this does not apply to contained resources, only to root resources. In other words, if this is set to true, contained resources will still have local IDs but the outer/containing ID will not have an ID.

false

Boolean

camel.dataformat.fhirjson.override-resource-id-with-bundle-entry-full-url

If set to true (which is the default), the Bundle.entry.fullUrl will override the Bundle.entry.resource’s resource id if the fullUrl is defined. This behavior happens when parsing the source data into a Bundle object. Set this to false if this is not the desired behavior (e.g. the client code wishes to perform additional validation checks between the fullUrl and the resource id).

false

Boolean

camel.dataformat.fhirjson.pretty-print

Sets the pretty print flag, meaning that the parser will encode resources with human-readable spacing and newlines between elements instead of condensing output as much as possible.

false

Boolean

camel.dataformat.fhirjson.server-base-url

Sets the server’s base URL used by this parser. If a value is set, resource references will be turned into relative references if they are provided as absolute URLs but have a base matching the given base.

 

String

camel.dataformat.fhirjson.strip-versions-from-references

If set to true (which is the default), resource references containing a version will have the version removed when the resource is encoded. This is generally good behaviour because in most situations, references from one resource to another should be to the resource by ID, not by ID and version. In some cases though, it may be desirable to preserve the version in resource links. In that case, this value should be set to false. This method provides the ability to globally disable reference encoding. If finer-grained control is needed, use setDontStripVersionsFromReferencesAtPaths(List).

false

Boolean

camel.dataformat.fhirjson.summary-mode

If set to true (default is false) only elements marked by the FHIR specification as being summary elements will be included.

false

Boolean

camel.dataformat.fhirjson.suppress-narratives

If set to true (default is false), narratives will not be included in the encoded values.

false

Boolean

camel.dataformat.fhirxml.content-type-header

Whether the data format should set the Content-Type header with the type from the data format. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON.

true

Boolean

camel.dataformat.fhirxml.dont-encode-elements

If provided, specifies the elements which should NOT be encoded. Valid values for this field would include: Patient - Don’t encode patient and all its children Patient.name - Don’t encode the patient’s name Patient.name.family - Don’t encode the patient’s family name .text - Don’t encode the text element on any resource (only the very first position may contain a wildcard) DSTU2 note: Note that values including meta, such as Patient.meta will work for DSTU2 parsers, but values with subelements on meta such as Patient.meta.lastUpdated will only work in DSTU3 mode.

 

Set

camel.dataformat.fhirxml.dont-strip-versions-from-references-at-paths

If supplied value(s), any resource references at the specified paths will have their resource versions encoded instead of being automatically stripped during the encoding process. This setting has no effect on the parsing process. This method provides a finer-grained level of control than setStripVersionsFromReferences(String) and any paths specified by this method will be encoded even if setStripVersionsFromReferences(String) has been set to true (which is the default).

 

List

camel.dataformat.fhirxml.enabled

Whether to enable auto configuration of the fhirXml data format. This is enabled by default.

 

Boolean

camel.dataformat.fhirxml.encode-elements

If provided, specifies the elements which should be encoded, to the exclusion of all others. Valid values for this field would include: Patient - Encode patient and all its children Patient.name - Encode only the patient’s name Patient.name.family - Encode only the patient’s family name .text - Encode the text element on any resource (only the very first position may contain a wildcard) .(mandatory) - This is a special case which causes any mandatory fields (min 0) to be encoded.

 

Set

camel.dataformat.fhirxml.encode-elements-applies-to-child-resources-only

If set to true (default is false), the values supplied to setEncodeElements(Set) will not be applied to the root resource (typically a Bundle), but will be applied to any sub-resources contained within it (i.e. search result resources in that bundle).

false

Boolean

camel.dataformat.fhirxml.fhir-version

The version of FHIR to use. Possible values are: DSTU2,DSTU2_HL7ORG,DSTU2_1,DSTU3,R4.

DSTU3

String

camel.dataformat.fhirxml.omit-resource-id

If set to true (default is false) the ID of any resources being encoded will not be included in the output. Note that this does not apply to contained resources, only to root resources. In other words, if this is set to true, contained resources will still have local IDs but the outer/containing ID will not have an ID.

false

Boolean

camel.dataformat.fhirxml.override-resource-id-with-bundle-entry-full-url

If set to true (which is the default), the Bundle.entry.fullUrl will override the Bundle.entry.resource’s resource id if the fullUrl is defined. This behavior happens when parsing the source data into a Bundle object. Set this to false if this is not the desired behavior (e.g. the client code wishes to perform additional validation checks between the fullUrl and the resource id).

false

Boolean

camel.dataformat.fhirxml.pretty-print

Sets the pretty print flag, meaning that the parser will encode resources with human-readable spacing and newlines between elements instead of condensing output as much as possible.

false

Boolean

camel.dataformat.fhirxml.server-base-url

Sets the server’s base URL used by this parser. If a value is set, resource references will be turned into relative references if they are provided as absolute URLs but have a base matching the given base.

 

String

camel.dataformat.fhirxml.strip-versions-from-references

If set to true (which is the default), resource references containing a version will have the version removed when the resource is encoded. This is generally good behaviour because in most situations, references from one resource to another should be to the resource by ID, not by ID and version. In some cases though, it may be desirable to preserve the version in resource links. In that case, this value should be set to false. This method provides the ability to globally disable reference encoding. If finer-grained control is needed, use setDontStripVersionsFromReferencesAtPaths(List).

false

Boolean

camel.dataformat.fhirxml.summary-mode

If set to true (default is false) only elements marked by the FHIR specification as being summary elements will be included.

false

Boolean

camel.dataformat.fhirxml.suppress-narratives

If set to true (default is false), narratives will not be included in the encoded values.

false

Boolean

Chapter 34. File

Both producer and consumer are supported

The File component provides access to file systems, allowing files to be processed by any other Camel Components or messages from other components to be saved to disk.

34.1. Dependencies

When using file with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-file-starter</artifactId>
</dependency>

34.2. URI format

file:directoryName[?options]

Where directoryName represents the underlying file directory.

Only directories

Camel supports only endpoints configured with a starting directory. So the directoryName must be a directory. If you want to consume a single file only, you can use the fileName option, e.g. by setting fileName=thefilename. Also, the starting directory must not contain dynamic expressions with ${ } placeholders. Again use the fileName option to specify the dynamic part of the filename.

Note

Avoid reading files currently being written by another application
Beware the JDK File IO API is a bit limited in detecting whether another application is currently writing/copying a file. And the implementation can be different depending on OS platform as well. This could lead to that Camel thinks the file is not locked by another process and start consuming it. Therefore you have to do you own investigation what suites your environment. To help with this Camel provides different readLock options and doneFileName option that you can use. See also the section Consuming files from folders where others drop files directly.

34.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

34.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

34.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

34.4. Component Options

The File component supports 3 options, which are listed below.

NameDescriptionDefaultType

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

34.5. Endpoint Options

The File endpoint is configured using URI syntax:

file:directoryName

with the following path and query parameters:

34.5.1. Path Parameters (1 parameters)

NameDescriptionDefaultType

directoryName (common)

Required The starting directory.

 

File

34.5.2. Query Parameters (94 parameters)

NameDescriptionDefaultType

charset (common)

This option is used to specify the encoding of the file. You can use this on the consumer, to specify the encodings of the files, which allow Camel to know the charset it should load the file content in case the file content is being accessed. Likewise when writing a file, you can use this option to specify which charset to write the file as well. Do mind that when writing the file Camel may have to read the message content into memory to be able to convert the data into the configured charset, so do not use this if you have big messages.

 

String

doneFileName (common)

Producer: If provided, then Camel will write a 2nd done file when the original file has been written. The done file will be empty. This option configures what file name to use. Either you can specify a fixed name. Or you can use dynamic placeholders. The done file will always be written in the same folder as the original file. Consumer: If provided, Camel will only consume files if a done file exists. This option configures what file name to use. Either you can specify a fixed name. Or you can use dynamic placeholders.The done file is always expected in the same folder as the original file. Only $\\{file.name} and $\\{file.name.next} is supported as dynamic placeholders.

 

String

fileName (common)

Use Expression such as File Language to dynamically set the filename. For consumers, it’s used as a filename filter. For producers, it’s used to evaluate the filename to write. If an expression is set, it take precedence over the CamelFileName header. (Note: The header itself can also be an Expression). The expression options support both String and Expression types. If the expression is a String type, it is always evaluated using the File Language. If the expression is an Expression type, the specified Expression type is used - this allows you, for instance, to use OGNL expressions. For the consumer, you can use it to filter filenames, so you can for instance consume today’s file using the File Language syntax: mydata-$\\{date:now:yyyyMMdd}.txt. The producers support the CamelOverruleFileName header which takes precedence over any existing CamelFileName header; the CamelOverruleFileName is a header that is used only once, and makes it easier as this avoids to temporary store CamelFileName and have to restore it afterwards.

 

String

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

delete (consumer)

If true, the file will be deleted after it is processed successfully.

false

boolean

moveFailed (consumer)

Sets the move failure expression based on Simple language. For example, to move files into a .error subdirectory use: .error. Note: When moving the files to the fail location Camel will handle the error and will not pick up the file again.

 

String

noop (consumer)

If true, the file is not moved or deleted in any way. This option is good for readonly data, or for ETL type requirements. If noop=true, Camel will set idempotent=true as well, to avoid consuming the same files over and over again.

false

boolean

preMove (consumer)

Expression (such as File Language) used to dynamically set the filename when moving it before processing. For example to move in-progress files into the order directory set this value to order.

 

String

preSort (consumer)

When pre-sort is enabled then the consumer will sort the file and directory names during polling, that was retrieved from the file system. You may want to do this in case you need to operate on the files in a sorted order. The pre-sort is executed before the consumer starts to filter, and accept files to process by Camel. This option is default=false meaning disabled.

false

boolean

recursive (consumer)

If a directory, will look for files in all the sub-directories as well.

false

boolean

sendEmptyMessageWhenIdle (consumer)

If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead.

false

boolean

directoryMustExist (consumer (advanced))

Similar to the startingDirectoryMustExist option but this applies during polling (after starting the consumer).

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

extendedAttributes (consumer (advanced))

To define which file attributes of interest. Like posix:permissions,posix:owner,basic:lastAccessTime, it supports basic wildcard like posix:, basic:lastAccessTime.

 

String

inProgressRepository (consumer (advanced))

A pluggable in-progress repository org.apache.camel.spi.IdempotentRepository. The in-progress repository is used to account the current in progress files being consumed. By default a memory based repository is used.

 

IdempotentRepository

localWorkDirectory (consumer (advanced))

When consuming, a local work directory can be used to store the remote file content directly in local files, to avoid loading the content into memory. This is beneficial, if you consume a very big remote file and thus can conserve memory.

 

String

onCompletionExceptionHandler (consumer (advanced))

To use a custom org.apache.camel.spi.ExceptionHandler to handle any thrown exceptions that happens during the file on completion process where the consumer does either a commit or rollback. The default implementation will log any exception at WARN level and ignore.

 

ExceptionHandler

pollStrategy (consumer (advanced))

A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel.

 

PollingConsumerPollStrategy

probeContentType (consumer (advanced))

Whether to enable probing of the content type. If enable then the consumer uses Files#probeContentType(java.nio.file.Path) to determine the content-type of the file, and store that as a header with key Exchange#FILE_CONTENT_TYPE on the Message.

false

boolean

processStrategy (consumer (advanced))

A pluggable org.apache.camel.component.file.GenericFileProcessStrategy allowing you to implement your own readLock option or similar. Can also be used when special conditions must be met before a file can be consumed, such as a special ready file exists. If this option is set then the readLock option does not apply.

 

GenericFileProcessStrategy

resumeStrategy (consumer (advanced))

Set a resume strategy for files. This makes it possible to define a strategy for resuming reading files after the last point before stopping the application. See the FileConsumerResumeStrategy for implementation details.

 

FileConsumerResumeStrategy

startingDirectoryMustExist (consumer (advanced))

Whether the starting directory must exist. Mind that the autoCreate option is default enabled, which means the starting directory is normally auto created if it doesn’t exist. You can disable autoCreate and enable this to ensure the starting directory must exist. Will thrown an exception if the directory doesn’t exist.

false

boolean

startingDirectoryMustHaveAccess (consumer (advanced))

Whether the starting directory has access permissions. Mind that the startingDirectoryMustExist parameter must be set to true in order to verify that the directory exists. Will thrown an exception if the directory doesn’t have read and write permissions.

false

boolean

appendChars (producer)

Used to append characters (text) after writing files. This can for example be used to add new lines or other separators when writing and appending new files or existing files. To specify new-line (slash-n or slash-r) or tab (slash-t) characters then escape with an extra slash, eg slash-slash-n.

 

String

fileExist (producer)

What to do if a file already exists with the same name. Override, which is the default, replaces the existing file. - Append - adds content to the existing file. - Fail - throws a GenericFileOperationException, indicating that there is already an existing file. - Ignore - silently ignores the problem and does not override the existing file, but assumes everything is okay. - Move - option requires to use the moveExisting option to be configured as well. The option eagerDeleteTargetFile can be used to control what to do if an moving the file, and there exists already an existing file, otherwise causing the move operation to fail. The Move option will move any existing files, before writing the target file. - TryRename is only applicable if tempFileName option is in use. This allows to try renaming the file from the temporary name to the actual name, without doing any exists check. This check may be faster on some file systems and especially FTP servers.

Enum values:

  • Override
  • Append
  • Fail
  • Ignore
  • Move
  • TryRename

Override

GenericFileExist

flatten (producer)

Flatten is used to flatten the file name path to strip any leading paths, so it’s just the file name. This allows you to consume recursively into sub-directories, but when you eg write the files to another directory they will be written in a single directory. Setting this to true on the producer enforces that any file name in CamelFileName header will be stripped for any leading paths.

false

boolean

jailStartingDirectory (producer)

Used for jailing (restricting) writing files to the starting directory (and sub) only. This is enabled by default to not allow Camel to write files to outside directories (to be more secured out of the box). You can turn this off to allow writing files to directories outside the starting directory, such as parent or root folders.

true

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

moveExisting (producer)

Expression (such as File Language) used to compute file name to use when fileExist=Move is configured. To move files into a backup subdirectory just enter backup. This option only supports the following File Language tokens: file:name, file:name.ext, file:name.noext, file:onlyname, file:onlyname.noext, file:ext, and file:parent. Notice the file:parent is not supported by the FTP component, as the FTP component can only move any existing files to a relative directory based on current dir as base.

 

String

tempFileName (producer)

The same as tempPrefix option but offering a more fine grained control on the naming of the temporary filename as it uses the File Language. The location for tempFilename is relative to the final file location in the option 'fileName', not the target directory in the base uri. For example if option fileName includes a directory prefix: dir/finalFilename then tempFileName is relative to that subdirectory dir.

 

String

tempPrefix (producer)

This option is used to write the file using a temporary name and then, after the write is complete, rename it to the real name. Can be used to identify files being written and also avoid consumers (not using exclusive read locks) reading in progress files. Is often used by FTP when uploading big files.

 

String

allowNullBody (producer (advanced))

Used to specify if a null body is allowed during file writing. If set to true then an empty file will be created, when set to false, and attempting to send a null body to the file component, a GenericFileWriteException of 'Cannot write null body to file.' will be thrown. If the fileExist option is set to 'Override', then the file will be truncated, and if set to append the file will remain unchanged.

false

boolean

chmod (producer (advanced))

Specify the file permissions which is sent by the producer, the chmod value must be between 000 and 777; If there is a leading digit like in 0755 we will ignore it.

 

String

chmodDirectory (producer (advanced))

Specify the directory permissions used when the producer creates missing directories, the chmod value must be between 000 and 777; If there is a leading digit like in 0755 we will ignore it.

 

String

eagerDeleteTargetFile (producer (advanced))

Whether or not to eagerly delete any existing target file. This option only applies when you use fileExists=Override and the tempFileName option as well. You can use this to disable (set it to false) deleting the target file before the temp file is written. For example you may write big files and want the target file to exists during the temp file is being written. This ensure the target file is only deleted until the very last moment, just before the temp file is being renamed to the target filename. This option is also used to control whether to delete any existing files when fileExist=Move is enabled, and an existing file exists. If this option copyAndDeleteOnRenameFails false, then an exception will be thrown if an existing file existed, if its true, then the existing file is deleted before the move operation.

true

boolean

forceWrites (producer (advanced))

Whether to force syncing writes to the file system. You can turn this off if you do not want this level of guarantee, for example if writing to logs / audit logs etc; this would yield better performance.

true

boolean

keepLastModified (producer (advanced))

Will keep the last modified timestamp from the source file (if any). Will use the Exchange.FILE_LAST_MODIFIED header to located the timestamp. This header can contain either a java.util.Date or long with the timestamp. If the timestamp exists and the option is enabled it will set this timestamp on the written file. Note: This option only applies to the file producer. You cannot use this option with any of the ftp producers.

false

boolean

moveExistingFileStrategy (producer (advanced))

Strategy (Custom Strategy) used to move file with special naming token to use when fileExist=Move is configured. By default, there is an implementation used if no custom strategy is provided.

 

FileMoveExistingStrategy

autoCreate (advanced)

Automatically create missing directories in the file’s pathname. For the file consumer, that means creating the starting directory. For the file producer, it means the directory the files should be written to.

true

boolean

bufferSize (advanced)

Buffer size in bytes used for writing files (or in case of FTP for downloading and uploading files).

131072

int

copyAndDeleteOnRenameFail (advanced)

Whether to fallback and do a copy and delete file, in case the file could not be renamed directly. This option is not available for the FTP component.

true

boolean

renameUsingCopy (advanced)

Perform rename operations using a copy and delete strategy. This is primarily used in environments where the regular rename operation is unreliable (e.g. across different file systems or networks). This option takes precedence over the copyAndDeleteOnRenameFail parameter that will automatically fall back to the copy and delete strategy, but only after additional delays.

false

boolean

synchronous (advanced)

Sets whether synchronous processing should be strictly used.

false

boolean

antExclude (filter)

Ant style filter exclusion. If both antInclude and antExclude are used, antExclude takes precedence over antInclude. Multiple exclusions may be specified in comma-delimited format.

 

String

antFilterCaseSensitive (filter)

Sets case sensitive flag on ant filter.

true

boolean

antInclude (filter)

Ant style filter inclusion. Multiple inclusions may be specified in comma-delimited format.

 

String

eagerMaxMessagesPerPoll (filter)

Allows for controlling whether the limit from maxMessagesPerPoll is eager or not. If eager then the limit is during the scanning of files. Where as false would scan all files, and then perform sorting. Setting this option to false allows for sorting all files first, and then limit the poll. Mind that this requires a higher memory usage as all file details are in memory to perform the sorting.

true

boolean

exclude (filter)

Is used to exclude files, if filename matches the regex pattern (matching is case in-sensitive). Notice if you use symbols such as plus sign and others you would need to configure this using the RAW() syntax if configuring this as an endpoint uri. See more details at configuring endpoint uris.

 

String

excludeExt (filter)

Is used to exclude files matching file extension name (case insensitive). For example to exclude bak files, then use excludeExt=bak. Multiple extensions can be separated by comma, for example to exclude bak and dat files, use excludeExt=bak,dat. Note that the file extension includes all parts, for example having a file named mydata.tar.gz will have extension as tar.gz. For more flexibility then use the include/exclude options.

 

String

filter (filter)

Pluggable filter as a org.apache.camel.component.file.GenericFileFilter class. Will skip files if filter returns false in its accept() method.

 

GenericFileFilter

filterDirectory (filter)

Filters the directory based on Simple language. For example to filter on current date, you can use a simple date pattern such as $\\{date:now:yyyMMdd}.

 

String

filterFile (filter)

Filters the file based on Simple language. For example to filter on file size, you can use $\\{file:size} 5000.

 

String

idempotent (filter)

Option to use the Idempotent Consumer EIP pattern to let Camel skip already processed files. Will by default use a memory based LRUCache that holds 1000 entries. If noop=true then idempotent will be enabled as well to avoid consuming the same files over and over again.

false

Boolean

idempotentKey (filter)

To use a custom idempotent key. By default the absolute path of the file is used. You can use the File Language, for example to use the file name and file size, you can do: idempotentKey=$\\{file:name}-$\\{file:size}.

 

String

idempotentRepository (filter)

A pluggable repository org.apache.camel.spi.IdempotentRepository which by default use MemoryIdempotentRepository if none is specified and idempotent is true.

 

IdempotentRepository

include (filter)

Is used to include files, if filename matches the regex pattern (matching is case in-sensitive). Notice if you use symbols such as plus sign and others you would need to configure this using the RAW() syntax if configuring this as an endpoint uri. See more details at configuring endpoint uris.

 

String

includeExt (filter)

Is used to include files matching file extension name (case insensitive). For example to include txt files, then use includeExt=txt. Multiple extensions can be separated by comma, for example to include txt and xml files, use includeExt=txt,xml. Note that the file extension includes all parts, for example having a file named mydata.tar.gz will have extension as tar.gz. For more flexibility then use the include/exclude options.

 

String

maxDepth (filter)

The maximum depth to traverse when recursively processing a directory.

2147483647

int

maxMessagesPerPoll (filter)

To define a maximum messages to gather per poll. By default no maximum is set. Can be used to set a limit of e.g. 1000 to avoid when starting up the server that there are thousands of files. Set a value of 0 or negative to disabled it. Notice: If this option is in use then the File and FTP components will limit before any sorting. For example if you have 100000 files and use maxMessagesPerPoll=500, then only the first 500 files will be picked up, and then sorted. You can use the eagerMaxMessagesPerPoll option and set this to false to allow to scan all files first and then sort afterwards.

 

int

minDepth (filter)

The minimum depth to start processing when recursively processing a directory. Using minDepth=1 means the base directory. Using minDepth=2 means the first sub directory.

 

int

move (filter)

Expression (such as Simple Language) used to dynamically set the filename when moving it after processing. To move files into a .done subdirectory just enter .done.

 

String

exclusiveReadLockStrategy (lock)

Pluggable read-lock as a org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy implementation.

 

GenericFileExclusiveReadLockStrategy

readLock (lock)

Used by consumer, to only poll the files if it has exclusive read-lock on the file (i.e. the file is not in-progress or being written). Camel will wait until the file lock is granted. This option provides the build in strategies: - none - No read lock is in use - markerFile - Camel creates a marker file (fileName.camelLock) and then holds a lock on it. This option is not available for the FTP component - changed - Changed is using file length/modification timestamp to detect whether the file is currently being copied or not. Will at least use 1 sec to determine this, so this option cannot consume files as fast as the others, but can be more reliable as the JDK IO API cannot always determine whether a file is currently being used by another process. The option readLockCheckInterval can be used to set the check frequency. - fileLock - is for using java.nio.channels.FileLock. This option is not avail for Windows OS and the FTP component. This approach should be avoided when accessing a remote file system via a mount/share unless that file system supports distributed file locks. - rename - rename is for using a try to rename the file as a test if we can get exclusive read-lock. - idempotent - (only for file component) idempotent is for using a idempotentRepository as the read-lock. This allows to use read locks that supports clustering if the idempotent repository implementation supports that. - idempotent-changed - (only for file component) idempotent-changed is for using a idempotentRepository and changed as the combined read-lock. This allows to use read locks that supports clustering if the idempotent repository implementation supports that. - idempotent-rename - (only for file component) idempotent-rename is for using a idempotentRepository and rename as the combined read-lock. This allows to use read locks that supports clustering if the idempotent repository implementation supports that.Notice: The various read locks is not all suited to work in clustered mode, where concurrent consumers on different nodes is competing for the same files on a shared file system. The markerFile using a close to atomic operation to create the empty marker file, but its not guaranteed to work in a cluster. The fileLock may work better but then the file system need to support distributed file locks, and so on. Using the idempotent read lock can support clustering if the idempotent repository supports clustering, such as Hazelcast Component or Infinispan.

Enum values:

  • none
  • markerFile
  • fileLock
  • rename
  • changed
  • idempotent
  • idempotent-changed
  • idempotent-rename

none

String

readLockCheckInterval (lock)

Interval in millis for the read-lock, if supported by the read lock. This interval is used for sleeping between attempts to acquire the read lock. For example when using the changed read lock, you can set a higher interval period to cater for slow writes. The default of 1 sec. may be too fast if the producer is very slow writing the file. Notice: For FTP the default readLockCheckInterval is 5000. The readLockTimeout value must be higher than readLockCheckInterval, but a rule of thumb is to have a timeout that is at least 2 or more times higher than the readLockCheckInterval. This is needed to ensure that amble time is allowed for the read lock process to try to grab the lock before the timeout was hit.

1000

long

readLockDeleteOrphanLockFiles (lock)

Whether or not read lock with marker files should upon startup delete any orphan read lock files, which may have been left on the file system, if Camel was not properly shutdown (such as a JVM crash). If turning this option to false then any orphaned lock file will cause Camel to not attempt to pickup that file, this could also be due another node is concurrently reading files from the same shared directory.

true

boolean

readLockIdempotentReleaseAsync (lock)

Whether the delayed release task should be synchronous or asynchronous. See more details at the readLockIdempotentReleaseDelay option.

false

boolean

readLockIdempotentReleaseAsyncPoolSize (lock)

The number of threads in the scheduled thread pool when using asynchronous release tasks. Using a default of 1 core threads should be sufficient in almost all use-cases, only set this to a higher value if either updating the idempotent repository is slow, or there are a lot of files to process. This option is not in-use if you use a shared thread pool by configuring the readLockIdempotentReleaseExecutorService option. See more details at the readLockIdempotentReleaseDelay option.

 

int

readLockIdempotentReleaseDelay (lock)

Whether to delay the release task for a period of millis. This can be used to delay the release tasks to expand the window when a file is regarded as read-locked, in an active/active cluster scenario with a shared idempotent repository, to ensure other nodes cannot potentially scan and acquire the same file, due to race-conditions. By expanding the time-window of the release tasks helps prevents these situations. Note delaying is only needed if you have configured readLockRemoveOnCommit to true.

 

int

readLockIdempotentReleaseExecutorService (lock)

To use a custom and shared thread pool for asynchronous release tasks. See more details at the readLockIdempotentReleaseDelay option.

 

ScheduledExecutorService

readLockLoggingLevel (lock)

Logging level used when a read lock could not be acquired. By default a DEBUG is logged. You can change this level, for example to OFF to not have any logging. This option is only applicable for readLock of types: changed, fileLock, idempotent, idempotent-changed, idempotent-rename, rename.

Enum values:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • OFF

DEBUG

LoggingLevel

readLockMarkerFile (lock)

Whether to use marker file with the changed, rename, or exclusive read lock types. By default a marker file is used as well to guard against other processes picking up the same files. This behavior can be turned off by setting this option to false. For example if you do not want to write marker files to the file systems by the Camel application.

true

boolean

readLockMinAge (lock)

This option is applied only for readLock=changed. It allows to specify a minimum age the file must be before attempting to acquire the read lock. For example use readLockMinAge=300s to require the file is at last 5 minutes old. This can speedup the changed read lock as it will only attempt to acquire files which are at least that given age.

0

long

readLockMinLength (lock)

This option is applied only for readLock=changed. It allows you to configure a minimum file length. By default Camel expects the file to contain data, and thus the default value is 1. You can set this option to zero, to allow consuming zero-length files.

1

long

readLockRemoveOnCommit (lock)

This option is applied only for readLock=idempotent. It allows to specify whether to remove the file name entry from the idempotent repository when processing the file is succeeded and a commit happens. By default the file is not removed which ensures that any race-condition do not occur so another active node may attempt to grab the file. Instead the idempotent repository may support eviction strategies that you can configure to evict the file name entry after X minutes - this ensures no problems with race conditions. See more details at the readLockIdempotentReleaseDelay option.

false

boolean

readLockRemoveOnRollback (lock)

This option is applied only for readLock=idempotent. It allows to specify whether to remove the file name entry from the idempotent repository when processing the file failed and a rollback happens. If this option is false, then the file name entry is confirmed (as if the file did a commit).

true

boolean

readLockTimeout (lock)

Optional timeout in millis for the read-lock, if supported by the read-lock. If the read-lock could not be granted and the timeout triggered, then Camel will skip the file. At next poll Camel, will try the file again, and this time maybe the read-lock could be granted. Use a value of 0 or lower to indicate forever. Currently fileLock, changed and rename support the timeout. Notice: For FTP the default readLockTimeout value is 20000 instead of 10000. The readLockTimeout value must be higher than readLockCheckInterval, but a rule of thumb is to have a timeout that is at least 2 or more times higher than the readLockCheckInterval. This is needed to ensure that amble time is allowed for the read lock process to try to grab the lock before the timeout was hit.

10000

long

backoffErrorThreshold (scheduler)

The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in.

 

int

backoffIdleThreshold (scheduler)

The number of subsequent idle polls that should happen before the backoffMultipler should kick-in.

 

int

backoffMultiplier (scheduler)

To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured.

 

int

delay (scheduler)

Milliseconds before the next poll.

500

long

greedy (scheduler)

If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages.

false

boolean

initialDelay (scheduler)

Milliseconds before the first poll starts.

1000

long

repeatCount (scheduler)

Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever.

0

long

runLoggingLevel (scheduler)

The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that.

Enum values:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • OFF

TRACE

LoggingLevel

scheduledExecutorService (scheduler)

Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool.

 

ScheduledExecutorService

scheduler (scheduler)

To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler.

none

Object

schedulerProperties (scheduler)

To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler.

 

Map

startScheduler (scheduler)

Whether the scheduler should be auto started.

true

boolean

timeUnit (scheduler)

Time unit for initialDelay and delay options.

Enum values:

  • NANOSECONDS
  • MICROSECONDS
  • MILLISECONDS
  • SECONDS
  • MINUTES
  • HOURS
  • DAYS

MILLISECONDS

TimeUnit

useFixedDelay (scheduler)

Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details.

true

boolean

shuffle (sort)

To shuffle the list of files (sort in random order).

false

boolean

sortBy (sort)

Built-in sort by using the File Language. Supports nested sorts, so you can have a sort by file name and as a 2nd group sort by modified date.

 

String

sorter (sort)

Pluggable sorter as a java.util.Comparator class.

 

Comparator

Note

Default behavior for file producer
By default it will override any existing file, if one exist with the same name.

34.6. Move and Delete operations

Any move or delete operations is executed after (post command) the routing has completed; so during processing of the Exchange the file is still located in the inbox folder.

Lets illustrate this with an example:

from("file://inbox?move=.done").to("bean:handleOrder");

When a file is dropped in the inbox folder, the file consumer notices this and creates a new FileExchange that is routed to the handleOrder bean. The bean then processes the File object. At this point in time the file is still located in the inbox folder. After the bean completes, and thus the route is completed, the file consumer will perform the move operation and move the file to the .done sub-folder.

The move and the preMove options are considered as a directory name (though if you use an expression such as File Language, or Simple then the result of the expression evaluation is the file name to be used. For example, if you set:

move=../backup/copy-of-${file:name}

then that’s using the File language which we use return the file name to be used), which can be either relative or absolute. If relative, the directory is created as a sub-folder from within the folder where the file was consumed.

By default, Camel will move consumed files to the .camel sub-folder relative to the directory where the file was consumed.

If you want to delete the file after processing, the route should be:

from("file://inbox?delete=true").to("bean:handleOrder");

We have introduced a pre move operation to move files before they are processed. This allows you to mark which files have been scanned as they are moved to this sub folder before being processed.

from("file://inbox?preMove=inprogress").to("bean:handleOrder");

You can combine the pre move and the regular move:

from("file://inbox?preMove=inprogress&move=.done").to("bean:handleOrder");

So in this situation, the file is in the inprogress folder when being processed and after it’s processed, it’s moved to the .done folder.

34.7. Fine grained control over Move and PreMove option

The move and preMove options are Expression-based, so we have the full power of the File Language to do advanced configuration of the directory and name pattern.
Camel will, in fact, internally convert the directory name you enter into a File Language expression. So when we enter move=.done Camel will convert this into: ${file:parent}/.done/${file:onlyname}. This is only done if Camel detects that you have not provided a $\{ } in the option value yourself. So when you enter a $\{ } Camel will not convert it and thus you have the full power.

So if we want to move the file into a backup folder with today’s date as the pattern, we can do:

move=backup/${date:now:yyyyMMdd}/${file:name}

34.8. About moveFailed

The moveFailed option allows you to move files that could not be processed successfully to another location such as an error folder of your choice. For example to move the files in an error folder with a timestamp you can use moveFailed=/error/${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.${\'\'file:ext}.

34.9. Message Headers

The following headers are supported by this component:

34.9.1. File producer only

HeaderDescription

CamelFileName

Specifies the name of the file to write (relative to the endpoint directory). This name can be a String; a String with a File Language or Simple language expression; or an Expression object. If it’s null then Camel will auto-generate a filename based on the message unique ID.

CamelFileNameProduced

The actual absolute filepath (path + name) for the output file that was written. This header is set by Camel and its purpose is providing end-users with the name of the file that was written.

CamelOverruleFileName

Is used for overruling CamelFileName header and use the value instead (but only once, as the producer will remove this header after writing the file). The value can be only be a String. Notice that if the option fileName has been configured, then this is still being evaluated.

34.9.2. File consumer only

HeaderDescription

CamelFileName

Name of the consumed file as a relative file path with offset from the starting directory configured on the endpoint.

CamelFileNameOnly

Only the file name (the name with no leading paths).

CamelFileAbsolute

A boolean option specifying whether the consumed file denotes an absolute path or not. Should normally be false for relative paths. Absolute paths should normally not be used but we added to the move option to allow moving files to absolute paths. But can be used elsewhere as well.

CamelFileAbsolutePath

The absolute path to the file. For relative files this path holds the relative path instead.

CamelFilePath

The file path. For relative files this is the starting directory + the relative filename. For absolute files this is the absolute path.

CamelFileRelativePath

The relative path.

CamelFileParent

The parent path.

CamelFileLength

A long value containing the file size.

CamelFileLastModified

A Long value containing the last modified timestamp of the file.

34.10. Batch Consumer

This component implements the Batch Consumer.

34.11. Exchange Properties, file consumer only

As the file consumer implements the BatchConsumer it supports batching the files it polls. By batching we mean that Camel will add the following additional properties to the Exchange, so you know the number of files polled, the current index, and whether the batch is already completed.

PropertyDescription

CamelBatchSize

The total number of files that was polled in this batch.

CamelBatchIndex

The current index of the batch. Starts from 0.

CamelBatchComplete

A boolean value indicating the last Exchange in the batch. Is only true for the last entry.

This allows you for instance to know how many files exist in this batch and for instance let the Aggregator2 aggregate this number of files.

34.12. Using charset

The charset option allows for configuring an encoding of the files on both the consumer and producer endpoints. For example if you read utf-8 files, and want to convert the files to iso-8859-1, you can do:

from("file:inbox?charset=utf-8")
  .to("file:outbox?charset=iso-8859-1")

You can also use the convertBodyTo in the route. In the example below we have still input files in utf-8 format, but we want to convert the file content to a byte array in iso-8859-1 format. And then let a bean process the data. Before writing the content to the outbox folder using the current charset.

from("file:inbox?charset=utf-8")
  .convertBodyTo(byte[].class, "iso-8859-1")
  .to("bean:myBean")
  .to("file:outbox");

If you omit the charset on the consumer endpoint, then Camel does not know the charset of the file, and would by default use "UTF-8". However you can configure a JVM system property to override and use a different default encoding with the key org.apache.camel.default.charset.

In the example below this could be a problem if the files is not in UTF-8 encoding, which would be the default encoding for read the files.
In this example when writing the files, the content has already been converted to a byte array, and thus would write the content directly as is (without any further encodings).

from("file:inbox")
  .convertBodyTo(byte[].class, "iso-8859-1")
  .to("bean:myBean")
  .to("file:outbox");

You can also override and control the encoding dynamic when writing files, by setting a property on the exchange with the key Exchange.CHARSET_NAME. For example in the route below we set the property with a value from a message header.

from("file:inbox")
  .convertBodyTo(byte[].class, "iso-8859-1")
  .to("bean:myBean")
  .setProperty(Exchange.CHARSET_NAME, header("someCharsetHeader"))
  .to("file:outbox");

We suggest to keep things simpler, so if you pickup files with the same encoding, and want to write the files in a specific encoding, then favor to use the charset option on the endpoints.

Notice that if you have explicit configured a charset option on the endpoint, then that configuration is used, regardless of the Exchange.CHARSET_NAME property.

If you have some issues then you can enable DEBUG logging on org.apache.camel.component.file, and Camel logs when it reads/write a file using a specific charset.
For example the route below will log the following:

from("file:inbox?charset=utf-8")
  .to("file:outbox?charset=iso-8859-1")

And the logs:

DEBUG GenericFileConverter           - Read file /Users/davsclaus/workspace/camel/camel-core/target/charset/input/input.txt with charset utf-8
DEBUG FileOperations                 - Using Reader to write file: target/charset/output.txt with charset: iso-8859-1

34.13. Common gotchas with folder and filenames

When Camel is producing files (writing files) there are a few gotchas affecting how to set a filename of your choice. By default, Camel will use the message ID as the filename, and since the message ID is normally a unique generated ID, you will end up with filenames such as: ID-MACHINENAME-2443-1211718892437-1-0. If such a filename is not desired, then you must provide a filename in the CamelFileName message header. The constant, Exchange.FILE_NAME, can also be used.

The sample code below produces files using the message ID as the filename:

from("direct:report").to("file:target/reports");

To use report.txt as the filename you have to do:

from("direct:report").setHeader(Exchange.FILE_NAME, constant("report.txt")).to( "file:target/reports");
  • the same as above, but with CamelFileName:
from("direct:report").setHeader("CamelFileName", constant("report.txt")).to( "file:target/reports");

And a syntax where we set the filename on the endpoint with the fileName URI option.

from("direct:report").to("file:target/reports/?fileName=report.txt");

34.14. Filename Expression

Filename can be set either using the expression option or as a string-based File language expression in the CamelFileName header. See the File language for syntax and samples.

34.15. Consuming files from folders where others drop files directly

Beware if you consume files from a folder where other applications write files to directly. Take a look at the different readLock options to see what suits your use cases. The best approach is however to write to another folder and after the write move the file in the drop folder. However if you write files directly to the drop folder then the option changed could better detect whether a file is currently being written/copied as it uses a file changed algorithm to see whether the file size / modification changes over a period of time. The other readLock options rely on Java File API that sadly is not always very good at detecting this. You may also want to look at the doneFileName option, which uses a marker file (done file) to signal when a file is done and ready to be consumed.

34.16. Using done files

See also section writing done files below.

If you want only to consume files when a done file exists, then you can use the doneFileName option on the endpoint.

from("file:bar?doneFileName=done");

Will only consume files from the bar folder, if a done file exists in the same directory as the target files. Camel will automatically delete the done file when it’s done consuming the files. Camel does not delete automatically the done file if noop=true is configured.

However it is more common to have one done file per target file. This means there is a 1:1 correlation. To do this you must use dynamic placeholders in the doneFileName option. Currently Camel supports the following two dynamic tokens: file:name and file:name.noext which must be enclosed in $\{ }. The consumer only supports the static part of the done file name as either prefix or suffix (not both).

from("file:bar?doneFileName=${file:name}.done");

In this example only files will be polled if there exists a done file with the name file name.done. For example

  • hello.txt - is the file to be consumed
  • hello.txt.done - is the associated done file

You can also use a prefix for the done file, such as:

from("file:bar?doneFileName=ready-${file:name}");
  • hello.txt - is the file to be consumed
  • ready-hello.txt - is the associated done file

34.17. Writing done files

After you have written a file you may want to write an additional donefile as a kind of marker, to indicate to others that the file is finished and has been written. To do that you can use the doneFileName option on the file producer endpoint.

.to("file:bar?doneFileName=done");

Will simply create a file named done in the same directory as the target file.

However it is more common to have one done file per target file. This means there is a 1:1 correlation. To do this you must use dynamic placeholders in the doneFileName option. Currently Camel supports the following two dynamic tokens: file:name and file:name.noext which must be enclosed in $\{ }.

.to("file:bar?doneFileName=done-${file:name}");

Will for example create a file named done-foo.txt if the target file was foo.txt in the same directory as the target file.

.to("file:bar?doneFileName=${file:name}.done");

Will for example create a file named foo.txt.done if the target file was foo.txt in the same directory as the target file.

.to("file:bar?doneFileName=${file:name.noext}.done");

Will for example create a file named foo.done if the target file was foo.txt in the same directory as the target file.

34.18. Samples

34.18.1. Read from a directory and write to another directory

from("file://inputdir/?delete=true").to("file://outputdir")

34.18.2. Read from a directory and write to another directory using a overrule dynamic name

from("file://inputdir/?delete=true").to("file://outputdir?overruleFile=copy-of-${file:name}")

Listen on a directory and create a message for each file dropped there. Copy the contents to the outputdir and delete the file in the inputdir.

34.18.3. Reading recursively from a directory and writing to another

from("file://inputdir/?recursive=true&delete=true").to("file://outputdir")

Listen on a directory and create a message for each file dropped there. Copy the contents to the outputdir and delete the file in the inputdir. Will scan recursively into sub-directories. Will lay out the files in the same directory structure in the outputdir as the inputdir, including any sub-directories.

inputdir/foo.txt
inputdir/sub/bar.txt

Will result in the following output layout:

outputdir/foo.txt
outputdir/sub/bar.txt

34.19. Using flatten

If you want to store the files in the outputdir directory in the same directory, disregarding the source directory layout (e.g. to flatten out the path), you just add the flatten=true option on the file producer side:

from("file://inputdir/?recursive=true&delete=true").to("file://outputdir?flatten=true")

Will result in the following output layout:

outputdir/foo.txt
outputdir/bar.txt

34.20. Reading from a directory and the default move operation

Camel will by default move any processed file into a .camel subdirectory in the directory the file was consumed from.

from("file://inputdir/?recursive=true&delete=true").to("file://outputdir")

Affects the layout as follows:
before

inputdir/foo.txt
inputdir/sub/bar.txt

after

inputdir/.camel/foo.txt
inputdir/sub/.camel/bar.txt
outputdir/foo.txt
outputdir/sub/bar.txt

34.21. Read from a directory and process the message in java

from("file://inputdir/").process(new Processor() {
  public void process(Exchange exchange) throws Exception {
    Object body = exchange.getIn().getBody();
    // do some business logic with the input body
  }
});

The body will be a File object that points to the file that was just dropped into the inputdir directory.

34.22. Writing to files

Camel is of course also able to write files, i.e. produce files. In the sample below we receive some reports on the SEDA queue that we process before they are being written to a directory.

34.22.1. Write to subdirectory using Exchange.FILE_NAME

Using a single route, it is possible to write a file to any number of subdirectories. If you have a route setup as such:

<route>
  <from uri="bean:myBean"/>
  <to uri="file:/rootDirectory"/>
</route>

You can have myBean set the header Exchange.FILE_NAME to values such as:

Exchange.FILE_NAME = hello.txt => /rootDirectory/hello.txt
Exchange.FILE_NAME = foo/bye.txt => /rootDirectory/foo/bye.txt

This allows you to have a single route to write files to multiple destinations.

34.22.2. Writing file through the temporary directory relative to the final destination

Sometime you need to temporarily write the files to some directory relative to the destination directory. Such situation usually happens when some external process with limited filtering capabilities is reading from the directory you are writing to. In the example below files will be written to the /var/myapp/filesInProgress directory and after data transfer is done, they will be atomically moved to the` /var/myapp/finalDirectory `directory.

from("direct:start").
  to("file:///var/myapp/finalDirectory?tempPrefix=/../filesInProgress/");

34.23. Using expression for filenames

In this sample we want to move consumed files to a backup folder using today’s date as a sub-folder name:

from("file://inbox?move=backup/${date:now:yyyyMMdd}/${file:name}").to("...");

See File language for more samples.

34.24. Avoiding reading the same file more than once (idempotent consumer)

Camel supports Idempotent Consumer directly within the component so it will skip already processed files. This feature can be enabled by setting the idempotent=true option.

from("file://inbox?idempotent=true").to("...");

Camel uses the absolute file name as the idempotent key, to detect duplicate files. You can customize this key by using an expression in the idempotentKey option. For example to use both the name and the file size as the key

<route>
  <from uri="file://inbox?idempotent=true&amp;idempotentKey=${file:name}-${file:size}"/>
  <to uri="bean:processInbox"/>
</route>

By default Camel uses a in memory based store for keeping track of consumed files, it uses a least recently used cache holding up to 1000 entries. You can plugin your own implementation of this store by using the idempotentRepository option using the # sign in the value to indicate it’s a referring to a bean in the Registry with the specified id.

 <!-- define our store as a plain spring bean -->
 <bean id="myStore" class="com.mycompany.MyIdempotentStore"/>

<route>
  <from uri="file://inbox?idempotent=true&amp;idempotentRepository=#myStore"/>
  <to uri="bean:processInbox"/>
</route>

Camel will log at DEBUG level if it skips a file because it has been consumed before:

DEBUG FileConsumer is idempotent and the file has been consumed before. Will skip this file: target\idempotent\report.txt

34.25. Using a file based idempotent repository

In this section we will use the file based idempotent repository org.apache.camel.processor.idempotent.FileIdempotentRepository instead of the in-memory based that is used as default.
This repository uses a 1st level cache to avoid reading the file repository. It will only use the file repository to store the content of the 1st level cache. Thereby the repository can survive server restarts. It will load the content of the file into the 1st level cache upon startup. The file structure is very simple as it stores the key in separate lines in the file. By default, the file store has a size limit of 1mb. When the file grows larger Camel will truncate the file store, rebuilding the content by flushing the 1st level cache into a fresh empty file.

We configure our repository using Spring XML creating our file idempotent repository and define our file consumer to use our repository with the idempotentRepository using # sign to indicate Registry lookup:

34.26. Using a JPA based idempotent repository

In this section we will use the JPA based idempotent repository instead of the in-memory based that is used as default.

First we need a persistence-unit in META-INF/persistence.xml where we need to use the class org.apache.camel.processor.idempotent.jpa.MessageProcessed as model.

<persistence-unit name="idempotentDb" transaction-type="RESOURCE_LOCAL">
  <class>org.apache.camel.processor.idempotent.jpa.MessageProcessed</class>

  <properties>
    <property name="openjpa.ConnectionURL" value="jdbc:derby:target/idempotentTest;create=true"/>
    <property name="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.EmbeddedDriver"/>
    <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
    <property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO"/>
    <property name="openjpa.Multithreaded" value="true"/>
  </properties>
</persistence-unit>

Next, we can create our JPA idempotent repository in the spring XML file as well:

<!-- we define our jpa based idempotent repository we want to use in the file consumer -->
<bean id="jpaStore" class="org.apache.camel.processor.idempotent.jpa.JpaMessageIdRepository">
    <!-- Here we refer to the entityManagerFactory -->
    <constructor-arg index="0" ref="entityManagerFactory"/>
    <!-- This 2nd parameter is the name  (= a category name).
         You can have different repositories with different names -->
    <constructor-arg index="1" value="FileConsumer"/>
</bean>

And yes then we just need to refer to the jpaStore bean in the file consumer endpoint using the idempotentRepository using the # syntax option:

<route>
  <from uri="file://inbox?idempotent=true&amp;idempotentRepository=#jpaStore"/>
  <to uri="bean:processInbox"/>
</route>

34.27. Filter using org.apache.camel.component.file.GenericFileFilter

Camel supports pluggable filtering strategies. You can then configure the endpoint with such a filter to skip certain files being processed.

In the sample we have built our own filter that skips files starting with skip in the filename:

And then we can configure our route using the filter attribute to reference our filter (using # notation) that we have defined in the spring XML file:

<!-- define our filter as a plain spring bean -->
<bean id="myFilter" class="com.mycompany.MyFileFilter"/>

<route>
  <from uri="file://inbox?filter=#myFilter"/>
  <to uri="bean:processInbox"/>
</route>

34.28. Filtering using ANT path matcher

The ANT path matcher is based on AntPathMatcher.

The file paths is matched with the following rules:

  • ? matches one character
  • * matches zero or more characters
  • ** matches zero or more directories in a path

The antInclude and antExclude options make it easy to specify ANT style include/exclude without having to define the filter. See the URI options above for more information. The sample below demonstrates how to use it.

Note

When using minDepth/maxDepth with the combination of recursive=true, antExclude=…​, and readLockDeleteOrphanLockFiles=true results in scanning all the files/subfolders deeper than value mentioned in the maxDepth. The workaround is to configure readLockDeleteOrphanLockFiles=false.

34.28.1. Sorting using Comparator

Camel supports pluggable sorting strategies. This strategy it to use the build in java.util.Comparator in Java. You can then configure the endpoint with such a comparator and have Camel sort the files before being processed.

In the sample we have built our own comparator that just sorts by file name:

And then we can configure our route using the sorter option to reference to our sorter (mySorter) we have defined in the spring XML file:

 <!-- define our sorter as a plain spring bean -->
 <bean id="mySorter" class="com.mycompany.MyFileSorter"/>

<route>
  <from uri="file://inbox?sorter=#mySorter"/>
  <to uri="bean:processInbox"/>
</route>
Note

URI options can reference beans using the # syntax
In the Spring DSL route above notice that we can refer to beans in the Registry by prefixing the id with #. So writing sorter=#mySorter, will instruct Camel to go look in the Registry for a bean with the ID, mySorter.

34.28.2. Sorting using sortBy

Camel supports pluggable sorting strategies. This strategy it to use the File language to configure the sorting. The sortBy option is configured as follows:

sortBy=group 1;group 2;group 3;...

Where each group is separated with semi colon. In the simple situations you just use one group, so a simple example could be:

sortBy=file:name

This will sort by file name, you can reverse the order by prefixing reverse: to the group, so the sorting is now Z..A:

sortBy=reverse:file:name

As we have the full power of File language we can use some of the other parameters, so if we want to sort by file size we do:

sortBy=file:length

You can configure to ignore the case, using ignoreCase: for string comparison, so if you want to use file name sorting but to ignore the case then we do:

sortBy=ignoreCase:file:name

You can combine ignore case and reverse, however reverse must be specified first:

sortBy=reverse:ignoreCase:file:name

In the sample below we want to sort by last modified file, so we do:

sortBy=file:modified

And then we want to group by name as a 2nd option so files with same modifcation is sorted by name:

sortBy=file:modified;file:name

Now there is an issue here, can you spot it? Well the modified timestamp of the file is too fine as it will be in milliseconds, but what if we want to sort by date only and then subgroup by name?
Well as we have the true power of File language we can use its date command that supports patterns. So this can be solved as:

sortBy=date:file:yyyyMMdd;file:name

Yeah, that is pretty powerful, oh by the way you can also use reverse per group, so we could reverse the file names:

sortBy=date:file:yyyyMMdd;reverse:file:name

34.29. Using GenericFileProcessStrategy

The option processStrategy can be used to use a custom GenericFileProcessStrategy that allows you to implement your own begin, commit and rollback logic.
For instance lets assume a system writes a file in a folder you should consume. But you should not start consuming the file before another ready file has been written as well.

So by implementing our own GenericFileProcessStrategy we can implement this as:

  • In the begin() method we can test whether the special ready file exists. The begin method returns a boolean to indicate if we can consume the file or not.
  • In the abort() method special logic can be executed in case the begin operation returned false, for example to cleanup resources etc.
  • in the commit() method we can move the actual file and also delete the ready file.

34.30. Using filter

The filter option allows you to implement a custom filter in Java code by implementing the org.apache.camel.component.file.GenericFileFilter interface. This interface has an accept method that returns a boolean. Return true to include the file, and false to skip the file. There is a isDirectory method on GenericFile whether the file is a directory. This allows you to filter unwanted directories, to avoid traversing down unwanted directories.

For example to skip any directories which starts with "skip" in the name, can be implemented as follows:

34.31. Using bridgeErrorHandler

If you want to use the Camel Error Handler to deal with any exception occurring in the file consumer, then you can enable the bridgeErrorHandler option as shown below:

// to handle any IOException being thrown
onException(IOException.class)
    .handled(true)
    .log("IOException occurred due: ${exception.message}")
    .transform().simple("Error ${exception.message}")
    .to("mock:error");

// this is the file route that pickup files, notice how we bridge the consumer to use the Camel routing error handler
// the exclusiveReadLockStrategy is only configured because this is from an unit test, so we use that to simulate exceptions
from("file:target/nospace?bridgeErrorHandler=true")
    .convertBodyTo(String.class)
    .to("mock:result");

So all you have to do is to enable this option, and the error handler in the route will take it from there.

Important

When using bridgeErrorHandler
When using bridgeErrorHandler, then interceptors, OnCompletions does not apply. The Exchange is processed directly by the Camel Error Handler, and does not allow prior actions such as interceptors, onCompletion to take action.

34.32. Debug logging

This component has log level TRACE that can be helpful if you have problems.

34.33. Spring Boot Auto-Configuration

The component supports 11 options, which are listed below.

NameDescriptionDefaultType

camel.cluster.file.acquire-lock-delay

The time to wait before starting to try to acquire lock.

 

String

camel.cluster.file.acquire-lock-interval

The time to wait between attempts to try to acquire lock.

 

String

camel.cluster.file.attributes

Custom service attributes.

 

Map

camel.cluster.file.enabled

Sets if the file cluster service should be enabled or not, default is false.

false

Boolean

camel.cluster.file.id

Cluster Service ID.

 

String

camel.cluster.file.order

Service lookup order/priority.

 

Integer

camel.cluster.file.root

The root path.

 

String

camel.component.file.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.file.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.file.enabled

Whether to enable auto configuration of the file component. This is enabled by default.

 

Boolean

camel.component.file.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

Chapter 35. File language

The File Expression Language is an extension to the language, adding file related capabilities. These capabilities are related to common use cases working with file path and names. The goal is to allow expressions to be used with the

components for setting dynamic file patterns for both consumer and producer.

Note

The file language is merged with language which means you can use all the file syntax directly within the simple language.

35.1. Dependencies

The File language is part of camel-core.

When using file with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-core-starter</artifactId>
</dependency>

35.2. File Language options

The File language supports 2 options, which are listed below.

NameDefaultJava TypeDescription

resultType

 

String

Sets the class name of the result type (type from output).

trim

 

Boolean

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

35.3. Syntax

This language is an extension to the language so the syntax applies also. So the table below only lists the additional file related functions.

All the file tokens use the same expression name as the method on the java.io.File object, for instance file:absolute refers to the java.io.File.getAbsolute() method. Notice that not all expressions are supported by the current Exchange. For instance the component supports some options, whereas the File component supports all of them.

ExpressionTypeFile ConsumerFile ProducerFTP ConsumerFTP ProducerDescription

file:name

String

yes

no

yes

no

refers to the file name (is relative to the starting directory, see note below)

file:name.ext

String

yes

no

yes

no

refers to the file extension only

file:name.ext.single

String

yes

no

yes

no

refers to the file extension. If the file extension has multiple dots, then this expression strips and only returns the last part.

file:name.noext

String

yes

no

yes

no

refers to the file name with no extension (is relative to the starting directory, see note below)

file:name.noext.single

String

yes

no

yes

no

refers to the file name with no extension (is relative to the starting directory, see note below). If the file extension has multiple dots, then this expression strips only the last part, and keep the others.

file:onlyname

String

yes

no

yes

no

refers to the file name only with no leading paths.

file:onlyname.noext

String

yes

no

yes

no

refers to the file name only with no extension and with no leading paths.

file:onlyname.noext.single

String

yes

no

yes

no

refers to the file name only with no extension and with no leading paths. If the file extension has multiple dots, then this expression strips only the last part, and keep the others.

file:ext

String

yes

no

yes

no

refers to the file extension only

file:parent

String

yes

no

yes

no

refers to the file parent

file:path

String

yes

no

yes

no

refers to the file path

file:absolute

Boolean

yes

no

no

no

refers to whether the file is regarded as absolute or relative

file:absolute.path

String

yes

no

no

no

refers to the absolute file path

file:length

Long

yes

no

yes

no

refers to the file length returned as a Long type

file:size

Long

yes

no

yes

no

refers to the file length returned as a Long type

file:modified

Date

yes

no

yes

no

Refers to the file last modified returned as a Date type

date:_command:pattern_

String

yes

yes

yes

yes

for date formatting using the java.text.SimpleDateFormat patterns. Is an extension to the language. Additional command is: file (consumers only) for the last modified timestamp of the file. Notice: all the commands from the language can also be used.

35.4. File token example

35.4.1. Relative paths

We have a java.io.File handle for the file hello.txt in the following relative directory: .\filelanguage\test. And we configure our endpoint to use this starting directory .\filelanguage. The file tokens will return as:

ExpressionReturns

file:name

test\hello.txt

file:name.ext

txt

file:name.noext

test\hello

file:onlyname

hello.txt

file:onlyname.noext

hello

file:ext

txt

file:parent

filelanguage\test

file:path

filelanguage\test\hello.txt

file:absolute

false

file:absolute.path

\workspace\camel\camel-core\target\filelanguage\test\hello.txt

35.4.2. Absolute paths

We have a java.io.File handle for the file hello.txt in the following absolute directory: \workspace\camel\camel-core\target\filelanguage\test. And we configure out endpoint to use the absolute starting directory \workspace\camel\camel-core\target\filelanguage. The file tokens will return as:

ExpressionReturns

file:name

test\hello.txt

file:name.ext

txt

file:name.noext

test\hello

file:onlyname

hello.txt

file:onlyname.noext

hello

file:ext

txt

file:parent

\workspace\camel\camel-core\target\filelanguage\test

file:path

\workspace\camel\camel-core\target\filelanguage\test\hello.txt

file:absolute

true

file:absolute.path

\workspace\camel\camel-core\target\filelanguage\test\hello.txt

35.5. Samples

You can enter a fixed file name such as myfile.txt:

fileName="myfile.txt"

Let’s assume we use the file consumer to read files and want to move the read files to back up folder with the current date as a sub folder. This can be done using an expression like:

fileName="backup/${date:now:yyyyMMdd}/${file:name.noext}.bak"

relative folder names are also supported so suppose the backup folder should be a sibling folder then you can append .. as shown:

fileName="../backup/${date:now:yyyyMMdd}/${file:name.noext}.bak"

As this is an extension to the language we have access to all the goodies from this language also, so in this use case we want to use the in.header.type as a parameter in the dynamic expression:

fileName="../backup/${date:now:yyyyMMdd}/type-${in.header.type}/backup-of-${file:name.noext}.bak"

If you have a custom date you want to use in the expression then Camel supports retrieving dates from the message header:

fileName="orders/order-${in.header.customerId}-${date:in.header.orderDate:yyyyMMdd}.xml"

And finally we can also use a bean expression to invoke a POJO class that generates some String output (or convertible to String) to be used:

fileName="uniquefile-${bean:myguidgenerator.generateid}.txt"

Of course all this can be combined in one expression where you can use the and the language in one combined expression. This is pretty powerful for those common file path patterns.

35.6. Spring Boot Auto-Configuration

The component supports 147 options, which are listed below.

NameDescriptionDefaultType

camel.cloud.consul.service-discovery.acl-token

Sets the ACL token to be used with Consul.

 

String

camel.cloud.consul.service-discovery.block-seconds

The seconds to wait for a watch event, default 10 seconds.

10

Integer

camel.cloud.consul.service-discovery.configurations

Define additional configuration definitions.

 

Map

camel.cloud.consul.service-discovery.connect-timeout-millis

Connect timeout for OkHttpClient.

 

Long

camel.cloud.consul.service-discovery.datacenter

The data center.

 

String

camel.cloud.consul.service-discovery.enabled

Enable the component.

true

Boolean

camel.cloud.consul.service-discovery.password

Sets the password to be used for basic authentication.

 

String

camel.cloud.consul.service-discovery.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.consul.service-discovery.read-timeout-millis

Read timeout for OkHttpClient.

 

Long

camel.cloud.consul.service-discovery.url

The Consul agent URL.

 

String

camel.cloud.consul.service-discovery.user-name

Sets the username to be used for basic authentication.

 

String

camel.cloud.consul.service-discovery.write-timeout-millis

Write timeout for OkHttpClient.

 

Long

camel.cloud.dns.service-discovery.configurations

Define additional configuration definitions.

 

Map

camel.cloud.dns.service-discovery.domain

The domain name;.

 

String

camel.cloud.dns.service-discovery.enabled

Enable the component.

true

Boolean

camel.cloud.dns.service-discovery.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.dns.service-discovery.proto

The transport protocol of the desired service.

_tcp

String

camel.cloud.etcd.service-discovery.configurations

Define additional configuration definitions.

 

Map

camel.cloud.etcd.service-discovery.enabled

Enable the component.

true

Boolean

camel.cloud.etcd.service-discovery.password

The password to use for basic authentication.

 

String

camel.cloud.etcd.service-discovery.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.etcd.service-discovery.service-path

The path to look for for service discovery.

/services/

String

camel.cloud.etcd.service-discovery.timeout

To set the maximum time an action could take to complete.

 

Long

camel.cloud.etcd.service-discovery.type

To set the discovery type, valid values are on-demand and watch.

on-demand

String

camel.cloud.etcd.service-discovery.uris

The URIs the client can connect to.

 

String

camel.cloud.etcd.service-discovery.user-name

The user name to use for basic authentication.

 

String

camel.cloud.kubernetes.service-discovery.api-version

Sets the API version when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.ca-cert-data

Sets the Certificate Authority data when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.ca-cert-file

Sets the Certificate Authority data that are loaded from the file when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-cert-data

Sets the Client Certificate data when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-cert-file

Sets the Client Certificate data that are loaded from the file when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-key-algo

Sets the Client Keystore algorithm, such as RSA when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-key-data

Sets the Client Keystore data when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-key-file

Sets the Client Keystore data that are loaded from the file when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-key-passphrase

Sets the Client Keystore passphrase when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.configurations

Define additional configuration definitions.

 

Map

camel.cloud.kubernetes.service-discovery.dns-domain

Sets the DNS domain to use for DNS lookup.

 

String

camel.cloud.kubernetes.service-discovery.enabled

Enable the component.

true

Boolean

camel.cloud.kubernetes.service-discovery.lookup

How to perform service lookup. Possible values: client, dns, environment. When using client, then the client queries the kubernetes master to obtain a list of active pods that provides the service, and then random (or round robin) select a pod. When using dns the service name is resolved as name.namespace.svc.dnsDomain. When using dnssrv the service name is resolved with SRV query for .…​svc…​ When using environment then environment variables are used to lookup the service. By default environment is used.

environment

String

camel.cloud.kubernetes.service-discovery.master-url

Sets the URL to the master when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.namespace

Sets the namespace to use. Will by default use namespace from the ENV variable KUBERNETES_MASTER.

 

String

camel.cloud.kubernetes.service-discovery.oauth-token

Sets the OAUTH token for authentication (instead of username/password) when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.password

Sets the password for authentication when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.port-name

Sets the Port Name to use for DNS/DNSSRV lookup.

 

String

camel.cloud.kubernetes.service-discovery.port-protocol

Sets the Port Protocol to use for DNS/DNSSRV lookup.

 

String

camel.cloud.kubernetes.service-discovery.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.kubernetes.service-discovery.trust-certs

Sets whether to turn on trust certificate check when using client lookup.

false

Boolean

camel.cloud.kubernetes.service-discovery.username

Sets the username for authentication when using client lookup.

 

String

camel.cloud.ribbon.load-balancer.client-name

Sets the Ribbon client name.

 

String

camel.cloud.ribbon.load-balancer.configurations

Define additional configuration definitions.

 

Map

camel.cloud.ribbon.load-balancer.enabled

Enable the component.

true

Boolean

camel.cloud.ribbon.load-balancer.namespace

The namespace.

 

String

camel.cloud.ribbon.load-balancer.password

The password.

 

String

camel.cloud.ribbon.load-balancer.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.ribbon.load-balancer.username

The username.

 

String

camel.hystrix.allow-maximum-size-to-diverge-from-core-size

Allows the configuration for maximumSize to take effect. That value can then be equal to, or higher, than coreSize.

false

Boolean

camel.hystrix.circuit-breaker-enabled

Whether to use a HystrixCircuitBreaker or not. If false no circuit-breaker logic will be used and all requests permitted. This is similar in effect to circuitBreakerForceClosed() except that continues tracking metrics and knowing whether it should be open/closed, this property results in not even instantiating a circuit-breaker.

true

Boolean

camel.hystrix.circuit-breaker-error-threshold-percentage

Error percentage threshold (as whole number such as 50) at which point the circuit breaker will trip open and reject requests. It will stay tripped for the duration defined in circuitBreakerSleepWindowInMilliseconds; The error percentage this is compared against comes from HystrixCommandMetrics.getHealthCounts().

50

Integer

camel.hystrix.circuit-breaker-force-closed

If true the HystrixCircuitBreaker#allowRequest() will always return true to allow requests regardless of the error percentage from HystrixCommandMetrics.getHealthCounts(). The circuitBreakerForceOpen() property takes precedence so if it set to true this property does nothing.

false

Boolean

camel.hystrix.circuit-breaker-force-open

If true the HystrixCircuitBreaker.allowRequest() will always return false, causing the circuit to be open (tripped) and reject all requests. This property takes precedence over circuitBreakerForceClosed();.

false

Boolean

camel.hystrix.circuit-breaker-request-volume-threshold

Minimum number of requests in the metricsRollingStatisticalWindowInMilliseconds() that must exist before the HystrixCircuitBreaker will trip. If below this number the circuit will not trip regardless of error percentage.

20

Integer

camel.hystrix.circuit-breaker-sleep-window-in-milliseconds

The time in milliseconds after a HystrixCircuitBreaker trips open that it should wait before trying requests again.

5000

Integer

camel.hystrix.configurations

Define additional configuration definitions.

 

Map

camel.hystrix.core-pool-size

Core thread-pool size that gets passed to java.util.concurrent.ThreadPoolExecutor#setCorePoolSize(int).

10

Integer

camel.hystrix.enabled

Enable the component.

true

Boolean

camel.hystrix.execution-isolation-semaphore-max-concurrent-requests

Number of concurrent requests permitted to HystrixCommand.run(). Requests beyond the concurrent limit will be rejected. Applicable only when executionIsolationStrategy == SEMAPHORE.

20

Integer

camel.hystrix.execution-isolation-strategy

What isolation strategy HystrixCommand.run() will be executed with. If THREAD then it will be executed on a separate thread and concurrent requests limited by the number of threads in the thread-pool. If SEMAPHORE then it will be executed on the calling thread and concurrent requests limited by the semaphore count.

THREAD

String

camel.hystrix.execution-isolation-thread-interrupt-on-timeout

Whether the execution thread should attempt an interrupt (using Future#cancel ) when a thread times out. Applicable only when executionIsolationStrategy() == THREAD.

true

Boolean

camel.hystrix.execution-timeout-enabled

Whether the timeout mechanism is enabled for this command.

true

Boolean

camel.hystrix.execution-timeout-in-milliseconds

Time in milliseconds at which point the command will timeout and halt execution. If executionIsolationThreadInterruptOnTimeout == true and the command is thread-isolated, the executing thread will be interrupted. If the command is semaphore-isolated and a HystrixObservableCommand, that command will get unsubscribed.

1000

Integer

camel.hystrix.fallback-enabled

Whether HystrixCommand.getFallback() should be attempted when failure occurs.

true

Boolean

camel.hystrix.fallback-isolation-semaphore-max-concurrent-requests

Number of concurrent requests permitted to HystrixCommand.getFallback(). Requests beyond the concurrent limit will fail-fast and not attempt retrieving a fallback.

10

Integer

camel.hystrix.group-key

Sets the group key to use. The default value is CamelHystrix.

CamelHystrix

String

camel.hystrix.keep-alive-time

Keep-alive time in minutes that gets passed to ThreadPoolExecutor#setKeepAliveTime(long,TimeUnit).

1

Integer

camel.hystrix.max-queue-size

Max queue size that gets passed to BlockingQueue in HystrixConcurrencyStrategy.getBlockingQueue(int) This should only affect the instantiation of a threadpool - it is not eliglible to change a queue size on the fly. For that, use queueSizeRejectionThreshold().

-1

Integer

camel.hystrix.maximum-size

Maximum thread-pool size that gets passed to ThreadPoolExecutor#setMaximumPoolSize(int) . This is the maximum amount of concurrency that can be supported without starting to reject HystrixCommands. Please note that this setting only takes effect if you also set allowMaximumSizeToDivergeFromCoreSize.

10

Integer

camel.hystrix.metrics-health-snapshot-interval-in-milliseconds

Time in milliseconds to wait between allowing health snapshots to be taken that calculate success and error percentages and affect HystrixCircuitBreaker.isOpen() status. On high-volume circuits the continual calculation of error percentage can become CPU intensive thus this controls how often it is calculated.

500

Integer

camel.hystrix.metrics-rolling-percentile-bucket-size

Maximum number of values stored in each bucket of the rolling percentile. This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.

10

Integer

camel.hystrix.metrics-rolling-percentile-enabled

Whether percentile metrics should be captured using HystrixRollingPercentile inside HystrixCommandMetrics.

true

Boolean

camel.hystrix.metrics-rolling-percentile-window-buckets

Number of buckets the rolling percentile window is broken into. This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.

6

Integer

camel.hystrix.metrics-rolling-percentile-window-in-milliseconds

Duration of percentile rolling window in milliseconds. This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.

10000

Integer

camel.hystrix.metrics-rolling-statistical-window-buckets

Number of buckets the rolling statistical window is broken into. This is passed into HystrixRollingNumber inside HystrixCommandMetrics.

10

Integer

camel.hystrix.metrics-rolling-statistical-window-in-milliseconds

This property sets the duration of the statistical rolling window, in milliseconds. This is how long metrics are kept for the thread pool. The window is divided into buckets and rolls by those increments.

10000

Integer

camel.hystrix.queue-size-rejection-threshold

Queue size rejection threshold is an artificial max size at which rejections will occur even if maxQueueSize has not been reached. This is done because the maxQueueSize of a BlockingQueue can not be dynamically changed and we want to support dynamically changing the queue size that affects rejections. This is used by HystrixCommand when queuing a thread for execution.

5

Integer

camel.hystrix.request-log-enabled

Whether HystrixCommand execution and events should be logged to HystrixRequestLog.

true

Boolean

camel.hystrix.thread-pool-key

Sets the thread pool key to use. Will by default use the same value as groupKey has been configured to use.

CamelHystrix

String

camel.hystrix.thread-pool-rolling-number-statistical-window-buckets

Number of buckets the rolling statistical window is broken into. This is passed into HystrixRollingNumber inside each HystrixThreadPoolMetrics instance.

10

Integer

camel.hystrix.thread-pool-rolling-number-statistical-window-in-milliseconds

Duration of statistical rolling window in milliseconds. This is passed into HystrixRollingNumber inside each HystrixThreadPoolMetrics instance.

10000

Integer

camel.language.constant.enabled

Whether to enable auto configuration of the constant language. This is enabled by default.

 

Boolean

camel.language.constant.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.csimple.enabled

Whether to enable auto configuration of the csimple language. This is enabled by default.

 

Boolean

camel.language.csimple.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.exchangeproperty.enabled

Whether to enable auto configuration of the exchangeProperty language. This is enabled by default.

 

Boolean

camel.language.exchangeproperty.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.file.enabled

Whether to enable auto configuration of the file language. This is enabled by default.

 

Boolean

camel.language.file.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.header.enabled

Whether to enable auto configuration of the header language. This is enabled by default.

 

Boolean

camel.language.header.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.ref.enabled

Whether to enable auto configuration of the ref language. This is enabled by default.

 

Boolean

camel.language.ref.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.simple.enabled

Whether to enable auto configuration of the simple language. This is enabled by default.

 

Boolean

camel.language.simple.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.tokenize.enabled

Whether to enable auto configuration of the tokenize language. This is enabled by default.

 

Boolean

camel.language.tokenize.group-delimiter

Sets the delimiter to use when grouping. If this has not been set then token will be used as the delimiter.

 

String

camel.language.tokenize.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.resilience4j.automatic-transition-from-open-to-half-open-enabled

Enables automatic transition from OPEN to HALF_OPEN state once the waitDurationInOpenState has passed.

false

Boolean

camel.resilience4j.circuit-breaker-ref

Refers to an existing io.github.resilience4j.circuitbreaker.CircuitBreaker instance to lookup and use from the registry. When using this, then any other circuit breaker options are not in use.

 

String

camel.resilience4j.config-ref

Refers to an existing io.github.resilience4j.circuitbreaker.CircuitBreakerConfig instance to lookup and use from the registry.

 

String

camel.resilience4j.configurations

Define additional configuration definitions.

 

Map

camel.resilience4j.enabled

Enable the component.

true

Boolean

camel.resilience4j.failure-rate-threshold

Configures the failure rate threshold in percentage. If the failure rate is equal or greater than the threshold the CircuitBreaker transitions to open and starts short-circuiting calls. The threshold must be greater than 0 and not greater than 100. Default value is 50 percentage.

 

Float

camel.resilience4j.minimum-number-of-calls

Configures the minimum number of calls which are required (per sliding window period) before the CircuitBreaker can calculate the error rate. For example, if minimumNumberOfCalls is 10, then at least 10 calls must be recorded, before the failure rate can be calculated. If only 9 calls have been recorded the CircuitBreaker will not transition to open even if all 9 calls have failed. Default minimumNumberOfCalls is 100.

100

Integer

camel.resilience4j.permitted-number-of-calls-in-half-open-state

Configures the number of permitted calls when the CircuitBreaker is half open. The size must be greater than 0. Default size is 10.

10

Integer

camel.resilience4j.sliding-window-size

Configures the size of the sliding window which is used to record the outcome of calls when the CircuitBreaker is closed. slidingWindowSize configures the size of the sliding window. Sliding window can either be count-based or time-based. If slidingWindowType is COUNT_BASED, the last slidingWindowSize calls are recorded and aggregated. If slidingWindowType is TIME_BASED, the calls of the last slidingWindowSize seconds are recorded and aggregated. The slidingWindowSize must be greater than 0. The minimumNumberOfCalls must be greater than 0. If the slidingWindowType is COUNT_BASED, the minimumNumberOfCalls cannot be greater than slidingWindowSize . If the slidingWindowType is TIME_BASED, you can pick whatever you want. Default slidingWindowSize is 100.

100

Integer

camel.resilience4j.sliding-window-type

Configures the type of the sliding window which is used to record the outcome of calls when the CircuitBreaker is closed. Sliding window can either be count-based or time-based. If slidingWindowType is COUNT_BASED, the last slidingWindowSize calls are recorded and aggregated. If slidingWindowType is TIME_BASED, the calls of the last slidingWindowSize seconds are recorded and aggregated. Default slidingWindowType is COUNT_BASED.

COUNT_BASED

String

camel.resilience4j.slow-call-duration-threshold

Configures the duration threshold (seconds) above which calls are considered as slow and increase the slow calls percentage. Default value is 60 seconds.

60

Integer

camel.resilience4j.slow-call-rate-threshold

Configures a threshold in percentage. The CircuitBreaker considers a call as slow when the call duration is greater than slowCallDurationThreshold Duration. When the percentage of slow calls is equal or greater the threshold, the CircuitBreaker transitions to open and starts short-circuiting calls. The threshold must be greater than 0 and not greater than 100. Default value is 100 percentage which means that all recorded calls must be slower than slowCallDurationThreshold.

 

Float

camel.resilience4j.wait-duration-in-open-state

Configures the wait duration (in seconds) which specifies how long the CircuitBreaker should stay open, before it switches to half open. Default value is 60 seconds.

60

Integer

camel.resilience4j.writable-stack-trace-enabled

Enables writable stack traces. When set to false, Exception.getStackTrace returns a zero length array. This may be used to reduce log spam when the circuit breaker is open as the cause of the exceptions is already known (the circuit breaker is short-circuiting calls).

true

Boolean

camel.rest.api-component

The name of the Camel component to use as the REST API (such as swagger) If no API Component has been explicit configured, then Camel will lookup if there is a Camel component responsible for servicing and generating the REST API documentation, or if a org.apache.camel.spi.RestApiProcessorFactory is registered in the registry. If either one is found, then that is being used.

 

String

camel.rest.api-context-path

Sets a leading API context-path the REST API services will be using. This can be used when using components such as camel-servlet where the deployed web application is deployed using a context-path.

 

String

camel.rest.api-context-route-id

Sets the route id to use for the route that services the REST API. The route will by default use an auto assigned route id.

 

String

camel.rest.api-host

To use an specific hostname for the API documentation (eg swagger) This can be used to override the generated host with this configured hostname.

 

String

camel.rest.api-property

Allows to configure as many additional properties for the api documentation (swagger). For example set property api.title to my cool stuff.

 

Map

camel.rest.api-vendor-extension

Whether vendor extension is enabled in the Rest APIs. If enabled then Camel will include additional information as vendor extension (eg keys starting with x-) such as route ids, class names etc. Not all 3rd party API gateways and tools supports vendor-extensions when importing your API docs.

false

Boolean

camel.rest.binding-mode

Sets the binding mode to use. The default value is off.

 

RestBindingMode

camel.rest.client-request-validation

Whether to enable validation of the client request to check whether the Content-Type and Accept headers from the client is supported by the Rest-DSL configuration of its consumes/produces settings. This can be turned on, to enable this check. In case of validation error, then HTTP Status codes 415 or 406 is returned. The default value is false.

false

Boolean

camel.rest.component

The Camel Rest component to use for the REST transport (consumer), such as netty-http, jetty, servlet, undertow. If no component has been explicit configured, then Camel will lookup if there is a Camel component that integrates with the Rest DSL, or if a org.apache.camel.spi.RestConsumerFactory is registered in the registry. If either one is found, then that is being used.

 

String

camel.rest.component-property

Allows to configure as many additional properties for the rest component in use.

 

Map

camel.rest.consumer-property

Allows to configure as many additional properties for the rest consumer in use.

 

Map

camel.rest.context-path

Sets a leading context-path the REST services will be using. This can be used when using components such as camel-servlet where the deployed web application is deployed using a context-path. Or for components such as camel-jetty or camel-netty-http that includes a HTTP server.

 

String

camel.rest.cors-headers

Allows to configure custom CORS headers.

 

Map

camel.rest.data-format-property

Allows to configure as many additional properties for the data formats in use. For example set property prettyPrint to true to have json outputted in pretty mode. The properties can be prefixed to denote the option is only for either JSON or XML and for either the IN or the OUT. The prefixes are: json.in. json.out. xml.in. xml.out. For example a key with value xml.out.mustBeJAXBElement is only for the XML data format for the outgoing. A key without a prefix is a common key for all situations.

 

Map

camel.rest.enable-cors

Whether to enable CORS headers in the HTTP response. The default value is false.

false

Boolean

camel.rest.endpoint-property

Allows to configure as many additional properties for the rest endpoint in use.

 

Map

camel.rest.host

The hostname to use for exposing the REST service.

 

String

camel.rest.host-name-resolver

If no hostname has been explicit configured, then this resolver is used to compute the hostname the REST service will be using.

 

RestHostNameResolver

camel.rest.json-data-format

Name of specific json data format to use. By default json-jackson will be used. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance.

 

String

camel.rest.port

The port number to use for exposing the REST service. Notice if you use servlet component then the port number configured here does not apply, as the port number in use is the actual port number the servlet component is using. eg if using Apache Tomcat its the tomcat http port, if using Apache Karaf its the HTTP service in Karaf that uses port 8181 by default etc. Though in those situations setting the port number here, allows tooling and JMX to know the port number, so its recommended to set the port number to the number that the servlet engine uses.

 

String

camel.rest.producer-api-doc

Sets the location of the api document (swagger api) the REST producer will use to validate the REST uri and query parameters are valid accordingly to the api document. This requires adding camel-swagger-java to the classpath, and any miss configuration will let Camel fail on startup and report the error(s). The location of the api document is loaded from classpath by default, but you can use file: or http: to refer to resources to load from file or http url.

 

String

camel.rest.producer-component

Sets the name of the Camel component to use as the REST producer.

 

String

camel.rest.scheme

The scheme to use for exposing the REST service. Usually http or https is supported. The default value is http.

 

String

camel.rest.skip-binding-on-error-code

Whether to skip binding on output if there is a custom HTTP error code header. This allows to build custom error messages that do not bind to json / xml etc, as success messages otherwise will do.

false

Boolean

camel.rest.use-x-forward-headers

Whether to use X-Forward headers for Host and related setting. The default value is true.

true

Boolean

camel.rest.xml-data-format

Name of specific XML data format to use. By default jaxb will be used. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance.

 

String

camel.rest.api-context-id-pattern

Deprecated Sets an CamelContext id pattern to only allow Rest APIs from rest services within CamelContext’s which name matches the pattern. The pattern name refers to the CamelContext name, to match on the current CamelContext only. For any other value, the pattern uses the rules from PatternHelper#matchPattern(String,String).

 

String

camel.rest.api-context-listing

Deprecated Sets whether listing of all available CamelContext’s with REST services in the JVM is enabled. If enabled it allows to discover these contexts, if false then only the current CamelContext is in use.

false

Boolean

Chapter 37. FTP

Both producer and consumer are supported

This component provides access to remote file systems over the FTP and SFTP protocols.

When consuming from remote FTP server make sure you read the section titled Default when consuming files further below for details related to consuming files.

Absolute path is not supported. Camel translates absolute path to relative by trimming all leading slashes from directoryname. There’ll be WARN message printed in the logs.

37.1. Dependencies

When using ftp with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-ftp-starter</artifactId>
</dependency>

37.2. URI format

ftp://[username@]hostname[:port]/directoryname[?options]
sftp://[username@]hostname[:port]/directoryname[?options]
ftps://[username@]hostname[:port]/directoryname[?options]

Where directoryname represents the underlying directory. The directory name is a relative path. Absolute path’s is not supported. The relative path can contain nested folders, such as /inbox/us.

The autoCreate option is supported. When consumer starts, before polling is scheduled, there’s additional FTP operation performed to create the directory configured for endpoint. The default value for autoCreate is true.

If no username is provided, then anonymous login is attempted using no password.
If no port number is provided, Camel will provide default values according to the protocol (ftp = 21, sftp = 22, ftps = 2222).

You can append query options to the URI in the following format, ?option=value&option=value&…​

This component uses two different libraries for the actual FTP work. FTP and FTPS uses Apache Commons Net while SFTP uses JCraft JSCH.

FTPS (also known as FTP Secure) is an extension to FTP that adds support for the Transport Layer Security (TLS) and the Secure Sockets Layer (SSL) cryptographic protocols.

37.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

37.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

37.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

37.4. Component Options

The FTP component supports 3 options, which are listed below.

NameDescriptionDefaultType

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

37.5. Endpoint Options

The FTP endpoint is configured using URI syntax:

ftp:host:port/directoryName

with the following path and query parameters:

37.5.1. Path Parameters (3 parameters)

NameDescriptionDefaultType

host (common)

Required Hostname of the FTP server.

 

String

port (common)

Port of the FTP server.

 

int

directoryName (common)

The starting directory.

 

String

37.5.2. Query Parameters (111 parameters)

NameDescriptionDefaultType

binary (common)

Specifies the file transfer mode, BINARY or ASCII. Default is ASCII (false).

false

boolean

charset (common)

This option is used to specify the encoding of the file. You can use this on the consumer, to specify the encodings of the files, which allow Camel to know the charset it should load the file content in case the file content is being accessed. Likewise when writing a file, you can use this option to specify which charset to write the file as well. Do mind that when writing the file Camel may have to read the message content into memory to be able to convert the data into the configured charset, so do not use this if you have big messages.

 

String

disconnect (common)

Whether or not to disconnect from remote FTP server right after use. Disconnect will only disconnect the current connection to the FTP server. If you have a consumer which you want to stop, then you need to stop the consumer/route instead.

false

boolean

doneFileName (common)

Producer: If provided, then Camel will write a 2nd done file when the original file has been written. The done file will be empty. This option configures what file name to use. Either you can specify a fixed name. Or you can use dynamic placeholders. The done file will always be written in the same folder as the original file. Consumer: If provided, Camel will only consume files if a done file exists. This option configures what file name to use. Either you can specify a fixed name. Or you can use dynamic placeholders.The done file is always expected in the same folder as the original file. Only $\\{file.name} and $\\{file.name.next} is supported as dynamic placeholders.

 

String

fileName (common)

Use Expression such as File Language to dynamically set the filename. For consumers, it’s used as a filename filter. For producers, it’s used to evaluate the filename to write. If an expression is set, it take precedence over the CamelFileName header. (Note: The header itself can also be an Expression). The expression options support both String and Expression types. If the expression is a String type, it is always evaluated using the File Language. If the expression is an Expression type, the specified Expression type is used - this allows you, for instance, to use OGNL expressions. For the consumer, you can use it to filter filenames, so you can for instance consume today’s file using the File Language syntax: mydata-$\\{date:now:yyyyMMdd}.txt. The producers support the CamelOverruleFileName header which takes precedence over any existing CamelFileName header; the CamelOverruleFileName is a header that is used only once, and makes it easier as this avoids to temporary store CamelFileName and have to restore it afterwards.

 

String

passiveMode (common)

Sets passive mode connections. Default is active mode connections.

false

boolean

separator (common)

Sets the path separator to be used. UNIX = Uses unix style path separator Windows = Uses windows style path separator Auto = (is default) Use existing path separator in file name.

Enum values:

  • UNIX
  • Windows
  • Auto

UNIX

PathSeparator

transferLoggingIntervalSeconds (common)

Configures the interval in seconds to use when logging the progress of upload and download operations that are in-flight. This is used for logging progress when operations takes longer time.

5

int

transferLoggingLevel (common)

Configure the logging level to use when logging the progress of upload and download operations.

Enum values:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • OFF

DEBUG

LoggingLevel

transferLoggingVerbose (common)

Configures whether the perform verbose (fine grained) logging of the progress of upload and download operations.

false

boolean

fastExistsCheck (common (advanced))

If set this option to be true, camel-ftp will use the list file directly to check if the file exists. Since some FTP server may not support to list the file directly, if the option is false, camel-ftp will use the old way to list the directory and check if the file exists. This option also influences readLock=changed to control whether it performs a fast check to update file information or not. This can be used to speed up the process if the FTP server has a lot of files.

false

boolean

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

delete (consumer)

If true, the file will be deleted after it is processed successfully.

false

boolean

moveFailed (consumer)

Sets the move failure expression based on Simple language. For example, to move files into a .error subdirectory use: .error. Note: When moving the files to the fail location Camel will handle the error and will not pick up the file again.

 

String

noop (consumer)

If true, the file is not moved or deleted in any way. This option is good for readonly data, or for ETL type requirements. If noop=true, Camel will set idempotent=true as well, to avoid consuming the same files over and over again.

false

boolean

preMove (consumer)

Expression (such as File Language) used to dynamically set the filename when moving it before processing. For example to move in-progress files into the order directory set this value to order.

 

String

preSort (consumer)

When pre-sort is enabled then the consumer will sort the file and directory names during polling, that was retrieved from the file system. You may want to do this in case you need to operate on the files in a sorted order. The pre-sort is executed before the consumer starts to filter, and accept files to process by Camel. This option is default=false meaning disabled.

false

boolean

recursive (consumer)

If a directory, will look for files in all the sub-directories as well.

false

boolean

resumeDownload (consumer)

Configures whether resume download is enabled. This must be supported by the FTP server (almost all FTP servers support it). In addition the options localWorkDirectory must be configured so downloaded files are stored in a local directory, and the option binary must be enabled, which is required to support resuming of downloads.

false

boolean

sendEmptyMessageWhenIdle (consumer)

If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead.

false

boolean

streamDownload (consumer)

Sets the download method to use when not using a local working directory. If set to true, the remote files are streamed to the route as they are read. When set to false, the remote files are loaded into memory before being sent into the route. If enabling this option then you must set stepwise=false as both cannot be enabled at the same time.

false

boolean

download (consumer (advanced))

Whether the FTP consumer should download the file. If this option is set to false, then the message body will be null, but the consumer will still trigger a Camel Exchange that has details about the file such as file name, file size, etc. It’s just that the file will not be downloaded.

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

handleDirectoryParserAbsoluteResult (consumer (advanced))

Allows you to set how the consumer will handle subfolders and files in the path if the directory parser results in with absolute paths The reason for this is that some FTP servers may return file names with absolute paths, and if so then the FTP component needs to handle this by converting the returned path into a relative path.

false

boolean

ignoreFileNotFoundOrPermissionError (consumer (advanced))

Whether to ignore when (trying to list files in directories or when downloading a file), which does not exist or due to permission error. By default when a directory or file does not exists or insufficient permission, then an exception is thrown. Setting this option to true allows to ignore that instead.

false

boolean

inProgressRepository (consumer (advanced))

A pluggable in-progress repository org.apache.camel.spi.IdempotentRepository. The in-progress repository is used to account the current in progress files being consumed. By default a memory based repository is used.

 

IdempotentRepository

localWorkDirectory (consumer (advanced))

When consuming, a local work directory can be used to store the remote file content directly in local files, to avoid loading the content into memory. This is beneficial, if you consume a very big remote file and thus can conserve memory.

 

String

onCompletionExceptionHandler (consumer (advanced))

To use a custom org.apache.camel.spi.ExceptionHandler to handle any thrown exceptions that happens during the file on completion process where the consumer does either a commit or rollback. The default implementation will log any exception at WARN level and ignore.

 

ExceptionHandler

pollStrategy (consumer (advanced))

A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel.

 

PollingConsumerPollStrategy

processStrategy (consumer (advanced))

A pluggable org.apache.camel.component.file.GenericFileProcessStrategy allowing you to implement your own readLock option or similar. Can also be used when special conditions must be met before a file can be consumed, such as a special ready file exists. If this option is set then the readLock option does not apply.

 

GenericFileProcessStrategy

useList (consumer (advanced))

Whether to allow using LIST command when downloading a file. Default is true. In some use cases you may want to download a specific file and are not allowed to use the LIST command, and therefore you can set this option to false. Notice when using this option, then the specific file to download does not include meta-data information such as file size, timestamp, permissions etc, because those information is only possible to retrieve when LIST command is in use.

true

boolean

fileExist (producer)

What to do if a file already exists with the same name. Override, which is the default, replaces the existing file. - Append - adds content to the existing file. - Fail - throws a GenericFileOperationException, indicating that there is already an existing file. - Ignore - silently ignores the problem and does not override the existing file, but assumes everything is okay. - Move - option requires to use the moveExisting option to be configured as well. The option eagerDeleteTargetFile can be used to control what to do if an moving the file, and there exists already an existing file, otherwise causing the move operation to fail. The Move option will move any existing files, before writing the target file. - TryRename is only applicable if tempFileName option is in use. This allows to try renaming the file from the temporary name to the actual name, without doing any exists check. This check may be faster on some file systems and especially FTP servers.

Enum values:

  • Override
  • Append
  • Fail
  • Ignore
  • Move
  • TryRename

Override

GenericFileExist

flatten (producer)

Flatten is used to flatten the file name path to strip any leading paths, so it’s just the file name. This allows you to consume recursively into sub-directories, but when you eg write the files to another directory they will be written in a single directory. Setting this to true on the producer enforces that any file name in CamelFileName header will be stripped for any leading paths.

false

boolean

jailStartingDirectory (producer)

Used for jailing (restricting) writing files to the starting directory (and sub) only. This is enabled by default to not allow Camel to write files to outside directories (to be more secured out of the box). You can turn this off to allow writing files to directories outside the starting directory, such as parent or root folders.

true

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

moveExisting (producer)

Expression (such as File Language) used to compute file name to use when fileExist=Move is configured. To move files into a backup subdirectory just enter backup. This option only supports the following File Language tokens: file:name, file:name.ext, file:name.noext, file:onlyname, file:onlyname.noext, file:ext, and file:parent. Notice the file:parent is not supported by the FTP component, as the FTP component can only move any existing files to a relative directory based on current dir as base.

 

String

tempFileName (producer)

The same as tempPrefix option but offering a more fine grained control on the naming of the temporary filename as it uses the File Language. The location for tempFilename is relative to the final file location in the option 'fileName', not the target directory in the base uri. For example if option fileName includes a directory prefix: dir/finalFilename then tempFileName is relative to that subdirectory dir.

 

String

tempPrefix (producer)

This option is used to write the file using a temporary name and then, after the write is complete, rename it to the real name. Can be used to identify files being written and also avoid consumers (not using exclusive read locks) reading in progress files. Is often used by FTP when uploading big files.

 

String

allowNullBody (producer (advanced))

Used to specify if a null body is allowed during file writing. If set to true then an empty file will be created, when set to false, and attempting to send a null body to the file component, a GenericFileWriteException of 'Cannot write null body to file.' will be thrown. If the fileExist option is set to 'Override', then the file will be truncated, and if set to append the file will remain unchanged.

false

boolean

chmod (producer (advanced))

Allows you to set chmod on the stored file. For example chmod=640.

 

String

disconnectOnBatchComplete (producer (advanced))

Whether or not to disconnect from remote FTP server right after a Batch upload is complete. disconnectOnBatchComplete will only disconnect the current connection to the FTP server.

false

boolean

eagerDeleteTargetFile (producer (advanced))

Whether or not to eagerly delete any existing target file. This option only applies when you use fileExists=Override and the tempFileName option as well. You can use this to disable (set it to false) deleting the target file before the temp file is written. For example you may write big files and want the target file to exists during the temp file is being written. This ensure the target file is only deleted until the very last moment, just before the temp file is being renamed to the target filename. This option is also used to control whether to delete any existing files when fileExist=Move is enabled, and an existing file exists. If this option copyAndDeleteOnRenameFails false, then an exception will be thrown if an existing file existed, if its true, then the existing file is deleted before the move operation.

true

boolean

keepLastModified (producer (advanced))

Will keep the last modified timestamp from the source file (if any). Will use the Exchange.FILE_LAST_MODIFIED header to located the timestamp. This header can contain either a java.util.Date or long with the timestamp. If the timestamp exists and the option is enabled it will set this timestamp on the written file. Note: This option only applies to the file producer. You cannot use this option with any of the ftp producers.

false

boolean

moveExistingFileStrategy (producer (advanced))

Strategy (Custom Strategy) used to move file with special naming token to use when fileExist=Move is configured. By default, there is an implementation used if no custom strategy is provided.

 

FileMoveExistingStrategy

sendNoop (producer (advanced))

Whether to send a noop command as a pre-write check before uploading files to the FTP server. This is enabled by default as a validation of the connection is still valid, which allows to silently re-connect to be able to upload the file. However if this causes problems, you can turn this option off.

true

boolean

activePortRange (advanced)

Set the client side port range in active mode. The syntax is: minPort-maxPort Both port numbers are inclusive, eg 10000-19999 to include all 1xxxx ports.

 

String

autoCreate (advanced)

Automatically create missing directories in the file’s pathname. For the file consumer, that means creating the starting directory. For the file producer, it means the directory the files should be written to.

true

boolean

bufferSize (advanced)

Buffer size in bytes used for writing files (or in case of FTP for downloading and uploading files).

131072

int

connectTimeout (advanced)

Sets the connect timeout for waiting for a connection to be established Used by both FTPClient and JSCH.

10000

int

ftpClient (advanced)

To use a custom instance of FTPClient.

 

FTPClient

ftpClientConfig (advanced)

To use a custom instance of FTPClientConfig to configure the FTP client the endpoint should use.

 

FTPClientConfig

ftpClientConfigParameters (advanced)

Used by FtpComponent to provide additional parameters for the FTPClientConfig.

 

Map

ftpClientParameters (advanced)

Used by FtpComponent to provide additional parameters for the FTPClient.

 

Map

maximumReconnectAttempts (advanced)

Specifies the maximum reconnect attempts Camel performs when it tries to connect to the remote FTP server. Use 0 to disable this behavior.

 

int

reconnectDelay (advanced)

Delay in millis Camel will wait before performing a reconnect attempt.

1000

long

siteCommand (advanced)

Sets optional site command(s) to be executed after successful login. Multiple site commands can be separated using a new line character.

 

String

soTimeout (advanced)

Sets the so timeout FTP and FTPS Is the SocketOptions.SO_TIMEOUT value in millis. Recommended option is to set this to 300000 so as not have a hanged connection. On SFTP this option is set as timeout on the JSCH Session instance.

300000

int

stepwise (advanced)

Sets whether we should stepwise change directories while traversing file structures when downloading files, or as well when uploading a file to a directory. You can disable this if you for example are in a situation where you cannot change directory on the FTP server due security reasons. Stepwise cannot be used together with streamDownload.

true

boolean

synchronous (advanced)

Sets whether synchronous processing should be strictly used.

false

boolean

throwExceptionOnConnectFailed (advanced)

Should an exception be thrown if connection failed (exhausted)By default exception is not thrown and a WARN is logged. You can use this to enable exception being thrown and handle the thrown exception from the org.apache.camel.spi.PollingConsumerPollStrategy rollback method.

false

boolean

timeout (advanced)

Sets the data timeout for waiting for reply Used only by FTPClient.

30000

int

antExclude (filter)

Ant style filter exclusion. If both antInclude and antExclude are used, antExclude takes precedence over antInclude. Multiple exclusions may be specified in comma-delimited format.

 

String

antFilterCaseSensitive (filter)

Sets case sensitive flag on ant filter.

true

boolean

antInclude (filter)

Ant style filter inclusion. Multiple inclusions may be specified in comma-delimited format.

 

String

eagerMaxMessagesPerPoll (filter)

Allows for controlling whether the limit from maxMessagesPerPoll is eager or not. If eager then the limit is during the scanning of files. Where as false would scan all files, and then perform sorting. Setting this option to false allows for sorting all files first, and then limit the poll. Mind that this requires a higher memory usage as all file details are in memory to perform the sorting.

true

boolean

exclude (filter)

Is used to exclude files, if filename matches the regex pattern (matching is case in-sensitive). Notice if you use symbols such as plus sign and others you would need to configure this using the RAW() syntax if configuring this as an endpoint uri. See more details at configuring endpoint uris.

 

String

excludeExt (filter)

Is used to exclude files matching file extension name (case insensitive). For example to exclude bak files, then use excludeExt=bak. Multiple extensions can be separated by comma, for example to exclude bak and dat files, use excludeExt=bak,dat. Note that the file extension includes all parts, for example having a file named mydata.tar.gz will have extension as tar.gz. For more flexibility then use the include/exclude options.

 

String

filter (filter)

Pluggable filter as a org.apache.camel.component.file.GenericFileFilter class. Will skip files if filter returns false in its accept() method.

 

GenericFileFilter

filterDirectory (filter)

Filters the directory based on Simple language. For example to filter on current date, you can use a simple date pattern such as $\\{date:now:yyyMMdd}.

 

String

filterFile (filter)

Filters the file based on Simple language. For example to filter on file size, you can use $\\{file:size} 5000.

 

String

idempotent (filter)

Option to use the Idempotent Consumer EIP pattern to let Camel skip already processed files. Will by default use a memory based LRUCache that holds 1000 entries. If noop=true then idempotent will be enabled as well to avoid consuming the same files over and over again.

false

Boolean

idempotentKey (filter)

To use a custom idempotent key. By default the absolute path of the file is used. You can use the File Language, for example to use the file name and file size, you can do: idempotentKey=$\\{file:name}-$\\{file:size}.

 

String

idempotentRepository (filter)

A pluggable repository org.apache.camel.spi.IdempotentRepository which by default use MemoryIdempotentRepository if none is specified and idempotent is true.

 

IdempotentRepository

include (filter)

Is used to include files, if filename matches the regex pattern (matching is case in-sensitive). Notice if you use symbols such as plus sign and others you would need to configure this using the RAW() syntax if configuring this as an endpoint uri. See more details at configuring endpoint uris.

 

String

includeExt (filter)

Is used to include files matching file extension name (case insensitive). For example to include txt files, then use includeExt=txt. Multiple extensions can be separated by comma, for example to include txt and xml files, use includeExt=txt,xml. Note that the file extension includes all parts, for example having a file named mydata.tar.gz will have extension as tar.gz. For more flexibility then use the include/exclude options.

 

String

maxDepth (filter)

The maximum depth to traverse when recursively processing a directory.

2147483647

int

maxMessagesPerPoll (filter)

To define a maximum messages to gather per poll. By default no maximum is set. Can be used to set a limit of e.g. 1000 to avoid when starting up the server that there are thousands of files. Set a value of 0 or negative to disabled it. Notice: If this option is in use then the File and FTP components will limit before any sorting. For example if you have 100000 files and use maxMessagesPerPoll=500, then only the first 500 files will be picked up, and then sorted. You can use the eagerMaxMessagesPerPoll option and set this to false to allow to scan all files first and then sort afterwards.

 

int

minDepth (filter)

The minimum depth to start processing when recursively processing a directory. Using minDepth=1 means the base directory. Using minDepth=2 means the first sub directory.

 

int

move (filter)

Expression (such as Simple Language) used to dynamically set the filename when moving it after processing. To move files into a .done subdirectory just enter .done.

 

String

exclusiveReadLockStrategy (lock)

Pluggable read-lock as a org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy implementation.

 

GenericFileExclusiveReadLockStrategy

readLock (lock)

Used by consumer, to only poll the files if it has exclusive read-lock on the file (i.e. the file is not in-progress or being written). Camel will wait until the file lock is granted. This option provides the build in strategies: - none - No read lock is in use - markerFile - Camel creates a marker file (fileName.camelLock) and then holds a lock on it. This option is not available for the FTP component - changed - Changed is using file length/modification timestamp to detect whether the file is currently being copied or not. Will at least use 1 sec to determine this, so this option cannot consume files as fast as the others, but can be more reliable as the JDK IO API cannot always determine whether a file is currently being used by another process. The option readLockCheckInterval can be used to set the check frequency. - fileLock - is for using java.nio.channels.FileLock. This option is not avail for Windows OS and the FTP component. This approach should be avoided when accessing a remote file system via a mount/share unless that file system supports distributed file locks. - rename - rename is for using a try to rename the file as a test if we can get exclusive read-lock. - idempotent - (only for file component) idempotent is for using a idempotentRepository as the read-lock. This allows to use read locks that supports clustering if the idempotent repository implementation supports that. - idempotent-changed - (only for file component) idempotent-changed is for using a idempotentRepository and changed as the combined read-lock. This allows to use read locks that supports clustering if the idempotent repository implementation supports that. - idempotent-rename - (only for file component) idempotent-rename is for using a idempotentRepository and rename as the combined read-lock. This allows to use read locks that supports clustering if the idempotent repository implementation supports that.Notice: The various read locks is not all suited to work in clustered mode, where concurrent consumers on different nodes is competing for the same files on a shared file system. The markerFile using a close to atomic operation to create the empty marker file, but its not guaranteed to work in a cluster. The fileLock may work better but then the file system need to support distributed file locks, and so on. Using the idempotent read lock can support clustering if the idempotent repository supports clustering, such as Hazelcast Component or Infinispan.

Enum values:

  • none
  • markerFile
  • fileLock
  • rename
  • changed
  • idempotent
  • idempotent-changed
  • idempotent-rename

none

String

readLockCheckInterval (lock)

Interval in millis for the read-lock, if supported by the read lock. This interval is used for sleeping between attempts to acquire the read lock. For example when using the changed read lock, you can set a higher interval period to cater for slow writes. The default of 1 sec. may be too fast if the producer is very slow writing the file. Notice: For FTP the default readLockCheckInterval is 5000. The readLockTimeout value must be higher than readLockCheckInterval, but a rule of thumb is to have a timeout that is at least 2 or more times higher than the readLockCheckInterval. This is needed to ensure that amble time is allowed for the read lock process to try to grab the lock before the timeout was hit.

1000

long

readLockDeleteOrphanLockFiles (lock)

Whether or not read lock with marker files should upon startup delete any orphan read lock files, which may have been left on the file system, if Camel was not properly shutdown (such as a JVM crash). If turning this option to false then any orphaned lock file will cause Camel to not attempt to pickup that file, this could also be due another node is concurrently reading files from the same shared directory.

true

boolean

readLockLoggingLevel (lock)

Logging level used when a read lock could not be acquired. By default a DEBUG is logged. You can change this level, for example to OFF to not have any logging. This option is only applicable for readLock of types: changed, fileLock, idempotent, idempotent-changed, idempotent-rename, rename.

Enum values:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • OFF

DEBUG

LoggingLevel

readLockMarkerFile (lock)

Whether to use marker file with the changed, rename, or exclusive read lock types. By default a marker file is used as well to guard against other processes picking up the same files. This behavior can be turned off by setting this option to false. For example if you do not want to write marker files to the file systems by the Camel application.

true

boolean

readLockMinAge (lock)

This option is applied only for readLock=changed. It allows to specify a minimum age the file must be before attempting to acquire the read lock. For example use readLockMinAge=300s to require the file is at last 5 minutes old. This can speedup the changed read lock as it will only attempt to acquire files which are at least that given age.

0

long

readLockMinLength (lock)

This option is applied only for readLock=changed. It allows you to configure a minimum file length. By default Camel expects the file to contain data, and thus the default value is 1. You can set this option to zero, to allow consuming zero-length files.

1

long

readLockRemoveOnCommit (lock)

This option is applied only for readLock=idempotent. It allows to specify whether to remove the file name entry from the idempotent repository when processing the file is succeeded and a commit happens. By default the file is not removed which ensures that any race-condition do not occur so another active node may attempt to grab the file. Instead the idempotent repository may support eviction strategies that you can configure to evict the file name entry after X minutes - this ensures no problems with race conditions. See more details at the readLockIdempotentReleaseDelay option.

false

boolean

readLockRemoveOnRollback (lock)

This option is applied only for readLock=idempotent. It allows to specify whether to remove the file name entry from the idempotent repository when processing the file failed and a rollback happens. If this option is false, then the file name entry is confirmed (as if the file did a commit).

true

boolean

readLockTimeout (lock)

Optional timeout in millis for the read-lock, if supported by the read-lock. If the read-lock could not be granted and the timeout triggered, then Camel will skip the file. At next poll Camel, will try the file again, and this time maybe the read-lock could be granted. Use a value of 0 or lower to indicate forever. Currently fileLock, changed and rename support the timeout. Notice: For FTP the default readLockTimeout value is 20000 instead of 10000. The readLockTimeout value must be higher than readLockCheckInterval, but a rule of thumb is to have a timeout that is at least 2 or more times higher than the readLockCheckInterval. This is needed to ensure that amble time is allowed for the read lock process to try to grab the lock before the timeout was hit.

10000

long

backoffErrorThreshold (scheduler)

The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in.

 

int

backoffIdleThreshold (scheduler)

The number of subsequent idle polls that should happen before the backoffMultipler should kick-in.

 

int

backoffMultiplier (scheduler)

To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured.

 

int

delay (scheduler)

Milliseconds before the next poll.

500

long

greedy (scheduler)

If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages.

false

boolean

initialDelay (scheduler)

Milliseconds before the first poll starts.

1000

long

repeatCount (scheduler)

Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever.

0

long

runLoggingLevel (scheduler)

The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that.

Enum values:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • OFF

TRACE

LoggingLevel

scheduledExecutorService (scheduler)

Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool.

 

ScheduledExecutorService

scheduler (scheduler)

To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler.

none

Object

schedulerProperties (scheduler)

To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler.

 

Map

startScheduler (scheduler)

Whether the scheduler should be auto started.

true

boolean

timeUnit (scheduler)

Time unit for initialDelay and delay options.

Enum values:

  • NANOSECONDS
  • MICROSECONDS
  • MILLISECONDS
  • SECONDS
  • MINUTES
  • HOURS
  • DAYS

MILLISECONDS

TimeUnit

useFixedDelay (scheduler)

Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details.

true

boolean

account (security)

Account to use for login.

 

String

password (security)

Password to use for login.

 

String

username (security)

Username to use for login.

 

String

shuffle (sort)

To shuffle the list of files (sort in random order).

false

boolean

sortBy (sort)

Built-in sort by using the File Language. Supports nested sorts, so you can have a sort by file name and as a 2nd group sort by modified date.

 

String

sorter (sort)

Pluggable sorter as a java.util.Comparator class.

 

Comparator

37.6. FTPS component default trust store

When using the ftpClient. properties related to SSL with the FTPS component, the trust store accept all certificates. If you only want trust selective certificates, you have to configure the trust store with the ftpClient.trustStore.xxx options or by configuring a custom ftpClient.

When using sslContextParameters, the trust store is managed by the configuration of the provided SSLContextParameters instance.

You can configure additional options on the ftpClient and ftpClientConfig from the URI directly by using the ftpClient. or ftpClientConfig. prefix.

For example to set the setDataTimeout on the FTPClient to 30 seconds you can do:

from("ftp://foo@myserver?password=secret&ftpClient.dataTimeout=30000").to("bean:foo");

You can mix and match and have use both prefixes, for example to configure date format or timezones.

from("ftp://foo@myserver?password=secret&ftpClient.dataTimeout=30000&ftpClientConfig.serverLanguageCode=fr").to("bean:foo");

You can have as many of these options as you like.

See the documentation of the Apache Commons FTP FTPClientConfig for possible options and more details. And as well for Apache Commons FTP FTPClient.

If you do not like having many and long configuration in the url you can refer to the ftpClient or ftpClientConfig to use by letting Camel lookup in the Registry for it.

For example:

   <bean id="myConfig" class="org.apache.commons.net.ftp.FTPClientConfig">
       <property name="lenientFutureDates" value="true"/>
       <property name="serverLanguageCode" value="fr"/>
   </bean>

And then let Camel lookup this bean when you use the # notation in the url.

from("ftp://foo@myserver?password=secret&ftpClientConfig=#myConfig").to("bean:foo");

37.7. Examples

ftp://someone@someftpserver.com/public/upload/images/holiday2008?password=secret&binary=true

ftp://someoneelse@someotherftpserver.co.uk:12049/reports/2008/password=secret&binary=false

ftp://publicftpserver.com/download

37.8. Concurrency

FTP Consumer does not support concurrency

The FTP consumer (with the same endpoint) does not support concurrency (the backing FTP client is not thread safe).
You can use multiple FTP consumers to poll from different endpoints. It is only a single endpoint that does not support concurrent consumers.

The FTP producer does not have this issue, it supports concurrency.

37.9. More information

This component is an extension of the File component. So there are more samples and details on the File component page.

37.10. Default when consuming files

The FTP consumer will by default leave the consumed files untouched on the remote FTP server. You have to configure it explicitly if you want it to delete the files or move them to another location. For example you can use delete=true to delete the files, or use move=.done to move the files into a hidden done sub directory.

The regular File consumer is different as it will by default move files to a .camel sub directory. The reason Camel does not do this by default for the FTP consumer is that it may lack permissions by default to be able to move or delete files.

37.10.1. limitations

The option readLock can be used to force Camel not to consume files that is currently in the progress of being written. However, this option is turned off by default, as it requires that the user has write access. See the options table at File2 for more details about read locks.
There are other solutions to avoid consuming files that are currently being written over FTP; for instance, you can write to a temporary destination and move the file after it has been written.

When moving files using move or preMove option the files are restricted to the FTP_ROOT folder. That prevents you from moving files outside the FTP area. If you want to move files to another area you can use soft links and move files into a soft linked folder.

37.11. Message Headers

The following message headers can be used to affect the behavior of the component

HeaderDescription

CamelFileName

Specifies the output file name (relative to the endpoint directory) to be used for the output message when sending to the endpoint. If this is not present and no expression either, then a generated message ID is used as the filename instead.

CamelFileNameProduced

The actual filepath (path + name) for the output file that was written. This header is set by Camel and its purpose is providing end-users the name of the file that was written.

CamelFileNameConsumed

The file name of the file consumed

CamelFileHost

The remote hostname.

CamelFileLocalWorkPath

Path to the local work file, if local work directory is used.

In addition the FTP/FTPS consumer and producer will enrich the Camel Message with the following headers

HeaderDescription

CamelFtpReplyCode

The FTP client reply code (the type is a integer)

CamelFtpReplyString

The FTP client reply string

37.11.1. Exchange Properties

Camel sets the following exchange properties

HeaderDescription

CamelBatchIndex

Current index out of total number of files being consumed in this batch.

CamelBatchSize

Total number of files being consumed in this batch.

CamelBatchComplete

True if there are no more files in this batch.

37.12. About timeouts

The two set of libraries (see top) has different API for setting timeout. You can use the connectTimeout option for both of them to set a timeout in millis to establish a network connection. An individual soTimeout can also be set on the FTP/FTPS, which corresponds to using ftpClient.soTimeout. Notice SFTP will automatically use connectTimeout as its soTimeout. The timeout option only applies for FTP/FTPS as the data timeout, which corresponds to the ftpClient.dataTimeout value. All timeout values are in millis.

37.13. Using Local Work Directory

Camel supports consuming from remote FTP servers and downloading the files directly into a local work directory. This avoids reading the entire remote file content into memory as it is streamed directly into the local file using FileOutputStream.

Camel will store to a local file with the same name as the remote file, though with .inprogress as extension while the file is being downloaded. Afterwards, the file is renamed to remove the .inprogress suffix. And finally, when the Exchange is complete the local file is deleted.

So if you want to download files from a remote FTP server and store it as files then you need to route to a file endpoint such as:

from("ftp://someone@someserver.com?password=secret&localWorkDirectory=/tmp").to("file://inbox");
Note

The route above is ultra efficient as it avoids reading the entire file content into memory. It will download the remote file directly to a local file stream. The java.io.File handle is then used as the Exchange body. The file producer leverages this fact and can work directly on the work file java.io.File handle and perform a java.io.File.rename to the target filename. As Camel knows it’s a local work file, it can optimize and use a rename instead of a file copy, as the work file is meant to be deleted anyway.

37.14. Stepwise changing directories

Camel FTP can operate in two modes in terms of traversing directories when consuming files (eg downloading) or producing files (eg uploading)

  • stepwise
  • not stepwise

You may want to pick either one depending on your situation and security issues. Some Camel end users can only download files if they use stepwise, while others can only download if they do not.

You can use the stepwise option to control the behavior.

Note that stepwise changing of directory will in most cases only work when the user is confined to it’s home directory and when the home directory is reported as "/".

The difference between the two of them is best illustrated with an example. Suppose we have the following directory structure on the remote FTP server we need to traverse and download files:

/
/one
/one/two
/one/two/sub-a
/one/two/sub-b

And that we have a file in each of sub-a (a.txt) and sub-b (b.txt) folder.

37.15. Using stepwise=true (default mode)

TYPE A
200 Type set to A
PWD
257 "/" is current directory.
CWD one
250 CWD successful. "/one" is current directory.
CWD two
250 CWD successful. "/one/two" is current directory.
SYST
215 UNIX emulated by FileZilla
PORT 127,0,0,1,17,94
200 Port command successful
LIST
150 Opening data channel for directory list.
226 Transfer OK
CWD sub-a
250 CWD successful. "/one/two/sub-a" is current directory.
PORT 127,0,0,1,17,95
200 Port command successful
LIST
150 Opening data channel for directory list.
226 Transfer OK
CDUP
200 CDUP successful. "/one/two" is current directory.
CWD sub-b
250 CWD successful. "/one/two/sub-b" is current directory.
PORT 127,0,0,1,17,96
200 Port command successful
LIST
150 Opening data channel for directory list.
226 Transfer OK
CDUP
200 CDUP successful. "/one/two" is current directory.
CWD /
250 CWD successful. "/" is current directory.
PWD
257 "/" is current directory.
CWD one
250 CWD successful. "/one" is current directory.
CWD two
250 CWD successful. "/one/two" is current directory.
PORT 127,0,0,1,17,97
200 Port command successful
RETR foo.txt
150 Opening data channel for file transfer.
226 Transfer OK
CWD /
250 CWD successful. "/" is current directory.
PWD
257 "/" is current directory.
CWD one
250 CWD successful. "/one" is current directory.
CWD two
250 CWD successful. "/one/two" is current directory.
CWD sub-a
250 CWD successful. "/one/two/sub-a" is current directory.
PORT 127,0,0,1,17,98
200 Port command successful
RETR a.txt
150 Opening data channel for file transfer.
226 Transfer OK
CWD /
250 CWD successful. "/" is current directory.
PWD
257 "/" is current directory.
CWD one
250 CWD successful. "/one" is current directory.
CWD two
250 CWD successful. "/one/two" is current directory.
CWD sub-b
250 CWD successful. "/one/two/sub-b" is current directory.
PORT 127,0,0,1,17,99
200 Port command successful
RETR b.txt
150 Opening data channel for file transfer.
226 Transfer OK
CWD /
250 CWD successful. "/" is current directory.
QUIT
221 Goodbye
disconnected.

As you can see when stepwise is enabled, it will traverse the directory structure using CD xxx.

37.16. Using stepwise=false

230 Logged on
TYPE A
200 Type set to A
SYST
215 UNIX emulated by FileZilla
PORT 127,0,0,1,4,122
200 Port command successful
LIST one/two
150 Opening data channel for directory list
226 Transfer OK
PORT 127,0,0,1,4,123
200 Port command successful
LIST one/two/sub-a
150 Opening data channel for directory list
226 Transfer OK
PORT 127,0,0,1,4,124
200 Port command successful
LIST one/two/sub-b
150 Opening data channel for directory list
226 Transfer OK
PORT 127,0,0,1,4,125
200 Port command successful
RETR one/two/foo.txt
150 Opening data channel for file transfer.
226 Transfer OK
PORT 127,0,0,1,4,126
200 Port command successful
RETR one/two/sub-a/a.txt
150 Opening data channel for file transfer.
226 Transfer OK
PORT 127,0,0,1,4,127
200 Port command successful
RETR one/two/sub-b/b.txt
150 Opening data channel for file transfer.
226 Transfer OK
QUIT
221 Goodbye
disconnected.

As you can see when not using stepwise, there are no CD operation invoked at all.

37.17. Samples

In the sample below we set up Camel to download all the reports from the FTP server once every hour (60 min) as BINARY content and store it as files on the local file system.

And the route using XML DSL:

  <route>
     <from uri="ftp://scott@localhost/public/reports?password=tiger&amp;binary=true&amp;delay=60000"/>
     <to uri="file://target/test-reports"/>
  </route>

37.17.1. Consuming a remote FTPS server (implicit SSL) and client authentication

from("ftps://admin@localhost:2222/public/camel?password=admin&securityProtocol=SSL&implicit=true
      &ftpClient.keyStore.file=./src/test/resources/server.jks
      &ftpClient.keyStore.password=password&ftpClient.keyStore.keyPassword=password")
  .to("bean:foo");

37.17.2. Consuming a remote FTPS server (explicit TLS) and a custom trust store configuration

from("ftps://admin@localhost:2222/public/camel?password=admin&ftpClient.trustStore.file=./src/test/resources/server.jks&ftpClient.trustStore.password=password")
  .to("bean:foo");

37.18. Custom filtering

Camel supports pluggable filtering strategies. This strategy it to use the build in org.apache.camel.component.file.GenericFileFilter in Java. You can then configure the endpoint with such a filter to skip certain filters before being processed.

In the sample we have built our own filter that only accepts files starting with report in the filename.

And then we can configure our route using the filter attribute to reference our filter (using # notation) that we have defined in the spring XML file:

   <!-- define our sorter as a plain spring bean -->
   <bean id="myFilter" class="com.mycompany.MyFileFilter"/>

  <route>
    <from uri="ftp://someuser@someftpserver.com?password=secret&amp;filter=#myFilter"/>
    <to uri="bean:processInbox"/>
  </route>

37.19. Filtering using ANT path matcher

The ANT path matcher is a filter that is shipped out-of-the-box in the camel-spring jar. So you need to depend on camel-spring if you are using Maven.
The reason is that we leverage Spring’s AntPathMatcher to do the actual matching.

The file paths are matched with the following rules:

  • ? matches one character
  • * matches zero or more characters
  • ** matches zero or more directories in a path

The sample below demonstrates how to use it:

37.20. Using a proxy with SFTP

To use an HTTP proxy to connect to your remote host, you can configure your route in the following way:

<!-- define our sorter as a plain spring bean -->
<bean id="proxy" class="com.jcraft.jsch.ProxyHTTP">
  <constructor-arg value="localhost"/>
  <constructor-arg value="7777"/>
</bean>

<route>
  <from uri="sftp://localhost:9999/root?username=admin&password=admin&proxy=#proxy"/>
  <to uri="bean:processFile"/>
</route>

You can also assign a user name and password to the proxy, if necessary. Please consult the documentation for com.jcraft.jsch.Proxy to discover all options.

37.21. Setting preferred SFTP authentication method

If you want to explicitly specify the list of authentication methods that should be used by sftp component, use preferredAuthentications option. If for example you would like Camel to attempt to authenticate with private/public SSH key and fallback to user/password authentication in the case when no public key is available, use the following route configuration:

from("sftp://localhost:9999/root?username=admin&password=admin&preferredAuthentications=publickey,password").
  to("bean:processFile");

37.22. Consuming a single file using a fixed name

When you want to download a single file and knows the file name, you can use fileName=myFileName.txt to tell Camel the name of the file to download. By default the consumer will still do a FTP LIST command to do a directory listing and then filter these files based on the fileName option. Though in this use-case it may be desirable to turn off the directory listing by setting useList=false. For example the user account used to login to the FTP server may not have permission to do a FTP LIST command. So you can turn off this with useList=false, and then provide the fixed name of the file to download with fileName=myFileName.txt, then the FTP consumer can still download the file. If the file for some reason does not exist, then Camel will by default throw an exception, you can turn this off and ignore this by setting ignoreFileNotFoundOrPermissionError=true.

For example to have a Camel route that pickup a single file, and delete it after use you can do

from("ftp://admin@localhost:21/nolist/?password=admin&stepwise=false&useList=false&ignoreFileNotFoundOrPermissionError=true&fileName=report.txt&delete=true")
  .to("activemq:queue:report");

Notice that we have used all the options we talked above.

You can also use this with ConsumerTemplate. For example to download a single file (if it exists) and grab the file content as a String type:

String data = template.retrieveBodyNoWait("ftp://admin@localhost:21/nolist/?password=admin&stepwise=false&useList=false&ignoreFileNotFoundOrPermissionError=true&fileName=report.txt&delete=true", String.class);

37.23. Debug logging

This component has log level TRACE that can be helpful if you have problems.

37.24. Spring Boot Auto-Configuration

The component supports 13 options, which are listed below.

NameDescriptionDefaultType

camel.component.ftp.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.ftp.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.ftp.enabled

Whether to enable auto configuration of the ftp component. This is enabled by default.

 

Boolean

camel.component.ftp.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.ftps.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.ftps.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.ftps.enabled

Whether to enable auto configuration of the ftps component. This is enabled by default.

 

Boolean

camel.component.ftps.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.ftps.use-global-ssl-context-parameters

Enable usage of global SSL context parameters.

false

Boolean

camel.component.sftp.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.sftp.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.sftp.enabled

Whether to enable auto configuration of the sftp component. This is enabled by default.

 

Boolean

camel.component.sftp.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

Chapter 38. Google BigQuery

Since Camel 2.20

Only producer is supported.

The Google Bigquery component provides access to the Cloud BigQuery Infrastructure via the link:https://developers.google.com/api-client-library/java/apis/bigquery/v2 [Google Client Services API].

The current implementation does not use gRPC.

The current implementation does not support querying BigQuery, it is only a producer.

38.1. Dependencies

When using google-bigquery with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-google-bigquery-starter</artifactId>
</dependency>

38.2. Authentication Configuration

Google BigQuery component authentication is targeted for use with the GCP Service Accounts. For more information please refer to Google Cloud Platform Auth Guide.

Google security credentials can be set explicitly by providing the path to the GCP credentials file location.

Or they are set implicitly, where the connection factory falls back on Application Default Credentials.

When you have the service account key you can provide authentication credentials to your application code. Google security credentials can be set through the component endpoint:

String endpoint = "google-bigquery://project-id:datasetId[:tableId]?serviceAccountKey=/home/user/Downloads/my-key.json";

You can also use the base64 encoded content of the authentication credentials file if you don’t want to set a file system path.

String endpoint = "google-bigquery://project-id:datasetId[:tableId]?serviceAccountKey=base64:<base64 encoded>";

Or by setting the environment variable GOOGLE_APPLICATION_CREDENTIALS :

export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/my-key.json"

38.3. URI Format

google-bigquery://project-id:datasetId[:tableId]?[options]

38.4. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

38.4.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

38.4.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

38.5. Component Options

The Google BigQuery component supports 5 options, which are listed below.

NameDescriptionDefaultType

connectionFactory (producer)

Autowired ConnectionFactory to obtain connection to Bigquery Service. If not provided the default one will be used.

 

GoogleBigQueryConnectionFactory

datasetId (producer)

BigQuery Dataset Id.

 

String

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

projectId (producer)

Google Cloud Project Id.

 

String

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

38.6. Endpoint Options

The Google BigQuery endpoint is configured using URI syntax:

google-bigquery:projectId:datasetId:tableId

with the following path and query parameters:

38.6.1. Path Parameters (3 parameters)

NameDescriptionDefaultType

projectId (common)

Required Google Cloud Project Id.

 

String

datasetId (common)

Required BigQuery Dataset Id.

 

String

tableId (common)

BigQuery table id.

 

String

38.6.2. Query Parameters (4 parameters)

NameDescriptionDefaultType

connectionFactory (producer)

Autowired ConnectionFactory to obtain connection to Bigquery Service. If not provided the default one will be used.

 

GoogleBigQueryConnectionFactory

useAsInsertId (producer)

Field name to use as insert id.

 

String

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

serviceAccountKey (security)

Service account key in json format to authenticate an application as a service account to google cloud platform.

 

String

38.7. Message Headers

The Google BigQuery component supports 4 message header(s), which is/are listed below:

NameDescriptionDefaultType

CamelGoogleBigQueryTableSuffix (producer)

Constant: TABLE_SUFFIX

Table suffix to use when inserting data.

 

String

CamelGoogleBigQueryTableId (producer)

Constant: TABLE_ID

Table id where data will be submitted. If specified will override endpoint configuration.

 

String

CamelGoogleBigQueryInsertId (producer)

Constant: INSERT_ID

InsertId to use when inserting data.

 

String

CamelGoogleBigQueryPartitionDecorator (producer)

Constant: PARTITION_DECORATOR

Partition decorator to indicate partition to use when inserting data.

 

String

38.8. Producer Endpoints

Producer endpoints can accept and deliver to BigQuery individual and grouped exchanges alike. Grouped exchanges have Exchange.GROUPED_EXCHANGE property set.

Google BigQuery producer will send a grouped exchange in a single api call unless different table suffix or partition decorators are specified in which case it will break it down to ensure data is written with the correct suffix or partition decorator.

Google BigQuery endpoint expects the payload to be either a map or list of maps. A payload containing a map will insert a single row and a payload containing a list of map’s will insert a row for each entry in the list.

38.9. Template tables

Templated tables can be specified using the GoogleBigQueryConstants.TABLE_SUFFIX header. For example, the following route will create tables and insert records sharded on a per day basis:

from("direct:start")
  .header(GoogleBigQueryConstants.TABLE_SUFFIX, "_${date:now:yyyyMMdd}")
  .to("google-bigquery:sampleDataset:sampleTable")
Note

It is recommended to use partitioning for this use case.

For more information about Template table, see Template Tables.

38.10. Partitioning

Partitioning is specified when creating a table and if set data will be automatically partitioned into separate tables. When inserting data a specific partition can be specified by setting the GoogleBigQueryConstants.PARTITION_DECORATOR header on the exchange.

For more information about partitioning, see Creating partitioned tables.

38.11. Ensuring data consistency

An insert id can be set on the exchange with the header GoogleBigQueryConstants.INSERT_ID or by specifying query parameter useAsInsertId. As an insert id need to be specified per row, the inserted the exchange header can’t be used when the payload is a list. If the payload is a list then the GoogleBigQueryConstants.INSERT_ID will be ignored. In that case use the query parameter useAsInsertId.

For more information, see Data consistency

38.12. Spring Boot Auto-Configuration

The component supports 11 options, which are listed below.

NameDescriptionDefaultType

camel.component.google-bigquery-sql.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.google-bigquery-sql.connection-factory

ConnectionFactory to obtain connection to Bigquery Service. If not provided the default one will be used. The option is a org.apache.camel.component.google.bigquery.GoogleBigQueryConnectionFactory type.

 

GoogleBigQueryConnectionFactory

camel.component.google-bigquery-sql.enabled

Whether to enable auto configuration of the google-bigquery-sql component. This is enabled by default.

 

Boolean

camel.component.google-bigquery-sql.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.google-bigquery-sql.project-id

Google Cloud Project Id.

 

String

camel.component.google-bigquery.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.google-bigquery.connection-factory

ConnectionFactory to obtain connection to Bigquery Service. If not provided the default one will be used. The option is a org.apache.camel.component.google.bigquery.GoogleBigQueryConnectionFactory type.

 

GoogleBigQueryConnectionFactory

camel.component.google-bigquery.dataset-id

BigQuery Dataset Id.

 

String

camel.component.google-bigquery.enabled

Whether to enable auto configuration of the google-bigquery component. This is enabled by default.

 

Boolean

camel.component.google-bigquery.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.google-bigquery.project-id

Google Cloud Project Id.

 

String

Chapter 39. Google Pubsub

Since Camel 2.19

Both producer and consumer are supported.

The Google Pubsub component provides access to the Cloud Pub/Sub Infrastructure via the Google Cloud Java Client for Google Cloud Pub/Sub.

39.1. Dependencies

When using google-pubsub with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-google-pubsub-starter</artifactId>
</dependency>

39.2. URI Format

The Google Pubsub Component uses the following URI format:

google-pubsub://project-id:destinationName?[options]

Destination Name can be either a topic or a subscription name.

39.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

39.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

39.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

39.4. Component Options

The Google Pubsub component supports 10 options, which are listed below.

NameDescriptionDefaultType

authenticate (common)

Use Credentials when interacting with PubSub service (no authentication is required when using emulator).

true

boolean

endpoint (common)

Endpoint to use with local Pub/Sub emulator.

 

String

serviceAccountKey (common)

The Service account key that can be used as credentials for the PubSub publisher/subscriber. It can be loaded by default from classpath, but you can prefix with classpath:, file:, or http: to load the resource from different systems.

 

String

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

synchronousPullRetryableCodes (consumer)

Comma-separated list of additional retryable error codes for synchronous pull. By default the PubSub client library retries ABORTED, UNAVAILABLE, UNKNOWN.

 

String

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

publisherCacheSize (producer)

Maximum number of producers to cache. This could be increased if you have producers for lots of different topics.

 

int

publisherCacheTimeout (producer)

How many milliseconds should each producer stay alive in the cache.

 

int

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

publisherTerminationTimeout (advanced)

How many milliseconds should a producer be allowed to terminate.

 

int

39.5. Endpoint Options

The Google Pubsub endpoint is configured using URI syntax:

google-pubsub:projectId:destinationName

with the following path and query parameters:

39.5.1. Path Parameters (2 parameters)

NameDescriptionDefaultType

projectId (common)

Required The Google Cloud PubSub Project Id.

 

String

destinationName (common)

Required The Destination Name. For the consumer this will be the subscription name, while for the producer this will be the topic name.

 

String

39.5.2. Query Parameters (15 parameters)

NameDescriptionDefaultType

authenticate (common)

Use Credentials when interacting with PubSub service (no authentication is required when using emulator).

true

boolean

loggerId (common)

Logger ID to use when a match to the parent route required.

 

String

serviceAccountKey (common)

The Service account key that can be used as credentials for the PubSub publisher/subscriber. It can be loaded by default from classpath, but you can prefix with classpath:, file:, or http: to load the resource from different systems.

 

String

ackMode (consumer)

AUTO = exchange gets ack’ed/nack’ed on completion. NONE = downstream process has to ack/nack explicitly.

Enum values:

  • AUTO
  • NONE

AUTO

AckMode

concurrentConsumers (consumer)

The number of parallel streams consuming from the subscription.

1

Integer

maxAckExtensionPeriod (consumer)

Set the maximum period a message ack deadline will be extended. Value in seconds.

3600

int

maxMessagesPerPoll (consumer)

The max number of messages to receive from the server in a single API call.

1

Integer

synchronousPull (consumer)

Synchronously pull batches of messages.

false

boolean

bridgeErrorHandler (consumer (advanced))

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

messageOrderingEnabled (producer (advanced))

Should message ordering be enabled.

false

boolean

pubsubEndpoint (producer (advanced))

Pub/Sub endpoint to use. Required when using message ordering, and ensures that messages are received in order even when multiple publishers are used.

 

String

serializer (producer (advanced))

Autowired A custom GooglePubsubSerializer to use for serializing message payloads in the producer.

 

GooglePubsubSerializer

39.6. Message Headers

The Google Pubsub component supports 5 message header(s), which are listed below:

NameDescriptionDefaultType

CamelGooglePubsubMessageId (common)

Constant: MESSAGE_ID

The ID of the message, assigned by the server when the message is published.

 

String

CamelGooglePubsubMsgAckId (consumer)

Constant: ACK_ID

The ID used to acknowledge the received message.

 

String

CamelGooglePubsubPublishTime (consumer)

Constant: PUBLISH_TIME

The time at which the message was published.

 

Timestamp

CamelGooglePubsubAttributes (common)

Constant: ATTRIBUTES

The attributes of the message.

 

Map

CamelGooglePubsubOrderingKey (producer)

Constant: ORDERING_KEY

If non-empty, identifies related messages for which publish order should be respected.

 

String

39.7. Producer Endpoints

Producer endpoints can accept and deliver to PubSub individual and grouped exchanges alike. Grouped exchanges have Exchange.GROUPED_EXCHANGE property set.

Google PubSub expects the payload to be byte[] array, Producer endpoints will send:

  • String body as byte[] encoded as UTF-8
  • byte[] body as is
  • Everything else will be serialised into byte[] array

A Map set as message header GooglePubsubConstants.ATTRIBUTES will be sent as PubSub attributes.

Google PubSub supports ordered message delivery.

To enable this set set the options messageOrderingEnabled to true, and the pubsubEndpoint to a GCP region.

When producing messages set the message header GooglePubsubConstants.ORDERING_KEY . This will be set as the PubSub orderingKey for the message.

More information in Ordering messages.

Once exchange has been delivered to PubSub the PubSub Message ID will be assigned to the header GooglePubsubConstants.MESSAGE_ID.

39.8. Consumer Endpoints

Google PubSub will redeliver the message if it has not been acknowledged within the time period set as a configuration option on the subscription.

The component will acknowledge the message once exchange processing has been completed.

If the route throws an exception, the exchange is marked as failed and the component will NACK the message - it will be redelivered immediately.

To ack/nack the message the component uses Acknowledgement ID stored as header GooglePubsubConstants.ACK_ID. If the header is removed or tampered with, the ack will fail and the message will be redelivered again after the ack deadline.

39.9. Message Body

The consumer endpoint returns the content of the message as byte[] - exactly as the underlying system sends it. It is up for the route to convert/unmarshall the contents.

39.10. Authentication Configuration

By default this component aquires credentials using GoogleCredentials.getApplicationDefault(). This behavior can be disabled by setting authenticate option to false, in which case requests to Google API will be made without authentication details. This is only desirable when developing against an emulator. This behavior can be altered by supplying a path to a service account key file.

39.11. Rollback and Redelivery

The rollback for Google PubSub relies on the idea of the Acknowledgement Deadline - the time period where Google PubSub expects to receive the acknowledgement. If the acknowledgement has not been received, the message is redelivered.

Google provides an API to extend the deadline for a message.

More information in Google PubSub Documentation.

So, rollback is effectively a deadline extension API call with zero value - i.e. deadline is reached now and message can be redelivered to the next consumer.

It is possible to delay the message redelivery by setting the acknowledgement deadline explicitly for the rollback by setting the message header GooglePubsubConstants.ACK_DEADLINE to the value in seconds.

39.12. Spring Boot Auto-Configuration

The component supports 11 options, which are listed below.

NameDescriptionDefaultType

camel.component.google-pubsub.authenticate

Use Credentials when interacting with PubSub service (no authentication is required when using emulator).

true

Boolean

camel.component.google-pubsub.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.google-pubsub.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.google-pubsub.enabled

Whether to enable auto configuration of the google-pubsub component. This is enabled by default.

 

Boolean

camel.component.google-pubsub.endpoint

Endpoint to use with local Pub/Sub emulator.

 

String

camel.component.google-pubsub.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.google-pubsub.publisher-cache-size

Maximum number of producers to cache. This could be increased if you have producers for lots of different topics.

 

Integer

camel.component.google-pubsub.publisher-cache-timeout

How many milliseconds should each producer stay alive in the cache.

 

Integer

camel.component.google-pubsub.publisher-termination-timeout

How many milliseconds should a producer be allowed to terminate.

 

Integer

camel.component.google-pubsub.service-account-key

The Service account key that can be used as credentials for the PubSub publisher/subscriber. It can be loaded by default from classpath, but you can prefix with classpath:, file:, or http: to load the resource from different systems.

 

String

camel.component.google-pubsub.synchronous-pull-retryable-codes

Comma-separated list of additional retryable error codes for synchronous pull. By default the PubSub client library retries ABORTED, UNAVAILABLE, UNKNOWN.

 

String

Chapter 40. Groovy

Since Camel 1.3

Camel has support for using Groovy. For example, you can use Groovy in a Predicate with the Message Filter EIP.

40.1. Dependencies

When using camel-groovy with Red Hat build of Camel Spring Boot, add the following Maven dependency to your pom.xml to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-groovy-starter</artifactId>
</dependency>

40.2. URI Format

The camel-groovy language component uses the following URI notation:

groovy("someGroovyExpression")

40.3. Groovy Options

The Groovy language supports 2 options, which are listed below.

NameDefaultJava TypeDescription

resultType

 

String

Sets the class of the result type (type from output).

trim

true

Boolean

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

40.4. Examples

Following example uses a groovy script as predicate in the message filter, to determine if any line items are over $100:

Java
from("queue:foo")
    .filter(groovy("request.lineItems.any { i -> i.value > 100 }"))
        .to("queue:bar")
XML DSL
<route>
    <from uri="queue:foo"/>
    <filter>
        <groovy>request.lineItems.any { i -> i.value > 100 }</groovy>
        <to uri="queue:bar"/>
    </filter>
</route>

40.5. Groovy Context

Camel provides an exchange information in the Groovy context (just a Map). The Exchange is transferred as:

keyvalue

exchange

The Exchange itself.

exchangeProperties

The Exchange properties.

variables

The variables

headers

The headers of the In message.

camelContext

The Camel Context.

request

The In message.

body

The In message body.

response

The Out message (only for InOut message exchange pattern).

40.6. How to get the result from multiple statements script

As the Groovy script engine evaluate method returns a Null if it runs a multiple statements script. Camel looks up the value of script result by using the key of result from the value set. If you have multiple statements scripts, make sure to set the value of result variable as the script return value.

bar = "baz";
# some other statements ...
# camel take the result value as the script evaluation result
result = body * 2 + 1

40.7. Customizing Groovy Shell

For very special use cases you may need to use a custom GroovyShell instance in your Groovy expressions. To provide the custom GroovyShell, add an implementation of the org.apache.camel.language.groovy.GroovyShellFactory SPI interface to the Camel registry.

public class CustomGroovyShellFactory implements GroovyShellFactory {

  public GroovyShell createGroovyShell(Exchange exchange) {
    ImportCustomizer importCustomizer = new ImportCustomizer();
    importCustomizer.addStaticStars("com.example.Utils");
    CompilerConfiguration configuration = new CompilerConfiguration();
    configuration.addCompilationCustomizers(importCustomizer);
    return new GroovyShell(configuration);
  }

}

Camel will then use your custom GroovyShell instance (containing your custom static imports), instead of the default one.

40.8. Loading script from external resource

You can externalize the script and have Camel load it from a resource such as "classpath:", "file:", or "http:". You can achieve this by using the following syntax:

`"resource:scheme:location"`,

For example, to refer to a file on the classpath you can use the following:

.setHeader("myHeader").groovy("resource:classpath:mygroovy.groovy")

40.9. Spring Boot Auto-Configuration

The component supports 2 options, which are listed below.

NameDescriptionDefaultType

camel.language.groovy.enabled

Whether to enable auto configuration of the groovy language. This is enabled by default.

 

Boolean

camel.language.groovy.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

Chapter 41. gRPC

Since Camel 2.19

Both producer and consumer are supported

The gRPC component allows you to call or expose Remote Procedure Call (RPC) services using Protocol Buffers (protobuf) exchange format over HTTP/2 transport.

41.1. Dependencies

When using grpc with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-grpc-starter</artifactId>
</dependency>

41.2. URI format

grpc:host:port/service[?options]

41.3. Configuring Options

Camel components are configured on two separate levels:

  • component level
  • endpoint level

41.3.1. Configuring component options

The component level is the highest level which holds general and common configurations that are inherited by the endpoints. For example a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

Configuring components can be done with the Component DSL, in a configuration file (application.properties|yaml), or directly with Java code.

41.3.2. Configuring endpoint options

Where you find yourself configuring the most is on endpoints, as endpoints often have many options, which allows you to configure what you need the endpoint to do. The options are also categorized into whether the endpoint is used as consumer (from) or as a producer (to), or used for both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

A good practice when configuring options is to use Property Placeholders, which allows to not hardcode urls, port numbers, sensitive information, and other settings. In other words placeholders allows to externalize the configuration from your code, and gives more flexibility and reuse.

The following two sections lists all the options, firstly for the component followed by the endpoint.

41.4. Component Options

The gRPC component supports 3 options, which are listed below.

NameDescriptionDefaultType

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

41.5. Endpoint Options

The gRPC endpoint is configured using URI syntax:

grpc:host:port/service

with the following path and query parameters:

41.5.1. Path Parameters (3 parameters)

NameDescriptionDefaultType

host (common)

Required The gRPC server host name. This is localhost or 0.0.0.0 when being a consumer or remote server host name when using producer.

 

String

port (common)

Required The gRPC local or remote server port.

 

int

service (common)

Required Fully qualified service name from the protocol buffer descriptor file (package dot service definition name).

 

String

41.5.2. Query Parameters (29 parameters)

NameDescriptionDefaultType

flowControlWindow (common)

The HTTP/2 flow control window size (MiB).

1048576

int

maxMessageSize (common)

The maximum message size allowed to be received/sent (MiB).

4194304

int

autoDiscoverServerInterceptors (consumer)

Setting the autoDiscoverServerInterceptors mechanism, if true, the component will look for a ServerInterceptor instance in the registry automatically otherwise it will skip that checking.

true

boolean

consumerStrategy (consumer)

This option specifies the top-level strategy for processing service requests and responses in streaming mode. If an aggregation strategy is selected, all requests will be accumulated in the list, then transferred to the flow, and the accumulated responses will be sent to the sender. If a propagation strategy is selected, request is sent to the stream, and the response will be immediately sent back to the sender.

Enum values:

  • AGGREGATION
  • PROPAGATION

PROPAGATION

GrpcConsumerStrategy

forwardOnCompleted (consumer)

Determines if onCompleted events should be pushed to the Camel route.

false

boolean

forwardOnError (consumer)

Determines if onError events should be pushed to the Camel route. Exceptions will be set as message body.

false

boolean

maxConcurrentCallsPerConnection (consumer)

The maximum number of concurrent calls permitted for each incoming server connection.

2147483647

int

routeControlledStreamObserver (consumer)

Lets the route to take control over stream observer. If this value is set to true, then the response observer of gRPC call will be set with the name GrpcConstants.GRPC_RESPONSE_OBSERVER in the Exchange object. Please note that the stream observer’s onNext(), onError(), onCompleted() methods should be called in the route.

false

boolean

bridgeErrorHandler (consumer (advanced))

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
 

ExchangePattern

autoDiscoverClientInterceptors (producer)

Setting the autoDiscoverClientInterceptors mechanism, if true, the component will look for a ClientInterceptor instance in the registry automatically otherwise it will skip that checking.

true

boolean

method (producer)

gRPC method name.

 

String

producerStrategy (producer)

The mode used to communicate with a remote gRPC server. In SIMPLE mode a single exchange is translated into a remote procedure call. In STREAMING mode all exchanges will be sent within the same request (input and output of the recipient gRPC service must be of type 'stream').

Enum values:

  • SIMPLE
  • STREAMING

SIMPLE

GrpcProducerStrategy

streamRepliesTo (producer)

When using STREAMING client mode, it indicates the endpoint where responses should be forwarded.

 

String

userAgent (producer)

The user agent header passed to the server.

 

String

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

synchronous (advanced)

Sets whether synchronous processing should be strictly used.

false

boolean

authenticationType (security)

Authentication method type in advance to the SSL/TLS negotiation.

Enum values:

  • NONE
  • GOOGLE
  • JWT

NONE

GrpcAuthType

jwtAlgorithm (security)

JSON Web Token sign algorithm.

Enum values:

  • HMAC256
  • HMAC384
  • HMAC512

HMAC256

JwtAlgorithm

jwtIssuer (security)

JSON Web Token issuer.

 

String

jwtSecret (security)

JSON Web Token secret.

 

String

jwtSubject (security)

JSON Web Token subject.

 

String

keyCertChainResource (security)

The X.509 certificate chain file resource in PEM format link.

 

String

keyPassword (security)

The PKCS#8 private key file password.

 

String

keyResource (security)

The PKCS#8 private key file resource in PEM format link.

 

String

negotiationType (security)

Identifies the security negotiation type used for HTTP/2 communication.

Enum values:

  • TLS
  • PLAINTEXT_UPGRADE
  • PLAINTEXT

PLAINTEXT

NegotiationType

serviceAccountResource (security)

Service Account key file in JSON format resource link supported by the Google Cloud SDK.

 

String

trustCertCollectionResource (security)

The trusted certificates collection file resource in PEM format for verifying the remote endpoint’s certificate.

 

String

41.6. Message Headers

The gRPC component supports 3 message header(s), which is/are listed below:

NameDescriptionDefaultType

CamelGrpcMethodName (consumer)

Constant: GRPC_METHOD_NAME_HEADER

Method name handled by the consumer service.

 

String

CamelGrpcUserAgent (consumer)

Constant: GRPC_USER_AGENT_HEADER

If provided, the given agent will prepend the gRPC library’s user agent information.

 

String

CamelGrpcEventType (consumer)

Constant: GRPC_EVENT_TYPE_HEADER

Received event type from the sent request. Possible values: onNext onCompleted onError.

 

String

41.7. Transport security and authentication support

The following authentication mechanisms are built-in to gRPC and available in this component:

  • SSL/TLS: gRPC has SSL/TLS integration and promotes the use of SSL/TLS to authenticate the server, and to encrypt all the data exchanged between the client and the server. Optional mechanisms are available for clients to provide certificates for mutual authentication.
  • Token-based authentication with Google: gRPC provides a generic mechanism to attach metadata based credentials to requests and responses. Additional support for acquiring access tokens while accessing Google APIs through gRPC is provided. In general this mechanism must be used as well as SSL/TLS on the channel.

To enable these features the following component properties combinations must be configured:

Num.OptionParameterValueRequired/Optional

1

SSL/TLS

negotiationType

TLS

Required

  

keyCertChainResource

 

Required

  

keyResource

 

Required

  

keyPassword

 

Optional

  

trustCertCollectionResource

 

Optional

2

Token-based authentication with Google API

authenticationType

GOOGLE

Required

  

negotiationType

TLS

Required

  

serviceAccountResource

 

Required

3

Custom JSON Web Token implementation authentication

authenticationType

JWT

Required

  

negotiationType

NONE or TLS

Optional. The TLS/SSL not checking for this type, but strongly recommended.

  

jwtAlgorithm

HMAC256(default) or (HMAC384,HMAC512)

Optional

  

jwtSecret

 

Required

  

jwtIssuer

 

Optional

  

jwtSubject

 

Optional

41.8. gRPC producer resource type mapping

The table below shows the types of objects in the message body, depending on the types (simple or stream) of incoming and outgoing parameters, as well as the invocation style (synchronous or asynchronous). Please note, that invocation of the procedures with incoming stream parameter in asynchronous style are not allowed.

Invocation styleRequest typeResponse typeRequest Body TypeResult Body Type

synchronous

simple

simple

Object

Object

synchronous

simple

stream

Object

List<Object>

synchronous

stream

simple

not allowed

not allowed

synchronous

stream

stream

not allowed

not allowed

asynchronous

simple

simple

Object

List<Object>

asynchronous

simple

stream

Object

List<Object>

asynchronous

stream

simple

Object or List<Object>

List<Object>

asynchronous

stream

stream

Object or List<Object>

List<Object>

41.9. Examples

Below is a simple synchronous method invoke with host and port parameters:

from("direct:grpc-sync")
.to("grpc://remotehost:1101/org.apache.camel.component.grpc.PingPong?method=sendPing&synchronous=true");
<route>
    <from uri="direct:grpc-sync" />
    <to uri="grpc://remotehost:1101/org.apache.camel.component.grpc.PingPong?method=sendPing&synchronous=true"/>
</route>

An asynchronous method invokes

from("direct:grpc-async")
.to("grpc://remotehost:1101/org.apache.camel.component.grpc.PingPong?method=pingAsyncResponse");

a gRPC service consumer with propagation consumer strategy:

from("grpc://localhost:1101/org.apache.camel.component.grpc.PingPong?consumerStrategy=PROPAGATION")
.to("direct:grpc-service");

gRPC service producer with streaming producer strategy (requires a service that uses "stream" mode as input and output):

from("direct:grpc-request-stream")
.to("grpc://remotehost:1101/org.apache.camel.component.grpc.PingPong?method=PingAsyncAsync&producerStrategy=STREAMING&streamRepliesTo=direct:grpc-response-stream");

from("direct:grpc-response-stream")
.log("Response received: ${body}");

gRPC service consumer TLS/SSL security negotiation enabled:

from("grpc://localhost:1101/org.apache.camel.component.grpc.PingPong?consumerStrategy=PROPAGATION&negotiationType=TLS&keyCertChainResource=file:src/test/resources/certs/server.pem&keyResource=file:src/test/resources/certs/server.key&trustCertCollectionResource=file:src/test/resources/certs/ca.pem")
.to("direct:tls-enable")

gRPC service producer with custom JSON Web Token (JWT) implementation authentication:

from("direct:grpc-jwt")
.to("grpc://localhost:1101/org.apache.camel.component.grpc.PingPong?method=pingSyncSync&synchronous=true&authenticationType=JWT&jwtSecret=supersecuredsecret");

41.10. Configuration

Use the protobuf-maven-plugin, which calls the Protocol Buffer Compiler (protoc) to generate Java source files from .proto (protocol buffer definition) files. This plugin will generate procedures request and response classes, their builders and gRPC procedures stubs classes as well.

Following steps are required:

Insert operating system and CPU architecture detection extension inside <build> tag of the project pom.xml or set $\{os.detected.classifier} parameter manually

<extensions>
  <extension>
    <groupId>kr.motd.maven</groupId>
    <artifactId>os-maven-plugin</artifactId>
    <version>1.7.1</version>
  </extension>
</extensions>

Insert the gRPC and protobuf Java code generator plugins into the <plugins> tag of the project’s pom.xml.

<plugin>
  <groupId>org.xolstice.maven.plugins</groupId>
  <artifactId>protobuf-maven-plugin</artifactId>
  <version>0.6.1</version>
  <configuration>
    <protocArtifact>com.google.protobuf:protoc:${protobuf-version}:exe:${os.detected.classifier}</protocArtifact>
    <pluginId>grpc-java</pluginId>
    <pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc-version}:exe:${os.detected.classifier}</pluginArtifact>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>compile</goal>
        <goal>compile-custom</goal>
        <goal>test-compile</goal>
        <goal>test-compile-custom</goal>
      </goals>
    </execution>
  </executions>
</plugin>

41.11. Additional resources

See these resources:

41.12. Spring Boot Auto-Configuration

The component supports 4 options, which are listed below.

NameDescriptionDefaultType

camel.component.grpc.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.grpc.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.grpc.enabled

Whether to enable auto configuration of the grpc component. This is enabled by default.

 

Boolean

camel.component.grpc.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

Chapter 42. Header

The Header Expression Language allows you to extract values of named headers.

42.1. Dependencies

The Header language is part of camel-core.

When using header with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-core-starter</artifactId>
</dependency>

42.2. Header Options

The Header language supports 1 options, which are listed below.

NameDefaultJava TypeDescription

trim

 

Boolean

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

42.3. Example usage

The recipientList EIP can utilize a header:

<route>
  <from uri="direct:a" />
  <recipientList>
    <header>myHeader</header>
  </recipientList>
</route>

In this case, the list of recipients are contained in the header 'myHeader'.

And the same example in Java DSL:

from("direct:a").recipientList(header("myHeader"));

42.4. Spring Boot Auto-Configuration

The component supports 147 options, which are listed below.

NameDescriptionDefaultType

camel.cloud.consul.service-discovery.acl-token

Sets the ACL token to be used with Consul.

 

String

camel.cloud.consul.service-discovery.block-seconds

The seconds to wait for a watch event, default 10 seconds.

10

Integer

camel.cloud.consul.service-discovery.configurations

Define additional configuration definitions.

 

Map

camel.cloud.consul.service-discovery.connect-timeout-millis

Connect timeout for OkHttpClient.

 

Long

camel.cloud.consul.service-discovery.datacenter

The data center.

 

String

camel.cloud.consul.service-discovery.enabled

Enable the component.

true

Boolean

camel.cloud.consul.service-discovery.password

Sets the password to be used for basic authentication.

 

String

camel.cloud.consul.service-discovery.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.consul.service-discovery.read-timeout-millis

Read timeout for OkHttpClient.

 

Long

camel.cloud.consul.service-discovery.url

The Consul agent URL.

 

String

camel.cloud.consul.service-discovery.user-name

Sets the username to be used for basic authentication.

 

String

camel.cloud.consul.service-discovery.write-timeout-millis

Write timeout for OkHttpClient.

 

Long

camel.cloud.dns.service-discovery.configurations

Define additional configuration definitions.

 

Map

camel.cloud.dns.service-discovery.domain

The domain name;.

 

String

camel.cloud.dns.service-discovery.enabled

Enable the component.

true

Boolean

camel.cloud.dns.service-discovery.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.dns.service-discovery.proto

The transport protocol of the desired service.

_tcp

String

camel.cloud.etcd.service-discovery.configurations

Define additional configuration definitions.

 

Map

camel.cloud.etcd.service-discovery.enabled

Enable the component.

true

Boolean

camel.cloud.etcd.service-discovery.password

The password to use for basic authentication.

 

String

camel.cloud.etcd.service-discovery.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.etcd.service-discovery.service-path

The path to look for for service discovery.

/services/

String

camel.cloud.etcd.service-discovery.timeout

To set the maximum time an action could take to complete.

 

Long

camel.cloud.etcd.service-discovery.type

To set the discovery type, valid values are on-demand and watch.

on-demand

String

camel.cloud.etcd.service-discovery.uris

The URIs the client can connect to.

 

String

camel.cloud.etcd.service-discovery.user-name

The user name to use for basic authentication.

 

String

camel.cloud.kubernetes.service-discovery.api-version

Sets the API version when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.ca-cert-data

Sets the Certificate Authority data when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.ca-cert-file

Sets the Certificate Authority data that are loaded from the file when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-cert-data

Sets the Client Certificate data when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-cert-file

Sets the Client Certificate data that are loaded from the file when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-key-algo

Sets the Client Keystore algorithm, such as RSA when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-key-data

Sets the Client Keystore data when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-key-file

Sets the Client Keystore data that are loaded from the file when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.client-key-passphrase

Sets the Client Keystore passphrase when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.configurations

Define additional configuration definitions.

 

Map

camel.cloud.kubernetes.service-discovery.dns-domain

Sets the DNS domain to use for DNS lookup.

 

String

camel.cloud.kubernetes.service-discovery.enabled

Enable the component.

true

Boolean

camel.cloud.kubernetes.service-discovery.lookup

How to perform service lookup. Possible values: client, dns, environment. When using client, then the client queries the kubernetes master to obtain a list of active pods that provides the service, and then random (or round robin) select a pod. When using dns the service name is resolved as name.namespace.svc.dnsDomain. When using dnssrv the service name is resolved with SRV query for .…​svc…​ When using environment then environment variables are used to lookup the service. By default environment is used.

environment

String

camel.cloud.kubernetes.service-discovery.master-url

Sets the URL to the master when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.namespace

Sets the namespace to use. Will by default use namespace from the ENV variable KUBERNETES_MASTER.

 

String

camel.cloud.kubernetes.service-discovery.oauth-token

Sets the OAUTH token for authentication (instead of username/password) when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.password

Sets the password for authentication when using client lookup.

 

String

camel.cloud.kubernetes.service-discovery.port-name

Sets the Port Name to use for DNS/DNSSRV lookup.

 

String

camel.cloud.kubernetes.service-discovery.port-protocol

Sets the Port Protocol to use for DNS/DNSSRV lookup.

 

String

camel.cloud.kubernetes.service-discovery.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.kubernetes.service-discovery.trust-certs

Sets whether to turn on trust certificate check when using client lookup.

false

Boolean

camel.cloud.kubernetes.service-discovery.username

Sets the username for authentication when using client lookup.

 

String

camel.cloud.ribbon.load-balancer.client-name

Sets the Ribbon client name.

 

String

camel.cloud.ribbon.load-balancer.configurations

Define additional configuration definitions.

 

Map

camel.cloud.ribbon.load-balancer.enabled

Enable the component.

true

Boolean

camel.cloud.ribbon.load-balancer.namespace

The namespace.

 

String

camel.cloud.ribbon.load-balancer.password

The password.

 

String

camel.cloud.ribbon.load-balancer.properties

Set client properties to use. These properties are specific to what service call implementation are in use. For example if using ribbon, then the client properties are define in com.netflix.client.config.CommonClientConfigKey.

 

Map

camel.cloud.ribbon.load-balancer.username

The username.

 

String

camel.hystrix.allow-maximum-size-to-diverge-from-core-size

Allows the configuration for maximumSize to take effect. That value can then be equal to, or higher, than coreSize.

false

Boolean

camel.hystrix.circuit-breaker-enabled

Whether to use a HystrixCircuitBreaker or not. If false no circuit-breaker logic will be used and all requests permitted. This is similar in effect to circuitBreakerForceClosed() except that continues tracking metrics and knowing whether it should be open/closed, this property results in not even instantiating a circuit-breaker.

true

Boolean

camel.hystrix.circuit-breaker-error-threshold-percentage

Error percentage threshold (as whole number such as 50) at which point the circuit breaker will trip open and reject requests. It will stay tripped for the duration defined in circuitBreakerSleepWindowInMilliseconds; The error percentage this is compared against comes from HystrixCommandMetrics.getHealthCounts().

50

Integer

camel.hystrix.circuit-breaker-force-closed

If true the HystrixCircuitBreaker#allowRequest() will always return true to allow requests regardless of the error percentage from HystrixCommandMetrics.getHealthCounts(). The circuitBreakerForceOpen() property takes precedence so if it set to true this property does nothing.

false

Boolean

camel.hystrix.circuit-breaker-force-open

If true the HystrixCircuitBreaker.allowRequest() will always return false, causing the circuit to be open (tripped) and reject all requests. This property takes precedence over circuitBreakerForceClosed();.

false

Boolean

camel.hystrix.circuit-breaker-request-volume-threshold

Minimum number of requests in the metricsRollingStatisticalWindowInMilliseconds() that must exist before the HystrixCircuitBreaker will trip. If below this number the circuit will not trip regardless of error percentage.

20

Integer

camel.hystrix.circuit-breaker-sleep-window-in-milliseconds

The time in milliseconds after a HystrixCircuitBreaker trips open that it should wait before trying requests again.

5000

Integer

camel.hystrix.configurations

Define additional configuration definitions.

 

Map

camel.hystrix.core-pool-size

Core thread-pool size that gets passed to java.util.concurrent.ThreadPoolExecutor#setCorePoolSize(int).

10

Integer

camel.hystrix.enabled

Enable the component.

true

Boolean

camel.hystrix.execution-isolation-semaphore-max-concurrent-requests

Number of concurrent requests permitted to HystrixCommand.run(). Requests beyond the concurrent limit will be rejected. Applicable only when executionIsolationStrategy == SEMAPHORE.

20

Integer

camel.hystrix.execution-isolation-strategy

What isolation strategy HystrixCommand.run() will be executed with. If THREAD then it will be executed on a separate thread and concurrent requests limited by the number of threads in the thread-pool. If SEMAPHORE then it will be executed on the calling thread and concurrent requests limited by the semaphore count.

THREAD

String

camel.hystrix.execution-isolation-thread-interrupt-on-timeout

Whether the execution thread should attempt an interrupt (using Future#cancel ) when a thread times out. Applicable only when executionIsolationStrategy() == THREAD.

true

Boolean

camel.hystrix.execution-timeout-enabled

Whether the timeout mechanism is enabled for this command.

true

Boolean

camel.hystrix.execution-timeout-in-milliseconds

Time in milliseconds at which point the command will timeout and halt execution. If executionIsolationThreadInterruptOnTimeout == true and the command is thread-isolated, the executing thread will be interrupted. If the command is semaphore-isolated and a HystrixObservableCommand, that command will get unsubscribed.

1000

Integer

camel.hystrix.fallback-enabled

Whether HystrixCommand.getFallback() should be attempted when failure occurs.

true

Boolean

camel.hystrix.fallback-isolation-semaphore-max-concurrent-requests

Number of concurrent requests permitted to HystrixCommand.getFallback(). Requests beyond the concurrent limit will fail-fast and not attempt retrieving a fallback.

10

Integer

camel.hystrix.group-key

Sets the group key to use. The default value is CamelHystrix.

CamelHystrix

String

camel.hystrix.keep-alive-time

Keep-alive time in minutes that gets passed to ThreadPoolExecutor#setKeepAliveTime(long,TimeUnit).

1

Integer

camel.hystrix.max-queue-size

Max queue size that gets passed to BlockingQueue in HystrixConcurrencyStrategy.getBlockingQueue(int) This should only affect the instantiation of a threadpool - it is not eliglible to change a queue size on the fly. For that, use queueSizeRejectionThreshold().

-1

Integer

camel.hystrix.maximum-size

Maximum thread-pool size that gets passed to ThreadPoolExecutor#setMaximumPoolSize(int) . This is the maximum amount of concurrency that can be supported without starting to reject HystrixCommands. Please note that this setting only takes effect if you also set allowMaximumSizeToDivergeFromCoreSize.

10

Integer

camel.hystrix.metrics-health-snapshot-interval-in-milliseconds

Time in milliseconds to wait between allowing health snapshots to be taken that calculate success and error percentages and affect HystrixCircuitBreaker.isOpen() status. On high-volume circuits the continual calculation of error percentage can become CPU intensive thus this controls how often it is calculated.

500

Integer

camel.hystrix.metrics-rolling-percentile-bucket-size

Maximum number of values stored in each bucket of the rolling percentile. This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.

10

Integer

camel.hystrix.metrics-rolling-percentile-enabled

Whether percentile metrics should be captured using HystrixRollingPercentile inside HystrixCommandMetrics.

true

Boolean

camel.hystrix.metrics-rolling-percentile-window-buckets

Number of buckets the rolling percentile window is broken into. This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.

6

Integer

camel.hystrix.metrics-rolling-percentile-window-in-milliseconds

Duration of percentile rolling window in milliseconds. This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.

10000

Integer

camel.hystrix.metrics-rolling-statistical-window-buckets

Number of buckets the rolling statistical window is broken into. This is passed into HystrixRollingNumber inside HystrixCommandMetrics.

10

Integer

camel.hystrix.metrics-rolling-statistical-window-in-milliseconds

This property sets the duration of the statistical rolling window, in milliseconds. This is how long metrics are kept for the thread pool. The window is divided into buckets and rolls by those increments.

10000

Integer

camel.hystrix.queue-size-rejection-threshold

Queue size rejection threshold is an artificial max size at which rejections will occur even if maxQueueSize has not been reached. This is done because the maxQueueSize of a BlockingQueue can not be dynamically changed and we want to support dynamically changing the queue size that affects rejections. This is used by HystrixCommand when queuing a thread for execution.

5

Integer

camel.hystrix.request-log-enabled

Whether HystrixCommand execution and events should be logged to HystrixRequestLog.

true

Boolean

camel.hystrix.thread-pool-key

Sets the thread pool key to use. Will by default use the same value as groupKey has been configured to use.

CamelHystrix

String

camel.hystrix.thread-pool-rolling-number-statistical-window-buckets

Number of buckets the rolling statistical window is broken into. This is passed into HystrixRollingNumber inside each HystrixThreadPoolMetrics instance.

10

Integer

camel.hystrix.thread-pool-rolling-number-statistical-window-in-milliseconds

Duration of statistical rolling window in milliseconds. This is passed into HystrixRollingNumber inside each HystrixThreadPoolMetrics instance.

10000

Integer

camel.language.constant.enabled

Whether to enable auto configuration of the constant language. This is enabled by default.

 

Boolean

camel.language.constant.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.csimple.enabled

Whether to enable auto configuration of the csimple language. This is enabled by default.

 

Boolean

camel.language.csimple.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.exchangeproperty.enabled

Whether to enable auto configuration of the exchangeProperty language. This is enabled by default.

 

Boolean

camel.language.exchangeproperty.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.file.enabled

Whether to enable auto configuration of the file language. This is enabled by default.

 

Boolean

camel.language.file.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.header.enabled

Whether to enable auto configuration of the header language. This is enabled by default.

 

Boolean

camel.language.header.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.ref.enabled

Whether to enable auto configuration of the ref language. This is enabled by default.

 

Boolean

camel.language.ref.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.simple.enabled

Whether to enable auto configuration of the simple language. This is enabled by default.

 

Boolean

camel.language.simple.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.language.tokenize.enabled

Whether to enable auto configuration of the tokenize language. This is enabled by default.

 

Boolean

camel.language.tokenize.group-delimiter

Sets the delimiter to use when grouping. If this has not been set then token will be used as the delimiter.

 

String

camel.language.tokenize.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

camel.resilience4j.automatic-transition-from-open-to-half-open-enabled

Enables automatic transition from OPEN to HALF_OPEN state once the waitDurationInOpenState has passed.

false

Boolean

camel.resilience4j.circuit-breaker-ref

Refers to an existing io.github.resilience4j.circuitbreaker.CircuitBreaker instance to lookup and use from the registry. When using this, then any other circuit breaker options are not in use.

 

String

camel.resilience4j.config-ref

Refers to an existing io.github.resilience4j.circuitbreaker.CircuitBreakerConfig instance to lookup and use from the registry.

 

String

camel.resilience4j.configurations

Define additional configuration definitions.

 

Map

camel.resilience4j.enabled

Enable the component.

true

Boolean

camel.resilience4j.failure-rate-threshold

Configures the failure rate threshold in percentage. If the failure rate is equal or greater than the threshold the CircuitBreaker transitions to open and starts short-circuiting calls. The threshold must be greater than 0 and not greater than 100. Default value is 50 percentage.

 

Float

camel.resilience4j.minimum-number-of-calls

Configures the minimum number of calls which are required (per sliding window period) before the CircuitBreaker can calculate the error rate. For example, if minimumNumberOfCalls is 10, then at least 10 calls must be recorded, before the failure rate can be calculated. If only 9 calls have been recorded the CircuitBreaker will not transition to open even if all 9 calls have failed. Default minimumNumberOfCalls is 100.

100

Integer

camel.resilience4j.permitted-number-of-calls-in-half-open-state

Configures the number of permitted calls when the CircuitBreaker is half open. The size must be greater than 0. Default size is 10.

10

Integer

camel.resilience4j.sliding-window-size

Configures the size of the sliding window which is used to record the outcome of calls when the CircuitBreaker is closed. slidingWindowSize configures the size of the sliding window. Sliding window can either be count-based or time-based. If slidingWindowType is COUNT_BASED, the last slidingWindowSize calls are recorded and aggregated. If slidingWindowType is TIME_BASED, the calls of the last slidingWindowSize seconds are recorded and aggregated. The slidingWindowSize must be greater than 0. The minimumNumberOfCalls must be greater than 0. If the slidingWindowType is COUNT_BASED, the minimumNumberOfCalls cannot be greater than slidingWindowSize . If the slidingWindowType is TIME_BASED, you can pick whatever you want. Default slidingWindowSize is 100.

100

Integer

camel.resilience4j.sliding-window-type

Configures the type of the sliding window which is used to record the outcome of calls when the CircuitBreaker is closed. Sliding window can either be count-based or time-based. If slidingWindowType is COUNT_BASED, the last slidingWindowSize calls are recorded and aggregated. If slidingWindowType is TIME_BASED, the calls of the last slidingWindowSize seconds are recorded and aggregated. Default slidingWindowType is COUNT_BASED.

COUNT_BASED

String

camel.resilience4j.slow-call-duration-threshold

Configures the duration threshold (seconds) above which calls are considered as slow and increase the slow calls percentage. Default value is 60 seconds.

60

Integer

camel.resilience4j.slow-call-rate-threshold

Configures a threshold in percentage. The CircuitBreaker considers a call as slow when the call duration is greater than slowCallDurationThreshold Duration. When the percentage of slow calls is equal or greater the threshold, the CircuitBreaker transitions to open and starts short-circuiting calls. The threshold must be greater than 0 and not greater than 100. Default value is 100 percentage which means that all recorded calls must be slower than slowCallDurationThreshold.

 

Float

camel.resilience4j.wait-duration-in-open-state

Configures the wait duration (in seconds) which specifies how long the CircuitBreaker should stay open, before it switches to half open. Default value is 60 seconds.

60

Integer

camel.resilience4j.writable-stack-trace-enabled

Enables writable stack traces. When set to false, Exception.getStackTrace returns a zero length array. This may be used to reduce log spam when the circuit breaker is open as the cause of the exceptions is already known (the circuit breaker is short-circuiting calls).

true

Boolean

camel.rest.api-component

The name of the Camel component to use as the REST API (such as swagger) If no API Component has been explicit configured, then Camel will lookup if there is a Camel component responsible for servicing and generating the REST API documentation, or if a org.apache.camel.spi.RestApiProcessorFactory is registered in the registry. If either one is found, then that is being used.

 

String

camel.rest.api-context-path

Sets a leading API context-path the REST API services will be using. This can be used when using components such as camel-servlet where the deployed web application is deployed using a context-path.

 

String

camel.rest.api-context-route-id

Sets the route id to use for the route that services the REST API. The route will by default use an auto assigned route id.

 

String

camel.rest.api-host

To use an specific hostname for the API documentation (eg swagger) This can be used to override the generated host with this configured hostname.

 

String

camel.rest.api-property

Allows to configure as many additional properties for the api documentation (swagger). For example set property api.title to my cool stuff.

 

Map

camel.rest.api-vendor-extension

Whether vendor extension is enabled in the Rest APIs. If enabled then Camel will include additional information as vendor extension (eg keys starting with x-) such as route ids, class names etc. Not all 3rd party API gateways and tools supports vendor-extensions when importing your API docs.

false

Boolean

camel.rest.binding-mode

Sets the binding mode to use. The default value is off.

 

RestBindingMode

camel.rest.client-request-validation

Whether to enable validation of the client request to check whether the Content-Type and Accept headers from the client is supported by the Rest-DSL configuration of its consumes/produces settings. This can be turned on, to enable this check. In case of validation error, then HTTP Status codes 415 or 406 is returned. The default value is false.

false

Boolean

camel.rest.component

The Camel Rest component to use for the REST transport (consumer), such as netty-http, jetty, servlet, undertow. If no component has been explicit configured, then Camel will lookup if there is a Camel component that integrates with the Rest DSL, or if a org.apache.camel.spi.RestConsumerFactory is registered in the registry. If either one is found, then that is being used.

 

String

camel.rest.component-property

Allows to configure as many additional properties for the rest component in use.

 

Map

camel.rest.consumer-property

Allows to configure as many additional properties for the rest consumer in use.

 

Map

camel.rest.context-path

Sets a leading context-path the REST services will be using. This can be used when using components such as camel-servlet where the deployed web application is deployed using a context-path. Or for components such as camel-jetty or camel-netty-http that includes a HTTP server.

 

String

camel.rest.cors-headers

Allows to configure custom CORS headers.

 

Map

camel.rest.data-format-property

Allows to configure as many additional properties for the data formats in use. For example set property prettyPrint to true to have json outputted in pretty mode. The properties can be prefixed to denote the option is only for either JSON or XML and for either the IN or the OUT. The prefixes are: json.in. json.out. xml.in. xml.out. For example a key with value xml.out.mustBeJAXBElement is only for the XML data format for the outgoing. A key without a prefix is a common key for all situations.

 

Map

camel.rest.enable-cors

Whether to enable CORS headers in the HTTP response. The default value is false.

false

Boolean

camel.rest.endpoint-property

Allows to configure as many additional properties for the rest endpoint in use.

 

Map

camel.rest.host

The hostname to use for exposing the REST service.

 

String

camel.rest.host-name-resolver

If no hostname has been explicit configured, then this resolver is used to compute the hostname the REST service will be using.

 

RestHostNameResolver

camel.rest.json-data-format

Name of specific json data format to use. By default json-jackson will be used. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance.

 

String

camel.rest.port

The port number to use for exposing the REST service. Notice if you use servlet component then the port number configured here does not apply, as the port number in use is the actual port number the servlet component is using. eg if using Apache Tomcat its the tomcat http port, if using Apache Karaf its the HTTP service in Karaf that uses port 8181 by default etc. Though in those situations setting the port number here, allows tooling and JMX to know the port number, so its recommended to set the port number to the number that the servlet engine uses.

 

String

camel.rest.producer-api-doc

Sets the location of the api document (swagger api) the REST producer will use to validate the REST uri and query parameters are valid accordingly to the api document. This requires adding camel-swagger-java to the classpath, and any miss configuration will let Camel fail on startup and report the error(s). The location of the api document is loaded from classpath by default, but you can use file: or http: to refer to resources to load from file or http url.

 

String

camel.rest.producer-component

Sets the name of the Camel component to use as the REST producer.

 

String

camel.rest.scheme

The scheme to use for exposing the REST service. Usually http or https is supported. The default value is http.

 

String

camel.rest.skip-binding-on-error-code

Whether to skip binding on output if there is a custom HTTP error code header. This allows to build custom error messages that do not bind to json / xml etc, as success messages otherwise will do.

false

Boolean

camel.rest.use-x-forward-headers

Whether to use X-Forward headers for Host and related setting. The default value is true.

true

Boolean

camel.rest.xml-data-format

Name of specific XML data format to use. By default jaxb will be used. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance.

 

String

camel.rest.api-context-id-pattern

Deprecated Sets an CamelContext id pattern to only allow Rest APIs from rest services within CamelContext’s which name matches the pattern. The pattern name refers to the CamelContext name, to match on the current CamelContext only. For any other value, the pattern uses the rules from PatternHelper#matchPattern(String,String).

 

String

camel.rest.api-context-listing

Deprecated Sets whether listing of all available CamelContext’s with REST services in the JVM is enabled. If enabled it allows to discover these contexts, if false then only the current CamelContext is in use.

false

Boolean

Chapter 43. HL7

The HL7 component is used for working with the HL7 MLLP protocol and HL7 v2 messages using the HAPI library.

This component supports the following:

  • HL7 MLLP codec for Mina
  • HL7 MLLP codec for Netty
  • Type Converter from/to HAPI and String
  • HL7 DataFormat using the HAPI library

43.1. Dependencies

When using hl7 with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-hl7-starter</artifactId>
</dependency>

43.2. HL7 MLLP protocol

HL7 is often used with the HL7 MLLP protocol, which is a text based TCP socket based protocol. This component ships with a Mina and Netty Codec that conforms to the MLLP protocol so you can easily expose an HL7 listener accepting HL7 requests over the TCP transport layer. To expose a HL7 listener service, the camel-mina or link:camel-netty component is used with the HL7MLLPCodec (mina) or HL7MLLPNettyDecoder/HL7MLLPNettyEncoder (Netty).

HL7 MLLP codec can be configured as follows:

NameDefault ValueDescription

startByte

0x0b

The start byte spanning the HL7 payload.

endByte1

0x1c

The first end byte spanning the HL7 payload.

endByte2

0x0d

The 2nd end byte spanning the HL7 payload.

charset

JVM Default

The encoding (a charset name) to use for the codec. If not provided, Camel will use the JVM default Charset.

produceString

true

If true, the codec creates a string using the defined charset. If false, the codec sends a plain byte array into the route, so that the HL7 Data Format can determine the actual charset from the HL7 message content.

convertLFtoCR

false

Will convert \n to \r (0x0d, 13 decimal) as HL7 stipulates \r as segment terminators. The HAPI library requires the use of \r.

43.2.1. Exposing an HL7 listener using Mina

In the Spring XML file, we configure a mina endpoint to listen for HL7 requests using TCP on port 8888:

<endpoint id="hl7MinaListener" uri="mina:tcp://localhost:8888?sync=true&amp;codec=#hl7codec"/>

sync=true indicates that this listener is synchronous and therefore will return a HL7 response to the caller. The HL7 codec is setup with codec=#hl7codec. Note that hl7codec is just a Spring bean ID, so it could be named mygreatcodecforhl7 or whatever. The codec is also set up in the Spring XML file:

<bean id="hl7codec" class="org.apache.camel.component.hl7.HL7MLLPCodec">
    <property name="charset" value="iso-8859-1"/>
</bean>

The endpoint hl7MinaLlistener can then be used in a route as a consumer, as this Java DSL example illustrates:

from("hl7MinaListener")
  .bean("patientLookupService");

This is a very simple route that will listen for HL7 and route it to a service named patientLookupService. This is also Spring bean ID, configured in the Spring XML as:

<bean id="patientLookupService" class="com.mycompany.healthcare.service.PatientLookupService"/>

The business logic can be implemented in POJO classes that do not depend on Camel, as shown here:

import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.model.v24.segment.QRD;

public class PatientLookupService {
    public Message lookupPatient(Message input) throws HL7Exception {
        QRD qrd = (QRD)input.get("QRD");
        String patientId = qrd.getWhoSubjectFilter(0).getIDNumber().getValue();

        // find patient data based on the patient id and create a HL7 model object with the response
        Message response = ... create and set response data
        return response
    }

43.2.2. Exposing an HL7 listener using Netty (available from Camel 2.15 onwards)

In the Spring XML file, we configure a netty endpoint to listen for HL7 requests using TCP on port 8888:

<endpoint id="hl7NettyListener" uri="netty:tcp://localhost:8888?sync=true&amp;encoders=#hl7encoder&amp;decoders=#hl7decoder"/>

sync=true indicates that this listener is synchronous and therefore will return a HL7 response to the caller. The HL7 codec is setup with encoders=#hl7encoder*and*decoders=#hl7decoder. Note that hl7encoder and hl7decoder are just bean IDs, so they could be named differently. The beans can be set in the Spring XML file:

<bean id="hl7decoder" class="org.apache.camel.component.hl7.HL7MLLPNettyDecoderFactory"/>
<bean id="hl7encoder" class="org.apache.camel.component.hl7.HL7MLLPNettyEncoderFactory"/>

The endpoint hl7NettyListener can then be used in a route as a consumer, as this Java DSL example illustrates:

from("hl7NettyListener")
  .bean("patientLookupService");

43.3. HL7 Model using java.lang.String or byte[]

The HL7 MLLP codec uses plain String as its data format. Camel uses its Type Converter to convert to/from strings to the HAPI HL7 model objects, but you can use the plain String objects if you prefer, for instance if you wish to parse the data yourself.

You can also let both the Mina and Netty codecs use a plain byte[] as its data format by setting the produceString property to false. The Type Converter is also capable of converting the byte[] to/from HAPI HL7 model objects.

43.4. HL7v2 Model using HAPI

The HL7v2 model uses Java objects from the HAPI library. Using this library, you can encode and decode from the EDI format (ER7) that is mostly used with HL7v2.

The sample below is a request to lookup a patient with the patient ID 0101701234.

MSH|^~\\&|MYSENDER|MYRECEIVER|MYAPPLICATION||200612211200||QRY^A19|1234|P|2.4
QRD|200612211200|R|I|GetPatient|||1^RD|0101701234|DEM||

Using the HL7 model you can work with a ca.uhn.hl7v2.model.Message object, e.g. to retrieve a patient ID:

Message msg = exchange.getIn().getBody(Message.class);
QRD qrd = (QRD)msg.get("QRD");
String patientId = qrd.getWhoSubjectFilter(0).getIDNumber().getValue();  // 0101701234

This is powerful when combined with the HL7 listener, because you don’t have to work with byte[], String or any other simple object formats. You can just use the HAPI HL7v2 model objects. If you know the message type in advance, you can be more type-safe:

QRY_A19 msg = exchange.getIn().getBody(QRY_A19.class);
String patientId = msg.getQRD().getWhoSubjectFilter(0).getIDNumber().getValue();

43.5. HL7 DataFormat

The camel-hl7 JAR ships with a HL7 data format that can be used to marshal or unmarshal HL7 model objects.

The HL7 dataformat supports 1 options, which are listed below.

NameDefaultJava TypeDescription

validate

 

Boolean

Whether to validate the HL7 message Is by default true.

  • marshal = from Message to byte stream (can be used when responding using the HL7 MLLP codec)
  • unmarshal = from byte stream to Message (can be used when receiving streamed data from the HL7 MLLP

To use the data format, simply instantiate an instance and invoke the marshal or unmarshal operation in the route builder:

  DataFormat hl7 = new HL7DataFormat();

  from("direct:hl7in")
    .marshal(hl7)
    .to("jms:queue:hl7out");

In the sample above, the HL7 is marshalled from a HAPI Message object to a byte stream and put on a JMS queue.
The next example is the opposite:

  DataFormat hl7 = new HL7DataFormat();

  from("jms:queue:hl7out")
    .unmarshal(hl7)
    .to("patientLookupService");

Here we unmarshal the byte stream into a HAPI Message object that is passed to our patient lookup service.

43.5.1. Segment separators

Unmarshalling does not automatically fix segment separators anymore by converting \n to \r. If you
need this conversion, org.apache.camel.component.hl7.HL7#convertLFToCR provides a handy Expression for this purpose.

43.5.2. Charset

Both marshal and unmarshal evaluate the charset provided in the field MSH-18. If this field is empty, by default the charset contained in the corresponding Camel charset property/header is assumed. You can even change this default behavior by overriding the guessCharsetName method when inheriting from the HL7DataFormat class.

There is a shorthand syntax in Camel for well-known data formats that are commonly used. Then you don’t need to create an instance of the HL7DataFormat object:

  from("direct:hl7in")
    .marshal().hl7()
    .to("jms:queue:hl7out");

  from("jms:queue:hl7out")
    .unmarshal().hl7()
    .to("patientLookupService");

43.6. Message Headers

The unmarshal operation adds these fields from the MSH segment as headers on the Camel message:

KeyMSH fieldExample

CamelHL7SendingApplication

MSH-3

MYSERVER

CamelHL7SendingFacility

MSH-4

MYSERVERAPP

CamelHL7ReceivingApplication

MSH-5

MYCLIENT

CamelHL7ReceivingFacility

MSH-6

MYCLIENTAPP

CamelHL7Timestamp

MSH-7

20071231235900

CamelHL7Security

MSH-8

null

CamelHL7MessageType

MSH-9-1

ADT

CamelHL7TriggerEvent

MSH-9-2

A01

CamelHL7MessageControl

MSH-10

1234

CamelHL7ProcessingId

MSH-11

P

CamelHL7VersionId

MSH-12

2.4

CamelHL7Context

``

contains the that was used to parse the message

CamelHL7Charset

MSH-18

UNICODE UTF-8

All headers except CamelHL7Context are String types. If a header value is missing, its value is null.

43.7. Dependencies

To use HL7 in your Camel routes you’ll need to add a dependency on camel-hl7 listed above, which implements this data format.

The HAPI library is split into a base library and several structure libraries, one for each HL7v2 message version:

By default camel-hl7 only references the HAPI base library. Applications are responsible for including structure libraries themselves. For example, if an application works with HL7v2 message versions 2.4 and 2.5 then the following dependencies must be added:

<dependency>
    <groupId>ca.uhn.hapi</groupId>
    <artifactId>hapi-structures-v24</artifactId>
    <version>2.2</version>
    <!-- use the same version as your hapi-base version -->
</dependency>
<dependency>
    <groupId>ca.uhn.hapi</groupId>
    <artifactId>hapi-structures-v25</artifactId>
    <version>2.2</version>
    <!-- use the same version as your hapi-base version -->
</dependency>

Alternatively, an OSGi bundle containing the base library, all structures libraries and required dependencies (on the bundle classpath) can be downloaded from the central Maven repository.

<dependency>
    <groupId>ca.uhn.hapi</groupId>
    <artifactId>hapi-osgi-base</artifactId>
    <version>2.2</version>
</dependency>

43.8. Spring Boot Auto-Configuration

The component supports 4 options, which are listed below.

NameDescriptionDefaultType

camel.dataformat.hl7.enabled

Whether to enable auto configuration of the hl7 data format. This is enabled by default.

 

Boolean

camel.dataformat.hl7.validate

Whether to validate the HL7 message Is by default true.

true

Boolean

camel.language.hl7terser.enabled

Whether to enable auto configuration of the hl7terser language. This is enabled by default.

 

Boolean

camel.language.hl7terser.trim

Whether to trim the value to remove leading and trailing whitespaces and line breaks.

true

Boolean

Chapter 44. HTTP

Only producer is supported

The HTTP component provides HTTP based endpoints for calling external HTTP resources (as a client to call external servers using HTTP).

44.1. Dependencies

When using http with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-http-starter</artifactId>
</dependency>

44.2. URI format

http:hostname[:port][/resourceUri][?options]

Will by default use port 80 for HTTP and 443 for HTTPS.

44.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

44.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

44.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

44.4. Component Options

The HTTP component supports 37 options, which are listed below.

NameDescriptionDefaultType

cookieStore (producer)

To use a custom org.apache.http.client.CookieStore. By default the org.apache.http.impl.client.BasicCookieStore is used which is an in-memory only cookie store. Notice if bridgeEndpoint=true then the cookie store is forced to be a noop cookie store as cookie shouldn’t be stored as we are just bridging (eg acting as a proxy).

 

CookieStore

copyHeaders (producer)

If this option is true then IN exchange headers will be copied to OUT exchange headers according to copy strategy. Setting this to false, allows to only include the headers from the HTTP response (not propagating IN headers).

true

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

responsePayloadStreamingThreshold (producer)

This threshold in bytes controls whether the response payload should be stored in memory as a byte array or be streaming based. Set this to -1 to always use streaming mode.

8192

int

skipRequestHeaders (producer (advanced))

Whether to skip mapping all the Camel headers as HTTP request headers. If there are no data from Camel headers needed to be included in the HTTP request then this can avoid parsing overhead with many object allocations for the JVM garbage collector.

false

boolean

skipResponseHeaders (producer (advanced))

Whether to skip mapping all the HTTP response headers to Camel headers. If there are no data needed from HTTP headers then this can avoid parsing overhead with many object allocations for the JVM garbage collector.

false

boolean

allowJavaSerializedObject (advanced)

Whether to allow java serialization when a request uses context-type=application/x-java-serialized-object. This is by default turned off. If you enable this then be aware that Java will deserialize the incoming data from the request to Java and that can be a potential security risk.

false

boolean

authCachingDisabled (advanced)

Disables authentication scheme caching.

false

boolean

automaticRetriesDisabled (advanced)

Disables automatic request recovery and re-execution.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

clientConnectionManager (advanced)

To use a custom and shared HttpClientConnectionManager to manage connections. If this has been configured then this is always used for all endpoints created by this component.

 

HttpClientConnectionManager

connectionsPerRoute (advanced)

The maximum number of connections per route.

20

int

connectionStateDisabled (advanced)

Disables connection state tracking.

false

boolean

connectionTimeToLive (advanced)

The time for connection to live, the time unit is millisecond, the default value is always keep alive.

 

long

contentCompressionDisabled (advanced)

Disables automatic content decompression.

false

boolean

cookieManagementDisabled (advanced)

Disables state (cookie) management.

false

boolean

defaultUserAgentDisabled (advanced)

Disables the default user agent set by this builder if none has been provided by the user.

false

boolean

httpBinding (advanced)

To use a custom HttpBinding to control the mapping between Camel message and HttpClient.

 

HttpBinding

httpClientConfigurer (advanced)

To use the custom HttpClientConfigurer to perform configuration of the HttpClient that will be used.

 

HttpClientConfigurer

httpConfiguration (advanced)

To use the shared HttpConfiguration as base configuration.

 

HttpConfiguration

httpContext (advanced)

To use a custom org.apache.http.protocol.HttpContext when executing requests.

 

HttpContext

maxTotalConnections (advanced)

The maximum number of connections.

200

int

redirectHandlingDisabled (advanced)

Disables automatic redirect handling.

false

boolean

headerFilterStrategy (filter)

To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message.

 

HeaderFilterStrategy

proxyAuthDomain (proxy)

Proxy authentication domain to use.

 

String

proxyAuthHost (proxy)

Proxy authentication host.

 

String

proxyAuthMethod (proxy)

Proxy authentication method to use.

Enum values:

  • Basic
  • Digest
  • NTLM
 

String

proxyAuthNtHost (proxy)

Proxy authentication domain (workstation name) to use with NTML.

 

String

proxyAuthPassword (proxy)

Proxy authentication password.

 

String

proxyAuthPort (proxy)

Proxy authentication port.

 

Integer

proxyAuthUsername (proxy)

Proxy authentication username.

 

String

sslContextParameters (security)

To configure security using SSLContextParameters. Important: Only one instance of org.apache.camel.support.jsse.SSLContextParameters is supported per HttpComponent. If you need to use 2 or more different instances, you need to define a new HttpComponent per instance you need.

 

SSLContextParameters

useGlobalSslContextParameters (security)

Enable usage of global SSL context parameters.

false

boolean

x509HostnameVerifier (security)

To use a custom X509HostnameVerifier such as DefaultHostnameVerifier or NoopHostnameVerifier.

 

HostnameVerifier

connectionRequestTimeout (timeout)

The timeout in milliseconds used when requesting a connection from the connection manager. A timeout value of zero is interpreted as an infinite timeout. A timeout value of zero is interpreted as an infinite timeout. A negative value is interpreted as undefined (system default).

-1

int

connectTimeout (timeout)

Determines the timeout in milliseconds until a connection is established. A timeout value of zero is interpreted as an infinite timeout. A timeout value of zero is interpreted as an infinite timeout. A negative value is interpreted as undefined (system default).

-1

int

socketTimeout (timeout)

Defines the socket timeout in milliseconds, which is the timeout for waiting for data or, put differently, a maximum period inactivity between two consecutive data packets). A timeout value of zero is interpreted as an infinite timeout. A negative value is interpreted as undefined (system default).

-1

int

44.5. Endpoint Options

The HTTP endpoint is configured using URI syntax:

http://httpUri

with the following path and query parameters:

44.5.1. Path Parameters (1 parameters)

NameDescriptionDefaultType

httpUri (common)

Required The url of the HTTP endpoint to call.

 

URI

44.5.2. Query Parameters (51 parameters)

NameDescriptionDefaultType

chunked (producer)

If this option is false the Servlet will disable the HTTP streaming and set the content-length header on the response.

true

boolean

disableStreamCache (common)

Determines whether or not the raw input stream from Servlet is cached or not (Camel will read the stream into a in memory/overflow to file, Stream caching) cache. By default Camel will cache the Servlet input stream to support reading it multiple times to ensure it Camel can retrieve all data from the stream. However you can set this option to true when you for example need to access the raw stream, such as streaming it directly to a file or other persistent store. DefaultHttpBinding will copy the request input stream into a stream cache and put it into message body if this option is false to support reading the stream multiple times. If you use Servlet to bridge/proxy an endpoint then consider enabling this option to improve performance, in case you do not need to read the message payload multiple times. The http producer will by default cache the response body stream. If setting this option to true, then the producers will not cache the response body stream but use the response stream as-is as the message body.

false

boolean

headerFilterStrategy (common)

To use a custom HeaderFilterStrategy to filter header to and from Camel message.

 

HeaderFilterStrategy

httpBinding (common (advanced))

To use a custom HttpBinding to control the mapping between Camel message and HttpClient.

 

HttpBinding

bridgeEndpoint (producer)

If the option is true, HttpProducer will ignore the Exchange.HTTP_URI header, and use the endpoint’s URI for request. You may also set the option throwExceptionOnFailure to be false to let the HttpProducer send all the fault response back.

false

boolean

clearExpiredCookies (producer)

Whether to clear expired cookies before sending the HTTP request. This ensures the cookies store does not keep growing by adding new cookies which is newer removed when they are expired. If the component has disabled cookie management then this option is disabled too.

true

boolean

connectionClose (producer)

Specifies whether a Connection Close header must be added to HTTP Request. By default connectionClose is false.

false

boolean

copyHeaders (producer)

If this option is true then IN exchange headers will be copied to OUT exchange headers according to copy strategy. Setting this to false, allows to only include the headers from the HTTP response (not propagating IN headers).

true

boolean

customHostHeader (producer)

To use custom host header for producer. When not set in query will be ignored. When set will override host header derived from url.

 

String

httpMethod (producer)

Configure the HTTP method to use. The HttpMethod header cannot override this option if set.

Enum values:

  • GET
  • POST
  • PUT
  • DELETE
  • HEAD
  • OPTIONS
  • TRACE
  • PATCH
 

HttpMethods

ignoreResponseBody (producer)

If this option is true, The http producer won’t read response body and cache the input stream.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

preserveHostHeader (producer)

If the option is true, HttpProducer will set the Host header to the value contained in the current exchange Host header, useful in reverse proxy applications where you want the Host header received by the downstream server to reflect the URL called by the upstream client, this allows applications which use the Host header to generate accurate URL’s for a proxied service.

false

boolean

throwExceptionOnFailure (producer)

Option to disable throwing the HttpOperationFailedException in case of failed responses from the remote server. This allows you to get all responses regardless of the HTTP status code.

true

boolean

transferException (producer)

If enabled and an Exchange failed processing on the consumer side, and if the caused Exception was send back serialized in the response as a application/x-java-serialized-object content type. On the producer side the exception will be deserialized and thrown as is, instead of the HttpOperationFailedException. The caused exception is required to be serialized. This is by default turned off. If you enable this then be aware that Java will deserialize the incoming data from the request to Java and that can be a potential security risk.

false

boolean

cookieHandler (producer (advanced))

Configure a cookie handler to maintain a HTTP session.

 

CookieHandler

cookieStore (producer (advanced))

To use a custom CookieStore. By default the BasicCookieStore is used which is an in-memory only cookie store. Notice if bridgeEndpoint=true then the cookie store is forced to be a noop cookie store as cookie shouldn’t be stored as we are just bridging (eg acting as a proxy). If a cookieHandler is set then the cookie store is also forced to be a noop cookie store as cookie handling is then performed by the cookieHandler.

 

CookieStore

deleteWithBody (producer (advanced))

Whether the HTTP DELETE should include the message body or not. By default HTTP DELETE do not include any HTTP body. However in some rare cases users may need to be able to include the message body.

false

boolean

getWithBody (producer (advanced))

Whether the HTTP GET should include the message body or not. By default HTTP GET do not include any HTTP body. However in some rare cases users may need to be able to include the message body.

false

boolean

okStatusCodeRange (producer (advanced))

The status codes which are considered a success response. The values are inclusive. Multiple ranges can be defined, separated by comma, e.g. 200-204,209,301-304. Each range must be a single number or from-to with the dash included.

200-299

String

skipRequestHeaders (producer (advanced))

Whether to skip mapping all the Camel headers as HTTP request headers. If there are no data from Camel headers needed to be included in the HTTP request then this can avoid parsing overhead with many object allocations for the JVM garbage collector.

false

boolean

skipResponseHeaders (producer (advanced))

Whether to skip mapping all the HTTP response headers to Camel headers. If there are no data needed from HTTP headers then this can avoid parsing overhead with many object allocations for the JVM garbage collector.

false

boolean

userAgent (producer (advanced))

To set a custom HTTP User-Agent request header.

 

String

clientBuilder (advanced)

Provide access to the http client request parameters used on new RequestConfig instances used by producers or consumers of this endpoint.

 

HttpClientBuilder

clientConnectionManager (advanced)

To use a custom HttpClientConnectionManager to manage connections.

 

HttpClientConnectionManager

connectionsPerRoute (advanced)

The maximum number of connections per route.

20

int

httpClient (advanced)

Sets a custom HttpClient to be used by the producer.

 

HttpClient

httpClientConfigurer (advanced)

Register a custom configuration strategy for new HttpClient instances created by producers or consumers such as to configure authentication mechanisms etc.

 

HttpClientConfigurer

httpClientOptions (advanced)

To configure the HttpClient using the key/values from the Map.

 

Map

httpContext (advanced)

To use a custom HttpContext instance.

 

HttpContext

maxTotalConnections (advanced)

The maximum number of connections.

200

int

useSystemProperties (advanced)

To use System Properties as fallback for configuration.

false

boolean

proxyAuthDomain (proxy)

Proxy authentication domain to use with NTML.

 

String

proxyAuthHost (proxy)

Proxy authentication host.

 

String

proxyAuthMethod (proxy)

Proxy authentication method to use.

Enum values:

  • Basic
  • Digest
  • NTLM
 

String

proxyAuthNtHost (proxy)

Proxy authentication domain (workstation name) to use with NTML.

 

String

proxyAuthPassword (proxy)

Proxy authentication password.

 

String

proxyAuthPort (proxy)

Proxy authentication port.

 

int

proxyAuthScheme (proxy)

Proxy authentication scheme to use.

Enum values:

  • http
  • https
 

String

proxyAuthUsername (proxy)

Proxy authentication username.

 

String

proxyHost (proxy)

Proxy hostname to use.

 

String

proxyPort (proxy)

Proxy port to use.

 

int

authDomain (security)

Authentication domain to use with NTML.

 

String

authenticationPreemptive (security)

If this option is true, camel-http sends preemptive basic authentication to the server.

false

boolean

authHost (security)

Authentication host to use with NTML.

 

String

authMethod (security)

Authentication methods allowed to use as a comma separated list of values Basic, Digest or NTLM.

 

String

authMethodPriority (security)

Which authentication method to prioritize to use, either as Basic, Digest or NTLM.

Enum values:

  • Basic
  • Digest
  • NTLM
 

String

authPassword (security)

Authentication password.

 

String

authUsername (security)

Authentication username.

 

String

sslContextParameters (security)

To configure security using SSLContextParameters. Important: Only one instance of org.apache.camel.util.jsse.SSLContextParameters is supported per HttpComponent. If you need to use 2 or more different instances, you need to define a new HttpComponent per instance you need.

 

SSLContextParameters

x509HostnameVerifier (security)

To use a custom X509HostnameVerifier such as DefaultHostnameVerifier or NoopHostnameVerifier.

 

HostnameVerifier

44.6. Message Headers

NameTypeDescription

Exchange.HTTP_URI

String

URI to call. Will override existing URI set directly on the endpoint. This uri is the uri of the http server to call. Its not the same as the Camel endpoint uri, where you can configure endpoint options, such as security and so on. This header does not support that, it is only the URI of the http server.

Exchange.HTTP_PATH

String

Request URI’s path, the header will be used to build the request URI with the HTTP_URI.

Exchange.HTTP_QUERY

String

URI parameters. Will override existing URI parameters set directly on the endpoint.

Exchange.HTTP_RESPONSE_CODE

int

The HTTP response code from the external server. Is 200 for OK.

Exchange.HTTP_RESPONSE_TEXT

String

The HTTP response text from the external server.

Exchange.HTTP_CHARACTER_ENCODING

String

Character encoding.

Exchange.CONTENT_TYPE

String

The HTTP content type. Is set on both the IN and OUT message to provide a content type, such as text/html.

Exchange.CONTENT_ENCODING

String

The HTTP content encoding. Is set on both the IN and OUT message to provide a content encoding, such as gzip.

Note

Avoid creating your own HTTP server instances in a Camel Spring Boot application by using either of the cxf-rt-transports-jetty, cxf-rt-transports-netty-server, cxf-rt-transports-undertow libraries. It is recommended to use the Spring Boot embedded HTTP server stack which is created when you use the spring-boot-starter-web, cxf-spring-boot-starter-jaxrs, or cxf-spring-boot-starter-jaxws dependencies.

44.7. Message Body

Camel will store the HTTP response from the external server on the OUT body. All headers from the IN message will be copied to the OUT message, so headers are preserved during routing. Additionally Camel will add the HTTP response headers as well to the OUT message headers.

44.8. Using System Properties

When setting useSystemProperties to true, the HTTP Client will look for the following System Properties and it will use it:

  • ssl.TrustManagerFactory.algorithm
  • javax.net.ssl.trustStoreType
  • javax.net.ssl.trustStore
  • javax.net.ssl.trustStoreProvider
  • javax.net.ssl.trustStorePassword
  • java.home
  • ssl.KeyManagerFactory.algorithm
  • javax.net.ssl.keyStoreType
  • javax.net.ssl.keyStore
  • javax.net.ssl.keyStoreProvider
  • javax.net.ssl.keyStorePassword
  • http.proxyHost
  • http.proxyPort
  • http.nonProxyHosts
  • http.keepAlive
  • http.maxConnections

44.9. Response code

Camel will handle according to the HTTP response code:

  • Response code is in the range 100..299, Camel regards it as a success response.
  • Response code is in the range 300..399, Camel regards it as a redirection response and will throw a HttpOperationFailedException with the information.
  • Response code is 400+, Camel regards it as an external server failure and will throw a HttpOperationFailedException with the information.

throwExceptionOnFailure The option, throwExceptionOnFailure, can be set to false to prevent the HttpOperationFailedException from being thrown for failed response codes. This allows you to get any response from the remote server.
There is a sample below demonstrating this.

44.10. Exceptions

HttpOperationFailedException exception contains the following information:

  • The HTTP status code
  • The HTTP status line (text of the status code)
  • Redirect location, if server returned a redirect
  • Response body as a java.lang.String, if server provided a body as response

44.11. Which HTTP method will be used

The following algorithm is used to determine what HTTP method should be used:
1. Use method provided as endpoint configuration (httpMethod).
2. Use method provided in header (Exchange.HTTP_METHOD).
3. GET if query string is provided in header.
4. GET if endpoint is configured with a query string.
5. POST if there is data to send (body is not null).
6. GET otherwise.

44.12. How to get access to HttpServletRequest and HttpServletResponse

You can get access to these two using the Camel type converter system using

HttpServletRequest request = exchange.getIn().getBody(HttpServletRequest.class);
HttpServletResponse response = exchange.getIn().getBody(HttpServletResponse.class);
Note

You can get the request and response not just from the processor after the camel-jetty or camel-cxf endpoint.

44.13. Configuring URI to call

You can set the HTTP producer’s URI directly form the endpoint URI. In the route below, Camel will call out to the external server, oldhost, using HTTP.

from("direct:start")
        .to("http://oldhost");

And the equivalent Spring sample:

<camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
  <route>
    <from uri="direct:start"/>
    <to uri="http://oldhost"/>
  </route>
</camelContext>

You can override the HTTP endpoint URI by adding a header with the key, Exchange.HTTP_URI, on the message.

from("direct:start")
  .setHeader(Exchange.HTTP_URI, constant("http://newhost"))
  .to("http://oldhost");

In the sample above Camel will call the http://newhost/ despite the endpoint is configured with http://oldhost/.
If the http endpoint is working in bridge mode, it will ignore the message header of Exchange.HTTP_URI.

44.14. Configuring URI Parameters

The http producer supports URI parameters to be sent to the HTTP server. The URI parameters can either be set directly on the endpoint URI or as a header with the key Exchange.HTTP_QUERY on the message.

from("direct:start")
  .to("http://oldhost?order=123&detail=short");

Or options provided in a header:

from("direct:start")
  .setHeader(Exchange.HTTP_QUERY, constant("order=123&detail=short"))
  .to("http://oldhost");

44.15. How to set the http method (GET/PATCH/POST/PUT/DELETE/HEAD/OPTIONS/TRACE) to the HTTP producer

The HTTP component provides a way to set the HTTP request method by setting the message header. Here is an example:

from("direct:start")
  .setHeader(Exchange.HTTP_METHOD, constant(org.apache.camel.component.http.HttpMethods.POST))
  .to("http://www.google.com")
  .to("mock:results");

The method can be written a bit shorter using the string constants:

.setHeader("CamelHttpMethod", constant("POST"))

And the equivalent Spring sample:

<camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
  <route>
    <from uri="direct:start"/>
    <setHeader name="CamelHttpMethod">
        <constant>POST</constant>
    </setHeader>
    <to uri="http://www.google.com"/>
    <to uri="mock:results"/>
  </route>
</camelContext>

44.16. Using client timeout - SO_TIMEOUT

See the HttpSOTimeoutTest unit test.

44.17. Configuring a Proxy

The HTTP component provides a way to configure a proxy.

from("direct:start")
  .to("http://oldhost?proxyAuthHost=www.myproxy.com&proxyAuthPort=80");

There is also support for proxy authentication via the proxyAuthUsername and proxyAuthPassword options.

44.17.1. Using proxy settings outside of URI

To avoid System properties conflicts, you can set proxy configuration only from the CamelContext or URI.
Java DSL :

 context.getGlobalOptions().put("http.proxyHost", "172.168.18.9");
 context.getGlobalOptions().put("http.proxyPort", "8080");

Spring XML

   <camelContext>
       <properties>
           <property key="http.proxyHost" value="172.168.18.9"/>
           <property key="http.proxyPort" value="8080"/>
      </properties>
   </camelContext>

Camel will first set the settings from Java System or CamelContext Properties and then the endpoint proxy options if provided.
So you can override the system properties with the endpoint options.

There is also a http.proxyScheme property you can set to explicit configure the scheme to use.

44.18. Configuring charset

If you are using POST to send data you can configure the charset using the Exchange property:

exchange.setProperty(Exchange.CHARSET_NAME, "ISO-8859-1");

44.18.1. Sample with scheduled poll

This sample polls the Google homepage every 10 seconds and write the page to the file message.html:

from("timer://foo?fixedRate=true&delay=0&period=10000")
  .to("http://www.google.com")
  .setHeader(FileComponent.HEADER_FILE_NAME, "message.html")
  .to("file:target/google");

44.18.2. URI Parameters from the endpoint URI

In this sample we have the complete URI endpoint that is just what you would have typed in a web browser. Multiple URI parameters can of course be set using the & character as separator, just as you would in the web browser. Camel does no tricks here.

// we query for Camel at the Google page
template.sendBody("http://www.google.com/search?q=Camel", null);

44.18.3. URI Parameters from the Message

Map headers = new HashMap();
headers.put(Exchange.HTTP_QUERY, "q=Camel&lr=lang_en");
// we query for Camel and English language at Google
template.sendBody("http://www.google.com/search", null, headers);

In the header value above notice that it should not be prefixed with ? and you can separate parameters as usual with the & char.

44.18.4. Getting the Response Code

You can get the HTTP response code from the HTTP component by getting the value from the Out message header with Exchange.HTTP_RESPONSE_CODE.

Exchange exchange = template.send("http://www.google.com/search", new Processor() {
  public void process(Exchange exchange) throws Exception {
    exchange.getIn().setHeader(Exchange.HTTP_QUERY, constant("hl=en&q=activemq"));
  }
});
Message out = exchange.getOut();
int responseCode = out.getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class);

44.19. Disabling Cookies

To disable cookies you can set the HTTP Client to ignore cookies by adding the following URI option:

httpClient.cookieSpec=ignore

44.20. Basic auth with the streaming message body

In order to avoid the NonRepeatableRequestException, you need to do the Preemptive Basic Authentication by adding the option:
authenticationPreemptive=true

44.21. Advanced Usage

If you need more control over the HTTP producer you should use the HttpComponent where you can set various classes to give you custom behavior.

44.21.1. Setting up SSL for HTTP Client

Using the JSSE Configuration Utility

The HTTP component supports SSL/TLS configuration through the Camel JSSE Configuration Utility. This utility greatly decreases the amount of component specific code you need to write and is configurable at the endpoint and component levels.

The following examples demonstrate how to use the utility with the HTTP component.

Programmatic configuration of the component

KeyStoreParameters ksp = new KeyStoreParameters();
ksp.setResource("file:/users/home/server/keystore.jks");
ksp.setPassword("keystorePassword");

KeyManagersParameters kmp = new KeyManagersParameters();
kmp.setKeyStore(ksp);
kmp.setKeyPassword("keyPassword");

SSLContextParameters scp = new SSLContextParameters();
scp.setKeyManagers(kmp);

HttpComponent httpComponent = getContext().getComponent("https", HttpComponent.class);
httpComponent.setSslContextParameters(scp);

Spring DSL based configuration of endpoint

  <camel:sslContextParameters
      id="sslContextParameters">
    <camel:keyManagers
        keyPassword="keyPassword">
      <camel:keyStore
          resource="file:/users/home/server/keystore.jks"
          password="keystorePassword"/>
    </camel:keyManagers>
  </camel:sslContextParameters>

  <to uri="https://127.0.0.1/mail/?sslContextParameters=#sslContextParameters"/>

Configuring Apache HTTP Client Directly

Basically camel-http component is built on the top of Apache HttpClient. Please refer to SSL/TLS customization for details or have a look into the org.apache.camel.component.http.HttpsServerTestSupport unit test base class.
You can also implement a custom org.apache.camel.component.http.HttpClientConfigurer to do some configuration on the http client if you need full control of it.

However if you just want to specify the keystore and truststore you can do this with Apache HTTP HttpClientConfigurer, for example:

KeyStore keystore = ...;
KeyStore truststore = ...;

SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("https", 443, new SSLSocketFactory(keystore, "mypassword", truststore)));

And then you need to create a class that implements HttpClientConfigurer, and registers https protocol providing a keystore or truststore per example above. Then, from your camel route builder class you can hook it up like so:

HttpComponent httpComponent = getContext().getComponent("http", HttpComponent.class);
httpComponent.setHttpClientConfigurer(new MyHttpClientConfigurer());

If you are doing this using the Spring DSL, you can specify your HttpClientConfigurer using the URI. For example:

<bean id="myHttpClientConfigurer"
 class="my.https.HttpClientConfigurer">
</bean>

<to uri="https://myhostname.com:443/myURL?httpClientConfigurer=myHttpClientConfigurer"/>

As long as you implement the HttpClientConfigurer and configure your keystore and truststore as described above, it will work fine.

Using HTTPS to authenticate gotchas

An end user reported that he had problem with authenticating with HTTPS. The problem was eventually resolved by providing a custom configured org.apache.http.protocol.HttpContext:

  1. Create a (Spring) factory for HttpContexts.

    public class HttpContextFactory {
    
      private String httpHost = "localhost";
      private String httpPort = 9001;
    
      private BasicHttpContext httpContext = new BasicHttpContext();
      private BasicAuthCache authCache = new BasicAuthCache();
      private BasicScheme basicAuth = new BasicScheme();
    
      public HttpContext getObject() {
        authCache.put(new HttpHost(httpHost, httpPort), basicAuth);
    
        httpContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
    
        return httpContext;
      }
    
      // getter and setter
    }
  2. Declare an HttpContext in the Spring application context file.

    <bean id="myHttpContext" factory-bean="httpContextFactory" factory-method="getObject"/>
  3. Reference the context in the http URL:
<to uri="https://myhostname.com:443/myURL?httpContext=myHttpContext"/>

Using different SSLContextParameters

The HTTP component only support one instance of org.apache.camel.support.jsse.SSLContextParameters per component. If you need to use 2 or more different instances, then you need to setup multiple HTTP components as shown below. Where we have 2 components, each using their own instance of sslContextParameters property.

<bean id="http-foo" class="org.apache.camel.component.http.HttpComponent">
   <property name="sslContextParameters" ref="sslContextParams1"/>
   <property name="x509HostnameVerifier" ref="hostnameVerifier"/>
</bean>

<bean id="http-bar" class="org.apache.camel.component.http.HttpComponent">
   <property name="sslContextParameters" ref="sslContextParams2"/>
   <property name="x509HostnameVerifier" ref="hostnameVerifier"/>
</bean>

For more information about how to configure SSL see http-ssl example.

44.22. Spring Boot Auto-Configuration

The component supports 38 options, which are listed below.

NameDescriptionDefaultType

camel.component.http.allow-java-serialized-object

Whether to allow java serialization when a request uses context-type=application/x-java-serialized-object. This is by default turned off. If you enable this then be aware that Java will deserialize the incoming data from the request to Java and that can be a potential security risk.

false

Boolean

camel.component.http.auth-caching-disabled

Disables authentication scheme caching.

false

Boolean

camel.component.http.automatic-retries-disabled

Disables automatic request recovery and re-execution.

false

Boolean

camel.component.http.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.http.client-connection-manager

To use a custom and shared HttpClientConnectionManager to manage connections. If this has been configured then this is always used for all endpoints created by this component. The option is a org.apache.http.conn.HttpClientConnectionManager type.

 

HttpClientConnectionManager

camel.component.http.connect-timeout

Determines the timeout in milliseconds until a connection is established. A timeout value of zero is interpreted as an infinite timeout. A timeout value of zero is interpreted as an infinite timeout. A negative value is interpreted as undefined (system default).

-1

Integer

camel.component.http.connection-request-timeout

The timeout in milliseconds used when requesting a connection from the connection manager. A timeout value of zero is interpreted as an infinite timeout. A timeout value of zero is interpreted as an infinite timeout. A negative value is interpreted as undefined (system default).

-1

Integer

camel.component.http.connection-state-disabled

Disables connection state tracking.

false

Boolean

camel.component.http.connection-time-to-live

The time for connection to live, the time unit is millisecond, the default value is always keep alive.

 

Long

camel.component.http.connections-per-route

The maximum number of connections per route.

20

Integer

camel.component.http.content-compression-disabled

Disables automatic content decompression.

false

Boolean

camel.component.http.cookie-management-disabled

Disables state (cookie) management.

false

Boolean

camel.component.http.cookie-store

To use a custom org.apache.http.client.CookieStore. By default the org.apache.http.impl.client.BasicCookieStore is used which is an in-memory only cookie store. Notice if bridgeEndpoint=true then the cookie store is forced to be a noop cookie store as cookie shouldn’t be stored as we are just bridging (eg acting as a proxy). The option is a org.apache.http.client.CookieStore type.

 

CookieStore

camel.component.http.copy-headers

If this option is true then IN exchange headers will be copied to OUT exchange headers according to copy strategy. Setting this to false, allows to only include the headers from the HTTP response (not propagating IN headers).

true

Boolean

camel.component.http.default-user-agent-disabled

Disables the default user agent set by this builder if none has been provided by the user.

false

Boolean

camel.component.http.enabled

Whether to enable auto configuration of the http component. This is enabled by default.

 

Boolean

camel.component.http.header-filter-strategy

To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message. The option is a org.apache.camel.spi.HeaderFilterStrategy type.

 

HeaderFilterStrategy

camel.component.http.http-binding

To use a custom HttpBinding to control the mapping between Camel message and HttpClient. The option is a org.apache.camel.http.common.HttpBinding type.

 

HttpBinding

camel.component.http.http-client-configurer

To use the custom HttpClientConfigurer to perform configuration of the HttpClient that will be used. The option is a org.apache.camel.component.http.HttpClientConfigurer type.

 

HttpClientConfigurer

camel.component.http.http-configuration

To use the shared HttpConfiguration as base configuration. The option is a org.apache.camel.http.common.HttpConfiguration type.

 

HttpConfiguration

camel.component.http.http-context

To use a custom org.apache.http.protocol.HttpContext when executing requests. The option is a org.apache.http.protocol.HttpContext type.

 

HttpContext

camel.component.http.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.http.max-total-connections

The maximum number of connections.

200

Integer

camel.component.http.proxy-auth-domain

Proxy authentication domain to use.

 

String

camel.component.http.proxy-auth-host

Proxy authentication host.

 

String

camel.component.http.proxy-auth-method

Proxy authentication method to use.

 

String

camel.component.http.proxy-auth-nt-host

Proxy authentication domain (workstation name) to use with NTML.

 

String

camel.component.http.proxy-auth-password

Proxy authentication password.

 

String

camel.component.http.proxy-auth-port

Proxy authentication port.

 

Integer

camel.component.http.proxy-auth-username

Proxy authentication username.

 

String

camel.component.http.redirect-handling-disabled

Disables automatic redirect handling.

false

Boolean

camel.component.http.response-payload-streaming-threshold

This threshold in bytes controls whether the response payload should be stored in memory as a byte array or be streaming based. Set this to -1 to always use streaming mode.

8192

Integer

camel.component.http.skip-request-headers

Whether to skip mapping all the Camel headers as HTTP request headers. If there are no data from Camel headers needed to be included in the HTTP request then this can avoid parsing overhead with many object allocations for the JVM garbage collector.

false

Boolean

camel.component.http.skip-response-headers

Whether to skip mapping all the HTTP response headers to Camel headers. If there are no data needed from HTTP headers then this can avoid parsing overhead with many object allocations for the JVM garbage collector.

false

Boolean

camel.component.http.socket-timeout

Defines the socket timeout in milliseconds, which is the timeout for waiting for data or, put differently, a maximum period inactivity between two consecutive data packets). A timeout value of zero is interpreted as an infinite timeout. A negative value is interpreted as undefined (system default).

-1

Integer

camel.component.http.ssl-context-parameters

To configure security using SSLContextParameters. Important: Only one instance of org.apache.camel.support.jsse.SSLContextParameters is supported per HttpComponent. If you need to use 2 or more different instances, you need to define a new HttpComponent per instance you need. The option is a org.apache.camel.support.jsse.SSLContextParameters type.

 

SSLContextParameters

camel.component.http.use-global-ssl-context-parameters

Enable usage of global SSL context parameters.

false

Boolean

camel.component.http.x509-hostname-verifier

To use a custom X509HostnameVerifier such as DefaultHostnameVerifier or NoopHostnameVerifier. The option is a javax.net.ssl.HostnameVerifier type.

 

HostnameVerifier

Chapter 45. Infinispan

Both producer and consumer are supported

This component allows you to interact with Infinispan distributed data grid / cache using the Hot Rod procol. Infinispan is an extremely scalable, highly available key/value data store and data grid platform written in Java.

45.1. Dependencies

When using infinispan with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-infinispan-starter</artifactId>
</dependency>

45.2. URI format

infinispan://cacheName?[options]

The producer allows sending messages to a remote cache using the HotRod protocol. The consumer allows listening for events from a remote cache using the HotRod protocol.

45.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

45.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

45.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

45.4. Component Options

The Infinispan component supports 26 options, which are listed below.

NameDescriptionDefaultType

configuration (common)

Component configuration.

 

InfinispanRemoteConfiguration

hosts (common)

Specifies the host of the cache on Infinispan instance.

 

String

queryBuilder (common)

Specifies the query builder.

 

InfinispanQueryBuilder

secure (common)

Define if we are connecting to a secured Infinispan instance.

false

boolean

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

customListener (consumer)

Returns the custom listener in use, if provided.

 

InfinispanRemoteCustomListener

eventTypes (consumer)

Specifies the set of event types to register by the consumer.Multiple event can be separated by comma. The possible event types are: CLIENT_CACHE_ENTRY_CREATED, CLIENT_CACHE_ENTRY_MODIFIED, CLIENT_CACHE_ENTRY_REMOVED, CLIENT_CACHE_ENTRY_EXPIRED, CLIENT_CACHE_FAILOVER.

 

String

defaultValue (producer)

Set a specific default value for some producer operations.

 

Object

key (producer)

Set a specific key for producer operations.

 

Object

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

oldValue (producer)

Set a specific old value for some producer operations.

 

Object

operation (producer)

The operation to perform.

Enum values:

  • PUT
  • PUTASYNC
  • PUTALL
  • PUTALLASYNC
  • PUTIFABSENT
  • PUTIFABSENTASYNC
  • GET
  • GETORDEFAULT
  • CONTAINSKEY
  • CONTAINSVALUE
  • REMOVE
  • REMOVEASYNC
  • REPLACE
  • REPLACEASYNC
  • SIZE
  • CLEAR
  • CLEARASYNC
  • QUERY
  • STATS
  • COMPUTE
  • COMPUTEASYNC

PUT

InfinispanOperation

value (producer)

Set a specific value for producer operations.

 

Object

password ( security)

Define the password to access the infinispan instance.

 

String

saslMechanism ( security)

Define the SASL Mechanism to access the infinispan instance.

 

String

securityRealm ( security)

Define the security realm to access the infinispan instance.

 

String

securityServerName ( security)

Define the security server name to access the infinispan instance.

 

String

username ( security)

Define the username to access the infinispan instance.

 

String

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

cacheContainer (advanced)

Autowired Specifies the cache Container to connect.

 

RemoteCacheManager

cacheContainerConfiguration (advanced)

Autowired The CacheContainer configuration. Used if the cacheContainer is not defined.

 

Configuration

configurationProperties (advanced)

Implementation specific properties for the CacheManager.

 

Map

configurationUri (advanced)

An implementation specific URI for the CacheManager.

 

String

flags (advanced)

A comma separated list of org.infinispan.client.hotrod.Flag to be applied by default on each cache invocation.

 

String

remappingFunction (advanced)

Set a specific remappingFunction to use in a compute operation.

 

BiFunction

resultHeader (advanced)

Store the operation result in a header instead of the message body. By default, resultHeader == null and the query result is stored in the message body, any existing content in the message body is discarded. If resultHeader is set, the value is used as the name of the header to store the query result and the original message body is preserved. This value can be overridden by an in message header named: CamelInfinispanOperationResultHeader.

 

String

45.5. Endpoint Options

The Infinispan endpoint is configured using URI syntax:

infinispan:cacheName

with the following path and query parameters:

45.5.1. Path Parameters (1 parameters)

NameDescriptionDefaultType

cacheName (common)

Required The name of the cache to use. Use current to use the existing cache name from the currently configured cached manager. Or use default for the default cache manager name.

 

String

45.5.2. Query Parameters (26 parameters)

NameDescriptionDefaultType

hosts (common)

Specifies the host of the cache on Infinispan instance.

 

String

queryBuilder (common)

Specifies the query builder.

 

InfinispanQueryBuilder

secure (common)

Define if we are connecting to a secured Infinispan instance.

false

boolean

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

customListener (consumer)

Returns the custom listener in use, if provided.

 

InfinispanRemoteCustomListener

eventTypes (consumer)

Specifies the set of event types to register by the consumer.Multiple event can be separated by comma. The possible event types are: CLIENT_CACHE_ENTRY_CREATED, CLIENT_CACHE_ENTRY_MODIFIED, CLIENT_CACHE_ENTRY_REMOVED, CLIENT_CACHE_ENTRY_EXPIRED, CLIENT_CACHE_FAILOVER.

 

String

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

defaultValue (producer)

Set a specific default value for some producer operations.

 

Object

key (producer)

Set a specific key for producer operations.

 

Object

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

oldValue (producer)

Set a specific old value for some producer operations.

 

Object

operation (producer)

The operation to perform.

Enum values:

  • PUT
  • PUTASYNC
  • PUTALL
  • PUTALLASYNC
  • PUTIFABSENT
  • PUTIFABSENTASYNC
  • GET
  • GETORDEFAULT
  • CONTAINSKEY
  • CONTAINSVALUE
  • REMOVE
  • REMOVEASYNC
  • REPLACE
  • REPLACEASYNC
  • SIZE
  • CLEAR
  • CLEARASYNC
  • QUERY
  • STATS
  • COMPUTE
  • COMPUTEASYNC

PUT

InfinispanOperation

value (producer)

Set a specific value for producer operations.

 

Object

password ( security)

Define the password to access the infinispan instance.

 

String

saslMechanism ( security)

Define the SASL Mechanism to access the infinispan instance.

 

String

securityRealm ( security)

Define the security realm to access the infinispan instance.

 

String

securityServerName ( security)

Define the security server name to access the infinispan instance.

 

String

username ( security)

Define the username to access the infinispan instance.

 

String

cacheContainer (advanced)

Autowired Specifies the cache Container to connect.

 

RemoteCacheManager

cacheContainerConfiguration (advanced)

Autowired The CacheContainer configuration. Used if the cacheContainer is not defined.

 

Configuration

configurationProperties (advanced)

Implementation specific properties for the CacheManager.

 

Map

configurationUri (advanced)

An implementation specific URI for the CacheManager.

 

String

flags (advanced)

A comma separated list of org.infinispan.client.hotrod.Flag to be applied by default on each cache invocation.

 

String

remappingFunction (advanced)

Set a specific remappingFunction to use in a compute operation.

 

BiFunction

resultHeader (advanced)

Store the operation result in a header instead of the message body. By default, resultHeader == null and the query result is stored in the message body, any existing content in the message body is discarded. If resultHeader is set, the value is used as the name of the header to store the query result and the original message body is preserved. This value can be overridden by an in message header named: CamelInfinispanOperationResultHeader.

 

String

45.6. Camel Operations

This section lists all available operations, along with their header information.

Table 45.1. Table 1. Put Operations
Operation NameDescription

InfinispanOperation.PUT

Puts a key/value pair in the cache, optionally with expiration

InfinispanOperation.PUTASYNC

Asynchronously puts a key/value pair in the cache, optionally with expiration

InfinispanOperation.PUTIFABSENT

Puts a key/value pair in the cache if it did not exist, optionally with expiration

InfinispanOperation.PUTIFABSENTASYNC

Asynchronously puts a key/value pair in the cache if it did not exist, optionally with expiration

  • Required Headers:

    • CamelInfinispanKey
    • CamelInfinispanValue
  • Optional Headers:

    • CamelInfinispanLifespanTime
    • CamelInfinispanLifespanTimeUnit
    • CamelInfinispanMaxIdleTime
    • CamelInfinispanMaxIdleTimeUnit
  • Result Header:

    • CamelInfinispanOperationResult
Table 45.2. Table 2. Put All Operations
Operation NameDescription

InfinispanOperation.PUTALL

Adds multiple entries to a cache, optionally with expiration

CamelInfinispanOperation.PUTALLASYNC

Asynchronously adds multiple entries to a cache, optionally with expiration

  • Required Headers:

    • CamelInfinispanMap
  • Optional Headers:

    • CamelInfinispanLifespanTime
    • CamelInfinispanLifespanTimeUnit
    • CamelInfinispanMaxIdleTime
    • CamelInfinispanMaxIdleTimeUnit
Table 45.3. Table 3. Get Operations
Operation NameDescription

InfinispanOperation.GET

Retrieves the value associated with a specific key from the cache

InfinispanOperation.GETORDEFAULT

Retrieves the value, or default value, associated with a specific key from the cache

  • Required Headers:

    • CamelInfinispanKey
Table 45.4. Table 4. Contains Key Operation
Operation NameDescription

InfinispanOperation.CONTAINSKEY

Determines whether a cache contains a specific key

  • Required Headers

    • CamelInfinispanKey
  • Result Header

    • CamelInfinispanOperationResult
Table 45.5. Table 5. Contains Value Operation
Operation NameDescription

InfinispanOperation.CONTAINSVALUE

Determines whether a cache contains a specific value

  • Required Headers:

    • CamelInfinispanKey
Table 45.6. Table 6. Remove Operations
Operation NameDescription

InfinispanOperation.REMOVE

Removes an entry from a cache, optionally only if the value matches a given one

InfinispanOperation.REMOVEASYNC

Asynchronously removes an entry from a cache, optionally only if the value matches a given one

  • Required Headers:

    • CamelInfinispanKey
  • Optional Headers:

    • CamelInfinispanValue
  • Result Header:

    • CamelInfinispanOperationResult
Table 45.7. Table 7. Replace Operations
Operation NameDescription

InfinispanOperation.REPLACE

Conditionally replaces an entry in the cache, optionally with expiration

InfinispanOperation.REPLACEASYNC

Asynchronously conditionally replaces an entry in the cache, optionally with expiration

  • Required Headers:

    • CamelInfinispanKey
    • CamelInfinispanValue
    • CamelInfinispanOldValue
  • Optional Headers:

    • CamelInfinispanLifespanTime
    • CamelInfinispanLifespanTimeUnit
    • CamelInfinispanMaxIdleTime
    • CamelInfinispanMaxIdleTimeUnit
  • Result Header:

    • CamelInfinispanOperationResult
Table 45.8. Table 8. Clear Operations
Operation NameDescription

InfinispanOperation.CLEAR

Clears the cache

InfinispanOperation.CLEARASYNC

Asynchronously clears the cache

Table 45.9. Table 9. Size Operation
Operation NameDescription

InfinispanOperation.SIZE

Returns the number of entries in the cache

  • Result Header

    • CamelInfinispanOperationResult
Table 45.10. Table 10. Stats Operation
Operation NameDescription

InfinispanOperation.STATS

Returns statistics about the cache

  • Result Header:

    • CamelInfinispanOperationResult
Table 45.11. Table 11. Query Operation
Operation NameDescription

InfinispanOperation.QUERY

Executes a query on the cache

  • Required Headers:

    • CamelInfinispanQueryBuilder
  • Result Header:

    • CamelInfinispanOperationResult
Note

Write methods like put(key, value) and remove(key) do not return the previous value by default.

45.7. Message Headers

NameDefault ValueTypeContextDescription

CamelInfinispanCacheName

null

String

Shared

The cache participating in the operation or event.

CamelInfinispanOperation

PUT

InfinispanOperation

Producer

The operation to perform.

CamelInfinispanMap

null

Map

Producer

A Map to use in case of CamelInfinispanOperationPutAll operation

CamelInfinispanKey

null

Object

Shared

The key to perform the operation to or the key generating the event.

CamelInfinispanValue

null

Object

Producer

The value to use for the operation.

CamelInfinispanEventType

null

String

Consumer

The type of the received event.

CamelInfinispanLifespanTime

null

long

Producer

The Lifespan time of a value inside the cache. Negative values are interpreted as infinity.

CamelInfinispanTimeUnit

null

String

Producer

The Time Unit of an entry Lifespan Time.

CamelInfinispanMaxIdleTime

null

long

Producer

The maximum amount of time an entry is allowed to be idle for before it is considered as expired.

CamelInfinispanMaxIdleTimeUnit

null

String

Producer

The Time Unit of an entry Max Idle Time.

CamelInfinispanQueryBuilder

null

InfinispanQueryBuilder

Producer

The QueryBuilde to use for QUERY command, if not present the command defaults to InifinispanConfiguration’s one

CamelInfinispanOperationResultHeader

null

String

Producer

Store the operation result in a header instead of the message body

45.8. Examples

  • Put a key/value into a named cache:

    from("direct:start")
        .setHeader(InfinispanConstants.OPERATION).constant(InfinispanOperation.PUT) (1)
        .setHeader(InfinispanConstants.KEY).constant("123") (2)
        .to("infinispan:myCacheName&cacheContainer=#cacheContainer"); (3)

    Where,

  • 1 - Set the operation to perform
  • 2 - Set the key used to identify the element in the cache
  • 3 - Use the configured cache manager cacheContainer from the registry to put an element to the cache named myCacheName

    It is possible to configure the lifetime and/or the idle time before the entry expires and gets evicted from the cache, as example:

    from("direct:start")
        .setHeader(InfinispanConstants.OPERATION).constant(InfinispanOperation.GET)
        .setHeader(InfinispanConstants.KEY).constant("123")
        .setHeader(InfinispanConstants.LIFESPAN_TIME).constant(100L) (1)
        .setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT.constant(TimeUnit.MILLISECONDS.toString()) (2)
        .to("infinispan:myCacheName");

where,

  • 1 - Set the lifespan of the entry
  • 2 - Set the time unit for the lifespan

Queries

from("direct:start")
    .setHeader(InfinispanConstants.OPERATION, InfinispanConstants.QUERY)
    .setHeader(InfinispanConstants.QUERY_BUILDER, new InfinispanQueryBuilder() {
        @Override
        public Query build(QueryFactory<Query> qf) {
            return qf.from(User.class).having("name").like("%abc%").build();
        }
    })
    .to("infinispan:myCacheName?cacheContainer=#cacheManager") ;

Note

The .proto descriptors for domain objects must be registered with the remote Data Grid server, see Remote Query Example in the official Infinispan documentation.

Custom Listeners

from("infinispan://?cacheContainer=#cacheManager&customListener=#myCustomListener")
  .to("mock:result");

The instance of myCustomListener must exist and Camel should be able to look it up from the Registry. Users are encouraged to extend the org.apache.camel.component.infinispan.remote.InfinispanRemoteCustomListener class and annotate the resulting class with @ClientListener which can be found found in package org.infinispan.client.hotrod.annotation.

45.9. Using the Infinispan based idempotent repository

In this section we will use the Infinispan based idempotent repository.

Java Example

InfinispanRemoteConfiguration conf = new InfinispanRemoteConfiguration(); (1)
conf.setHosts("localhost:1122")

InfinispanRemoteIdempotentRepository repo = new InfinispanRemoteIdempotentRepository("idempotent");  (2)
repo.setConfiguration(conf);

context.addRoutes(new RouteBuilder() {
    @Override
    public void configure() {
        from("direct:start")
            .idempotentConsumer(header("MessageID"), repo) (3)
            .to("mock:result");
    }
});

where,

  • 1 - Configure the cache
  • 2 - Configure the repository bean
  • 3 - Set the repository to the route

XML Example

<bean id="infinispanRepo" class="org.apache.camel.component.infinispan.remote.InfinispanRemoteIdempotentRepository" destroy-method="stop">
  <constructor-arg value="idempotent"/> (1)
  <property name="configuration"> (2)
    <bean class="org.apache.camel.component.infinispan.remote.InfinispanRemoteConfiguration">
      <property name="hosts" value="localhost:11222"/>
    </bean>
  </property>
</bean>

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="direct:start" />
        <idempotentConsumer messageIdRepositoryRef="infinispanRepo"> (3)
            <header>MessageID</header>
            <to uri="mock:result" />
        </idempotentConsumer>
    </route>
</camelContext>

where,

  • 1 - Set the name of the cache that will be used by the repository
  • 2 - Configure the repository bean
  • 3 - Set the repository to the route

45.10. Using the Infinispan based aggregation repository

In this section we will use the Infinispan based aggregation repository.

Java Example

InfinispanRemoteConfiguration conf = new InfinispanRemoteConfiguration(); (1)
conf.setHosts("localhost:1122")

InfinispanRemoteAggregationRepository repo = new InfinispanRemoteAggregationRepository();  (2)
repo.setCacheName("aggregation");
repo.setConfiguration(conf);

context.addRoutes(new RouteBuilder() {
    @Override
    public void configure() {
        from("direct:start")
                .aggregate(header("MessageID"))
                .completionSize(3)
                .aggregationRepository(repo) (3)
                .aggregationStrategyRef("myStrategy")
                .to("mock:result");
    }
});

where,

  • 1 - Configure the cache
  • 2 - Create the repository bean
  • 3 - Set the repository to the route

XML Example

<bean id="infinispanRepo" class="org.apache.camel.component.infinispan.remote.InfinispanRemoteAggregationRepository" destroy-method="stop">
  <constructor-arg value="aggregation"/> (1)
  <property name="configuration"> (2)
    <bean class="org.apache.camel.component.infinispan.remote.InfinispanRemoteConfiguration">
      <property name="hosts" value="localhost:11222"/>
    </bean>
  </property>
</bean>

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="direct:start" />
        <aggregate strategyRef="myStrategy"
                   completionSize="3"
                   aggregationRepositoryRef="infinispanRepo"> (3)
            <correlationExpression>
                <header>MessageID</header>
            </correlationExpression>
            <to uri="mock:result"/>
        </aggregate>
    </route>
</camelContext>

where,

  • 1 - Set the name of the cache that will be used by the repository
  • 2 - Configure the repository bean
  • 3 - Set the repository to the route
Note

With the release of Infinispan 11, it is required to set the encoding configuration on any cache created. This is critical for consuming events too. For more information have a look at Data Encoding and MediaTypes in the official Infinispan documentation.

45.11. Spring Boot Auto-Configuration

The component supports 23 options, which are listed below.

NameDescriptionDefaultType

camel.component.infinispan.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.infinispan.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.infinispan.cache-container

Specifies the cache Container to connect. The option is a org.infinispan.client.hotrod.RemoteCacheManager type.

 

RemoteCacheManager

camel.component.infinispan.cache-container-configuration

The CacheContainer configuration. Used if the cacheContainer is not defined. The option is a org.infinispan.client.hotrod.configuration.Configuration type.

 

Configuration

camel.component.infinispan.configuration

Component configuration. The option is a org.apache.camel.component.infinispan.remote.InfinispanRemoteConfiguration type.

 

InfinispanRemoteConfiguration

camel.component.infinispan.configuration-properties

Implementation specific properties for the CacheManager.

 

Map

camel.component.infinispan.configuration-uri

An implementation specific URI for the CacheManager.

 

String

camel.component.infinispan.custom-listener

Returns the custom listener in use, if provided. The option is a org.apache.camel.component.infinispan.remote.InfinispanRemoteCustomListener type.

 

InfinispanRemoteCustomListener

camel.component.infinispan.enabled

Whether to enable auto configuration of the infinispan component. This is enabled by default.

 

Boolean

camel.component.infinispan.event-types

Specifies the set of event types to register by the consumer.Multiple event can be separated by comma. The possible event types are: CLIENT_CACHE_ENTRY_CREATED, CLIENT_CACHE_ENTRY_MODIFIED, CLIENT_CACHE_ENTRY_REMOVED, CLIENT_CACHE_ENTRY_EXPIRED, CLIENT_CACHE_FAILOVER.

 

String

camel.component.infinispan.flags

A comma separated list of org.infinispan.client.hotrod.Flag to be applied by default on each cache invocation.

 

String

camel.component.infinispan.hosts

Specifies the host of the cache on Infinispan instance.

 

String

camel.component.infinispan.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.infinispan.operation

The operation to perform.

 

InfinispanOperation

camel.component.infinispan.password

Define the password to access the infinispan instance.

 

String

camel.component.infinispan.query-builder

Specifies the query builder. The option is a org.apache.camel.component.infinispan.InfinispanQueryBuilder type.

 

InfinispanQueryBuilder

camel.component.infinispan.remapping-function

Set a specific remappingFunction to use in a compute operation. The option is a java.util.function.BiFunction type.

 

BiFunction

camel.component.infinispan.result-header

Store the operation result in a header instead of the message body. By default, resultHeader == null and the query result is stored in the message body, any existing content in the message body is discarded. If resultHeader is set, the value is used as the name of the header to store the query result and the original message body is preserved. This value can be overridden by an in message header named: CamelInfinispanOperationResultHeader.

 

String

camel.component.infinispan.sasl-mechanism

Define the SASL Mechanism to access the infinispan instance.

 

String

camel.component.infinispan.secure

Define if we are connecting to a secured Infinispan instance.

false

Boolean

camel.component.infinispan.security-realm

Define the security realm to access the infinispan instance.

 

String

camel.component.infinispan.security-server-name

Define the security server name to access the infinispan instance.

 

String

camel.component.infinispan.username

Define the username to access the infinispan instance.

 

String

Chapter 46. Infinispan Embedded

Since Camel 2.13

Both producer and consumer are supported

This component allows you to interact with Infinispan distributed data grid / cache. Infinispan is an extremely scalable, highly available key / value data store and data grid platform written in Java.

The camel-infinispan-embedded component includes the following features.

  • Local Camel Consumer - Receives cache change notifications and sends them to be processed. This can be done synchronously or asynchronously, and is also supported with a replicated or distributed cache.
  • Local Camel Producer - A producer creates and sends messages to an endpoint. The camel-infinispan producer uses GET, PUT, REMOVE, and CLEAR operations. The local producer is also supported with a replicated or distributed cache.

The events are processed asynchronously.

46.1. Dependencies

When using infinispan-embedded with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-infinispan-embedded-starter</artifactId>
  <version>x.x.x</version>
  <!-- use the same version as your Camel core version -->
</dependency>

46.2. URI format

infinispan-embedded://cacheName?[options]

The producer allows sending messages to a local infinispan cache. The consumer allows listening for events from local infinispan cache.

If no cache configuration is provided, embedded cacheContainer is created directly in the component.

46.3. Configuring Options

Camel components are configured on two separate levels.

  • component level
  • endpoint level

46.3.1. Configuring Component Options

The component level is the highest level which holds general and common configurations that are inherited by the endpoints. For example a component may have security settings, credentials for authentication, urls for network connection and more.

Because components typically have pre configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

Configuring components can be done with the Component DSL, in a configuration file (application.properties|yaml), or directly with Java code.

46.3.2. Configuring Endpoint Options

Endpoints have many options, which allows you to configure what you need the endpoint to do. The options are also categorized into whether the endpoint is used as consumer (from) or as a producer (to), or used for both.

Configuring endpoints is done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

Use Property Placeholders to configure options that allows to not hardcode urls, port numbers, sensitive information, and other settings. In other words placeholders allows to externalize the configuration from your code, and gives more flexibility and reuse.

The following two sections lists all the options, firstly for the component followed by the endpoint.

46.4. Component Options

The Infinispan Embedded component supports 20 options that are listed below.

NameDescriptionDefaultType

configuration (common)

Component configuration.

 

InfinispanEmbeddedConfiguration

queryBuilder (common)

Specifies the query builder.

 

InfinispanQueryBuilder

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

clusteredListener (consumer)

If true, the listener will be installed for the entire cluster.

false

boolean

customListener (consumer)

Returns the custom listener in use, if provided.

 

InfinispanEmbeddedCustomListener

eventTypes (consumer)

Specifies the set of event types to register by the consumer.Multiple event can be separated by comma. The possible event types are: CACHE_ENTRY_ACTIVATED, CACHE_ENTRY_PASSIVATED, CACHE_ENTRY_VISITED, CACHE_ENTRY_LOADED, CACHE_ENTRY_EVICTED, CACHE_ENTRY_CREATED, CACHE_ENTRY_REMOVED, CACHE_ENTRY_MODIFIED, TRANSACTION_COMPLETED, TRANSACTION_REGISTERED, CACHE_ENTRY_INVALIDATED, CACHE_ENTRY_EXPIRED, DATA_REHASHED, TOPOLOGY_CHANGED, PARTITION_STATUS_CHANGED, PERSISTENCE_AVAILABILITY_CHANGED.

 

String

sync (consumer)

If true, the consumer will receive notifications synchronously.

true

boolean

defaultValue (producer)

Set a specific default value for some producer operations.

 

Object

key (producer)

Set a specific key for producer operations.

 

Object

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

oldValue (producer)

Set a specific old value for some producer operations.

 

Object

operation (producer)

The operation to perform.

Enum values:

* PUT * PUTASYNC * PUTALL * PUTALLASYNC * PUTIFABSENT * PUTIFABSENTASYNC * GET * GETORDEFAULT * CONTAINSKEY * CONTAINSVALUE * REMOVE * REMOVEASYNC * REPLACE * REPLACEASYNC * SIZE * CLEAR * CLEARASYNC * QUERY * STATS * COMPUTE * COMPUTEASYNC

PUT

InfinispanOperation

value* (producer)

Set a specific value for producer operations.

 

Object

autowiredEnabled (advanced)

Whether auto-wiring is enabled. This is used for automatic auto-wiring options (the option must be marked as auto-wired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

cacheContainer (advanced)

Autowired Specifies the cache Container to connect.

 

EmbeddedCacheManager

cacheContainerConfiguration (advanced)

Autowired The CacheContainer configuration. Used if the cacheContainer is not defined.

 

Configuration

configurationUri (advanced)

An implementation specific URI for the CacheManager.

 

String

flags (advanced)

A comma separated list of org.infinispan.context.Flag to be applied by default on each cache invocation.

 

String

remappingFunction (advanced)

Set a specific remappingFunction to use in a compute operation.

 

BiFunction

resultHeader (advanced)

Store the operation result in a header instead of the message body. By default, resultHeader == null and the query result is stored in the message body, any existing content in the message body is discarded. If resultHeader is set, the value is used as the name of the header to store the query result and the original message body is preserved. This value can be overridden by an in message header named: CamelInfinispanOperationResultHeader.

 

String

46.5. Endpoint Options

The Infinispan Embedded endpoint is configured using URI syntax.

infinispan-embedded:cacheName

Following are the path and query parameters.

46.5.1. Path Parameters (1 parameters)

NameDescriptionDefaultType

cacheName (common)

Required The name of the cache to use. Use current to use the existing cache name from the currently configured cached manager. Or use default for the default cache manager name.

 

String

46.5.2. Query Parameters (20 parameters)

NameDescriptionDefaultType

queryBuilder (common)

Specifies the query builder.

 

InfinispanQueryBuilder

clusteredListener (consumer)

If true, the listener will be installed for the entire cluster.

false

boolean

customListener (consumer)

Returns the custom listener in use, if provided.

 

InfinispanEmbeddedCustomListener

eventTypes (consumer)

Specifies the set of event types to register by the consumer.Multiple event can be separated by comma. The possible event types are: CACHE_ENTRY_ACTIVATED, CACHE_ENTRY_PASSIVATED, CACHE_ENTRY_VISITED, CACHE_ENTRY_LOADED, CACHE_ENTRY_EVICTED, CACHE_ENTRY_CREATED, CACHE_ENTRY_REMOVED, CACHE_ENTRY_MODIFIED, TRANSACTION_COMPLETED, TRANSACTION_REGISTERED, CACHE_ENTRY_INVALIDATED, CACHE_ENTRY_EXPIRED, DATA_REHASHED, TOPOLOGY_CHANGED, PARTITION_STATUS_CHANGED, PERSISTENCE_AVAILABILITY_CHANGED.

 

String

sync (consumer)

If true, the consumer will receive notifications synchronously.

true

boolean

bridgeErrorHandler (consumer (advanced))

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

* InOnly * InOut * InOptionalOut

 

ExchangePattern

defaultValue (producer)

Set a specific default value for some producer operations.

 

Object

key (producer)

Set a specific key for producer operations.

 

Object

oldValue (producer)

Set a specific old value for some producer operations.

 

Object

operation (producer)

The operation to perform.

Enum values:

* PUT * PUTASYNC * PUTALL * PUTALLASYNC * PUTIFABSENT * PUTIFABSENTASYNC * GET * GETORDEFAULT * CONTAINSKEY * CONTAINSVALUE * REMOVE * REMOVEASYNC * REPLACE * REPLACEASYNC * SIZE * CLEAR * CLEARASYNC * QUERY * STATS * COMPUTE * COMPUTEASYNC

PUT

InfinispanOperation

value (producer)

Set a specific value for producer operations.

 

Object

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

cacheContainer (advanced)

Autowired Specifies the cache Container to connect.

 

EmbeddedCacheManager

cacheContainerConfiguration (advanced)

Autowired The CacheContainer configuration. Used if the cacheContainer is not defined.

 

Configuration

configurationUri (advanced)

An implementation specific URI for the CacheManager.

 

String

flags (advanced)

A comma separated list of org.infinispan.context.Flag to be applied by default on each cache invocation.

 

String

remappingFunction (advanced)

Set a specific remappingFunction to use in a compute operation.

 

BiFunction

resultHeader (advanced)

Store the operation result in a header instead of the message body. By default, resultHeader == null and the query result is stored in the message body, any existing content in the message body is discarded. If resultHeader is set, the value is used as the name of the header to store the query result and the original message body is preserved. This value can be overridden by an in message header named: CamelInfinispanOperationResultHeader.

 

String

46.6. Message Headers

The Infinispan Embedded component supports 22 message headers that are listed below.

NameDescriptionDefaultType

CamelInfinispanEventType (consumer)

Constant: EVENT_TYPE

The type of the received event.

 

String

CamelInfinispanIsPre (consumer)

Constant: IS_PRE

true if the notification is before the event has occurred, false if after the event has occurred.

 

boolean

CamelInfinispanCacheName (common)

Constant: CACHE_NAME

The cache participating in the operation or event.

 

String

CamelInfinispanKey (common)

Constant: KEY

The key to perform the operation to or the key generating the event.

 

Object

CamelInfinispanValue (producer)

Constant: VALUE

The value to use for the operation.

 

Object

CamelInfinispanDefaultValue (producer)

Constant: DEFAULT_VALUE

The default value to use for a getOrDefault.

 

Object

CamelInfinispanOldValue (producer)

Constant: OLD_VALUE

The old value to use for a replace.

 

Object

CamelInfinispanMap (producer)

Constant: MAP

A Map to use in case of CamelInfinispanOperationPutAll operation.

 

Map

CamelInfinispanOperation (producer)

Constant: OPERATION

The operation to perform.

Enum values:

* PUT * PUTASYNC * PUTALL * PUTALLASYNC * PUTIFABSENT * PUTIFABSENTASYNC * GET * GETORDEFAULT * CONTAINSKEY * CONTAINSVALUE * REMOVE * REMOVEASYNC * REPLACE * REPLACEASYNC * SIZE * CLEAR * CLEARASYNC * QUERY * STATS * COMPUTE * COMPUTEASYNC

 

InfinispanOperation

CamelInfinispanOperationResult (producer)

Constant: RESULT

The name of the header whose value is the result.

 

String

CamelInfinispanOperationResultHeader (producer)

Constant: RESULT_HEADER

Store the operation result in a header instead of the message body.

 

String

CamelInfinispanLifespanTime (producer)

Constant: LIFESPAN_TIME

The Lifespan time of a value inside the cache. Negative values are interpreted as infinity.

 

long

CamelInfinispanTimeUnit (producer)

Constant: LIFESPAN_TIME_UNIT

The Time Unit of an entry Lifespan Time.

Enum values:

* NANOSECONDS * MICROSECONDS * MILLISECONDS * SECONDS * MINUTES * HOURS * DAYS

 

TimeUnit

CamelInfinispanMaxIdleTime (producer)

Constant: MAX_IDLE_TIME

The maximum amount of time an entry is allowed to be idle for before it is considered as expired.

 

long

CamelInfinispanMaxIdleTimeUnit (producer)

Constant: MAX_IDLE_TIME_UNIT

The Time Unit of an entry Max Idle Time.

Enum values:

* NANOSECONDS * MICROSECONDS * MILLISECONDS * SECONDS * MINUTES * HOURS * DAYS

 

TimeUnit

CamelInfinispanIgnoreReturnValues (consumer)

Constant: IGNORE_RETURN_VALUES

Signals that write operation’s return value are ignored, so reading the existing value from a store or from a remote node is not necessary.

false

boolean

CamelInfinispanEventData (consumer)

Constant: EVENT_DATA

The event data.

 

Object

CamelInfinispanQueryBuilder (producer)

Constant: QUERY_BUILDER

The QueryBuilder to use for QUERY command, if not present the command defaults to InifinispanConfiguration’s one.

 

InfinispanQueryBuilder

CamelInfinispanCommandRetried (consumer)

Constant: COMMAND_RETRIED

This will be true if the write command that caused this had to be retried again due to a topology change.

 

boolean

CamelInfinispanEntryCreated (consumer)

Constant: ENTRY_CREATED

Indicates whether the cache entry modification event is the result of the cache entry being created.

 

boolean

CamelInfinispanOriginLocal (consumer)

Constant: ORIGIN_LOCAL

true if the call originated on the local cache instance; false if originated from a remote one.

 

boolean

CamelInfinispanCurrentState (consumer)

Constant: CURRENT_STATE

True if this event is generated from an existing entry as the listener has Listener.

 

boolean

46.7. Camel Operations

This section lists all available operations along with their header information.

Table 46.1. Table 1. Put Operations
Operation NameDescription

InfinispanOperation.PUT

Puts a key/value pair in the cache, optionally with expiration

InfinispanOperation.PUTASYNC

Asynchronously puts a key/value pair in the cache, optionally with expiration

InfinispanOperation.PUTIFABSENT

Puts a key/value pair in the cache if it did not exist, optionally with expiration

InfinispanOperation.PUTIFABSENTASYNC

Asynchronously puts a key/value pair in the cache if it did not exist, optionally with expiration

  • Required Headers:

    • CamelInfinispanKey
    • CamelInfinispanValue
  • Optional Headers:

    • CamelInfinispanLifespanTime
    • CamelInfinispanLifespanTimeUnit
    • CamelInfinispanMaxIdleTime
    • CamelInfinispanMaxIdleTimeUnit
  • Result Header:

    • CamelInfinispanOperationResult
Table 46.2. Table 2. Put All Operations
Operation NameDescription

InfinispanOperation.PUTALL

Adds multiple entries to a cache, optionally with expiration

CamelInfinispanOperation.PUTALLASYNC

Asynchronously adds multiple entries to a cache, optionally with expiration

  • Required Headers:

    • CamelInfinispanMap
  • Optional Headers:

    • CamelInfinispanLifespanTime
    • CamelInfinispanLifespanTimeUnit
    • CamelInfinispanMaxIdleTime
    • CamelInfinispanMaxIdleTimeUnit
Table 46.3. Table 3. Get Operations
Operation NameDescription

InfinispanOperation.GET

Retrieves the value associated with a specific key from the cache

InfinispanOperation.GETORDEFAULT

Retrieves the value, or default value, associated with a specific key from the cache

  • Required Headers:

    • CamelInfinispanKey
Table 46.4. Table 4. Contains Key Operation
Operation NameDescription

InfinispanOperation.CONTAINSKEY

Determines whether a cache contains a specific key

  • Required Headers

    • CamelInfinispanKey
  • Result Header

    • CamelInfinispanOperationResult
Table 46.5. Table 5. Contains Value Operation
Operation NameDescription

InfinispanOperation.CONTAINSVALUE

Determines whether a cache contains a specific value

  • Required Headers:

    • CamelInfinispanKey
Table 46.6. Table 6. Remove Operations
Operation NameDescription

InfinispanOperation.REMOVE

Removes an entry from a cache, optionally only if the value matches a given one

InfinispanOperation.REMOVEASYNC

Asynchronously removes an entry from a cache, optionally only if the value matches a given one

  • Required Headers:

    • CamelInfinispanKey
  • Optional Headers:

    • CamelInfinispanValue
  • Result Header:

    • CamelInfinispanOperationResult
Table 46.7. Table 7. Replace Operations
Operation NameDescription

InfinispanOperation.REPLACE

Conditionally replaces an entry in the cache, optionally with expiration

InfinispanOperation.REPLACEASYNC

Asynchronously conditionally replaces an entry in the cache, optionally with expiration

  • Required Headers:

    • CamelInfinispanKey
    • CamelInfinispanValue
    • CamelInfinispanOldValue
  • Optional Headers:

    • CamelInfinispanLifespanTime
    • CamelInfinispanLifespanTimeUnit
    • CamelInfinispanMaxIdleTime
    • CamelInfinispanMaxIdleTimeUnit
  • Result Header:

    • CamelInfinispanOperationResult
Table 46.8. Table 8. Clear Operations
Operation NameDescription

InfinispanOperation.CLEAR

Clears the cache

InfinispanOperation.CLEARASYNC

Asynchronously clears the cache

Table 46.9. Table 9. Size Operation
Operation NameDescription

InfinispanOperation.SIZE

Returns the number of entries in the cache

  • Result Header

    • CamelInfinispanOperationResult
Table 46.10. Table 10. Stats Operation
Operation NameDescription

InfinispanOperation.STATS

Returns statistics about the cache

  • Result Header:

    • CamelInfinispanOperationResult
Table 46.11. Table 11. Query Operation
Operation NameDescription

InfinispanOperation.QUERY

Executes a query on the cache

  • Required Headers:

    • CamelInfinispanQueryBuilder
  • Result Header:

    • CamelInfinispanOperationResult
Note

Write methods like put(key, value) and remove(key) do not return the previous value by default.

46.8. Examples

  • Put a key/value into a named cache:

    from("direct:start")
        .setHeader(InfinispanConstants.OPERATION).constant(InfinispanOperation.PUT) (1)
        .setHeader(InfinispanConstants.KEY).constant("123") (2)
        .to("infinispan:myCacheName&cacheContainer=#cacheContainer"); (3)
    • Set the operation to perform
    • Set the key used to identify the element in the cache
    • Use the configured cache manager cacheContainer from the registry to put an element to the cache named myCacheName

      It is possible to configure the lifetime and/or the idle time before the entry expires and gets evicted from the cache, as example.

    from("direct:start")
        .setHeader(InfinispanConstants.OPERATION).constant(InfinispanOperation.GET)
        .setHeader(InfinispanConstants.KEY).constant("123")
        .setHeader(InfinispanConstants.LIFESPAN_TIME).constant(100L) (1)
        .setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT.constant(TimeUnit.MILLISECONDS.toString()) (2)
        .to("infinispan:myCacheName");
    • Set the lifespan of the entry
    • Set the time unit for the lifespan
  • Queries

    from("direct:start")
        .setHeader(InfinispanConstants.OPERATION, InfinispanConstants.QUERY)
        .setHeader(InfinispanConstants.QUERY_BUILDER, new InfinispanQueryBuilder() {
            @Override
            public Query build(QueryFactory<Query> qf) {
                return qf.from(User.class).having("name").like("%abc%").build();
            }
        })
        .to("infinispan:myCacheName?cacheContainer=#cacheManager") ;
  • Custom Listeners

    from("infinispan://?cacheContainer=#cacheManager&customListener=#myCustomListener")
      .to("mock:result");
    • The instance of myCustomListener must exist and Camel should be able to look it up from the Registry. Users are encouraged to extend the org.apache.camel.component.infinispan.embedded.InfinispanEmbeddedCustomListener class and annotate the resulting class with @Listener which can be found in package org.infinispan.notifications.

46.9. Using the Infinispan based idempotent repository

Java Example

InfinispanEmbeddedConfiguration conf = new InfinispanEmbeddedConfiguration(); (1)
conf.setConfigurationUri("classpath:infinispan.xml")

InfinispanEmbeddedIdempotentRepository repo = new InfinispanEmbeddedIdempotentRepository("idempotent");  (2)
repo.setConfiguration(conf);

context.addRoutes(new RouteBuilder() {
    @Override
    public void configure() {
        from("direct:start")
            .idempotentConsumer(header("MessageID"), repo) (3)
            .to("mock:result");
    }
});
  • Configure the cache
  • Configure the repository bean
  • Set the repository to the route

XML Example

<bean id="infinispanRepo" class="org.apache.camel.component.infinispan.embedded.InfinispanEmbeddedIdempotentRepository" destroy-method="stop">
  <constructor-arg value="idempotent"/> (1)
  <property name="configuration"> (2)
    <bean class="org.apache.camel.component.infinispan.embedded.InfinispanEmbeddedConfiguration">
      <property name="configurationUrl" value="classpath:infinispan.xml"/>
    </bean>
  </property>
</bean>

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="direct:start" />
        <idempotentConsumer idempotentRepository="infinispanRepo"> (3)
            <header>MessageID</header>
            <to uri="mock:result" />
        </idempotentConsumer>
    </route>
</camelContext>
  • Set the name of the cache that will be used by the repository
  • Configure the repository bean
  • Set the repository to the route

46.10. Using the Infinispan based aggregation repository

Java Example

InfinispanEmbeddedConfiguration conf = new InfinispanEmbeddedConfiguration(); (1)
conf.setConfigurationUri("classpath:infinispan.xml")

InfinispanEmbeddedAggregationRepository repo = new InfinispanEmbeddedAggregationRepository("aggregation");  (2)
repo.setConfiguration(conf);

context.addRoutes(new RouteBuilder() {
    @Override
    public void configure() {
        from("direct:start")
                .aggregate(header("MessageID"))
                .completionSize(3)
                .aggregationRepository(repo) (3)
                .aggregationStrategy("myStrategy")
                .to("mock:result");
    }
});
  • Configure the cache
  • Create the repository bean
  • Set the repository to the route

XML Example

<bean id="infinispanRepo" class="org.apache.camel.component.infinispan.embedded.InfinispanEmbeddedAggregationRepository" destroy-method="stop">
  <constructor-arg value="aggregation"/> (1)
  <property name="configuration"> (2)
    <bean class="org.apache.camel.component.infinispan.embedded.InfinispanEmbeddedConfiguration">
      <property name="configurationUrl" value="classpath:infinispan.xml"/>
    </bean>
  </property>
</bean>

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="direct:start" />
        <aggregate aggregationStrategy="myStrategy"
                   completionSize="3"
                   aggregationRepository="infinispanRepo"> (3)
            <correlationExpression>
                <header>MessageID</header>
            </correlationExpression>
            <to uri="mock:result"/>
        </aggregate>
    </route>
</camelContext>
  • Set the name of the cache that will be used by the repository
  • Configure the repository bean
  • Set the repository to the route
Note

With the release of Infinispan 11, it is required to set the encoding configuration on any cache created. This is critical for consuming events too. For more information have a look at Data Encoding and MediaTypes in the official Infinispan documentation.

46.11. Spring Boot Auto-Configuration

The component supports 17 options that are listed below.

NameDescriptionDefaultType

camel.component.infinispan-embedded.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.infinispan-embedded.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.infinispan-embedded.cache-container

Specifies the cache Container to connect. The option is a org.infinispan.manager.EmbeddedCacheManager type.

 

EmbeddedCacheManager

camel.component.infinispan-embedded.cache-container-configuration

The CacheContainer configuration. Used if the cacheContainer is not defined. The option is a org.infinispan.configuration.cache.Configuration type.

 

Configuration

camel.component.infinispan-embedded.clustered-listener

If true, the listener will be installed for the entire cluster.

false

Boolean

camel.component.infinispan-embedded.configuration

Component configuration. The option is a org.apache.camel.component.infinispan.embedded.InfinispanEmbeddedConfiguration type.

 

InfinispanEmbeddedConfiguration

camel.component.infinispan-embedded.configuration-uri

An implementation specific URI for the CacheManager.

 

String

camel.component.infinispan-embedded.custom-listener

Returns the custom listener in use, if provided. The option is a org.apache.camel.component.infinispan.embedded.InfinispanEmbeddedCustomListener type.

 

InfinispanEmbeddedCustomListener

camel.component.infinispan-embedded.enabled

Whether to enable auto configuration of the infinispan-embedded component. This is enabled by default.

 

Boolean

camel.component.infinispan-embedded.event-types

Specifies the set of event types to register by the consumer.Multiple event can be separated by comma. The possible event types are: CACHE_ENTRY_ACTIVATED, CACHE_ENTRY_PASSIVATED, CACHE_ENTRY_VISITED, CACHE_ENTRY_LOADED, CACHE_ENTRY_EVICTED, CACHE_ENTRY_CREATED, CACHE_ENTRY_REMOVED, CACHE_ENTRY_MODIFIED, TRANSACTION_COMPLETED, TRANSACTION_REGISTERED, CACHE_ENTRY_INVALIDATED, CACHE_ENTRY_EXPIRED, DATA_REHASHED, TOPOLOGY_CHANGED, PARTITION_STATUS_CHANGED, PERSISTENCE_AVAILABILITY_CHANGED.

 

String

camel.component.infinispan-embedded.flags

A comma separated list of org.infinispan.context.Flag to be applied by default on each cache invocation.

 

String

camel.component.infinispan-embedded.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.infinispan-embedded.operation

The operation to perform.

 

InfinispanOperation

camel.component.infinispan-embedded.query-builder

Specifies the query builder. The option is a org.apache.camel.component.infinispan.InfinispanQueryBuilder type.

 

InfinispanQueryBuilder

camel.component.infinispan-embedded.remapping-function

Set a specific remappingFunction to use in a compute operation. The option is a java.util.function.BiFunction type.

 

BiFunction

camel.component.infinispan-embedded.result-header

Store the operation result in a header instead of the message body. By default, resultHeader == null and the query result is stored in the message body, any existing content in the message body is discarded. If resultHeader is set, the value is used as the name of the header to store the query result and the original message body is preserved. This value can be overridden by an in message header named: CamelInfinispanOperationResultHeader.

 

String

camel.component.infinispan-embedded.sync

If true, the consumer will receive notifications synchronously.

true

Boolean

Chapter 47. JacksonXML

Jackson XML is a Data Format which uses the Jackson library with the XMLMapper extension to unmarshal an XML payload into Java objects or to marshal Java objects into an XML payload. NOTE: If you are familiar with Jackson, this XML data format behaves in the same way as its JSON counterpart, and thus can be used with classes annotated for JSON serialization/deserialization.

This extension also mimics JAXB’s "Code first" approach.

This data format relies on Woodstox (especially for features like pretty printing), a fast and efficient XML processor.

from("activemq:My.Queue").
  unmarshal().jacksonxml().
  to("mqseries:Another.Queue");

47.1. Dependencies

When using jacksonxml with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-jacksonxml-starter</artifactId>
</dependency>

47.2. JacksonXML Options

The JacksonXML dataformat supports 15 options, which are listed below.

NameDefaultJava TypeDescription

xmlMapper

 

String

Lookup and use the existing XmlMapper with the given id.

prettyPrint

false

Boolean

To enable pretty printing output nicely formatted. Is by default false.

unmarshalType

 

String

Class name of the java type to use when unmarshalling.

jsonView

 

String

When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations.

include

 

String

If you want to marshal a pojo to JSON, and the pojo has some fields with null values. And you want to skip these null values, you can set this option to NON_NULL.

allowJmsType

 

Boolean

Used for JMS users to allow the JMSType header from the JMS spec to specify a FQN classname to use to unmarshal to.

collectionType

 

String

Refers to a custom collection type to lookup in the registry to use. This option should rarely be used, but allows to use different collection types than java.util.Collection based as default.

useList

 

Boolean

To unmarshal to a List of Map or a List of Pojo.

enableJaxbAnnotationModule

 

Boolean

Whether to enable the JAXB annotations module when using jackson. When enabled then JAXB annotations can be used by Jackson.

moduleClassNames

 

String

To use custom Jackson modules com.fasterxml.jackson.databind.Module specified as a String with FQN class names. Multiple classes can be separated by comma.

moduleRefs

 

String

To use custom Jackson modules referred from the Camel registry. Multiple modules can be separated by comma.

enableFeatures

 

String

Set of features to enable on the Jackson com.fasterxml.jackson.databind.ObjectMapper. The features should be a name that matches a enum from com.fasterxml.jackson.databind.SerializationFeature, com.fasterxml.jackson.databind.DeserializationFeature, or com.fasterxml.jackson.databind.MapperFeature Multiple features can be separated by comma.

disableFeatures

 

String

Set of features to disable on the Jackson com.fasterxml.jackson.databind.ObjectMapper. The features should be a name that matches a enum from com.fasterxml.jackson.databind.SerializationFeature, com.fasterxml.jackson.databind.DeserializationFeature, or com.fasterxml.jackson.databind.MapperFeature Multiple features can be separated by comma.

allowUnmarshallType

 

Boolean

If enabled then Jackson is allowed to attempt to use the CamelJacksonUnmarshalType header during the unmarshalling. This should only be enabled when desired to be used.

contentTypeHeader

 

Boolean

Whether the data format should set the Content-Type header with the type from the data format. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON.

47.2.1. Using Jackson XML in Spring DSL

When using Data Format in Spring DSL you need to declare the data formats first. This is done in the DataFormats XML tag.

        <dataFormats>
            <!-- here we define a Xml data format with the id jack and that it should use the TestPojo as the class type when
                 doing unmarshal. The unmarshalType is optional, if not provided Camel will use a Map as the type -->
            <jacksonxml id="jack" unmarshalType="org.apache.camel.component.jacksonxml.TestPojo"/>
        </dataFormats>

And then you can refer to this id in the route:

       <route>
            <from uri="direct:back"/>
            <unmarshal><custom ref="jack"/></unmarshal>
            <to uri="mock:reverse"/>
        </route>

47.2.2. Excluding POJO fields from marshalling

When marshalling a POJO to XML you might want to exclude certain fields from the XML output. With Jackson you can use JSON views to accomplish this. First create one or more marker classes.

Use the marker classes with the @JsonView annotation to include/exclude certain fields. The annotation also works on getters.

Finally use the Camel JacksonXMLDataFormat to marshall the above POJO to XML.

Note that the weight field is missing in the resulting XML:

<pojo age="30" weight="70"/>

47.3. Include/Exclude fields using the jsonView attribute with `JacksonXML`DataFormat

As an example of using this attribute you can instead of:

JacksonXMLDataFormat ageViewFormat = new JacksonXMLDataFormat(TestPojoView.class, Views.Age.class);
from("direct:inPojoAgeView").
  marshal(ageViewFormat);

Directly specify your JSON view inside the Java DSL as:

from("direct:inPojoAgeView").
  marshal().jacksonxml(TestPojoView.class, Views.Age.class);

And the same in XML DSL:

<from uri="direct:inPojoAgeView"/>
  <marshal>
    <jacksonxml unmarshalType="org.apache.camel.component.jacksonxml.TestPojoView" jsonView="org.apache.camel.component.jacksonxml.Views$Age"/>
  </marshal>

47.4. Setting serialization include option

If you want to marshal a pojo to XML, and the pojo has some fields with null values. And you want to skip these null values, then you need to set either an annotation on the pojo,

@JsonInclude(Include.NON_NULL)
public class MyPojo {
   ...
}

But this requires you to include that annotation in your pojo source code. You can also configure the Camel JacksonXMLDataFormat to set the include option, as shown below:

JacksonXMLDataFormat format = new JacksonXMLDataFormat();
format.setInclude("NON_NULL");

Or from XML DSL you configure this as

    <dataFormats>
      <jacksonxml id="jacksonxml" include="NON_NULL"/>
    </dataFormats>

47.5. Unmarshalling from XML to POJO with dynamic class name

If you use jackson to unmarshal XML to POJO, then you can now specify a header in the message that indicate which class name to unmarshal to.
The header has key CamelJacksonUnmarshalType if that header is present in the message, then Jackson will use that as FQN for the POJO class to unmarshal the XML payload as.

 For JMS end users there is the JMSType header from the JMS spec that
indicates that also. To enable support for JMSType you would need to
turn that on, on the jackson data format as shown:
JacksonDataFormat format = new JacksonDataFormat();
format.setAllowJmsType(true);

Or from XML DSL you configure this as

    <dataFormats>
      <jacksonxml id="jacksonxml" allowJmsType="true"/>
    </dataFormats>

47.6. Unmarshalling from XML to List<Map> or List<pojo>

If you are using Jackson to unmarshal XML to a list of map/pojo, you can now specify this by setting useList="true" or use the org.apache.camel.component.jacksonxml.ListJacksonXMLDataFormat. For example with Java you can do as shown below:

JacksonXMLDataFormat format = new ListJacksonXMLDataFormat();
// or
JacksonXMLDataFormat format = new JacksonXMLDataFormat();
format.useList();
// and you can specify the pojo class type also
format.setUnmarshalType(MyPojo.class);

And if you use XML DSL then you configure to use list using useList attribute as shown below:

    <dataFormats>
      <jacksonxml id="jack" useList="true"/>
    </dataFormats>

And you can specify the pojo type also

    <dataFormats>
      <jacksonxml id="jack" useList="true" unmarshalType="com.foo.MyPojo"/>
    </dataFormats>

47.7. Using custom Jackson modules

You can use custom Jackson modules by specifying the class names of those using the moduleClassNames option as shown below.

    <dataFormats>
      <jacksonxml id="jack" useList="true" unmarshalType="com.foo.MyPojo" moduleClassNames="com.foo.MyModule,com.foo.MyOtherModule"/>
    </dataFormats>

When using moduleClassNames then the custom jackson modules are not configured, by created using default constructor and used as-is. If a custom module needs any custom configuration, then an instance of the module can be created and configured, and then use modulesRefs to refer to the module as shown below:

    <bean id="myJacksonModule" class="com.foo.MyModule">
      ... // configure the module as you want
    </bean>

    <dataFormats>
      <jacksonxml id="jacksonxml" useList="true" unmarshalType="com.foo.MyPojo" moduleRefs="myJacksonModule"/>
    </dataFormats>
 Multiple modules can be specified separated by comma, such as
moduleRefs="myJacksonModule,myOtherModule"

47.8. Enabling or disable features using Jackson

Jackson has a number of features you can enable or disable, which its ObjectMapper uses. For example to disable failing on unknown properties when marshalling, you can configure this using the disableFeatures:

 <dataFormats>
      <jacksonxml id="jacksonxml" unmarshalType="com.foo.MyPojo" disableFeatures="FAIL_ON_UNKNOWN_PROPERTIES"/>
 </dataFormats>

You can disable multiple features by separating the values using comma. The values for the features must be the name of the enums from Jackson from the following enum classes

  • com.fasterxml.jackson.databind.SerializationFeature
  • com.fasterxml.jackson.databind.DeserializationFeature
  • com.fasterxml.jackson.databind.MapperFeature

To enable a feature use the enableFeatures options instead.

From Java code you can use the type safe methods from camel-jackson module:

JacksonDataFormat df = new JacksonDataFormat(MyPojo.class);
df.disableFeature(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
df.disableFeature(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES);

47.9. Converting Maps to POJO using Jackson

Jackson ObjectMapper can be used to convert maps to POJO objects. Jackson component comes with the data converter that can be used to convert java.util.Map instance to non-String, non-primitive and non-Number objects.

Map<String, Object> invoiceData = new HashMap<String, Object>();
invoiceData.put("netValue", 500);
producerTemplate.sendBody("direct:mapToInvoice", invoiceData);
...
// Later in the processor
Invoice invoice = exchange.getIn().getBody(Invoice.class);

If there is a single ObjectMapper instance available in the Camel registry, it will used by the converter to perform the conversion. Otherwise the default mapper will be used.

47.10. Formatted XML marshalling (pretty-printing)

Using the prettyPrint option one can output a well formatted XML while marshalling:

 <dataFormats>
      <jacksonxml id="jack" prettyPrint="true"/>
 </dataFormats>

And in Java DSL:

from("direct:inPretty").marshal().jacksonxml(true);

Please note that there are 5 different overloaded jacksonxml() DSL methods which support the prettyPrint option in combination with other settings for unmarshalType, jsonView etc.

47.11. Spring Boot Auto-Configuration

The component supports 16 options, which are listed below.

NameDescriptionDefaultType

camel.dataformat.jacksonxml.allow-jms-type

Used for JMS users to allow the JMSType header from the JMS spec to specify a FQN classname to use to unmarshal to.

false

Boolean

camel.dataformat.jacksonxml.allow-unmarshall-type

If enabled then Jackson is allowed to attempt to use the CamelJacksonUnmarshalType header during the unmarshalling. This should only be enabled when desired to be used.

false

Boolean

camel.dataformat.jacksonxml.collection-type

Refers to a custom collection type to lookup in the registry to use. This option should rarely be used, but allows to use different collection types than java.util.Collection based as default.

 

String

camel.dataformat.jacksonxml.content-type-header

Whether the data format should set the Content-Type header with the type from the data format. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON.

true

Boolean

camel.dataformat.jacksonxml.disable-features

Set of features to disable on the Jackson com.fasterxml.jackson.databind.ObjectMapper. The features should be a name that matches a enum from com.fasterxml.jackson.databind.SerializationFeature, com.fasterxml.jackson.databind.DeserializationFeature, or com.fasterxml.jackson.databind.MapperFeature Multiple features can be separated by comma.

 

String

camel.dataformat.jacksonxml.enable-features

Set of features to enable on the Jackson com.fasterxml.jackson.databind.ObjectMapper. The features should be a name that matches a enum from com.fasterxml.jackson.databind.SerializationFeature, com.fasterxml.jackson.databind.DeserializationFeature, or com.fasterxml.jackson.databind.MapperFeature Multiple features can be separated by comma.

 

String

camel.dataformat.jacksonxml.enable-jaxb-annotation-module

Whether to enable the JAXB annotations module when using jackson. When enabled then JAXB annotations can be used by Jackson.

false

Boolean

camel.dataformat.jacksonxml.enabled

Whether to enable auto configuration of the jacksonxml data format. This is enabled by default.

 

Boolean

camel.dataformat.jacksonxml.include

If you want to marshal a pojo to JSON, and the pojo has some fields with null values. And you want to skip these null values, you can set this option to NON_NULL.

 

String

camel.dataformat.jacksonxml.json-view

When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations.

 

String

camel.dataformat.jacksonxml.module-class-names

To use custom Jackson modules com.fasterxml.jackson.databind.Module specified as a String with FQN class names. Multiple classes can be separated by comma.

 

String

camel.dataformat.jacksonxml.module-refs

To use custom Jackson modules referred from the Camel registry. Multiple modules can be separated by comma.

 

String

camel.dataformat.jacksonxml.pretty-print

To enable pretty printing output nicely formatted. Is by default false.

false

Boolean

camel.dataformat.jacksonxml.unmarshal-type

Class name of the java type to use when unmarshalling.

 

String

camel.dataformat.jacksonxml.use-list

To unmarshal to a List of Map or a List of Pojo.

false

Boolean

camel.dataformat.jacksonxml.xml-mapper

Lookup and use the existing XmlMapper with the given id.

 

String

Chapter 48. JAXB

Since Camel 1.0

JAXB is a Data Format which uses the JAXB XML marshalling standard to unmarshal an XML payload into Java objects or to marshal Java objects into an XML payload.

48.1. Dependencies

When using jaxb with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-jaxb-starter</artifactId>
</dependency>

48.2. Options

The JAXB dataformat supports 20 options, which are listed below.

NameDefaultJava TypeDescription

contextPath

 

String

Required Package name where your JAXB classes are located.

contextPathIsClassName

false

Boolean

This can be set to true to mark that the contextPath is referring to a classname and not a package name.

schema

 

String

To validate against an existing schema. Your can use the prefix classpath:, file: or http: to specify how the resource should be resolved. You can separate multiple schema files by using the ',' character.

schemaSeverityLevel

0

Enum

Sets the schema severity level to use when validating against a schema. This level determines the minimum severity error that triggers JAXB to stop continue parsing. The default value of 0 (warning) means that any error (warning, error or fatal error) will trigger JAXB to stop. There are the following three levels: 0=warning, 1=error, 2=fatal error.

Enum values:

  • 0
  • 1
  • 2

prettyPrint

false

Boolean

To enable pretty printing output nicely formatted. Is by default false.

objectFactory

false

Boolean

Whether to allow using ObjectFactory classes to create the POJO classes during marshalling. This only applies to POJO classes that has not been annotated with JAXB and providing jaxb.index descriptor files.

ignoreJAXBElement

false

Boolean

Whether to ignore JAXBElement elements - only needed to be set to false in very special use-cases.

mustBeJAXBElement

false

Boolean

Whether marhsalling must be java objects with JAXB annotations. And if not then it fails. This option can be set to false to relax that, such as when the data is already in XML format.

filterNonXmlChars

false

Boolean

To ignore non xml characheters and replace them with an empty space.

encoding

 

String

To overrule and use a specific encoding.

fragment

false

Boolean

To turn on marshalling XML fragment trees. By default JAXB looks for XmlRootElement annotation on given class to operate on whole XML tree. This is useful but not always - sometimes generated code does not have XmlRootElement annotation, sometimes you need unmarshall only part of tree. In that case you can use partial unmarshalling. To enable this behaviours you need set property partClass. Camel will pass this class to JAXB’s unmarshaler.

partClass

 

String

Name of class used for fragment parsing. See more details at the fragment option.

partNamespace

 

String

XML namespace to use for fragment parsing. See more details at the fragment option.

namespacePrefixRef

 

String

When marshalling using JAXB or SOAP then the JAXB implementation will automatic assign namespace prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you to refer to a map which contains the desired mapping.

xmlStreamWriterWrapper

 

String

To use a custom xml stream writer.

schemaLocation

 

String

To define the location of the schema.

noNamespaceSchemaLocation

 

String

To define the location of the namespaceless schema.

jaxbProviderProperties

 

String

Refers to a custom java.util.Map to lookup in the registry containing custom JAXB provider properties to be used with the JAXB marshaller.

contentTypeHeader

true

Boolean

Whether the data format should set the Content-Type header with the type from the data format. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON.

accessExternalSchemaProtocols

false

String

Only in use if schema validation has been enabled. Restrict access to the protocols specified for external reference set by the schemaLocation attribute, Import and Include element. Examples of protocols are file, http, jar:file. false or none to deny all access to external references; a specific protocol, such as file, to give permission to only the protocol; the keyword all to grant permission to all protocols.

48.3. Using the Java DSL

The following example uses a named DataFormat of jaxb which is configured with a Java package name to initialize the JAXBContext.

DataFormat jaxb = new JaxbDataFormat("com.acme.model");

from("activemq:My.Queue").
  unmarshal(jaxb).
  to("mqseries:Another.Queue");

You can use a named reference to a data format which can then be defined in your Registry such as via your Spring XML file.

from("activemq:My.Queue").
  unmarshal("myJaxbDataType").
  to("mqseries:Another.Queue");

48.4. Using Spring XML

The following example shows how to configure the JaxbDataFormat and use it in multiple routes.

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

  <bean id="myJaxb" class="org.apache.camel.converter.jaxb.JaxbDataFormat">
    <property name="contextPath" value="org.apache.camel.example"/>
  </bean>

  <camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
      <from uri="direct:start"/>
      <marshal><custom ref="myJaxb"/></marshal>
      <to uri="direct:marshalled"/>
    </route>
    <route>
      <from uri="direct:marshalled"/>
      <unmarshal><custom ref="myJaxb"/></unmarshal>
      <to uri="mock:result"/>
    </route>
  </camelContext>

</beans>

48.5. Multiple context paths

It is possible to use this data format with more than one context path. You can specify multiple context paths using : as a separator, for example com.mycompany:com.mycompany2.

48.6. Partial marshalling / unmarshalling

JAXB 2 supports marshalling and unmarshalling XML tree fragments. By default JAXB looks for the @XmlRootElement annotation on a given class to operate on whole XML tree. Sometimes the generated code does not have the @XmlRootElement annotation and sometimes you need to unmarshall only part of the tree.

In that case you can use partial unmarshalling. To enable this behaviour you need set property partClass on the JaxbDataFormat. Camel will pass this class to the JAXB unmarshaller. If JaxbConstants.JAXB_PART_CLASS is set as one of the exchange headers, its value is used to override the partClass property on the JaxbDataFormat.

For marshalling you have to add the partNamespace attribute with the QName of the destination namespace.

If JaxbConstants.JAXB_PART_NAMESPACE is set as one of the exchange headers, its value is used to override the partNamespace property on the JaxbDataFormat.

While setting partNamespace through JaxbConstants.JAXB_PART_NAMESPACE, please note that you need to specify its value in the format {namespaceUri}localPart, as per the example below.

.setHeader(JaxbConstants.JAXB_PART_NAMESPACE, constant("{http://www.camel.apache.org/jaxb/example/address/1}address"));

48.7. Fragment

JaxbDataFormat has a property named fragment which can set the Marshaller.JAXB_FRAGMENT property on the JAXB Marshaller. If you don’t want the JAXB Marshaller to generate the XML declaration, you can set this option to be true. The default value of this property is false.

48.8. Ignoring Non-XML Characters

JaxbDataFormat supports ignoring Non-XML Characters. Set the filterNonXmlChars property to true. The JaxbDataFormat will replace any non-XML character with a space character (" ") during message marshalling or unmarshalling. You can also set the Exchange property Exchange.FILTER_NON_XML_CHARS.

 JDK 1.5JDK 1.6+

Filtering in use

StAX API and implementation

No

Filtering not in use

StAX API only

No

This feature has been tested with Woodstox 3.2.9 and Sun JDK 1.6 StAX implementation.

JaxbDataFormat now allows you to customize the XMLStreamWriter used to marshal the stream to XML. Using this configuration, you can add your own stream writer to completely remove, escape, or replace non-XML characters.

JaxbDataFormat customWriterFormat = new JaxbDataFormat("org.apache.camel.foo.bar");
customWriterFormat.setXmlStreamWriterWrapper(new TestXmlStreamWriter());

The following example shows using the Spring DSL and also enabling Camel’s non-XML filtering:

<bean id="testXmlStreamWriterWrapper" class="org.apache.camel.jaxb.TestXmlStreamWriter"/>
<jaxb filterNonXmlChars="true" contextPath="org.apache.camel.foo.bar" xmlStreamWriterWrapper="#testXmlStreamWriterWrapper" />

48.9. Working with the ObjectFactory

If you use XJC to create the java class from the schema, you will get an ObjectFactory for your JAXB context. Since the ObjectFactory uses the JAXBElement to hold the reference of the schema and element instance value, JaxbDataformat will ignore the JAXBElement by default and you will get the element instance value instead of the JAXBElement object from the unmarshaled message body.

If you want to get the JAXBElement object form the unmarshaled message body, you need to set the JaxbDataFormat ignoreJAXBElement property to be false.

48.10. Setting the encoding

You can set the encoding option on the JaxbDataFormat to configure the Marshaller.JAXB_ENCODING encoding property on the JAXB Marshaller.

You can setup which encoding to use when you declare the JaxbDataFormat. You can also provide the encoding in the Exchange property Exchange.CHARSET_NAME. This property will override the encoding set on the JaxbDataFormat.

48.11. Controlling namespace prefix mapping

When marshalling using JAXB or SOAP then the JAXB implementation will automatic assign namespace prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you to refer to a map which contains the desired mapping.

For example, in Spring XML we can define a Map with the mapping. In the mapping file below, we map SOAP to use soap as as a prefix. While our custom namespace http://www.mycompany.com/foo/2 is not using any prefix.

 <util:map id="myMap">
    <entry key="http://www.w3.org/2003/05/soap-envelope" value="soap"/>
    <!-- we don't want any prefix for our namespace -->
    <entry key="http://www.mycompany.com/foo/2" value=""/>
 </util:map>

To use this in JAXB or SOAP data formats you refer to this map, using the namespacePrefixRef attribute as shown below. Then Camel will lookup in the Registry a java.util.Map with the id myMap, which was what we defined above.

 <marshal>
    <soap version="1.2" contextPath="com.mycompany.foo" namespacePrefixRef="myMap"/>
 </marshal>

48.12. Schema validation

The JaxbDataFormat supports validation by marshalling and unmarshalling from / to XML. You can use the prefix classpath:, file: or http: to specify how the resource should be resolved. You can separate multiple schema files by using the , character.

Note

If the XSD schema files import/access other files, then you need to enable file protocol (or others to allow access).

Using the Java DSL, you can configure it in the following way:

JaxbDataFormat jaxbDataFormat = new JaxbDataFormat();
jaxbDataFormat.setContextPath(Person.class.getPackage().getName());
jaxbDataFormat.setSchema("classpath:person.xsd,classpath:address.xsd");
jaxbDataFormat.setAccessExternalSchemaProtocols("file");

You can do the same using the XML DSL:

<marshal>
    <jaxb id="jaxb" schema="classpath:person.xsd,classpath:address.xsd"
          accessExternalSchemaProtocols="file"/>
</marshal>

48.13. Schema Location

The JaxbDataFormat supports to specify the SchemaLocation when marshalling the XML.

Using the Java DSL, you can configure it in the following way:

JaxbDataFormat jaxbDataFormat = new JaxbDataFormat();
jaxbDataFormat.setContextPath(Person.class.getPackage().getName());
jaxbDataFormat.setSchemaLocation("schema/person.xsd");

You can do the same using the XML DSL:

<marshal>
    <jaxb id="jaxb" schemaLocation="schema/person.xsd"/>
</marshal>

48.14. Marshal data that is already XML

The JAXB marshaller requires that the message body is JAXB compatible, e.g it is a JAXBElement, a java instance that has JAXB annotations, or extends JAXBElement. There can be situations where the message body is already in XML, e.g from a String type.

JaxbDataFormat has an option named mustBeJAXBElement which you can set to false to relax this check and have the JAXB marshaller only attempt marshalling on JAXBElement (javax.xml.bind.JAXBIntrospector#isElement returns true). In those situations the marshaller will fallback to marshal the message body as-is.

48.15. Spring Boot Auto-Configuration

The component supports 21 options, which are listed below.

NameDescriptionDefaultType

camel.dataformat.jaxb.access-external-schema-protocols

Only in use if schema validation has been enabled. Restrict access to the protocols specified for external reference set by the schemaLocation attribute, Import and Include element. Examples of protocols are file, http, jar:file. false or none to deny all access to external references; a specific protocol, such as file, to give permission to only the protocol; the keyword all to grant permission to all protocols.

false

String

camel.dataformat.jaxb.content-type-header

Whether the data format should set the Content-Type header with the type from the data format. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON.

true

Boolean

camel.dataformat.jaxb.context-path

Package name where your JAXB classes are located.

 

String

camel.dataformat.jaxb.context-path-is-class-name

This can be set to true to mark that the contextPath is referring to a classname and not a package name.

false

Boolean

camel.dataformat.jaxb.enabled

Whether to enable auto configuration of the jaxb data format. This is enabled by default.

 

Boolean

camel.dataformat.jaxb.encoding

To overrule and use a specific encoding.

 

String

camel.dataformat.jaxb.filter-non-xml-chars

To ignore non xml characheters and replace them with an empty space.

false

Boolean

camel.dataformat.jaxb.fragment

To turn on marshalling XML fragment trees. By default JAXB looks for XmlRootElement annotation on given class to operate on whole XML tree. This is useful but not always - sometimes generated code does not have XmlRootElement annotation, sometimes you need unmarshall only part of tree. In that case you can use partial unmarshalling. To enable this behaviours you need set property partClass. Camel will pass this class to JAXB’s unmarshaler.

false

Boolean

camel.dataformat.jaxb.ignore-j-a-x-b-element

Whether to ignore JAXBElement elements - only needed to be set to false in very special use-cases.

false

Boolean

camel.dataformat.jaxb.jaxb-provider-properties

Refers to a custom java.util.Map to lookup in the registry containing custom JAXB provider properties to be used with the JAXB marshaller.

 

String

camel.dataformat.jaxb.must-be-j-a-x-b-element

Whether marhsalling must be java objects with JAXB annotations. And if not then it fails. This option can be set to false to relax that, such as when the data is already in XML format.

false

Boolean

camel.dataformat.jaxb.namespace-prefix-ref

When marshalling using JAXB or SOAP then the JAXB implementation will automatic assign namespace prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you to refer to a map which contains the desired mapping.

 

String

camel.dataformat.jaxb.no-namespace-schema-location

To define the location of the namespaceless schema.

 

String

camel.dataformat.jaxb.object-factory

Whether to allow using ObjectFactory classes to create the POJO classes during marshalling. This only applies to POJO classes that has not been annotated with JAXB and providing jaxb.index descriptor files.

false

Boolean

camel.dataformat.jaxb.part-class

Name of class used for fragment parsing. See more details at the fragment option.

 

String

camel.dataformat.jaxb.part-namespace

XML namespace to use for fragment parsing. See more details at the fragment option.

 

String

camel.dataformat.jaxb.pretty-print

To enable pretty printing output nicely formatted. Is by default false.

false

Boolean

camel.dataformat.jaxb.schema

To validate against an existing schema. Your can use the prefix classpath:, file: or http: to specify how the resource should be resolved. You can separate multiple schema files by using the ',' character.

 

String

camel.dataformat.jaxb.schema-location

To define the location of the schema.

 

String

camel.dataformat.jaxb.schema-severity-level

Sets the schema severity level to use when validating against a schema. This level determines the minimum severity error that triggers JAXB to stop continue parsing. The default value of 0 (warning) means that any error (warning, error or fatal error) will trigger JAXB to stop. There are the following three levels: 0=warning, 1=error, 2=fatal error.

0

Integer

camel.dataformat.jaxb.xml-stream-writer-wrapper

To use a custom xml stream writer.

 

String

Chapter 49. Jasypt

Since Camel 2.5

Jasypt is a simplified encryption library which makes encryption and decryption easy. Camel integrates with Jasypt to allow sensitive information in Properties files to be encrypted. By dropping camel-jasypt on the classpath those encrypted values will automatically be decrypted on-the-fly by Camel. This ensures that human eyes can’t easily spot sensitive information such as usernames and passwords.

49.1. Dependencies

When using camel-jasypt with Red Hat build of Camel Spring Boot, add the following Maven dependency to your pom.xml to have support for auto configuration:

<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-jasypt-starter</artifactId>
</dependency>

49.2. Tooling

The Jasypt component is a runnable JAR that provides a command line utility to encrypt or decrypt values. The usage documentation can be output to the console to describe the syntax and options it provides:

Apache Camel Jasypt takes the following options

 -h or -help = Displays the help screen
 -c or -command <command> = Command either encrypt or decrypt
 -p or -password <password> = Password to use
 -i or -input <input> = Text to encrypt or decrypt
 -a or -algorithm <algorithm> = Optional algorithm to use
 -rsga or -algorithm <algorithm> = Optional random salt generator algorithm to use
 -riga or -algorithm <algorithm> = Optional random iv generator algorithm to use

A simple way of running the tool is with JBang. For example, to encrypt the value tiger, you can use the following parameters. Make sure to specify the version of camel-jasypt that you want to use.

$ jbang org.apache.camel:camel-jasypt:<camel version here> -c encrypt -p secret -i tiger

Which outputs the following result

Encrypted text: qaEEacuW7BUti8LcMgyjKw==

This means the encrypted representation qaEEacuW7BUti8LcMgyjKw== can be decrypted back to tiger if you know the master password which was secret.

If you run the tool again then the encrypted value will return a different result. But decrypting the value will always return the correct original value.

You can test decrypting the value by running the tooling using the following parameters:

$ jbang org.apache.camel:camel-jasypt:<camel version here> -c decrypt -p secret -i qaEEacuW7BUti8LcMgyjKw==

Which outputs the following result:

Decrypted text: tiger

The idea is then to use those encrypted values in your Properties files. For example,

# Encrypted value for 'tiger'
my.secret = ENC(qaEEacuW7BUti8LcMgyjKw==)

49.3. Protecting the master password

The master password used by Jasypt must be provided, so that it’s capable of decrypting the values. However, having this master password out in the open may not be an ideal solution. Therefore, you could for example provide it as a JVM system property or as an OS environment setting. If you decide to do so then the password option supports prefixes that dictates this.

  • sysenv: means to lookup the OS system environment with the given key.
  • sys: means to lookup a JVM system property.

For example, you could provide the password before you start the application

$ export CAMEL_ENCRYPTION_PASSWORD=secret

Then start the application, such as running the start script.

When the application is up and running you can unset the environment

$ unset CAMEL_ENCRYPTION_PASSWORD

On runtimes like Spring Boot and Quarkus, you can configure a password property in the application.properties file as follows.

password=sysenv:CAMEL_ENCRYPTION_PASSWORD

Or if configuring JasyptPropertiesParser manually, you can set the password like this.

jasyptPropertiesParser.setPassword("sysenv:CAMEL_ENCRYPTION_PASSWORD");

49.4. Example with Java DSL

On the Spring Boot and Quarkus runtimes, Camel Jasypt can be configured via configuration properties. Refer to their respective documentation pages for more information.

In Java DSL you need to configure Jasypt as a JasyptPropertiesParser instance and set the properties in the Properties component as shown below:

// create the jasypt properties parser
JasyptPropertiesParser jasypt = new JasyptPropertiesParser();
// set the master password (see above for how to do this in a secure way)
jasypt.setPassword("secret");

// create the properties' component
PropertiesComponent pc = new PropertiesComponent();
pc.setLocation("classpath:org/apache/camel/component/jasypt/secret.properties");
// and use the jasypt properties parser, so we can decrypt values
pc.setPropertiesParser(jasypt);
// end enable nested placeholder support
pc.setNestedPlaceholder(true);

// add properties component to camel context
context.setPropertiesComponent(pc);

It is possible to configure custom algorithms on the JasyptPropertiesParser like this.

JasyptPropertiesParser jasyptPropertiesParser = new JasyptPropertiesParser();

jasyptPropertiesParser.setAlgorithm("PBEWithHmacSHA256AndAES_256");
jasyptPropertiesParser.setRandomSaltGeneratorAlgorithm("PKCS11");
jasyptPropertiesParser.setRandomIvGeneratorAlgorithm("PKCS11");

The properties file secret.properties will contain your encrypted configuration values, such as shown below. Notice how the password value is encrypted and is surrounded like ENC(value here).

my.secret.password=ENC(bsW9uV37gQ0QHFu7KO03Ww==)

49.5. Example with Spring XML

In Spring XML you need to configure the JasyptPropertiesParser which is shown below. Then the Camel Properties component is told to use jasypt as the properties parser, which means Jasypt has its chance to decrypt values looked up in the properties.

<!-- define the jasypt properties parser with the given password to be used -->
<bean id="jasypt" class="org.apache.camel.component.jasypt.JasyptPropertiesParser">
    <property name="password" value="secret"/>
</bean>

<!-- define the camel properties component -->
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
    <!-- the properties file is in the classpath -->
    <property name="location" value="classpath:org/apache/camel/component/jasypt/secret.properties"/>
    <!-- and let it leverage the jasypt parser -->
    <property name="propertiesParser" ref="jasypt"/>
    <!-- end enable nested placeholder -->
    <property name="nestedPlaceholder" value="true"/>
</bean>

The Properties component can also be inlined inside the <camelContext> tag which is shown below. Notice how we use the propertiesParserRef attribute to refer to Jasypt.

<!-- define the jasypt properties parser with the given password to be used -->
<bean id="jasypt" class="org.apache.camel.component.jasypt.JasyptPropertiesParser">
    <!-- password is mandatory, you can prefix it with sysenv: or sys: to indicate it should use
         an OS environment or JVM system property value, so you dont have the master password defined here -->
    <property name="password" value="secret"/>
</bean>

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <!-- define the camel properties placeholder, and let it leverage jasypt -->
    <propertyPlaceholder id="properties"
                         location="classpath:org/apache/camel/component/jasypt/myproperties.properties"
                         nestedPlaceholder="true"
                         propertiesParserRef="jasypt"/>
    <route>
        <from uri="direct:start"/>
        <to uri="{{cool.result}}"/>
    </route>
</camelContext>

49.6. Spring Boot Auto-Configuration

The component supports 8 options, which are listed below.

NameDescriptionDefaultType

camel.component.jasypt.algorithm

The algorithm to be used for decryption.

PBEWithMD5AndDES

String

camel.component.jasypt.enabled

Enable the component.

false

Boolean

camel.component.jasypt.iv-generator-class-name

The initialization vector (IV) generator applied in decryption operations. Default: org.jasypt.iv.

 

String

camel.component.jasypt.password

The master password used by Jasypt for decrypting the values. This option supports prefixes which influence the master password lookup behaviour: sysenv: means to lookup the OS system environment with the given key. sys: means to lookup a JVM system property.

 

String

camel.component.jasypt.provider-name

The class name of the security provider to be used for obtaining the encryption algorithm.

 

String

camel.component.jasypt.random-iv-generator-algorithm

The algorithm for the random iv generator.

SHA1PRNG

String

camel.component.jasypt.random-salt-generator-algorithm

The algorithm for the salt generator.

SHA1PRNG

String

camel.component.jasypt.salt-generator-class-name

The salt generator applied in decryption operations. Default: org.jasypt.salt.RandomSaltGenerator.

org.jasypt.salt.RandomSaltGenerator

String

4.0// ParentAssemblies: assemblies/

Chapter 50. JDBC

Since Camel 1.2

Only producer is supported

The JDBC component enables you to access databases through JDBC, where SQL queries (SELECT) and operations (INSERT, UPDATE, etc) are sent in the message body. This component uses the standard JDBC API.

Note

Prerequisites

This component does not support transactions out of the box. For transactions, we recommend using the Spring JDBC Component instead.

50.1. Dependencies

When using jdbc with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
       <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-jdbc-starter</artifactId>
</dependency>

50.2. URI Format

jdbc:dataSourceName[?options]

50.3. Configuring Options

Camel components are configured on two separate levels:

  • component level
  • endpoint level

50.3.1. Configuring Component Options

The component level is the highest level which holds general and common configurations that are inherited by the endpoints. For example, a component may have security settings, credentials for authentication, URLs for network connection.

Components have pre-configured defaults that are commonly used. hence, you need to configure only a few options on a component or none at all.

Configuring components can be done with the Component DSL, in a configuration file (application.properties|yaml), or directly with Java code.

50.3.2. Configuring Endpoint Options

Endpoints have many options, which allows you to configure what you need the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

Configuring endpoints is done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

When configuring options is to use Property Placeholders, which allows to not hard-code urls, port numbers, sensitive information, and other settings. Placeholders allows to externalize the configuration from your code, and gives more flexibility and reuse.

The following two sections lists all the options, firstly for the component followed by the endpoint.

50.4. Component Options

The JDBC component supports 4 options, which are listed below.

NameDescriptionDefaultType

dataSource (producer)

To use the DataSource instance instead of looking up the data source by name from the registry.

 

DataSource

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (adcanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

connectionStrategy (advanced)

To use a custom strategy for working with connections. Do not use a custom strategy when using the spring-jdbc component because a special Spring ConnectionStrategy is used by default to support Spring Transactions.

 

ConnectionStrategy

50.5. Endpoint Options

The JDBC endpoint is configured using URI syntax:

jdbc:dataSourceName

with the following path and query parameter:

50.5.1. Path Parameter (1 parameter)

NameDescriptionDefaultType

dataSourceName (producer)

Required Name of DataSource to lookup in the Registry. If the name is dataSource or default, then Camel will attempt to lookup a default DataSource from the registry, meaning if there is a only one instance of DataSource found, then this DataSource will be used.

 

String

50.5.2. Query Parameters (14 parameters)

NameDescriptionDefaultType

allowNamedParameters (producer)

Whether to allow using named parameters in the queries.

True

Boolean

outputClass (producer)

Specify the full package and class name to use as conversion when outputType=SelectOne or SelectList.

 

String

outputType (producer)

Determines the output the producer should use. Enum values:

  • SelectOne
  • SelectList
  • StreamList

SelectList

JdbcOutputType

parameters (producer)

Optional parameters to the java.sql.Statement. For example to set maxRows, fetchSize etc.

 

Map

readSize (producer)

The default maximum number of rows that can be read by a polling query. The default value is 0.

 

int

resetAutoCommit (producer)

Camel will set the autoCommit on the JDBC connection to be false, commit the change after executed the statement and reset the autoCommit flag of the connection at the end, if the resetAutoCommit is true. If the JDBC connection doesn’t support to reset the autoCommit flag, you can set the resetAutoCommit flag to be false, and Camel will not try to reset the autoCommit flag. When used with XA transactions you most likely need to set it to false so that the transaction manager is in charge of committing this tx.

True

Boolean

transacted (producer)

Whether transactions are in use.

False

Boolean

useGetBytesForBlob (producer)

To read BLOB columns as bytes instead of string data. This may be needed for certain databases such as Oracle where you must read BLOB columns as bytes.

False

Boolean

useHeadersAsParameters (producer)

Set this option to true to use the prepareStatementStrategy with named parameters. This allows to define queries with named placeholders, and use headers with the dynamic values for the query placeholders.

False

Boolean

useJDBC4ColumnNameAndLabelSemantics (producer)

Sets whether to use JDBC 4 or JDBC 3.0 or older semantic when retrieving column name. JDBC 4.0 uses columnLabel to get the column name where as JDBC 3.0 uses both columnName or columnLabel. Unfortunately JDBC drivers behave differently so you can use this option to work out issues around your JDBC driver if you get problem using this component This option is default true.

True

Boolean

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

False

Boolean

beanRowMapper (advanced)

To use a custom org.apache.camel.component.jdbc.BeanRowMapper when using outputClass. The default implementation will lower case the row names and skip underscores, and dashes. For example CUST_ID is mapped as custId.

 

BeanRowMapper

connectionStrategy (advanced)

To use a custom strategy for working with connections. Do not use a custom strategy when using the spring-jdbc component because a special Spring ConnectionStrategy is used by default to support Spring Transactions.

 

ConnectionStrategy

prepareStatementStrategy (advanced)

Allows the plugin to use a custom org.apache.camel.component.jdbc.JdbcPrepareStatementStrategy to control preparation of the query and prepared statement.

 

JdbcPrepareStatementStrategy

50.6. Message Headers

The JBBC component supports 8 message header(s), which is/are listed below:

NameDescriptionDefaultType

CamelJdbcUpdateCount (producer)

Constant: JDBC_UPDATE_COUNT

If the query is an UPDATE, query the update count is returned in this OUT header.

 

int

CamelJdbcRowCount (producer)

Constant: JDBC_ROW_COUNT

If the query is a SELECT, query the row count is returned in this OUT header.

 

int

CamelJdbcColumnNames (producer)

Constant: JDBC_COLUMN_NAMES

The column names from the ResultSet as a java.util.Set type.

 

Set

CamelJdbcParameters (producer)

Constant: JDBC_PARAMETERS

A java.util.Map which has the headers to be used if useHeadersAsParameters has been enabled.

 

Map

CamelRetrieveGeneratedKeys (producer)

Constant: JDBC_RETRIEVE_GENERATED_KEYS

Set its value to true to retrieve generated keys.

False

Boolean

CamelGeneratedColumns (producer)

Constant: JDBC_GENERATED_COLUMNS

Set it to specify the expected generated columns.

 

String[] or int[]

CamelGeneratedKeysRowCount (producer)

Constant: JDBC_GENERATED_KEYS_ROW_COUNT

The number of rows in the header that contains generated keys.

 

int

CamelGeneratedKeysRows (producer)

Constant: JDBC_GENERATED_KEYS_DATA

Rows that contains the generated keys.

 

List

50.7. Result

By default the result is returned in the OUT body as an ArrayList<HashMap<String, Object>>. The List object contains the list of rows and the Map objects contain each row with the String key as the column name. You can use the option outputType to control the result.

Note

This component fetches ResultSetMetaData to be able to return the column name as the key in the Map.

50.8. Generated Keys

If you insert data using SQL INSERT, then the RDBMS may support auto generated keys. You can instruct the JDBC producer to return the generated keys in headers. To do that set the header CamelRetrieveGeneratedKeys=true. Then the generated keys will be provided as headers with the keys listed in the table above.

Note

Using generated keys does not work together with named parameters.

50.9. Using named parameters

In the given route below, we want to get all the projects from the projects table. Notice the SQL query has 2 named parameters, :?lic and :?min. Camel will then lookup these parameters from the message headers. Notice in the example above we set two headers with constant value for the named parameters:

  from("direct:projects")
     .setHeader(":?lic", constant("ASF"))
     .setHeader(":?min", constant(123))
     .setBody(simple("select * from projects where license = :?lic and id > :?min order by id"))
     .to("jdbc:myDataSource?useHeadersAsParameters=true")

You can also store the header values in a java.util.Map and store the map on the headers with the key CamelJdbcParameters.

50.10. Samples

In the following example, we setup the DataSource that camel-jdbc requires. First we register our datasource in the Camel registry as testdb:

EmbeddedDatabase db = new EmbeddedDatabaseBuilder()
      .setType(EmbeddedDatabaseType.DERBY).addScript("sql/init.sql").build();

CamelContext context = ...
context.getRegistry().bind("testdb", db);

Then we configure a route that routes to the JDBC component, so the SQL will be executed. Note how we refer to the testdb datasource that was bound in the previous step:

from("direct:hello")
    .to("jdbc:testdb");

We create an endpoint, add the SQL query to the body of the IN message, and then send the exchange. The result of the query is returned in the OUT body:

Endpoint endpoint = context.getEndpoint("direct:hello");
Exchange exchange = endpoint.createExchange();
// then we set the SQL on the in body
exchange.getMessage().setBody("select * from customer order by ID");
// now we send the exchange to the endpoint, and receives the response from Camel
Exchange out = template.send(endpoint, exchange);

If you want to work on the rows one by one instead of the entire ResultSet at once you need to use the Splitter EIP such as:

from("direct:hello")
// here we split the data from the testdb into new messages one by one
// so the mock endpoint will receive a message per row in the table
// the StreamList option allows to stream the result of the query without creating a List of rows
// and notice we also enable streaming mode on the splitter
.to("jdbc:testdb?outputType=StreamList")
  .split(body()).streaming()
  .to("mock:result");

50.11. Sample - Polling the database every minute

If we want to poll a database using the JDBC component, we need to combine it with a polling scheduler such as the Timer or Quartz etc. In the following example, we retrieve data from the database every 60 seconds:

from("timer://foo?period=60000")
  .setBody(constant("select * from customer"))
  .to("jdbc:testdb")
  .to("activemq:queue:customers");

50.12. Sample - Move data between data sources

A common use case is to query for data, process it and move it to another data source (ETL operations). In the following example, we retrieve new customer records from the source table every hour, filter/transform them and move them to a destination table:

from("timer://MoveNewCustomersEveryHour?period=3600000")
    .setBody(constant("select * from customer where create_time > (sysdate-1/24)"))
    .to("jdbc:testdb")
    .split(body())
        .process(new MyCustomerProcessor()) //filter/transform results as needed
        .setBody(simple("insert into processed_customer values('${body[ID]}','${body[NAME]}')"))
        .to("jdbc:testdb");

50.13. Spring Boot Auto-Configuration

The component supports 4 options, which are listed below.

NameDescriptionDefaultType

camel.component.jdbc.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatically configure JDBC data sources, JMS connection factories, AWS Clients, etc.

True

Boolean

camel.component.jdbc.connection-strategy

To use a custom strategy for working with connections. Do not use a custom strategy when using the spring-jdbc component because a special Spring ConnectionStrategy is used by default to support Spring Transactions. The option is a org.apache.camel.component.jdbc.ConnectionStrategy type.

 

ConnectionStrategy

camel.component.jdbc.enabled

Whether to enable auto configuration of the jdbc component. This is enabled by default.

 

Boolean

camel.component.jdbc.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

False

Boolean

Chapter 51. Jira

Both producer and consumer are supported

The JIRA component interacts with the JIRA API by encapsulating Atlassian’s REST Java Client for JIRA. It currently provides polling for new issues and new comments. It is also able to create new issues, add comments, change issues, add/remove watchers, add attachment and transition the state of an issue.

Rather than webhooks, this endpoint relies on simple polling. Reasons include:

  • Concern for reliability/stability
  • The types of payloads we’re polling aren’t typically large (plus, paging is available in the API)
  • The need to support apps running somewhere not publicly accessible where a webhook would fail

Note that the JIRA API is fairly expansive. Therefore, this component could be easily expanded to provide additional interactions.

51.1. Dependencies

When using jira with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-jira-starter</artifactId>
</dependency>

51.2. URI format

jira://type[?options]

The Jira type accepts the following operations:

For consumers:

  • newIssues: retrieve only new issues after the route is started
  • newComments: retrieve only new comments after the route is started
  • watchUpdates: retrieve only updated fields/issues based on provided jql

For producers:

  • addIssue: add an issue
  • addComment: add a comment on a given issue
  • attach: add an attachment on a given issue
  • deleteIssue: delete a given issue
  • updateIssue: update fields of a given issue
  • transitionIssue: transition a status of a given issue
  • watchers: add/remove watchers of a given issue

As Jira is fully customizable, you must assure the fields IDs exists for the project and workflow, as they can change between different Jira servers.

51.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

51.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

51.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

51.4. Component Options

The Jira component supports 12 options, which are listed below.

NameDescriptionDefaultType

delay (common)

Time in milliseconds to elapse for the next poll.

6000

Integer

jiraUrl (common)

Required The Jira server url, example: .

 

String

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

configuration (advanced)

To use a shared base jira configuration.

 

JiraConfiguration

accessToken (security)

(OAuth only) The access token generated by the Jira server.

 

String

consumerKey (security)

(OAuth only) The consumer key from Jira settings.

 

String

password (security)

(Basic authentication only) The password to authenticate to the Jira server. Use only if username basic authentication is used.

 

String

privateKey (security)

(OAuth only) The private key generated by the client to encrypt the conversation to the server.

 

String

username (security)

(Basic authentication only) The username to authenticate to the Jira server. Use only if OAuth is not enabled on the Jira server. Do not set the username and OAuth token parameter, if they are both set, the username basic authentication takes precedence.

 

String

verificationCode (security)

(OAuth only) The verification code from Jira generated in the first step of the authorization proccess.

 

String

51.5. Endpoint Options

The Jira endpoint is configured using URI syntax:

jira:type

with the following path and query parameters:

51.5.1. Path Parameters (1 parameters)

NameDescriptionDefaultType

type (common)

Required Operation to perform. Consumers: NewIssues, NewComments. Producers: AddIssue, AttachFile, DeleteIssue, TransitionIssue, UpdateIssue, Watchers. See this class javadoc description for more information.

Enum values:

  • ADDCOMMENT
  • ADDISSUE
  • ATTACH
  • DELETEISSUE
  • NEWISSUES
  • NEWCOMMENTS
  • WATCHUPDATES
  • UPDATEISSUE
  • TRANSITIONISSUE
  • WATCHERS
  • ADDISSUELINK
  • ADDWORKLOG
  • FETCHISSUE
  • FETCHCOMMENTS
 

JiraType

51.5.2. Query Parameters (16 parameters)

NameDescriptionDefaultType

delay (common)

Time in milliseconds to elapse for the next poll.

6000

Integer

jiraUrl (common)

Required The Jira server url, example: .

 

String

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

jql (consumer)

JQL is the query language from JIRA which allows you to retrieve the data you want. For example jql=project=MyProject Where MyProject is the product key in Jira. It is important to use the RAW() and set the JQL inside it to prevent camel parsing it, example: RAW(project in (MYP, COM) AND resolution = Unresolved).

 

String

maxResults (consumer)

Max number of issues to search for.

50

Integer

sendOnlyUpdatedField (consumer)

Indicator for sending only changed fields in exchange body or issue object. By default consumer sends only changed fields.

true

boolean

watchedFields (consumer)

Comma separated list of fields to watch for changes. Status,Priority are the defaults.

Status,Priority

String

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

accessToken (security)

(OAuth only) The access token generated by the Jira server.

 

String

consumerKey (security)

(OAuth only) The consumer key from Jira settings.

 

String

password (security)

(Basic authentication only) The password to authenticate to the Jira server. Use only if username basic authentication is used.

 

String

privateKey (security)

(OAuth only) The private key generated by the client to encrypt the conversation to the server.

 

String

username (security)

(Basic authentication only) The username to authenticate to the Jira server. Use only if OAuth is not enabled on the Jira server. Do not set the username and OAuth token parameter, if they are both set, the username basic authentication takes precedence.

 

String

verificationCode (security)

(OAuth only) The verification code from Jira generated in the first step of the authorization proccess.

 

String

51.6. Client Factory

You can bind the JiraRestClientFactory with name JiraRestClientFactory in the registry to have it automatically set in the Jira endpoint.

51.7. Authentication

Camel-jira supports Basic Authentication and OAuth 3 legged authentication.

We recommend to use OAuth whenever possible, as it provides the best security for your users and system.

51.7.1. Basic authentication requirements:

  • An username and password

51.7.2. OAuth authentication requirements:

Follow the tutorial in Jira OAuth documentation to generate the client private key, consumer key, verification code and access token.

  • a private key, generated locally on your system.
  • A verification code, generated by Jira server.
  • The consumer key, set in the Jira server settings.
  • An access token, generated by Jira server.

51.8. JQL

The JQL URI option is used by both consumer endpoints. Theoretically, items like "project key", etc. could be URI options themselves. However, by requiring the use of JQL, the consumers become much more flexible and powerful.

At the bare minimum, the consumers will require the following:

jira://[type]?[required options]&jql=project=[project key]

One important thing to note is that the newIssues consumer will automatically set the JQL as:

  • append ORDER BY key desc to your JQL
  • prepend id > latestIssueId to retrieve issues added after the camel route was started.

This is in order to optimize startup processing, rather than having to index every single issue in the project.

Another note is that, similarly, the newComments consumer will have to index every single issue and comment in the project. Therefore, for large projects, it’s vital to optimize the JQL expression as much as possible. For example, the JIRA Toolkit Plugin includes a "Number of comments" custom field — use '"Number of comments" > 0' in your query. Also try to minimize based on state (status=Open), increase the polling delay, etc. Example:

jira://[type]?[required options]&jql=RAW(project=[project key] AND status in (Open, \"Coding In Progress\") AND \"Number of comments\">0)"

51.9. Operations

See a list of required headers to set when using the Jira operations. The author field for the producers is automatically set to the authenticated user in the Jira side.

If any required field is not set, then an IllegalArgumentException is throw.

There are operations that requires id for fields suchs as: issue type, priority, transition. Check the valid id on your jira project as they may differ on a jira installation and project workflow.

51.10. AddIssue

Required:

Optional:

  • IssueAssignee: the assignee user
  • IssuePriorityId or IssuePriorityName: The priority of the issue, you can see the valid list in http://jira_server/rest/api/2/priority.
  • IssueComponents: A list of string with the valid component names.
  • IssueWatchersAdd: A list of strings with the usernames to add to the watcher list.
  • IssueDescription: The description of the issue.

51.11. AddComment

Required:

  • IssueKey: The issue key identifier.
  • body of the exchange is the description.

51.12. Attach

Only one file should attach per invocation.

Required:

  • IssueKey: The issue key identifier.
  • body of the exchange should be of type File

51.13. DeleteIssue

Required:

  • IssueKey: The issue key identifier.

51.14. TransitionIssue

Required:

  • IssueKey: The issue key identifier.
  • IssueTransitionId: The issue transition id.
  • body of the exchange is the description.

51.15. UpdateIssue

  • IssueKey: The issue key identifier.
  • IssueTypeId or IssueTypeName: The id of the issue type or the name of the issue type, you can see the valid list in http://jira_server/rest/api/2/issue/createmeta?projectKeys=SAMPLE_KEY.
  • IssueSummary: The summary of the issue.
  • IssueAssignee: the assignee user
  • IssuePriorityId or IssuePriorityName: The priority of the issue, you can see the valid list in http://jira_server/rest/api/2/priority.
  • IssueComponents: A list of string with the valid component names.
  • IssueDescription: The description of the issue.

51.16. Watcher

  • IssueKey: The issue key identifier.
  • IssueWatchersAdd: A list of strings with the usernames to add to the watcher list.
  • IssueWatchersRemove: A list of strings with the usernames to remove from the watcher list.

51.17. WatchUpdates (consumer)

  • watchedFields Comma separated list of fields to watch for changes i.e Status,Priority,Assignee,Components etc.
  • sendOnlyUpdatedField By default only changed field is send as the body.

All messages also contain following headers that add additional info about the change:

  • issueKey: Key of the updated issue
  • changed: name of the updated field (i.e Status)
  • watchedIssues: list of all issue keys that are watched in the time of update

51.18. Spring Boot Auto-Configuration

The component supports 13 options, which are listed below.

NameDescriptionDefaultType

camel.component.jira.access-token

(OAuth only) The access token generated by the Jira server.

 

String

camel.component.jira.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.jira.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.jira.configuration

To use a shared base jira configuration. The option is a org.apache.camel.component.jira.JiraConfiguration type.

 

JiraConfiguration

camel.component.jira.consumer-key

(OAuth only) The consumer key from Jira settings.

 

String

camel.component.jira.delay

Time in milliseconds to elapse for the next poll.

6000

Integer

camel.component.jira.enabled

Whether to enable auto configuration of the jira component. This is enabled by default.

 

Boolean

camel.component.jira.jira-url

The Jira server url, example: http://my_jira.com:8081/.

 

String

camel.component.jira.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.jira.password

(Basic authentication only) The password to authenticate to the Jira server. Use only if username basic authentication is used.

 

String

camel.component.jira.private-key

(OAuth only) The private key generated by the client to encrypt the conversation to the server.

 

String

camel.component.jira.username

(Basic authentication only) The username to authenticate to the Jira server. Use only if OAuth is not enabled on the Jira server. Do not set the username and OAuth token parameter, if they are both set, the username basic authentication takes precedence.

 

String

camel.component.jira.verification-code

(OAuth only) The verification code from Jira generated in the first step of the authorization proccess.

 

String

Chapter 52. JMS

Both producer and consumer are supported

This component allows messages to be sent to (or consumed from) a JMS Queue or Topic. It uses Spring’s JMS support for declarative transactions, including Spring’s JmsTemplate for sending and a MessageListenerContainer for consuming.

52.1. Dependencies

When using jms with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-jms-starter</artifactId>
</dependency>
Note

Using ActiveMQ
If you are using Apache ActiveMQ, you should prefer the ActiveMQ component as it has been optimized for ActiveMQ. All of the options and samples on this page are also valid for the ActiveMQ component.

Note

Transacted and caching
See section Transactions and Cache Levels below if you are using transactions with JMS as it can impact performance.

Note

Request/Reply over JMS
Make sure to read the section Request/reply over JMS further below on this page for important notes about request/reply, as Camel offers a number of options to configure for performance, and clustered environments.

52.2. URI format

jms:[queue:|topic:]destinationName[?options]

Where destinationName is a JMS queue or topic name. By default, the destinationName is interpreted as a queue name. For example, to connect to the queue, FOO.BAR use:

jms:FOO.BAR

You can include the optional queue: prefix, if you prefer:

jms:queue:FOO.BAR

To connect to a topic, you must include the topic: prefix. For example, to connect to the topic, Stocks.Prices, use:

jms:topic:Stocks.Prices

You append query options to the URI by using the following format,

?option=value&option=value&…​

52.2.1. Using ActiveMQ

The JMS component reuses Spring 2’s JmsTemplate for sending messages. This is not ideal for use in a non-J2EE container and typically requires some caching in the JMS provider to avoid poor performance .

If you intend to use Apache ActiveMQ as your message broker, the recommendation is that you do one of the following:

  • Use the ActiveMQ component, which is already optimized to use ActiveMQ efficiently
  • Use the PoolingConnectionFactory in ActiveMQ.

52.2.2. Transactions and Cache Levels

If you are consuming messages and using transactions (transacted=true) then the default settings for cache level can impact performance.

If you are using XA transactions then you cannot cache as it can cause the XA transaction to not work properly.

If you are not using XA, then you should consider caching as it speeds up performance, such as setting cacheLevelName=CACHE_CONSUMER.

The default setting for cacheLevelName is CACHE_AUTO. This default auto detects the mode and sets the cache level accordingly to:

  • CACHE_CONSUMER if transacted=false
  • CACHE_NONE if transacted=true

So you can say the default setting is conservative. Consider using cacheLevelName=CACHE_CONSUMER if you are using non-XA transactions.

52.2.3. Durable Subscriptions with JMS 1.1

If you wish to use durable topic subscriptions, you need to specify both clientId and durableSubscriptionName. The value of the clientId must be unique and can only be used by a single JMS connection instance in your entire network.

Note

If you are using the Apache ActiveMQ Classic, you may prefer to use a feature called Virtual Topic. This should remove the necessity of having a unique clientId. You can consult the specific documentation for Artemis or for ActiveMQ Classic for details about how to leverage this feature. You can find more details about durable messaging for ActiveMQ Classic here.

52.2.3.1. Durable Subscriptions with JMS 2.0

If you wish to use durable topic subscriptions, you need to specify the durableSubscriptionName.

52.2.4. Message Header Mapping

When using message headers, the JMS specification states that header names must be valid Java identifiers. So try to name your headers to be valid Java identifiers. One benefit of doing this is that you can then use your headers inside a JMS Selector (whose SQL92 syntax mandates Java identifier syntax for headers).

A simple strategy for mapping header names is used by default. The strategy is to replace any dots and hyphens in the header name as shown below and to reverse the replacement when the header name is restored from a JMS message sent over the wire. What does this mean? No more losing method names to invoke on a bean component, no more losing the filename header for the File Component, and so on.

The current header name strategy for accepting header names in Camel is as follows:

  • Dots are replaced by `DOT` and the replacement is reversed when Camel consume the message
  • Hyphen is replaced by `HYPHEN` and the replacement is reversed when Camel consumes the message

You can configure many different properties on the JMS endpoint, which map to properties on the JMSConfiguration object.

Note

Mapping to Spring JMS
Many of these properties map to properties on Spring JMS, which Camel uses for sending and receiving messages. So you can get more information about these properties by consulting the relevant Spring documentation.

52.3. Configuring Options

Camel components are configured on two levels:

  • Component level
  • Endpoint level

52.3.1. Component Level Options

The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on.

Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all.

You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code.

52.3.2. Endpoint Level Options

At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both.

You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java.

When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings.

Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code.

52.4. Component Options

The JMS component supports 98 options, which are listed below.

NameDescriptionDefaultType

clientId (common)

Sets the JMS client ID to use. Note that this value, if specified, must be unique and can only be used by a single JMS connection instance. The clientId option is compulsory with JMS 1.1 durable topic subscriptions, because the client ID is used to control which client messages have to be stored for. With JMS 2.0 clients, clientId may be omitted, which creates a 'global' subscription. If using Apache ActiveMQ you may prefer to use Virtual Topics instead.

 

String

connectionFactory (common)

The connection factory to be use. A connection factory must be configured either on the component or endpoint.

 

ConnectionFactory

disableReplyTo (common)

Specifies whether Camel ignores the JMSReplyTo header in messages. If true, Camel does not send a reply back to the destination specified in the JMSReplyTo header. You can use this option if you want Camel to consume from a route and you do not want Camel to automatically send back a reply message because another component in your code handles the reply message. You can also use this option if you want to use Camel as a proxy between different message brokers and you want to route message from one system to another.

false

boolean

durableSubscriptionName (common)

The durable subscriber name for specifying durable topic subscriptions. The clientId option must be configured for a JMS 1.1 durable subscription, and may be configured for JMS 2.0, to create a private durable subscription.

 

String

jmsMessageType (common)

Allows you to force the use of a specific javax.jms.Message implementation for sending JMS messages. Possible values are: Bytes, Map, Object, Stream, Text. By default, Camel would determine which JMS message type to use from the In body type. This option allows you to specify it.

Enum values:

  • Bytes
  • Map
  • Object
  • Stream
  • Text
 

JmsMessageType

replyTo (common)

Provides an explicit ReplyTo destination (overrides any incoming value of Message.getJMSReplyTo() in consumer).

 

String

testConnectionOnStartup (common)

Specifies whether to test the connection on startup. This ensures that when Camel starts that all the JMS consumers have a valid connection to the JMS broker. If a connection cannot be granted then Camel throws an exception on startup. This ensures that Camel is not started with failed connections. The JMS producers is tested as well.

false

boolean

acknowledgementModeName (consumer)

The JMS acknowledgement name, which is one of: SESSION_TRANSACTED, CLIENT_ACKNOWLEDGE, AUTO_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE.

Enum values:

  • SESSION_TRANSACTED
  • CLIENT_ACKNOWLEDGE
  • AUTO_ACKNOWLEDGE
  • DUPS_OK_ACKNOWLEDGE

AUTO_ACKNOWLEDGE

String

artemisConsumerPriority (consumer)

Consumer priorities allow you to ensure that high priority consumers receive messages while they are active. Normally, active consumers connected to a queue receive messages from it in a round-robin fashion. When consumer priorities are in use, messages are delivered round-robin if multiple active consumers exist with the same high priority. Messages will only going to lower priority consumers when the high priority consumers do not have credit available to consume the message, or those high priority consumers have declined to accept the message (for instance because it does not meet the criteria of any selectors associated with the consumer).

 

int

asyncConsumer (consumer)

Whether the JmsConsumer processes the Exchange asynchronously. If enabled then the JmsConsumer may pickup the next message from the JMS queue, while the previous message is being processed asynchronously (by the Asynchronous Routing Engine). This means that messages may be processed not 100% strictly in order. If disabled (as default) then the Exchange is fully processed before the JmsConsumer picks up the next message from the JMS queue. Note if transacted has been enabled, then asyncConsumer=true does not run asynchronously, as transaction must be executed synchronously (Camel 3.0 may support async transactions).

false

boolean

autoStartup (consumer)

Specifies whether the consumer container should auto-startup.

true

boolean

cacheLevel (consumer)

Sets the cache level by ID for the underlying JMS resources. See cacheLevelName option for more details.

 

int

cacheLevelName (consumer)

Sets the cache level by name for the underlying JMS resources. Possible values are: CACHE_AUTO, CACHE_CONNECTION, CACHE_CONSUMER, CACHE_NONE, and CACHE_SESSION. The default setting is CACHE_AUTO. See the Spring documentation and Transactions Cache Levels for more information.

Enum values:

  • CACHE_AUTO
  • CACHE_CONNECTION
  • CACHE_CONSUMER
  • CACHE_NONE
  • CACHE_SESSION

CACHE_AUTO

String

concurrentConsumers (consumer)

Specifies the default number of concurrent consumers when consuming from JMS (not for request/reply over JMS). See also the maxMessagesPerTask option to control dynamic scaling up/down of threads. When doing request/reply over JMS then the option replyToConcurrentConsumers is used to control number of concurrent consumers on the reply message listener.

1

int

maxConcurrentConsumers (consumer)

Specifies the maximum number of concurrent consumers when consuming from JMS (not for request/reply over JMS). See also the maxMessagesPerTask option to control dynamic scaling up/down of threads. When doing request/reply over JMS then the option replyToMaxConcurrentConsumers is used to control number of concurrent consumers on the reply message listener.

 

int

replyToDeliveryPersistent (consumer)

Specifies whether to use persistent delivery by default for replies.

true

boolean

selector (consumer)

Sets the JMS selector to use.

 

String

subscriptionDurable (consumer)

Set whether to make the subscription durable. The durable subscription name to be used can be specified through the subscriptionName property. Default is false. Set this to true to register a durable subscription, typically in combination with a subscriptionName value (unless your message listener class name is good enough as subscription name). Only makes sense when listening to a topic (pub-sub domain), therefore this method switches the pubSubDomain flag as well.

false

boolean

subscriptionName (consumer)

Set the name of a subscription to create. To be applied in case of a topic (pub-sub domain) with a shared or durable subscription. The subscription name needs to be unique within this client’s JMS client id, if the client ID is configured. Default is the class name of the specified message listener. Note: Only 1 concurrent consumer (which is the default of this message listener container) is allowed for each subscription, except for a shared subscription (which requires JMS 2.0).

 

String

subscriptionShared (consumer)

Set whether to make the subscription shared. The shared subscription name to be used can be specified through the subscriptionName property. Default is false. Set this to true to register a shared subscription, typically in combination with a subscriptionName value (unless your message listener class name is good enough as subscription name). Note that shared subscriptions may also be durable, so this flag can (and often will) be combined with subscriptionDurable as well. Only makes sense when listening to a topic (pub-sub domain), therefore this method switches the pubSubDomain flag as well. Requires a JMS 2.0 compatible message broker.

false

boolean

acceptMessagesWhileStopping (consumer (advanced))

Specifies whether the consumer accept messages while it is stopping. You may consider enabling this option, if you start and stop JMS routes at runtime, while there are still messages enqueued on the queue. If this option is false, and you stop the JMS route, then messages may be rejected, and the JMS broker would have to attempt redeliveries, which yet again may be rejected, and eventually the message may be moved at a dead letter queue on the JMS broker. To avoid this its recommended to enable this option.

false

boolean

allowReplyManagerQuickStop (consumer (advanced))

Whether the DefaultMessageListenerContainer used in the reply managers for request/reply messaging allow the DefaultMessageListenerContainer.runningAllowed flag to quick stop in case JmsConfiguration#isAcceptMessagesWhileStopping is enabled, and org.apache.camel.CamelContext is currently being stopped. This quick stop ability is enabled by default in the regular JMS consumers but to enable for reply managers you must enable this flag.

false

boolean

consumerType (consumer (advanced))

The consumer type to use, which can be one of: Simple, Default, or Custom. The consumer type determines which Spring JMS listener to use. Default will use org.springframework.jms.listener.DefaultMessageListenerContainer, Simple will use org.springframework.jms.listener.SimpleMessageListenerContainer. When Custom is specified, the MessageListenerContainerFactory defined by the messageListenerContainerFactory option will determine what org.springframework.jms.listener.AbstractMessageListenerContainer to use.

Enum values:

  • Simple
  • Default
  • Custom

Default

ConsumerType

defaultTaskExecutorType (consumer (advanced))

Specifies what default TaskExecutor type to use in the DefaultMessageListenerContainer, for both consumer endpoints and the ReplyTo consumer of producer endpoints. Possible values: SimpleAsync (uses Spring’s SimpleAsyncTaskExecutor) or ThreadPool (uses Spring’s ThreadPoolTaskExecutor with optimal values - cached threadpool-like). If not set, it defaults to the previous behaviour, which uses a cached thread pool for consumer endpoints and SimpleAsync for reply consumers. The use of ThreadPool is recommended to reduce thread trash in elastic configurations with dynamically increasing and decreasing concurrent consumers.

Enum values:

  • ThreadPool
  • SimpleAsync
 

DefaultTaskExecutorType

eagerLoadingOfProperties (consumer (advanced))

Enables eager loading of JMS properties and payload as soon as a message is loaded which generally is inefficient as the JMS properties may not be required but sometimes can catch early any issues with the underlying JMS provider and the use of JMS properties. See also the option eagerPoisonBody.

false

boolean

eagerPoisonBody (consumer (advanced))

If eagerLoadingOfProperties is enabled and the JMS message payload (JMS body or JMS properties) is poison (cannot be read/mapped), then set this text as the message body instead so the message can be processed (the cause of the poison are already stored as exception on the Exchange). This can be turned off by setting eagerPoisonBody=false. See also the option eagerLoadingOfProperties.

Poison JMS message due to $\{exception.message}

String

exposeListenerSession (consumer (advanced))

Specifies whether the listener session should be exposed when consuming messages.

false

boolean

replyToSameDestinationAllowed (consumer (advanced))

Whether a JMS consumer is allowed to send a reply message to the same destination that the consumer is using to consume from. This prevents an endless loop by consuming and sending back the same message to itself.

false

boolean

taskExecutor (consumer (advanced))

Allows you to specify a custom task executor for consuming messages.

 

TaskExecutor

deliveryDelay (producer)

Sets delivery delay to use for send calls for JMS. This option requires JMS 2.0 compliant broker.

-1

long

deliveryMode (producer)

Specifies the delivery mode to be used. Possible values are those defined by javax.jms.DeliveryMode. NON_PERSISTENT = 1 and PERSISTENT = 2.

Enum values:

  • 1
  • 2
 

Integer

deliveryPersistent (producer)

Specifies whether persistent delivery is used by default.

true

boolean

explicitQosEnabled (producer)

Set if the deliveryMode, priority or timeToLive qualities of service should be used when sending messages. This option is based on Spring’s JmsTemplate. The deliveryMode, priority and timeToLive options are applied to the current endpoint. This contrasts with the preserveMessageQos option, which operates at message granularity, reading QoS properties exclusively from the Camel In message headers.

false

Boolean

formatDateHeadersToIso8601 (producer)

Sets whether JMS date properties should be formatted according to the ISO 8601 standard.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

preserveMessageQos (producer)

Set to true, if you want to send message using the QoS settings specified on the message, instead of the QoS settings on the JMS endpoint. The following three headers are considered JMSPriority, JMSDeliveryMode, and JMSExpiration. You can provide all or only some of them. If not provided, Camel will fall back to use the values from the endpoint instead. So, when using this option, the headers override the values from the endpoint. The explicitQosEnabled option, by contrast, will only use options set on the endpoint, and not values from the message header.

false

boolean

priority (producer)

Values greater than 1 specify the message priority when sending (where 1 is the lowest priority and 9 is the highest). The explicitQosEnabled option must also be enabled in order for this option to have any effect.

Enum values:

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

4

int

replyToConcurrentConsumers (producer)

Specifies the default number of concurrent consumers when doing request/reply over JMS. See also the maxMessagesPerTask option to control dynamic scaling up/down of threads.

1

int

replyToMaxConcurrentConsumers (producer)

Specifies the maximum number of concurrent consumers when using request/reply over JMS. See also the maxMessagesPerTask option to control dynamic scaling up/down of threads.

 

int

replyToOnTimeoutMaxConcurrentConsumers (producer)

Specifies the maximum number of concurrent consumers for continue routing when timeout occurred when using request/reply over JMS.

1

int

replyToOverride (producer)

Provides an explicit ReplyTo destination in the JMS message, which overrides the setting of replyTo. It is useful if you want to forward the message to a remote Queue and receive the reply message from the ReplyTo destination.

 

String

replyToType (producer)

Allows for explicitly specifying which kind of strategy to use for replyTo queues when doing request/reply over JMS. Possible values are: Temporary, Shared, or Exclusive. By default Camel will use temporary queues. However if replyTo has been configured, then Shared is used by default. This option allows you to use exclusive queues instead of shared ones. See Camel JMS documentation for more details, and especially the notes about the implications if running in a clustered environment, and the fact that Shared reply queues has lower performance than its alternatives Temporary and Exclusive.

Enum values:

  • Temporary
  • Shared
  • Exclusive
 

ReplyToType

requestTimeout (producer)

The timeout for waiting for a reply when using the InOut Exchange Pattern (in milliseconds). The default is 20 seconds. You can include the header CamelJmsRequestTimeout to override this endpoint configured timeout value, and thus have per message individual timeout values. See also the requestTimeoutCheckerInterval option.

20000

long

timeToLive (producer)

When sending messages, specifies the time-to-live of the message (in milliseconds).

-1

long

allowAdditionalHeaders (producer (advanced))

This option is used to allow additional headers which may have values that are invalid according to JMS specification. For example some message systems such as WMQ do this with header names using prefix JMS_IBM_MQMD_ containing values with byte array or other invalid types. You can specify multiple header names separated by comma, and use as suffix for wildcard matching.

 

String

allowNullBody (producer (advanced))

Whether to allow sending messages with no body. If this option is false and the message body is null, then an JMSException is thrown.

true

boolean

alwaysCopyMessage (producer (advanced))

If true, Camel will always make a JMS message copy of the message when it is passed to the producer for sending. Copying the message is needed in some situations, such as when a replyToDestinationSelectorName is set (incidentally, Camel will set the alwaysCopyMessage option to true, if a replyToDestinationSelectorName is set).

false

boolean

correlationProperty (producer (advanced))

When using InOut exchange pattern use this JMS property instead of JMSCorrelationID JMS property to correlate messages. If set messages will be correlated solely on the value of this property JMSCorrelationID property will be ignored and not set by Camel.

 

String

disableTimeToLive (producer (advanced))

Use this option to force disabling time to live. For example when you do request/reply over JMS, then Camel will by default use the requestTimeout value as time to live on the message being sent. The problem is that the sender and receiver systems have to have their clocks synchronized, so they are in sync. This is not always so easy to archive. So you can use disableTimeToLive=true to not set a time to live value on the sent message. Then the message will not expire on the receiver system. See below in section About time to live for more details.

false

boolean

forceSendOriginalMessage (producer (advanced))

When using mapJmsMessage=false Camel will create a new JMS message to send to a new JMS destination if you touch the headers (get or set) during the route. Set this option to true to force Camel to send the original JMS message that was received.

false

boolean

includeSentJMSMessageID (producer (advanced))

Only applicable when sending to JMS destination using InOnly (eg fire and forget). Enabling this option will enrich the Camel Exchange with the actual JMSMessageID that was used by the JMS client when the message was sent to the JMS destination.

false

boolean

replyToCacheLevelName (producer (advanced))

Sets the cache level by name for the reply consumer when doing request/reply over JMS. This option only applies when using fixed reply queues (not temporary). Camel will by default use: CACHE_CONSUMER for exclusive or shared w/ replyToSelectorName. And CACHE_SESSION for shared without replyToSelectorName. Some JMS brokers such as IBM WebSphere may require to set the replyToCacheLevelName=CACHE_NONE to work. Note: If using temporary queues then CACHE_NONE is not allowed, and you must use a higher value such as CACHE_CONSUMER or CACHE_SESSION.

Enum values:

  • CACHE_AUTO
  • CACHE_CONNECTION
  • CACHE_CONSUMER
  • CACHE_NONE
  • CACHE_SESSION
 

String

replyToDestinationSelectorName (producer (advanced))

Sets the JMS Selector using the fixed name to be used so you can filter out your own replies from the others when using a shared queue (that is, if you are not using a temporary reply queue).

 

String

streamMessageTypeEnabled (producer (advanced))

Sets whether StreamMessage type is enabled or not. Message payloads of streaming kind such as files, InputStream, etc will either by sent as BytesMessage or StreamMessage. This option controls which kind will be used. By default BytesMessage is used which enforces the entire message payload to be read into memory. By enabling this option the message payload is read into memory in chunks and each chunk is then written to the StreamMessage until no more data.

false

boolean

allowAutoWiredConnectionFactory (advanced)

Whether to auto-discover ConnectionFactory from the registry, if no connection factory has been configured. If only one instance of ConnectionFactory is found then it will be used. This is enabled by default.

true

boolean

allowAutoWiredDestinationResolver (advanced)

Whether to auto-discover DestinationResolver from the registry, if no destination resolver has been configured. If only one instance of DestinationResolver is found then it will be used. This is enabled by default.

true

boolean

allowSerializedHeaders (advanced)

Controls whether or not to include serialized headers. Applies only when transferExchange is true. This requires that the objects are serializable. Camel will exclude any non-serializable objects and log it at WARN level.

false

boolean

artemisStreamingEnabled (advanced)

Whether optimizing for Apache Artemis streaming mode. This can reduce memory overhead when using Artemis with JMS StreamMessage types. This option must only be enabled if Apache Artemis is being used.

false

boolean

asyncStartListener (advanced)

Whether to startup the JmsConsumer message listener asynchronously, when starting a route. For example if a JmsConsumer cannot get a connection to a remote JMS broker, then it may block while retrying and/or failover. This will cause Camel to block while starting routes. By setting this option to true, you will let routes startup, while the JmsConsumer connects to the JMS broker using a dedicated thread in asynchronous mode. If this option is used, then beware that if the connection could not be established, then an exception is logged at WARN level, and the consumer will not be able to receive messages; You can then restart the route to retry.

false

boolean

asyncStopListener (advanced)

Whether to stop the JmsConsumer message listener asynchronously, when stopping a route.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

configuration (advanced)

To use a shared JMS configuration.

 

JmsConfiguration

destinationResolver (advanced)

A pluggable org.springframework.jms.support.destination.DestinationResolver that allows you to use your own resolver (for example, to lookup the real destination in a JNDI registry).

 

DestinationResolver

errorHandler (advanced)

Specifies a org.springframework.util.ErrorHandler to be invoked in case of any uncaught exceptions thrown while processing a Message. By default these exceptions will be logged at the WARN level, if no errorHandler has been configured. You can configure logging level and whether stack traces should be logged using errorHandlerLoggingLevel and errorHandlerLogStackTrace options. This makes it much easier to configure, than having to code a custom errorHandler.

 

ErrorHandler

exceptionListener (advanced)

Specifies the JMS Exception Listener that is to be notified of any underlying JMS exceptions.

 

ExceptionListener

idleConsumerLimit (advanced)

Specify the limit for the number of consumers that are allowed to be idle at any given time.

1

int

idleTaskExecutionLimit (advanced)

Specifies the limit for idle executions of a receive task, not having received any message within its execution. If this limit is reached, the task will shut down and leave receiving to other executing tasks (in the case of dynamic scheduling; see the maxConcurrentConsumers setting). There is additional doc available from Spring.

1

int

includeAllJMSXProperties (advanced)

Whether to include all JMSXxxx properties when mapping from JMS to Camel Message. Setting this to true will include properties such as JMSXAppID, and JMSXUserID etc. Note: If you are using a custom headerFilterStrategy then this option does not apply.

false

boolean

jmsKeyFormatStrategy (advanced)

Pluggable strategy for encoding and decoding JMS keys so they can be compliant with the JMS specification. Camel provides two implementations out of the box: default and passthrough. The default strategy will safely marshal dots and hyphens (. and -). The passthrough strategy leaves the key as is. Can be used for JMS brokers which do not care whether JMS header keys contain illegal characters. You can provide your own implementation of the org.apache.camel.component.jms.JmsKeyFormatStrategy and refer to it using the # notation.

Enum values:

  • default
  • passthrough
 

JmsKeyFormatStrategy

mapJmsMessage (advanced)

Specifies whether Camel should auto map the received JMS message to a suited payload type, such as javax.jms.TextMessage to a String etc.

true

boolean

maxMessagesPerTask (advanced)

The number of messages per task. -1 is unlimited. If you use a range for concurrent consumers (eg min max), then this option can be used to set a value to eg 100 to control how fast the consumers will shrink when less work is required.

-1

int

messageConverter (advanced)

To use a custom Spring org.springframework.jms.support.converter.MessageConverter so you can be in control how to map to/from a javax.jms.Message.

 

MessageConverter

messageCreatedStrategy (advanced)

To use the given MessageCreatedStrategy which are invoked when Camel creates new instances of javax.jms.Message objects when Camel is sending a JMS message.

 

MessageCreatedStrategy

messageIdEnabled (advanced)

When sending, specifies whether message IDs should be added. This is just an hint to the JMS broker. If the JMS provider accepts this hint, these messages must have the message ID set to null; if the provider ignores the hint, the message ID must be set to its normal unique value.

true

boolean

messageListenerContainerFactory (advanced)

Registry ID of the MessageListenerContainerFactory used to determine what org.springframework.jms.listener.AbstractMessageListenerContainer to use to consume messages. Setting this will automatically set consumerType to Custom.

 

MessageListenerContainerFactory

messageTimestampEnabled (advanced)

Specifies whether timestamps should be enabled by default on sending messages. This is just an hint to the JMS broker. If the JMS provider accepts this hint, these messages must have the timestamp set to zero; if the provider ignores the hint the timestamp must be set to its normal value.

true

boolean

pubSubNoLocal (advanced)

Specifies whether to inhibit the delivery of messages published by its own connection.

false

boolean

queueBrowseStrategy (advanced)

To use a custom QueueBrowseStrategy when browsing queues.

 

QueueBrowseStrategy

receiveTimeout (advanced)

The timeout for receiving messages (in milliseconds).

1000

long

recoveryInterval (advanced)

Specifies the interval between recovery attempts, i.e. when a connection is being refreshed, in milliseconds. The default is 5000 ms, that is, 5 seconds.

5000

long

requestTimeoutCheckerInterval (advanced)

Configures how often Camel should check for timed out Exchanges when doing request/reply over JMS. By default Camel checks once per second. But if you must react faster when a timeout occurs, then you can lower this interval, to check more frequently. The timeout is determined by the option requestTimeout.

1000

long

synchronous (advanced)

Sets whether synchronous processing should be strictly used.

false

boolean

transferException (advanced)

If enabled and you are using Request Reply messaging (InOut) and an Exchange failed on the consumer side, then the caused Exception will be send back in response as a javax.jms.ObjectMessage. If the client is Camel, the returned Exception is rethrown. This allows you to use Camel JMS as a bridge in your routing - for example, using persistent queues to enable robust routing. Notice that if you also have transferExchange enabled, this option takes precedence. The caught exception is required to be serializable. The original Exception on the consumer side can be wrapped in an outer exception such as org.apache.camel.RuntimeCamelException when returned to the producer. Use this with caution as the data is using Java Object serialization and requires the received to be able to deserialize the data at Class level, which forces a strong coupling between the producers and consumer!.

false

boolean

transferExchange (advanced)

You can transfer the exchange over the wire instead of just the body and headers. The following fields are transferred: In body, Out body, Fault body, In headers, Out headers, Fault headers, exchange properties, exchange exception. This requires that the objects are serializable. Camel will exclude any non-serializable objects and log it at WARN level. You must enable this option on both the producer and consumer side, so Camel knows the payloads is an Exchange and not a regular payload. Use this with caution as the data is using Java Object serialization and requires the receiver to be able to deserialize the data at Class level, which forces a strong coupling between the producers and consumers having to use compatible Camel versions!.

false

boolean

useMessageIDAsCorrelationID (advanced)

Specifies whether JMSMessageID should always be used as JMSCorrelationID for InOut messages.

false

boolean

waitForProvisionCorrelationToBeUpdatedCounter (advanced)

Number of times to wait for provisional correlation id to be updated to the actual correlation id when doing request/reply over JMS and when the option useMessageIDAsCorrelationID is enabled.

50

int

waitForProvisionCorrelationToBeUpdatedThreadSleepingTime (advanced)

Interval in millis to sleep each time while waiting for provisional correlation id to be updated.

100

long

headerFilterStrategy (filter)

To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message.

 

HeaderFilterStrategy

errorHandlerLoggingLevel (logging)

Allows to configure the default errorHandler logging level for logging uncaught exceptions.

Enum values:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • OFF

WARN

LoggingLevel

errorHandlerLogStackTrace (logging)

Allows to control whether stacktraces should be logged or not, by the default errorHandler.

true

boolean

password (security)

Password to use with the ConnectionFactory. You can also configure username/password directly on the ConnectionFactory.

 

String

username (security)

Username to use with the ConnectionFactory. You can also configure username/password directly on the ConnectionFactory.

 

String

transacted (transaction)

Specifies whether to use transacted mode.

false

boolean

transactedInOut (transaction)

Specifies whether InOut operations (request reply) default to using transacted mode If this flag is set to true, then Spring JmsTemplate will have sessionTransacted set to true, and the acknowledgeMode as transacted on the JmsTemplate used for InOut operations. Note from Spring JMS: that within a JTA transaction, the parameters passed to createQueue, createTopic methods are not taken into account. Depending on the Java EE transaction context, the container makes its own decisions on these values. Analogously, these parameters are not taken into account within a locally managed transaction either, since Spring JMS operates on an existing JMS Session in this case. Setting this flag to true will use a short local JMS transaction when running outside of a managed transaction, and a synchronized local JMS transaction in case of a managed transaction (other than an XA transaction) being present. This has the effect of a local JMS transaction being managed alongside the main transaction (which might be a native JDBC transaction), with the JMS transaction committing right after the main transaction.

false

boolean

lazyCreateTransactionManager (transaction (advanced))

If true, Camel will create a JmsTransactionManager, if there is no transactionManager injected when option transacted=true.

true

boolean

transactionManager (transaction (advanced))

The Spring transaction manager to use.

 

PlatformTransactionManager

transactionName (transaction (advanced))

The name of the transaction to use.

 

String

transactionTimeout (transaction (advanced))

The timeout value of the transaction (in seconds), if using transacted mode.

-1

int

52.5. Endpoint Options

The JMS endpoint is configured using URI syntax:

jms:destinationType:destinationName

with the following path and query parameters:

52.5.1. Path Parameters (2 parameters)

NameDescriptionDefaultType

destinationType (common)

The kind of destination to use.

Enum values:

  • queue
  • topic
  • temp-queue
  • temp-topic

queue

String

destinationName (common)

Required Name of the queue or topic to use as destination.

 

String

52.5.2. Query Parameters (95 parameters)

NameDescriptionDefaultType

clientId (common)

Sets the JMS client ID to use. Note that this value, if specified, must be unique and can only be used by a single JMS connection instance. It is typically only required for durable topic subscriptions with JMS 1.1. If using Apache ActiveMQ you may prefer to use Virtual Topics instead.

 

String

connectionFactory (common)

The connection factory to be use. A connection factory must be configured either on the component or endpoint.

 

ConnectionFactory

disableReplyTo (common)

Specifies whether Camel ignores the JMSReplyTo header in messages. If true, Camel does not send a reply back to the destination specified in the JMSReplyTo header. You can use this option if you want Camel to consume from a route and you do not want Camel to automatically send back a reply message because another component in your code handles the reply message. You can also use this option if you want to use Camel as a proxy between different message brokers and you want to route message from one system to another.

false

boolean

durableSubscriptionName (common)

The durable subscriber name for specifying durable topic subscriptions. The clientId option must be configured as well.

 

String

jmsMessageType (common)

Allows you to force the use of a specific javax.jms.Message implementation for sending JMS messages. Possible values are: Bytes, Map, Object, Stream, Text. By default, Camel would determine which JMS message type to use from the In body type. This option allows you to specify it.

Enum values:

  • Bytes
  • Map
  • Object
  • Stream
  • Text
 

JmsMessageType

replyTo (common)

Provides an explicit ReplyTo destination (overrides any incoming value of Message.getJMSReplyTo() in consumer).

 

String

testConnectionOnStartup (common)

Specifies whether to test the connection on startup. This ensures that when Camel starts that all the JMS consumers have a valid connection to the JMS broker. If a connection cannot be granted then Camel throws an exception on startup. This ensures that Camel is not started with failed connections. The JMS producers is tested as well.

false

boolean

acknowledgementModeName (consumer)

The JMS acknowledgement name, which is one of: SESSION_TRANSACTED, CLIENT_ACKNOWLEDGE, AUTO_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE.

Enum values:

  • SESSION_TRANSACTED
  • CLIENT_ACKNOWLEDGE
  • AUTO_ACKNOWLEDGE
  • DUPS_OK_ACKNOWLEDGE

AUTO_ACKNOWLEDGE

String

artemisConsumerPriority (consumer)

Consumer priorities allow you to ensure that high priority consumers receive messages while they are active. Normally, active consumers connected to a queue receive messages from it in a round-robin fashion. When consumer priorities are in use, messages are delivered round-robin if multiple active consumers exist with the same high priority. Messages will only going to lower priority consumers when the high priority consumers do not have credit available to consume the message, or those high priority consumers have declined to accept the message (for instance because it does not meet the criteria of any selectors associated with the consumer).

 

int

asyncConsumer (consumer)

Whether the JmsConsumer processes the Exchange asynchronously. If enabled then the JmsConsumer may pickup the next message from the JMS queue, while the previous message is being processed asynchronously (by the Asynchronous Routing Engine). This means that messages may be processed not 100% strictly in order. If disabled (as default) then the Exchange is fully processed before the JmsConsumer picks up the next message from the JMS queue. Note if transacted has been enabled, then asyncConsumer=true does not run asynchronously, as transaction must be executed synchronously (Camel 3.0 may support async transactions).

false

boolean

autoStartup (consumer)

Specifies whether the consumer container should auto-startup.

true

boolean

cacheLevel (consumer)

Sets the cache level by ID for the underlying JMS resources. See cacheLevelName option for more details.

 

int

cacheLevelName (consumer)

Sets the cache level by name for the underlying JMS resources. Possible values are: CACHE_AUTO, CACHE_CONNECTION, CACHE_CONSUMER, CACHE_NONE, and CACHE_SESSION. The default setting is CACHE_AUTO. See the Spring documentation and Transactions Cache Levels for more information.

Enum values:

  • CACHE_AUTO
  • CACHE_CONNECTION
  • CACHE_CONSUMER
  • CACHE_NONE
  • CACHE_SESSION

CACHE_AUTO

String

concurrentConsumers (consumer)

Specifies the default number of concurrent consumers when consuming from JMS (not for request/reply over JMS). See also the maxMessagesPerTask option to control dynamic scaling up/down of threads. When doing request/reply over JMS then the option replyToConcurrentConsumers is used to control number of concurrent consumers on the reply message listener.

1

int

maxConcurrentConsumers (consumer)

Specifies the maximum number of concurrent consumers when consuming from JMS (not for request/reply over JMS). See also the maxMessagesPerTask option to control dynamic scaling up/down of threads. When doing request/reply over JMS then the option replyToMaxConcurrentConsumers is used to control number of concurrent consumers on the reply message listener.

 

int

replyToDeliveryPersistent (consumer)

Specifies whether to use persistent delivery by default for replies.

true

boolean

selector (consumer)

Sets the JMS selector to use.

 

String

subscriptionDurable (consumer)

Set whether to make the subscription durable. The durable subscription name to be used can be specified through the subscriptionName property. Default is false. Set this to true to register a durable subscription, typically in combination with a subscriptionName value (unless your message listener class name is good enough as subscription name). Only makes sense when listening to a topic (pub-sub domain), therefore this method switches the pubSubDomain flag as well.

false

boolean

subscriptionName (consumer)

Set the name of a subscription to create. To be applied in case of a topic (pub-sub domain) with a shared or durable subscription. The subscription name needs to be unique within this client’s JMS client id. Default is the class name of the specified message listener. Note: Only 1 concurrent consumer (which is the default of this message listener container) is allowed for each subscription, except for a shared subscription (which requires JMS 2.0).

 

String

subscriptionShared (consumer)

Set whether to make the subscription shared. The shared subscription name to be used can be specified through the subscriptionName property. Default is false. Set this to true to register a shared subscription, typically in combination with a subscriptionName value (unless your message listener class name is good enough as subscription name). Note that shared subscriptions may also be durable, so this flag can (and often will) be combined with subscriptionDurable as well. Only makes sense when listening to a topic (pub-sub domain), therefore this method switches the pubSubDomain flag as well. Requires a JMS 2.0 compatible message broker.

false

boolean

acceptMessagesWhileStopping (consumer (advanced))

Specifies whether the consumer accept messages while it is stopping. You may consider enabling this option, if you start and stop JMS routes at runtime, while there are still messages enqueued on the queue. If this option is false, and you stop the JMS route, then messages may be rejected, and the JMS broker would have to attempt redeliveries, which yet again may be rejected, and eventually the message may be moved at a dead letter queue on the JMS broker. To avoid this its recommended to enable this option.

false

boolean

allowReplyManagerQuickStop (consumer (advanced))

Whether the DefaultMessageListenerContainer used in the reply managers for request/reply messaging allow the DefaultMessageListenerContainer.runningAllowed flag to quick stop in case JmsConfiguration#isAcceptMessagesWhileStopping is enabled, and org.apache.camel.CamelContext is currently being stopped. This quick stop ability is enabled by default in the regular JMS consumers but to enable for reply managers you must enable this flag.

false

boolean

consumerType (consumer (advanced))

The consumer type to use, which can be one of: Simple, Default, or Custom. The consumer type determines which Spring JMS listener to use. Default will use org.springframework.jms.listener.DefaultMessageListenerContainer, Simple will use org.springframework.jms.listener.SimpleMessageListenerContainer. When Custom is specified, the MessageListenerContainerFactory defined by the messageListenerContainerFactory option will determine what org.springframework.jms.listener.AbstractMessageListenerContainer to use.

Enum values:

  • Simple
  • Default
  • Custom

Default

ConsumerType

defaultTaskExecutorType (consumer (advanced))

Specifies what default TaskExecutor type to use in the DefaultMessageListenerContainer, for both consumer endpoints and the ReplyTo consumer of producer endpoints. Possible values: SimpleAsync (uses Spring’s SimpleAsyncTaskExecutor) or ThreadPool (uses Spring’s ThreadPoolTaskExecutor with optimal values - cached threadpool-like). If not set, it defaults to the previous behaviour, which uses a cached thread pool for consumer endpoints and SimpleAsync for reply consumers. The use of ThreadPool is recommended to reduce thread trash in elastic configurations with dynamically increasing and decreasing concurrent consumers.

Enum values:

  • ThreadPool
  • SimpleAsync
 

DefaultTaskExecutorType

eagerLoadingOfProperties (consumer (advanced))

Enables eager loading of JMS properties and payload as soon as a message is loaded which generally is inefficient as the JMS properties may not be required but sometimes can catch early any issues with the underlying JMS provider and the use of JMS properties. See also the option eagerPoisonBody.

false

boolean

eagerPoisonBody (consumer (advanced))

If eagerLoadingOfProperties is enabled and the JMS message payload (JMS body or JMS properties) is poison (cannot be read/mapped), then set this text as the message body instead so the message can be processed (the cause of the poison are already stored as exception on the Exchange). This can be turned off by setting eagerPoisonBody=false. See also the option eagerLoadingOfProperties.

Poison JMS message due to $\{exception.message}

String

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly
  • InOut
  • InOptionalOut
 

ExchangePattern

exposeListenerSession (consumer (advanced))

Specifies whether the listener session should be exposed when consuming messages.

false

boolean

replyToSameDestinationAllowed (consumer (advanced))

Whether a JMS consumer is allowed to send a reply message to the same destination that the consumer is using to consume from. This prevents an endless loop by consuming and sending back the same message to itself.

false

boolean

taskExecutor (consumer (advanced))

Allows you to specify a custom task executor for consuming messages.

 

TaskExecutor

deliveryDelay (producer)

Sets delivery delay to use for send calls for JMS. This option requires JMS 2.0 compliant broker.

-1

long

deliveryMode (producer)

Specifies the delivery mode to be used. Possible values are those defined by javax.jms.DeliveryMode. NON_PERSISTENT = 1 and PERSISTENT = 2.

Enum values:

  • 1
  • 2
 

Integer

deliveryPersistent (producer)

Specifies whether persistent delivery is used by default.

true

boolean

explicitQosEnabled (producer)

Set if the deliveryMode, priority or timeToLive qualities of service should be used when sending messages. This option is based on Spring’s JmsTemplate. The deliveryMode, priority and timeToLive options are applied to the current endpoint. This contrasts with the preserveMessageQos option, which operates at message granularity, reading QoS properties exclusively from the Camel In message headers.

false

Boolean

formatDateHeadersToIso8601 (producer)

Sets whether JMS date properties should be formatted according to the ISO 8601 standard.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

preserveMessageQos (producer)

Set to true, if you want to send message using the QoS settings specified on the message, instead of the QoS settings on the JMS endpoint. The following three headers are considered JMSPriority, JMSDeliveryMode, and JMSExpiration. You can provide all or only some of them. If not provided, Camel will fall back to use the values from the endpoint instead. So, when using this option, the headers override the values from the endpoint. The explicitQosEnabled option, by contrast, will only use options set on the endpoint, and not values from the message header.

false

boolean

priority (producer)

Values greater than 1 specify the message priority when sending (where 1 is the lowest priority and 9 is the highest). The explicitQosEnabled option must also be enabled in order for this option to have any effect.

Enum values:

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

4

int

replyToConcurrentConsumers (producer)

Specifies the default number of concurrent consumers when doing request/reply over JMS. See also the maxMessagesPerTask option to control dynamic scaling up/down of threads.

1

int

replyToMaxConcurrentConsumers (producer)

Specifies the maximum number of concurrent consumers when using request/reply over JMS. See also the maxMessagesPerTask option to control dynamic scaling up/down of threads.

 

int

replyToOnTimeoutMaxConcurrentConsumers (producer)

Specifies the maximum number of concurrent consumers for continue routing when timeout occurred when using request/reply over JMS.

1

int

replyToOverride (producer)

Provides an explicit ReplyTo destination in the JMS message, which overrides the setting of replyTo. It is useful if you want to forward the message to a remote Queue and receive the reply message from the ReplyTo destination.

 

String

replyToType (producer)

Allows for explicitly specifying which kind of strategy to use for replyTo queues when doing request/reply over JMS. Possible values are: Temporary, Shared, or Exclusive. By default Camel will use temporary queues. However if replyTo has been configured, then Shared is used by default. This option allows you to use exclusive queues instead of shared ones. See Camel JMS documentation for more details, and especially the notes about the implications if running in a clustered environment, and the fact that Shared reply queues has lower performance than its alternatives Temporary and Exclusive.

Enum values:

  • Temporary
  • Shared
  • Exclusive
 

ReplyToType

requestTimeout (producer)

The timeout for waiting for a reply when using the InOut Exchange Pattern (in milliseconds). The default is 20 seconds. You can include the header CamelJmsRequestTimeout to override this endpoint configured timeout value, and thus have per message individual timeout values. See also the requestTimeoutCheckerInterval option.

20000

long

timeToLive (producer)

When sending messages, specifies the time-to-live of the message (in milliseconds).

-1

long

allowAdditionalHeaders (producer (advanced))

This option is used to allow additional headers which may have values that are invalid according to JMS specification. For example some message systems such as WMQ do this with header names using prefix JMS_IBM_MQMD_ containing values with byte array or other invalid types. You can specify multiple header names separated by comma, and use as suffix for wildcard matching.

 

String

allowNullBody (producer (advanced))

Whether to allow sending messages with no body. If this option is false and the message body is null, then an JMSException is thrown.

true

boolean

alwaysCopyMessage (producer (advanced))

If true, Camel will always make a JMS message copy of the message when it is passed to the producer for sending. Copying the message is needed in some situations, such as when a replyToDestinationSelectorName is set (incidentally, Camel will set the alwaysCopyMessage option to true, if a replyToDestinationSelectorName is set).

false

boolean

correlationProperty (producer (advanced))

When using InOut exchange pattern use this JMS property instead of JMSCorrelationID JMS property to correlate messages. If set messages will be correlated solely on the value of this property JMSCorrelationID property will be ignored and not set by Camel.

 

String

disableTimeToLive (producer (advanced))

Use this option to force disabling time to live. For example when you do request/reply over JMS, then Camel will by default use the requestTimeout value as time to live on the message being sent. The problem is that the sender and receiver systems have to have their clocks synchronized, so they are in sync. This is not always so easy to archive. So you can use disableTimeToLive=true to not set a time to live value on the sent message. Then the message will not expire on the receiver system. See below in section About time to live for more details.

false

boolean

forceSendOriginalMessage (producer (advanced))

When using mapJmsMessage=false Camel will create a new JMS message to send to a new JMS destination if you touch the headers (get or set) during the route. Set this option to true to force Camel to send the original JMS message that was received.

false

boolean

includeSentJMSMessageID (producer (advanced))

Only applicable when sending to JMS destination using InOnly (eg fire and forget). Enabling this option will enrich the Camel Exchange with the actual JMSMessageID that was used by the JMS client when the message was sent to the JMS destination.

false

boolean

replyToCacheLevelName (producer (advanced))

Sets the cache level by name for the reply consumer when doing request/reply over JMS. This option only applies when using fixed reply queues (not temporary). Camel will by default use: CACHE_CONSUMER for exclusive or shared w/ replyToSelectorName. And CACHE_SESSION for shared without replyToSelectorName. Some JMS brokers such as IBM WebSphere may require to set the replyToCacheLevelName=CACHE_NONE to work. Note: If using temporary queues then CACHE_NONE is not allowed, and you must use a higher value such as CACHE_CONSUMER or CACHE_SESSION.

Enum values:

  • CACHE_AUTO
  • CACHE_CONNECTION
  • CACHE_CONSUMER
  • CACHE_NONE
  • CACHE_SESSION
 

String

replyToDestinationSelectorName (producer (advanced))

Sets the JMS Selector using the fixed name to be used so you can filter out your own replies from the others when using a shared queue (that is, if you are not using a temporary reply queue).

 

String

streamMessageTypeEnabled (producer (advanced))

Sets whether StreamMessage type is enabled or not. Message payloads of streaming kind such as files, InputStream, etc will either by sent as BytesMessage or StreamMessage. This option controls which kind will be used. By default BytesMessage is used which enforces the entire message payload to be read into memory. By enabling this option the message payload is read into memory in chunks and each chunk is then written to the StreamMessage until no more data.

false

boolean

allowSerializedHeaders (advanced)

Controls whether or not to include serialized headers. Applies only when transferExchange is true. This requires that the objects are serializable. Camel will exclude any non-serializable objects and log it at WARN level.

false

boolean

artemisStreamingEnabled (advanced)

Whether optimizing for Apache Artemis streaming mode. This can reduce memory overhead when using Artemis with JMS StreamMessage types. This option must only be enabled if Apache Artemis is being used.

false

boolean

asyncStartListener (advanced)

Whether to startup the JmsConsumer message listener asynchronously, when starting a route. For example if a JmsConsumer cannot get a connection to a remote JMS broker, then it may block while retrying and/or failover. This will cause Camel to block while starting routes. By setting this option to true, you will let routes startup, while the JmsConsumer connects to the JMS broker using a dedicated thread in asynchronous mode. If this option is used, then beware that if the connection could not be established, then an exception is logged at WARN level, and the consumer will not be able to receive messages; You can then restart the route to retry.

false

boolean

asyncStopListener (advanced)

Whether to stop the JmsConsumer message listener asynchronously, when stopping a route.

false

boolean

destinationResolver (advanced)

A pluggable org.springframework.jms.support.destination.DestinationResolver that allows you to use your own resolver (for example, to lookup the real destination in a JNDI registry).

 

DestinationResolver

errorHandler (advanced)

Specifies a org.springframework.util.ErrorHandler to be invoked in case of any uncaught exceptions thrown while processing a Message. By default these exceptions will be logged at the WARN level, if no errorHandler has been configured. You can configure logging level and whether stack traces should be logged using errorHandlerLoggingLevel and errorHandlerLogStackTrace options. This makes it much easier to configure, than having to code a custom errorHandler.

 

ErrorHandler

exceptionListener (advanced)

Specifies the JMS Exception Listener that is to be notified of any underlying JMS exceptions.

 

ExceptionListener

headerFilterStrategy (advanced)

To use a custom HeaderFilterStrategy to filter header to and from Camel message.

 

HeaderFilterStrategy

idleConsumerLimit (advanced)

Specify the limit for the number of consumers that are allowed to be idle at any given time.

1

int

idleTaskExecutionLimit (advanced)

Specifies the limit for idle executions of a receive task, not having received any message within its execution. If this limit is reached, the task will shut down and leave receiving to other executing tasks (in the case of dynamic scheduling; see the maxConcurrentConsumers setting). There is additional doc available from Spring.

1

int

includeAllJMSXProperties (advanced)

Whether to include all JMSXxxx properties when mapping from JMS to Camel Message. Setting this to true will include properties such as JMSXAppID, and JMSXUserID etc. Note: If you are using a custom headerFilterStrategy then this option does not apply.

false

boolean

jmsKeyFormatStrategy (advanced)

Pluggable strategy for encoding and decoding JMS keys so they can be compliant with the JMS specification. Camel provides two implementations out of the box: default and passthrough. The default strategy will safely marshal dots and hyphens (. and -). The passthrough strategy leaves the key as is. Can be used for JMS brokers which do not care whether JMS header keys contain illegal characters. You can provide your own implementation of the org.apache.camel.component.jms.JmsKeyFormatStrategy and refer to it using the # notation.

Enum values:

  • default
  • passthrough
 

JmsKeyFormatStrategy

mapJmsMessage (advanced)

Specifies whether Camel should auto map the received JMS message to a suited payload type, such as javax.jms.TextMessage to a String etc.

true

boolean

maxMessagesPerTask (advanced)

The number of messages per task. -1 is unlimited. If you use a range for concurrent consumers (eg min max), then this option can be used to set a value to eg 100 to control how fast the consumers will shrink when less work is required.

-1

int

messageConverter (advanced)

To use a custom Spring org.springframework.jms.support.converter.MessageConverter so you can be in control how to map to/from a javax.jms.Message.

 

MessageConverter

messageCreatedStrategy (advanced)

To use the given MessageCreatedStrategy which are invoked when Camel creates new instances of javax.jms.Message objects when Camel is sending a JMS message.

 

MessageCreatedStrategy

messageIdEnabled (advanced)

When sending, specifies whether message IDs should be added. This is just an hint to the JMS broker. If the JMS provider accepts this hint, these messages must have the message ID set to null; if the provider ignores the hint, the message ID must be set to its normal unique value.

true

boolean

messageListenerContainerFactory (advanced)

Registry ID of the MessageListenerContainerFactory used to determine what org.springframework.jms.listener.AbstractMessageListenerContainer to use to consume messages. Setting this will automatically set consumerType to Custom.

 

MessageListenerContainerFactory

messageTimestampEnabled (advanced)

Specifies whether timestamps should be enabled by default on sending messages. This is just an hint to the JMS broker. If the JMS provider accepts this hint, these messages must have the timestamp set to zero; if the provider ignores the hint the timestamp must be set to its normal value.

true

boolean

pubSubNoLocal (advanced)

Specifies whether to inhibit the delivery of messages published by its own connection.

false

boolean

receiveTimeout (advanced)

The timeout for receiving messages (in milliseconds).

1000

long

recoveryInterval (advanced)

Specifies the interval between recovery attempts, i.e. when a connection is being refreshed, in milliseconds. The default is 5000 ms, that is, 5 seconds.

5000

long

requestTimeoutCheckerInterval (advanced)

Configures how often Camel should check for timed out Exchanges when doing request/reply over JMS. By default Camel checks once per second. But if you must react faster when a timeout occurs, then you can lower this interval, to check more frequently. The timeout is determined by the option requestTimeout.

1000

long

synchronous (advanced)

Sets whether synchronous processing should be strictly used.

false

boolean

transferException (advanced)

If enabled and you are using Request Reply messaging (InOut) and an Exchange failed on the consumer side, then the caused Exception will be send back in response as a javax.jms.ObjectMessage. If the client is Camel, the returned Exception is rethrown. This allows you to use Camel JMS as a bridge in your routing - for example, using persistent queues to enable robust routing. Notice that if you also have transferExchange enabled, this option takes precedence. The caught exception is required to be serializable. The original Exception on the consumer side can be wrapped in an outer exception such as org.apache.camel.RuntimeCamelException when returned to the producer. Use this with caution as the data is using Java Object serialization and requires the received to be able to deserialize the data at Class level, which forces a strong coupling between the producers and consumer!.

false

boolean

transferExchange (advanced)

You can transfer the exchange over the wire instead of just the body and headers. The following fields are transferred: In body, Out body, Fault body, In headers, Out headers, Fault headers, exchange properties, exchange exception. This requires that the objects are serializable. Camel will exclude any non-serializable objects and log it at WARN level. You must enable this option on both the producer and consumer side, so Camel knows the payloads is an Exchange and not a regular payload. Use this with caution as the data is using Java Object serialization and requires the receiver to be able to deserialize the data at Class level, which forces a strong coupling between the producers and consumers having to use compatible Camel versions!.

false

boolean

useMessageIDAsCorrelationID (advanced)

Specifies whether JMSMessageID should always be used as JMSCorrelationID for InOut messages.

false

boolean

waitForProvisionCorrelationToBeUpdatedCounter (advanced)

Number of times to wait for provisional correlation id to be updated to the actual correlation id when doing request/reply over JMS and when the option useMessageIDAsCorrelationID is enabled.

50

int

waitForProvisionCorrelationToBeUpdatedThreadSleepingTime (advanced)

Interval in millis to sleep each time while waiting for provisional correlation id to be updated.

100

long

errorHandlerLoggingLevel (logging)

Allows to configure the default errorHandler logging level for logging uncaught exceptions.

Enum values:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • OFF

WARN

LoggingLevel

errorHandlerLogStackTrace (logging)

Allows to control whether stacktraces should be logged or not, by the default errorHandler.

true

boolean

password (security)

Password to use with the ConnectionFactory. You can also configure username/password directly on the ConnectionFactory.

 

String

username (security)

Username to use with the ConnectionFactory. You can also configure username/password directly on the ConnectionFactory.

 

String

transacted (transaction)

Specifies whether to use transacted mode.

false

boolean

transactedInOut (transaction)

Specifies whether InOut operations (request reply) default to using transacted mode If this flag is set to true, then Spring JmsTemplate will have sessionTransacted set to true, and the acknowledgeMode as transacted on the JmsTemplate used for InOut operations. Note from Spring JMS: that within a JTA transaction, the parameters passed to createQueue, createTopic methods are not taken into account. Depending on the Java EE transaction context, the container makes its own decisions on these values. Analogously, these parameters are not taken into account within a locally managed transaction either, since Spring JMS operates on an existing JMS Session in this case. Setting this flag to true will use a short local JMS transaction when running outside of a managed transaction, and a synchronized local JMS transaction in case of a managed transaction (other than an XA transaction) being present. This has the effect of a local JMS transaction being managed alongside the main transaction (which might be a native JDBC transaction), with the JMS transaction committing right after the main transaction.

false

boolean

lazyCreateTransactionManager (transaction (advanced))

If true, Camel will create a JmsTransactionManager, if there is no transactionManager injected when option transacted=true.

true

boolean

transactionManager (transaction (advanced))

The Spring transaction manager to use.

 

PlatformTransactionManager

transactionName (transaction (advanced))

The name of the transaction to use.

 

String

transactionTimeout (transaction (advanced))

The timeout value of the transaction (in seconds), if using transacted mode.

-1

int

52.6. Samples

JMS is used in many examples for other components as well. But we provide a few samples below to get started.

52.6.1. Receiving from JMS

In the following sample we configure a route that receives JMS messages and routes the message to a POJO:

from("jms:queue:foo").
   to("bean:myBusinessLogic");

You can of course use any of the EIP patterns so the route can be context based. For example, here’s how to filter an order topic for the big spenders:

from("jms:topic:OrdersTopic").
  filter().method("myBean", "isGoldCustomer").
  to("jms:queue:BigSpendersQueue");

52.6.2. Sending to JMS

In the sample below we poll a file folder and send the file content to a JMS topic. As we want the content of the file as a TextMessage instead of a BytesMessage, we need to convert the body to a String:

from("file://orders").
  convertBodyTo(String.class).
  to("jms:topic:OrdersTopic");

52.6.3. Using Annotations

Camel also has annotations so you can use POJO Consuming and POJO Producing.

52.6.4. Spring DSL sample

The preceding examples use the Java DSL. Camel also supports Spring XML DSL. Here is the big spender sample using Spring DSL:

<route>
  <from uri="jms:topic:OrdersTopic"/>
  <filter>
    <method ref="myBean" method="isGoldCustomer"/>
    <to uri="jms:queue:BigSpendersQueue"/>
  </filter>
</route>

52.6.5. Other samples

JMS appears in many of the examples for other components and EIP patterns, as well in this Camel documentation. So feel free to browse the documentation.

52.6.6. Using JMS as a Dead Letter Queue storing Exchange

Normally, when using JMS as the transport, it only transfers the body and headers as the payload. If you want to use JMS with a Dead Letter Channel, using a JMS queue as the Dead Letter Queue, then normally the caused Exception is not stored in the JMS message. You can, however, use the transferExchange option on the JMS dead letter queue to instruct Camel to store the entire Exchange in the queue as a javax.jms.ObjectMessage that holds a org.apache.camel.support.DefaultExchangeHolder. This allows you to consume from the Dead Letter Queue and retrieve the caused exception from the Exchange property with the key Exchange.EXCEPTION_CAUGHT. The demo below illustrates this:

// setup error handler to use JMS as queue and store the entire Exchange
errorHandler(deadLetterChannel("jms:queue:dead?transferExchange=true"));

Then you can consume from the JMS queue and analyze the problem:

from("jms:queue:dead").to("bean:myErrorAnalyzer");

// and in our bean
String body = exchange.getIn().getBody();
Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
// the cause message is
String problem = cause.getMessage();

52.6.7. Using JMS as a Dead Letter Channel storing error only

You can use JMS to store the cause error message or to store a custom body, which you can initialize yourself. The following example uses the Message Translator EIP to do a transformation on the failed exchange before it is moved to the JMS dead letter queue:

// we sent it to a seda dead queue first
errorHandler(deadLetterChannel("seda:dead"));

// and on the seda dead queue we can do the custom transformation before its sent to the JMS queue
from("seda:dead").transform(exceptionMessage()).to("jms:queue:dead");

Here we only store the original cause error message in the transform. You can, however, use any Expression to send whatever you like. For example, you can invoke a method on a Bean or use a custom processor.

52.7. Message Mapping between JMS and Camel

Camel automatically maps messages between javax.jms.Message and org.apache.camel.Message.

When sending a JMS message, Camel converts the message body to the following JMS message types:

Body TypeJMS MessageComment

String

javax.jms.TextMessage

 

org.w3c.dom.Node

javax.jms.TextMessage

The DOM will be converted to String.

Map

javax.jms.MapMessage

 

java.io.Serializable

javax.jms.ObjectMessage

 

byte[]

javax.jms.BytesMessage

 

java.io.File

javax.jms.BytesMessage

 

java.io.Reader

javax.jms.BytesMessage

 

java.io.InputStream

javax.jms.BytesMessage

 

java.nio.ByteBuffer

javax.jms.BytesMessage

 

When receiving a JMS message, Camel converts the JMS message to the following body type:

JMS MessageBody Type

javax.jms.TextMessage

String

javax.jms.BytesMessage

byte[]

javax.jms.MapMessage

Map<String, Object>

javax.jms.ObjectMessage

Object

52.7.1. Disabling auto-mapping of JMS messages

You can use the mapJmsMessage option to disable the auto-mapping above. If disabled, Camel will not try to map the received JMS message, but instead uses it directly as the payload. This allows you to avoid the overhead of mapping and let Camel just pass through the JMS message. For instance, it even allows you to route javax.jms.ObjectMessage JMS messages with classes you do not have on the classpath.

52.7.2. Using a custom MessageConverter

You can use the messageConverter option to do the mapping yourself in a Spring org.springframework.jms.support.converter.MessageConverter class.

For example, in the route below we use a custom message converter when sending a message to the JMS order queue:

from("file://inbox/order").to("jms:queue:order?messageConverter=#myMessageConverter");

You can also use a custom message converter when consuming from a JMS destination.

52.7.3. Controlling the mapping strategy selected

You can use the jmsMessageType option on the endpoint URL to force a specific message type for all messages.

In the route below, we poll files from a folder and send them as javax.jms.TextMessage as we have forced the JMS producer endpoint to use text messages:

from("file://inbox/order").to("jms:queue:order?jmsMessageType=Text");

You can also specify the message type to use for each message by setting the header with the key CamelJmsMessageType. For example:

from("file://inbox/order").setHeader("CamelJmsMessageType", JmsMessageType.Text).to("jms:queue:order");

The possible values are defined in the enum class, org.apache.camel.jms.JmsMessageType.

52.8. Message format when sending

The exchange that is sent over the JMS wire must conform to the JMS Message spec.

For the exchange.in.header the following rules apply for the header keys:

  • Keys starting with JMS or JMSX are reserved.
  • exchange.in.headers keys must be literals and all be valid Java identifiers (do not use dots in the key name).
  • Camel replaces dots & hyphens and the reverse when when consuming JMS messages:
    . is replaced by `DOT` and the reverse replacement when Camel consumes the message.
    - is replaced by `HYPHEN` and the reverse replacement when Camel consumes the message.
  • See also the option jmsKeyFormatStrategy, which allows use of your own custom strategy for formatting keys.

For the exchange.in.header, the following rules apply for the header values:

  • The values must be primitives or their counter objects (such as Integer, Long, Character). The types, String, CharSequence, Date, BigDecimal and BigInteger are all converted to their toString() representation. All other types are dropped.

Camel will log with category org.apache.camel.component.jms.JmsBinding at DEBUG level if it drops a given header value. For example:

2008-07-09 06:43:04,046 [main           ] DEBUG JmsBinding
  - Ignoring non primitive header: order of class: org.apache.camel.component.jms.issues.DummyOrder with value: DummyOrder{orderId=333, itemId=4444, quantity=2}

52.9. Message format when receiving

Camel adds the following properties to the Exchange when it receives a message:

PropertyTypeDescription

org.apache.camel.jms.replyDestination

javax.jms.Destination

The reply destination.

Camel adds the following JMS properties to the In message headers when it receives a JMS message:

HeaderTypeDescription

JMSCorrelationID

String

The JMS correlation ID.

JMSDeliveryMode

int

The JMS delivery mode.

JMSDestination

javax.jms.Destination

The JMS destination.

JMSExpiration

long

The JMS expiration.

JMSMessageID

String

The JMS unique message ID.

JMSPriority

int

The JMS priority (with 0 as the lowest priority and 9 as the highest).

JMSRedelivered

boolean

Is the JMS message redelivered.

JMSReplyTo

javax.jms.Destination

The JMS reply-to destination.

JMSTimestamp

long

The JMS timestamp.

JMSType

String

The JMS type.

JMSXGroupID

String

The JMS group ID.

As all the above information is s