Apache Camel Component Reference
Configuration reference for Camel components
Abstract
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. Components Overview
This chapter provides a summary of all the components available for Apache Camel.
1.1. Container types
Red Hat Fuse provides a variety of container types, into which you can deploy your Camel applications:
- Spring Boot
- Apache Karaf
- JBoss Enterprise Application Platform (JBoss EAP)
In addition, a Camel application can run as containerless: that is, where a Camel application runs directly in the JVM, without any special container.
In some cases, Fuse might support a Camel component in one container, but not in the others. There are various reasons for this, but in some cases a component is not suitable for all container types. For example, the camel-ejb
component is designed specifically for Java EE (that is, JBoss EAP), and cannot be supported in the other container types.
The camel-test
component and extended components such as camel-test-blueprint
, camel-test-karaf
, and camel-test-spring
are supported and can be used to run JUnit tests for each runtime. However, these components are not executed on the runtimes themselves but inside JUnit.
1.2. Supported components
Note the following key:
Symbol | Description |
---|---|
✔ | Supported |
❌ | Unsupported or not yet supported |
Deprecated | Likely to be removed in a future release |
Table 1.1, “Apache Camel Component Support Matrix” provides comprehensive details about which Camel components are supported in which containers.
Component | Containerless | Spring Boot 2.x | Karaf | JBoss EAP | IBM Power / Spring Boot 2 | IBM Z / Spring Boot 2 |
---|---|---|---|---|---|---|
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ❌ | ❌ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ❌ | ✔ | ✔ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| Deprecated | Deprecated | Deprecated | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ❌ | ❌ | ❌ |
| Deprecated | Deprecated | Deprecated | ✔ | ❌ | ❌ |
| ✔ | ❌ | ✔ | ❌ | ❌ | ❌ |
| ✔ | ❌ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| Deprecated | Deprecated | Deprecated | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ❌ | Deprecated | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| Deprecated | ❌ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| Deprecated | ❌ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ❌ | ❌ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ❌ | ✔ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ❌ | ✔ | ❌ | ❌ | Deprecated | Deprecated |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ❌ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| Deprecated | ❌ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ❌ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ❌ | ✔ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ❌ | ❌ | ❌ |
| Deprecated | ❌ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| Deprecated | Deprecated | ❌ | ❌ | ❌ | ❌ |
| Deprecated | Deprecated | Deprecated | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ❌ | ❌ | ❌ | ❌ |
| Deprecated | ❌ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| Deprecated | Deprecated | ✔ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| Deprecated | ❌ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ❌ | ✔ | ❌ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| Deprecated | ❌ | ❌ | ❌ | ❌ | ❌ |
| ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ❌ | ✔ | ❌ | ❌ | ❌ |
| ✔ | ❌ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| Deprecated | Deprecated | Deprecated | ❌ | ❌ | ❌ |
| ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ❌ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| Deprecated | Deprecated | Deprecated | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ❌ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| Deprecated | Deprecated | Deprecated | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| Deprecated | Deprecated | Deprecated | ❌ | ❌ | ❌ |
| Deprecated | Deprecated | Deprecated | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ❌ | ✔ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ❌ | ✔ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| Deprecated | ❌ | ✔ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| Deprecated | Deprecated | Deprecated | Deprecated | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| Deprecated | Deprecated | ✔ | ❌ | ❌ | ❌ |
| Deprecated | Deprecated | ✔ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ❌ | ❌ | ❌ |
| ❌ | ✔ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| Deprecated | ❌ | ✔ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ❌ | ✔ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ❌ | ❌ | ❌ |
| Deprecated | ❌ | ✔ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ❌ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| Deprecated | ❌ | ✔ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| Deprecated | Deprecated | Deprecated | ❌ | ❌ | ❌ |
| ❌ | ✔ | ❌ | ❌ | ❌ | ❌ |
| ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| Deprecated | Deprecated | Deprecated | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| Deprecated | ✔ | Deprecated | ❌ | ❌ | ❌ |
| Deprecated | Deprecated | Deprecated | Deprecated | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ❌ | ✔ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| Deprecated | Deprecated | Deprecated | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ❌ | ❌ | ✔ | ✔ |
| ✔ | ✔ | ❌ | ❌ | ✔ | ✔ |
| ❌ | ✔ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ❌ | ❌ | ❌ | ❌ |
| ❌ | ✔ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ❌ | ✔ | ✔ | ✔ |
| ✔ | ❌ | ❌ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ❌ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ❌ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| Deprecated | ❌ | Deprecated | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| Deprecated | Deprecated | Deprecated | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ❌ | ✔ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ❌ | ❌ | ❌ |
| ✔ | ❌ | ❌ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ❌ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ | ❌ | ❌ |
Component | Containerless | Spring Boot 2.x | Karaf | JBoss EAP |
---|---|---|---|---|
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| Deprecated | Deprecated | Deprecated | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| Deprecated | Deprecated | Deprecated | Deprecated |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| Deprecated | Deprecated | Deprecated | ✔ |
| Deprecated | Deprecated | Deprecated | Deprecated |
| ❌ | ❌ | ❌ | ❌ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
| ✔ | ✔ | ✔ | ✔ |
Language | Containerless | Spring Boot 2.x | Karaf | JBoss EAP |
---|---|---|---|---|
Bean method | ✔ | ✔ | ✔ | ✔ |
Constant | ✔ | ✔ | ✔ | ✔ |
EL | Deprecated | ❌ | ❌ | ❌ |
ExchangeProperty | ✔ | ✔ | ✔ | ✔ |
File | ✔ | ✔ | ✔ | ✔ |
Groovy | ✔ | ✔ | ✔ | ✔ |
Header | ✔ | ✔ | ✔ | ✔ |
JsonPath | ✔ | ✔ | ✔ | ✔ |
JXPath | Deprecated | ❌ | ❌ | ❌ |
MVEL | ✔ | ✔ | ✔ | ✔ |
OGNL | ✔ | ✔ | ✔ | ✔ |
PHP | Deprecated | Deprecated | ❌ | Deprecated |
Python | Deprecated | Deprecated | ❌ | Deprecated |
Ref | ✔ | ✔ | ✔ | ✔ |
Ruby | Deprecated | Deprecated | ❌ | Deprecated |
Simple | ✔ | ✔ | ✔ | ✔ |
SpEL | ✔ | ✔ | ❌ | ✔ |
Tokenize | ✔ | ✔ | ✔ | ✔ |
XML Tokenize | ✔ | ✔ | ✔ | ✔ |
XPath | ✔ | ✔ | ✔ | ✔ |
XQuery | ✔ | ✔ | ✔ | ✔ |
Chapter 2. ActiveMQ
ActiveMQ Component
Using the ActiveMQ component, you can send messages to a JMS Queue or Topic or consume messages from a JMS Queue or Topic using Apache ActiveMQ.
This component is based on JMS component and uses Spring’s JMS support for declarative transactions, using Spring’s JmsTemplate
for sending and a MessageListenerContainer
for consuming. All JMS component options also apply to the ActiveMQ Component.
To use this component, make sure you have the activemq.jar
or activemq-core.jar
on your classpath along with any Apache Camel dependencies such as camel-core.jar
, camel-spring.jar
and camel-jms.jar
.
See section Transactions and Cache Levels below on JMS page if you are using transactions with JMS as it can impact performance.
URI format
activemq:[queue:|topic:]destinationName
Where destinationName is an ActiveMQ queue or topic name. By default, the destinationName is interpreted as a queue name. For example, to connect to the queue, FOO.BAR
, use:
activemq:FOO.BAR
You can include the optional queue:
prefix, if you prefer:
activemq:queue:FOO.BAR
To connect to a topic, you must include the topic:
prefix. For example, to connect to the topic, Stocks.Prices
, use:
activemq:topic:Stocks.Prices
Options
All JMS component options also apply to the ActiveMQ Component.
Camel on EAP deployment
This component is supported by the Camel on EAP (Wildfly Camel) framework, which offers a simplified deployment model on the Red Hat JBoss Enterprise Application Platform (JBoss EAP) container.
You can configure the ActiveMQ Camel component to work either with an embedded broker or an external broker. To embed a broker in the JBoss EAP container, configure the ActiveMQ Resource Adapter in the EAP container configuration file — for details, see ActiveMQ Resource Adapter Configuration.
Configuring the Connection Factory
The following test case shows how to add an ActiveMQComponent to the CamelContext using the activeMQComponent()
method while specifying the brokerURL used to connect to ActiveMQ.
camelContext.addComponent("activemq", activeMQComponent("vm://localhost?broker.persistent=false"));
Configuring the Connection Factory using Spring XML
You can configure the ActiveMQ broker URL on the ActiveMQComponent as follows
<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-2.0.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <camelContext xmlns="http://camel.apache.org/schema/spring"> </camelContext> <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent"> <property name="brokerURL" value="tcp://somehost:61616"/> </bean> </beans>
Using connection pooling
When sending to an ActiveMQ broker using Camel it is best practice to use a pooled connection factory to handle efficient pooling of JMS connections, sessions, and producers. See ActiveMQ Spring Support for more information.
- Add the AMQ pool with Maven:
<dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-pool</artifactId> <version>5.11.0.redhat-630516</version> </dependency>
- Set up the activemq component as follows:
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="tcp://localhost:61616" /> </bean> <bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" init-method="start" destroy-method="stop"> <property name="maxConnections" value="8" /> <property name="connectionFactory" ref="jmsConnectionFactory" /> </bean> <bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration"> <property name="connectionFactory" ref="pooledConnectionFactory"/> <property name="concurrentConsumers" value="10"/> </bean> <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent"> <property name="configuration" ref="jmsConfig"/> </bean>
Notice the init and destroy methods on the pooled connection factory. These methods are important to ensure the connection pool is properly started and shut down.
The PooledConnectionFactory
will then create a connection pool with up to 8 connections in use at the same time. Each connection can be shared by many sessions.
There is an option named maxActive
you can use to configure the maximum number of sessions per connection; the default value is 500
.
From ActiveMQ 5.7 onwards, the option has been renamed to maxActiveSessionPerConnection
to reflect its purpose better.
Note that the concurrentConsumers
is set to a higher value than maxConnections
is. This is permitted, as each consumer is using a session, and as a session can share the same connection, this will work. In this example, we can have 8 * 500 = 4000 active sessions simultaneously.
Invoking MessageListener POJOs in a route
The ActiveMQ component also provides a helper Type Converter from a JMS MessageListener to a Processor. This means that the Bean component can invoke any JMS MessageListener bean directly inside any route.
You can create a MessageListener in JMS as follows:
Example
public class MyListener implements MessageListener { public void onMessage(Message jmsMessage) { // ... } }
Then use it in your route as follows
Example
from("file://foo/bar"). bean(MyListener.class);
That is, you can reuse any of the Apache Camel components and easily integrate them into your JMS MessageListener
POJO\!
Using ActiveMQ Destination Options
Available as of ActiveMQ 5.6
You can configure the Destination Options in the endpoint uri, using the "destination." prefix. For example, to mark a consumer as exclusive, and set its prefetch size to 50, you can do as follows: .Example
<camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="file://src/test/data?noop=true"/> <to uri="activemq:queue:foo"/> </route> <route> <!-- use consumer.exclusive ActiveMQ destination option, notice we have to prefix with destination. --> <from uri="activemq:foo?destination.consumer.exclusive=true&destination.consumer.prefetchSize=50"/> <to uri="mock:results"/> </route> </camelContext>
Consuming Advisory Messages
ActiveMQ can generate Advisory messages, which are put in topics you can consume. Such messages can help you send alerts in case you detect slow consumers or to build statistics (number of messages/produced per day, etc.) The following Spring DSL example shows you how to read messages from a topic.
Example
<route> <from uri="activemq:topic:ActiveMQ.Advisory.Connection?mapJmsMessage=false" /> <convertBodyTo type="java.lang.String"/> <transform> <simple>${in.body} </simple> </transform> <to uri="file://data/activemq/?fileExist=Append&ileName=advisoryConnection-${date:now:yyyyMMdd}.txt" /> </route>
If you consume a message on a queue, you should see the following files under the data/activemq folder :
advisoryConnection-20100312.txt advisoryProducer-20100312.txt
and containing string:
Example
ActiveMQMessage {commandId = 0, responseRequired = false, messageId = ID:dell-charles-3258-1268399815140 -1:0:0:0:221, originalDestination = null, originalTransactionId = null, producerId = ID:dell-charles- 3258-1268399815140-1:0:0:0, destination = topic://ActiveMQ.Advisory.Connection, transactionId = null, expiration = 0, timestamp = 0, arrival = 0, brokerInTime = 1268403383468, brokerOutTime = 1268403383468, correlationId = null, replyTo = null, persistent = false, type = Advisory, priority = 0, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = org.apache.activemq.util.ByteSequence@17e2705, dataStructure = ConnectionInfo {commandId = 1, responseRequired = true, connectionId = ID:dell-charles-3258-1268399815140-2:50, clientId = ID:dell-charles-3258-1268399815140-14:0, userName = , password = *****, brokerPath = null, brokerMasterConnector = false, manageable = true, clientMaster = true}, redeliveryCounter = 0, size = 0, properties = {originBrokerName=master, originBrokerId=ID:dell-charles- 3258-1268399815140-0:0, originBrokerURL=vm://master}, readOnlyProperties = true, readOnlyBody = true, droppable = false}
Getting Component JAR
You need this dependency:
-
camel-activemq
ActiveMQ is an extension of the JMS component released with the ActiveMQ project.
<dependency> <groupId>org.fusesource</groupId> <artifactId>camel-activemq</artifactId> <version>7.11.0.fuse-sb2-7_11_0-00035-redhat-00001</version> </dependency>
Chapter 3. AHC Component
Available as of Camel version 2.8
The ahc: component provides HTTP based endpoints for consuming external HTTP resources (as a client to call external servers using HTTP).
The component uses the Async Http Client library.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-ahc</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
3.1. URI format
ahc:http://hostname[:port][/resourceUri][?options] ahc:https://hostname[:port][/resourceUri][?options]
Will by default use port 80 for HTTP and 443 for HTTPS.
You can append query options to the URI in the following format, ?option=value&option=value&…
3.2. AhcEndpoint Options
The AHC endpoint is configured using URI syntax:
ahc:httpUri
with the following path and query parameters:
3.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
httpUri | Required The URI to use such as http://hostname:port/path | URI |
3.2.2. Query Parameters (13 parameters):
Name | Description | Default | Type |
---|---|---|---|
bridgeEndpoint (producer) | If the option is true, then the Exchange.HTTP_URI header is ignored, and use the endpoint’s URI for request. You may also set the throwExceptionOnFailure to be false to let the AhcProducer send all the fault response back. | false | boolean |
bufferSize (producer) | The initial in-memory buffer size used when transferring data between Camel and AHC Client. | 4096 | int |
connectionClose (producer) | Define if the Connection Close header has to be added to HTTP Request. This parameter is false by default | false | boolean |
cookieHandler (producer) | Configure a cookie handler to maintain a HTTP session | CookieHandler | |
headerFilterStrategy (producer) | To use a custom HeaderFilterStrategy to filter header to and from Camel message. | HeaderFilterStrategy | |
throwExceptionOnFailure (producer) | Option to disable throwing the AhcOperationFailedException 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 (for example using Jetty or Servlet Camel components). On the producer side the exception will be deserialized and thrown as is, instead of the AhcOperationFailedException. 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 |
binding (advanced) | To use a custom AhcBinding which allows to control how to bind between AHC and Camel. | AhcBinding | |
clientConfig (advanced) | To configure the AsyncHttpClient to use a custom com.ning.http.client.AsyncHttpClientConfig instance. | AsyncHttpClientConfig | |
clientConfigOptions (advanced) | To configure the AsyncHttpClientConfig using the key/values from the Map. | Map | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
clientConfigRealmOptions (security) | To configure the AsyncHttpClientConfig Realm using the key/values from the Map. | Map | |
sslContextParameters (security) | Reference to a org.apache.camel.util.jsse.SSLContextParameters in the Registry. This reference overrides any configured SSLContextParameters at the component level. See Using the JSSE Configuration Utility. Note that configuring this option will override any SSL/TLS configuration options provided through the clientConfig option at the endpoint or component level. | SSLContextParameters |
3.3. Spring Boot Auto-Configuration
The component supports 9 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.ahc.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.ahc.binding | To use a custom AhcBinding which allows to control how to bind between AHC and Camel. The option is a org.apache.camel.component.ahc.AhcBinding type. | String | |
camel.component.ahc.client | To use a custom AsyncHttpClient. The option is a org.asynchttpclient.AsyncHttpClient type. | String | |
camel.component.ahc.client-config | To configure the AsyncHttpClient to use a custom com.ning.http.client.AsyncHttpClientConfig instance. The option is a org.asynchttpclient.AsyncHttpClientConfig type. | String | |
camel.component.ahc.enabled | Enable ahc component | true | Boolean |
camel.component.ahc.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. | String | |
camel.component.ahc.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.ahc.ssl-context-parameters | Reference to a org.apache.camel.util.jsse.SSLContextParameters in the Registry. Note that configuring this option will override any SSL/TLS configuration options provided through the clientConfig option at the endpoint or component level. The option is a org.apache.camel.util.jsse.SSLContextParameters type. | String | |
camel.component.ahc.use-global-ssl-context-parameters | Enable usage of global SSL context parameters. | false | Boolean |
3.4. AhcComponent Options
The AHC component supports 8 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
client (advanced) | To use a custom AsyncHttpClient | AsyncHttpClient | |
binding (advanced) | To use a custom AhcBinding which allows to control how to bind between AHC and Camel. | AhcBinding | |
clientConfig (advanced) | To configure the AsyncHttpClient to use a custom com.ning.http.client.AsyncHttpClientConfig instance. | AsyncHttpClientConfig | |
sslContextParameters (security) | Reference to a org.apache.camel.util.jsse.SSLContextParameters in the Registry. Note that configuring this option will override any SSL/TLS configuration options provided through the clientConfig option at the endpoint or component level. | SSLContextParameters | |
allowJavaSerialized Object (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 |
useGlobalSslContext Parameters (security) | Enable usage of global SSL context parameters. | false | boolean |
headerFilterStrategy (filter) | To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message. | HeaderFilterStrategy | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
Notice that setting any of the options on the AhcComponent
will propagate those options to AhcEndpoints
being created. However the AhcEndpoint
can also configure/override a custom option. Options set on endpoints will always take precedence over options from the AhcComponent
.
3.5. Message Headers
Name | Type | Description |
---|---|---|
|
| URI to call. Will override existing URI set directly on the endpoint. |
|
|
Request URI’s path, the header will be used to build the request URI with the HTTP_URI. If the path is start with "/", http producer will try to find the relative path based on the Exchange.HTTP_BASE_URI header or the |
|
| Camel 2.11 onwards: URI parameters. Will override existing URI parameters set directly on the endpoint. |
|
| The HTTP response code from the external server. Is 200 for OK. |
|
| Character encoding. |
|
|
The HTTP content type. Is set on both the IN and OUT message to provide a content type, such as |
|
|
The HTTP content encoding. Is set on both the IN and OUT message to provide a content encoding, such as |
3.6. 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.
3.7. 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
AhcOperationFailedException
with the information. Response code is 400+, Camel regards it as an external server failure and will throw a
AhcOperationFailedException
with the information.throwExceptionOnFailure
The option,
throwExceptionOnFailure
, can be set tofalse
to prevent theAhcOperationFailedException
from being thrown for failed response codes. This allows you to get any response from the remote server.
3.8. AhcOperationFailedException
This 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
3.9. Calling using GET or POST
The following algorithm is used to determine if either GET
or POST
HTTP method should be used:
1. Use method provided in header.
2. GET
if query string is provided in header.
3. GET
if endpoint is configured with a query string.
4. POST
if there is data to send (body is not null).
5. GET
otherwise.
3.10. 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("ahc:http://oldhost");
And the equivalent Spring sample:
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring"> <route> <from uri="direct:start"/> <to uri="ahc: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("ahc:http://oldhost");
3.11. Configuring URI Parameters
The ahc 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("ahc: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("ahc:http://oldhost");
3.12. How to set the http method 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("POST")) .to("ahc:http://www.google.com") .to("mock:results");
And the equivalent Spring sample:
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring"> <route> <from uri="direct:start"/> <setHeader headerName="CamelHttpMethod"> <constant>POST</constant> </setHeader> <to uri="ahc:http://www.google.com"/> <to uri="mock:results"/> </route> </camelContext>
3.13. 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");
3.13.1. 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("ahc:http://www.google.com/search?q=Camel", null);
3.13.2. 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("ahc: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.
3.13.3. Getting the Response Code
You can get the HTTP response code from the AHC component by getting the value from the Out message header with Exchange.HTTP_RESPONSE_CODE
.
Exchange exchange = template.send("ahc: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);
3.14. Configuring AsyncHttpClient
The AsyncHttpClient
client uses a AsyncHttpClientConfig
to configure the client. See the documentation at
Async Http Client for more details.
In Camel 2.8, configuration is limited to using the builder pattern provided by AsyncHttpClientConfig.Builder
. In Camel 2.8, the AsyncHttpClientConfig
doesn’t support getters/setters so its not easy to create/configure using a Spring bean style (eg the <bean> tag in the XML file).
The example below shows how to use a builder to create the AsyncHttpClientConfig
which we configure on the AhcComponent
.
In Camel 2.9, the AHC component uses Async HTTP library 1.6.4. This newer version provides added support for plain bean style configuration. The AsyncHttpClientConfigBean
class provides getters and setters for the configuration options available in AsyncHttpClientConfig
. An instance of AsyncHttpClientConfigBean
may be passed directly to the AHC component or referenced in an endpoint URI using the clientConfig
URI parameter.
Also available in Camel 2.9 is the ability to set configuration options directly in the URI. URI parameters starting with "clientConfig." can be used to set the various configurable properties of AsyncHttpClientConfig
. The properties specified in the endpoint URI are merged with those specified in the configuration referenced by the "clientConfig" URI parameter with those being set using the "clientConfig." parameter taking priority. The AsyncHttpClientConfig
instance referenced is always copied for each endpoint such that settings on one endpoint will remain independent of settings on any previously created endpoints. The example below shows how to configure the AHC component using the "clientConfig." type URI parameters.
from("direct:start") .to("ahc:http://localhost:8080/foo?clientConfig.maxRequestRetry=3&clientConfig.followRedirects=true")
3.15. SSL Support (HTTPS)
Using the JSSE Configuration Utility
As of Camel 2.9, the AHC 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 AHC component.
Programmatic configuration of the component
KeyStoreParameters ksp = new KeyStoreParameters(); ksp.setResource("/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); AhcComponent component = context.getComponent("ahc", AhcComponent.class); component.setSslContextParameters(scp));
Spring DSL based configuration of endpoint
... <camel:sslContextParameters id="sslContextParameters"> <camel:keyManagers keyPassword="keyPassword"> <camel:keyStore resource="/users/home/server/keystore.jks" password="keystorePassword"/> </camel:keyManagers> </camel:sslContextParameters>... ... <to uri="ahc:https://localhost/foo?sslContextParameters=#sslContextParameters"/> ...
3.16. See Also
Chapter 4. AHC Websocket Component
Available as of Camel version 2.14
The ahc-ws component provides Websocket based endpoints for a client communicating with external servers over Websocket (as a client opening a websocket connection to an external server).
The component uses the AHC component that in turn uses the Async Http Client library.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-ahc-ws</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
4.1. URI Format
ahc-ws://hostname[:port][/resourceUri][?options] ahc-wss://hostname[:port][/resourceUri][?options]
Will by default use port 80 for ahc-ws and 443 for ahc-wss.
4.2. AHC-WS Options
As the AHC-WS component is based on the AHC component, you can use the various configuration options of the AHC component.
The AHC Websocket component supports 8 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
client (advanced) | To use a custom AsyncHttpClient | AsyncHttpClient | |
binding (advanced) | To use a custom AhcBinding which allows to control how to bind between AHC and Camel. | AhcBinding | |
clientConfig (advanced) | To configure the AsyncHttpClient to use a custom com.ning.http.client.AsyncHttpClientConfig instance. | AsyncHttpClientConfig | |
sslContextParameters (security) | Reference to a org.apache.camel.util.jsse.SSLContextParameters in the Registry. Note that configuring this option will override any SSL/TLS configuration options provided through the clientConfig option at the endpoint or component level. | SSLContextParameters | |
allowJavaSerialized Object (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 |
useGlobalSslContext Parameters (security) | Enable usage of global SSL context parameters. | false | boolean |
headerFilterStrategy (filter) | To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message. | HeaderFilterStrategy | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The AHC Websocket endpoint is configured using URI syntax:
ahc-ws:httpUri
with the following path and query parameters:
4.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
httpUri | Required The URI to use such as http://hostname:port/path | URI |
4.2.2. Query Parameters (18 parameters):
Name | Description | Default | Type |
---|---|---|---|
bridgeEndpoint (common) | If the option is true, then the Exchange.HTTP_URI header is ignored, and use the endpoint’s URI for request. You may also set the throwExceptionOnFailure to be false to let the AhcProducer send all the fault response back. | false | boolean |
bufferSize (common) | The initial in-memory buffer size used when transferring data between Camel and AHC Client. | 4096 | int |
headerFilterStrategy (common) | To use a custom HeaderFilterStrategy to filter header to and from Camel message. | HeaderFilterStrategy | |
throwExceptionOnFailure (common) | Option to disable throwing the AhcOperationFailedException 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 (common) | 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 (for example using Jetty or Servlet Camel components). On the producer side the exception will be deserialized and thrown as is, instead of the AhcOperationFailedException. 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 |
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 |
sendMessageOnError (consumer) | Whether to send an message if the web-socket listener received an error. | false | boolean |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
connectionClose (producer) | Define if the Connection Close header has to be added to HTTP Request. This parameter is false by default | false | boolean |
cookieHandler (producer) | Configure a cookie handler to maintain a HTTP session | CookieHandler | |
useStreaming (producer) | To enable streaming to send data as multiple text fragments. | false | boolean |
binding (advanced) | To use a custom AhcBinding which allows to control how to bind between AHC and Camel. | AhcBinding | |
clientConfig (advanced) | To configure the AsyncHttpClient to use a custom com.ning.http.client.AsyncHttpClientConfig instance. | AsyncHttpClientConfig | |
clientConfigOptions (advanced) | To configure the AsyncHttpClientConfig using the key/values from the Map. | Map | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
clientConfigRealmOptions (security) | To configure the AsyncHttpClientConfig Realm using the key/values from the Map. | Map | |
sslContextParameters (security) | Reference to a org.apache.camel.util.jsse.SSLContextParameters in the Registry. This reference overrides any configured SSLContextParameters at the component level. See Using the JSSE Configuration Utility. Note that configuring this option will override any SSL/TLS configuration options provided through the clientConfig option at the endpoint or component level. | SSLContextParameters |
4.3. Spring Boot Auto-Configuration
The component supports 9 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.ahc-ws.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.ahc-ws.binding | To use a custom AhcBinding which allows to control how to bind between AHC and Camel. The option is a org.apache.camel.component.ahc.AhcBinding type. | String | |
camel.component.ahc-ws.client | To use a custom AsyncHttpClient. The option is a org.asynchttpclient.AsyncHttpClient type. | String | |
camel.component.ahc-ws.client-config | To configure the AsyncHttpClient to use a custom com.ning.http.client.AsyncHttpClientConfig instance. The option is a org.asynchttpclient.AsyncHttpClientConfig type. | String | |
camel.component.ahc-ws.enabled | Enable ahc-ws component | true | Boolean |
camel.component.ahc-ws.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. | String | |
camel.component.ahc-ws.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.ahc-ws.ssl-context-parameters | Reference to a org.apache.camel.util.jsse.SSLContextParameters in the Registry. Note that configuring this option will override any SSL/TLS configuration options provided through the clientConfig option at the endpoint or component level. The option is a org.apache.camel.util.jsse.SSLContextParameters type. | String | |
camel.component.ahc-ws.use-global-ssl-context-parameters | Enable usage of global SSL context parameters. | false | Boolean |
4.4. Writing and Reading Data over Websocket
An ahc-ws endpoint can either write data to the socket or read from the socket, depending on whether the endpoint is configured as the producer or the consumer, respectively.
4.5. Configuring URI to Write or Read Data
In the route below, Camel will write to the specified websocket connection.
from("direct:start") .to("ahc-ws://targethost");
And the equivalent Spring sample:
<camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="direct:start"/> <to uri="ahc-ws://targethost"/> </route> </camelContext>
In the route below, Camel will read from the specified websocket connection.
from("ahc-ws://targethost") .to("direct:next");
And the equivalent Spring sample:
<camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="ahc-ws://targethost"/> <to uri="direct:next"/> </route> </camelContext>
4.6. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AHC
- Atmosphere-Websocket
Chapter 5. AMQP Component
Available as of Camel version 1.2
The amqp: component supports the AMQP 1.0 protocol using the JMS Client API of the Qpid project. In case you want to use AMQP 0.9 (in particular RabbitMQ) you might also be interested in the Camel RabbitMQ component. Please keep in mind that prior to the Camel 2.17.0 AMQP component supported AMQP 0.9 and above, however since Camel 2.17.0 it supports only AMQP 1.0.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-amqp</artifactId> <version>${camel.version}</version> <!-- use the same version as your Camel core version --> </dependency>
5.1. URI format
amqp:[queue:|topic:]destinationName[?options]
5.2. AMQP Options
You can specify all of the various configuration options of the JMS component after the destination name.
The AMQP component supports 81 options which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | To use a shared JMS configuration | JmsConfiguration | |
acceptMessagesWhile Stopping (consumer) | 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 |
allowReplyManagerQuick Stop (consumer) | 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 |
acknowledgementMode (consumer) | The JMS acknowledgement mode defined as an Integer. Allows you to set vendor-specific extensions to the acknowledgment mode.For the regular modes, it is preferable to use the acknowledgementModeName instead. | int | |
eagerLoadingOf Properties (consumer) | Enables eager loading of JMS properties 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 | false | boolean |
acknowledgementModeName (consumer) | The JMS acknowledgement name, which is one of: SESSION_TRANSACTED, CLIENT_ACKNOWLEDGE, AUTO_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE | AUTO_ ACKNOWLEDGE | String |
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. | CACHE_AUTO | String |
replyToCacheLevelName (producer) | 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 | |
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. If using Apache ActiveMQ you may prefer to use Virtual Topics instead. | 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 |
replyToConcurrent Consumers (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 |
connectionFactory (common) | The connection factory to be use. A connection factory must be configured either on the component or endpoint. | ConnectionFactory | |
username (security) | Username to use with the ConnectionFactory. You can also configure username/password directly on the ConnectionFactory. | String | |
password (security) | Password to use with the ConnectionFactory. You can also configure username/password directly on the ConnectionFactory. | String | |
deliveryPersistent (producer) | Specifies whether persistent delivery is used by default. | true | boolean |
deliveryMode (producer) | Specifies the delivery mode to be used. Possibles values are those defined by javax.jms.DeliveryMode. NON_PERSISTENT = 1 and PERSISTENT = 2. | Integer | |
durableSubscriptionName (common) | The durable subscriber name for specifying durable topic subscriptions. The clientId option must be configured as well. | String | |
exceptionListener (advanced) | Specifies the JMS Exception Listener that is to be notified of any underlying JMS exceptions. | ExceptionListener | |
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 | |
errorHandlerLogging Level (logging) | Allows to configure the default errorHandler logging level for logging uncaught exceptions. | WARN | LoggingLevel |
errorHandlerLogStack Trace (logging) | Allows to control whether stacktraces should be logged or not, by the default errorHandler. | 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 |
exposeListenerSession (consumer) | Specifies whether the listener session should be exposed when consuming messages. | false | boolean |
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 |
idleConsumerLimit (advanced) | Specify the limit for the number of consumers that are allowed to be idle at any given time. | 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 | |
replyToMaxConcurrent Consumers (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 | |
replyOnTimeoutToMax ConcurrentConsumers (producer) | Specifies the maximum number of concurrent consumers for continue routing when timeout occurred when using request/reply over JMS. | 1 | int |
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 | |
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 |
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 |
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 |
alwaysCopyMessage (producer) | 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 |
useMessageIDAs CorrelationID (advanced) | Specifies whether JMSMessageID should always be used as JMSCorrelationID for InOut messages. | false | boolean |
priority (producer) | Values greater than 1 specify the message priority when sending (where 0 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 | int |
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 |
taskExecutor (consumer) | 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 |
timeToLive (producer) | When sending messages, specifies the time-to-live of the message (in milliseconds). | -1 | long |
transacted (transaction) | Specifies whether to use transacted mode | false | boolean |
lazyCreateTransaction Manager (transaction) | If true, Camel will create a JmsTransactionManager, if there is no transactionManager injected when option transacted=true. | true | boolean |
transactionManager (transaction) | The Spring transaction manager to use. | PlatformTransaction Manager | |
transactionName (transaction) | The name of the transaction to use. | String | |
transactionTimeout (transaction) | The timeout value of the transaction (in seconds), if using transacted mode. | -1 | int |
testConnectionOn Startup (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 |
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 |
forceSendOriginal Message (producer) | 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 |
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 |
requestTimeoutChecker Interval (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 |
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. | 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. | false | boolean |
transferFault (advanced) | If enabled and you are using Request Reply messaging (InOut) and an Exchange failed with a SOAP fault (not exception) on the consumer side, then the fault flag on Message#isFault() will be send back in the response as a JMS header with the key org.apache.camel.component.jms.JmsConstants#JMS_TRANSFER_FAULT#JMS_TRANSFER_FAULT. If the client is Camel, the returned fault flag will be set on the org.apache.camel.Message#setFault(boolean). You may want to enable this when using Camel components that support faults such as SOAP based such as cxf or spring-ws. | false | boolean |
jmsOperations (advanced) | Allows you to use your own implementation of the org.springframework.jms.core.JmsOperations interface. Camel uses JmsTemplate as default. Can be used for testing purpose, but not used much as stated in the spring API docs. | JmsOperations | |
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 | |
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. | ReplyToType | |
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 |
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 will pickup 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 |
allowNullBody (producer) | 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 |
includeSentJMS MessageID (producer) | 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 |
includeAllJMSX Properties (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 |
defaultTaskExecutor Type (consumer) | 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. | DefaultTaskExecutor Type | |
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. | JmsKeyFormatStrategy | |
allowAdditionalHeaders (producer) | 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 | |
queueBrowseStrategy (advanced) | To use a custom QueueBrowseStrategy when browsing queues | QueueBrowseStrategy | |
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 | |
waitForProvision CorrelationToBeUpdated Counter (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 |
waitForProvision CorrelationToBeUpdated ThreadSleepingTime (advanced) | Interval in millis to sleep each time while waiting for provisional correlation id to be updated. | 100 | long |
correlationProperty (producer) | Use this JMS property to correlate messages in InOut exchange pattern (request-reply) instead of JMSCorrelationID property. This allows you to exchange messages with systems that do not correlate messages using JMSCorrelationID JMS property. If used JMSCorrelationID will not be used or set by Camel. The value of here named property will be generated if not supplied in the header of the message under the same name. | 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 |
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 |
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 | |
streamMessageType Enabled (producer) | 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 |
formatDateHeadersTo Iso8601 (producer) | Sets whether date headers should be formatted according to the ISO 8601 standard. | false | boolean |
headerFilterStrategy (filter) | To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message. | HeaderFilterStrategy | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The AMQP endpoint is configured using URI syntax:
amqp:destinationType:destinationName
with the following path and query parameters:
5.2.1. Path Parameters (2 parameters):
Name | Description | Default | Type |
---|---|---|---|
destinationType | The kind of destination to use | queue | String |
destinationName | Required Name of the queue or topic to use as destination | String |
5.2.2. Query Parameters (92 parameters):
Name | Description | Default | Type |
---|---|---|---|
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. 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. | JmsMessageType | |
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 | AUTO_ ACKNOWLEDGE | String |
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 will pickup 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 |
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 |
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. | 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 | |
replyTo (consumer) | Provides an explicit ReplyTo destination, which overrides any incoming value of Message.getJMSReplyTo(). | String | |
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) | 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) | 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) | 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. | Default | ConsumerType |
defaultTaskExecutorType (consumer) | 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. | DefaultTaskExecutor Type | |
eagerLoadingOfProperties (consumer) | 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 | false | boolean |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
exposeListenerSession (consumer) | Specifies whether the listener session should be exposed when consuming messages. | false | boolean |
replyToSameDestination Allowed (consumer) | 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) | 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. Possibles values are those defined by javax.jms.DeliveryMode. NON_PERSISTENT = 1 and PERSISTENT = 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 0 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 | 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 |
replyToMaxConcurrent Consumers (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 | |
replyToOnTimeoutMax ConcurrentConsumers (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. | 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) | 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) | 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) | 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) | 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) | 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) | 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) | 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) | 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 | |
replyToDestinationSelector Name (producer) | 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) | 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 |
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. | String | |
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 |
messageListenerContainer Factory (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. | MessageListener ContainerFactory | |
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 |
requestTimeoutChecker Interval (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, or Camel is allowed to use asynchronous processing (if supported). | 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. | 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. | false | boolean |
transferFault (advanced) | If enabled and you are using Request Reply messaging (InOut) and an Exchange failed with a SOAP fault (not exception) on the consumer side, then the fault flag on Message#isFault() will be send back in the response as a JMS header with the key org.apache.camel.component.jms.JmsConstants#JMS_TRANSFER_FAULT#JMS_TRANSFER_FAULT. If the client is Camel, the returned fault flag will be set on the org.apache.camel.Message#setFault(boolean). You may want to enable this when using Camel components that support faults such as SOAP based such as cxf or spring-ws. | false | boolean |
useMessageIDAsCorrelation ID (advanced) | Specifies whether JMSMessageID should always be used as JMSCorrelationID for InOut messages. | false | boolean |
waitForProvisionCorrelation ToBeUpdatedCounter (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 |
waitForProvisionCorrelation ToBeUpdatedThreadSleeping Time (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. | 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 |
lazyCreateTransaction Manager (transaction) | If true, Camel will create a JmsTransactionManager, if there is no transactionManager injected when option transacted=true. | true | boolean |
transactionManager (transaction) | The Spring transaction manager to use. | PlatformTransaction Manager | |
transactionName (transaction) | The name of the transaction to use. | String | |
transactionTimeout (transaction) | The timeout value of the transaction (in seconds), if using transacted mode. | -1 | int |
5.3. Spring Boot Auto-Configuration
The component supports 81 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
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 | The JMS acknowledgement mode defined as an Integer. Allows you to set vendor-specific extensions to the acknowledgment mode.For the regular modes, it is preferable to use the acknowledgementModeName instead. | Integer | |
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-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.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.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 will pickup 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.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. If using Apache ActiveMQ you may prefer to use Virtual Topics instead. | 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. | String | |
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. | String | |
camel.component.amqp.correlation-property | Use this JMS property to correlate messages in InOut exchange pattern (request-reply) instead of JMSCorrelationID property. This allows you to exchange messages with systems that do not correlate messages using JMSCorrelationID JMS property. If used JMSCorrelationID will not be used or set by Camel. The value of here named property will be generated if not supplied in the header of the message under the same name. | 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. | DefaultTaskExecutor Type | |
camel.component.amqp.delivery-mode | Specifies the delivery mode to be used. Possibles 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. | String | |
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 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 | false | Boolean |
camel.component.amqp.enabled | Enable amqp component | true | 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. | String | |
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. | String | |
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 date headers 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. | String | |
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-j-m-s-x-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-sent-j-m-s-message-i-d | 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. The option is a org.apache.camel.component.jms.JmsKeyFormatStrategy type. | String | |
camel.component.amqp.jms-operations | Allows you to use your own implementation of the org.springframework.jms.core.JmsOperations interface. Camel uses JmsTemplate as default. Can be used for testing purpose, but not used much as stated in the spring API docs. The option is a org.springframework.jms.core.JmsOperations type. | String | |
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.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. | String | |
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. | String | |
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-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 0 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. | String | |
camel.component.amqp.receive-timeout | The timeout for receiving messages (in milliseconds). | 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. | 5000 | Long |
camel.component.amqp.reply-on-timeout-to-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-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-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-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. | 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. | 1000 | Long |
camel.component.amqp.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
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.task-executor | Allows you to specify a custom task executor for consuming messages. The option is a org.springframework.core.task.TaskExecutor type. | String | |
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.transaction-manager | The Spring transaction manager to use. The option is a org.springframework.transaction.PlatformTransactionManager type. | String | |
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. | 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. | false | Boolean |
camel.component.amqp.transfer-fault | If enabled and you are using Request Reply messaging (InOut) and an Exchange failed with a SOAP fault (not exception) on the consumer side, then the fault flag on Message#isFault() will be send back in the response as a JMS header with the key org.apache.camel.component.jms.JmsConstants #JMS_TRANSFER_FAULT#JMS_TRANSFER_FAULT. If the client is Camel, the returned fault flag will be set on the org.apache.camel.Message#setFault(boolean). You may want to enable this when using Camel components that support faults such as SOAP based such as cxf or spring-ws. | false | Boolean |
camel.component.amqp.use-message-i-d-as-correlation-i-d | 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. | 100 | Long |
5.4. 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");
5.5. Configuring AMQP component
Starting from the Camel 2.16.1 you can also use the AMQPComponent#amqp10Component(String connectionURI)
factory method to return the AMQP 1.0 component with the pre-configured topic prefix:
Creating AMQP 1.0 component
AMQPComponent amqp = AMQPComponent.amqp10Component("amqp://guest:guest@localhost:5672");
Keep in mind that starting from the Camel 2.17 the AMQPComponent#amqp10Component(String connectionURI)
factory method has been deprecated on the behalf of the AMQPComponent#amqpComponent(String connectionURI)
:
Creating AMQP 1.0 component
AMQPComponent amqp = AMQPComponent.amqpComponent("amqp://localhost:5672"); AMQPComponent authorizedAmqp = AMQPComponent.amqpComponent("amqp://localhost:5672", "user", "password");
Starting from Camel 2.17, in order to automatically configure the AMQP component, you can also add an instance of org.apache.camel.component.amqp.AMQPConnectionDetails
to the registry. 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 Camel properties 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 take a look at the QPID JMS client configuration
5.6. 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.
5.7. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 6. APNS Component
Available as of Camel version 2.8
The apns component is used for sending notifications to iOS devices. The apns components use javapns library.
The component supports sending notifications to Apple Push Notification Servers (APNS) and consuming feedback from the servers.
The consumer is configured with 3600 seconds for polling by default because it is a best practice to consume feedback stream from Apple Push Notification Servers only from time to time. For example: every 1 hour to avoid flooding the servers.
The feedback stream gives informations about inactive devices. You only need to get this informations every some hours if your mobile application is not a heavily used one.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-apns</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
6.1. URI format
To send notifications:
apns:notify[?options]
To consume feedback:
apns:consumer[?options]
6.2. Options
The APNS component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
apnsService (common) | Required The ApnsService to use. The org.apache.camel.component.apns.factory.ApnsServiceFactory can be used to build a ApnsService | ApnsService | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The APNS endpoint is configured using URI syntax:
apns:name
with the following path and query parameters:
6.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
name | Name of the endpoint | String |
6.2.2. Query Parameters (20 parameters):
Name | Description | Default | Type |
---|---|---|---|
tokens (common) | Configure this property in case you want to statically declare tokens related to devices you want to notify. Tokens are 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 |
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) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
pollStrategy (consumer) | 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. | PollingConsumerPoll Strategy | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 1000 | 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. | 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. | ScheduledExecutor Service | |
scheduler (scheduler) | To use a cron scheduler from either camel-spring or camel-quartz2 component | none | ScheduledPollConsumer Scheduler |
schedulerProperties (scheduler) | To configure additional properties when using a custom scheduler or any of the Quartz2, Spring based scheduler. | Map | |
startScheduler (scheduler) | Whether the scheduler should be auto started. | true | boolean |
timeUnit (scheduler) | Time unit for initialDelay and delay options. | MILLISECONDS | TimeUnit |
useFixedDelay (scheduler) | Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean |
6.3. Spring Boot Auto-Configuration
The component supports 3 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.apns.apns-service | The ApnsService to use. The org.apache.camel.component.apns.factory.ApnsServiceFactory can be used to build a ApnsService. The option is a com.notnoop.apns.ApnsService type. | String | |
camel.component.apns.enabled | Enable apns component | true | Boolean |
camel.component.apns.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
You can append query options to the URI in the following format, ?option=value&option=value&…
6.3.1. Component
The ApnsComponent
must be configured with a com.notnoop.apns.ApnsService
. The service can be created and configured using the org.apache.camel.component.apns.factory.ApnsServiceFactory
. See further below for an example. And as well in the test source code.
6.3.1.1. SSL Setting
In order to use secure connection, an instance of org.apache.camel.util.jsse.SSLContextParameters
should be injected to org.apache.camel.component.apns.factory.ApnsServiceFactory
which is used to configure the component. See the test resources for an example. ssl example
6.4. Exchange data format
When Camel will fetch feedback data corresponding to inactive devices, it will retrieve a List of InactiveDevice objects. Each InactiveDevice object of the retrieved list will be setted as the In body, and then processed by the consumer endpoint.
6.5. Message Headers
Camel Apns uses these headers.
Property | Default | Description |
---|---|---|
| Empty by default. | |
|
| In case you choose PAYLOAD for the message type, then the message will be considered as a APNS payload and sent as is. In case you choose STRING, message will be converted as a APNS payload. From Camel 2.16 onwards APNS_NOTIFICATION is used for sending message body as com.notnoop.apns.ApnsNotification types. |
6.6. ApnsServiceFactory builder callback
ApnsServiceFactory
comes with the empty callback method that could be used to configure (or even replace) the default ApnsServiceBuilder
instance. The signature of the method could look as follows:
protected ApnsServiceBuilder configureServiceBuilder(ApnsServiceBuilder serviceBuilder);
And could be used like as follows:
ApnsServiceFactory proxiedApnsServiceFactory = new ApnsServiceFactory(){ @Override protected ApnsServiceBuilder configureServiceBuilder(ApnsServiceBuilder serviceBuilder) { return serviceBuilder.withSocksProxy("my.proxy.com", 6666); } };
6.7. Samples
6.7.1. Camel Xml route
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <!-- Replace by desired values --> <bean id="apnsServiceFactory" class="org.apache.camel.component.apns.factory.ApnsServiceFactory"> <!-- Optional configuration of feedback host and port --> <!-- <property name="feedbackHost" value="localhost" /> --> <!-- <property name="feedbackPort" value="7843" /> --> <!-- Optional configuration of gateway host and port --> <!-- <property name="gatewayHost" value="localhost" /> --> <!-- <property name="gatewayPort" value="7654" /> --> <!-- Declaration of certificate used --> <!-- from Camel 2.11 onwards you can use prefix: classpath:, file: to refer to load the certificate from classpath or file. Default it classpath --> <property name="certificatePath" value="certificate.p12" /> <property name="certificatePassword" value="MyCertPassword" /> <!-- Optional connection strategy - By Default: No need to configure --> <!-- Possible options: NON_BLOCKING, QUEUE, POOL or Nothing --> <!-- <property name="connectionStrategy" value="POOL" /> --> <!-- Optional pool size --> <!-- <property name="poolSize" value="15" /> --> <!-- Optional connection strategy - By Default: No need to configure --> <!-- Possible options: EVERY_HALF_HOUR, EVERY_NOTIFICATION or Nothing (Corresponds to NEVER javapns option) --> <!-- <property name="reconnectionPolicy" value="EVERY_HALF_HOUR" /> --> </bean> <bean id="apnsService" factory-bean="apnsServiceFactory" factory-method="getApnsService" /> <!-- Replace this declaration by wanted configuration --> <bean id="apns" class="org.apache.camel.component.apns.ApnsComponent"> <property name="apnsService" ref="apnsService" /> </bean> <camelContext id="camel-apns-test" xmlns="http://camel.apache.org/schema/spring"> <route id="apns-test"> <from uri="apns:consumer?initialDelay=10&delay=3600&timeUnit=SECONDS" /> <to uri="log:org.apache.camel.component.apns?showAll=true&multiline=true" /> <to uri="mock:result" /> </route> </camelContext> </beans>
6.7.2. Camel Java route
Create camel context and declare apns component programmatically
protected CamelContext createCamelContext() throws Exception { CamelContext camelContext = super.createCamelContext(); ApnsServiceFactory apnsServiceFactory = new ApnsServiceFactory(); apnsServiceFactory.setCertificatePath("classpath:/certificate.p12"); apnsServiceFactory.setCertificatePassword("MyCertPassword"); ApnsService apnsService = apnsServiceFactory.getApnsService(camelContext); ApnsComponent apnsComponent = new ApnsComponent(apnsService); camelContext.addComponent("apns", apnsComponent); return camelContext; }
[[APNS-ApnsProducer-iOStargetdevicedynamicallyconfiguredviaheader:"CamelApnsTokens"]] ApnsProducer - iOS target device dynamically configured via header: "CamelApnsTokens"
protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() throws Exception { from("direct:test") .setHeader(ApnsConstants.HEADER_TOKENS, constant(IOS_DEVICE_TOKEN)) .to("apns:notify"); } } }
ApnsProducer - iOS target device statically configured via uri
protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() throws Exception { from("direct:test"). to("apns:notify?tokens=" + IOS_DEVICE_TOKEN); } }; }
ApnsConsumer
from("apns:consumer?initialDelay=10&delay=3600&timeUnit=SECONDS") .to("log:com.apache.camel.component.apns?showAll=true&multiline=true") .to("mock:result");
6.8. See Also
Chapter 7. ASN.1 File DataFormat
Available as of Camel version 2.20
The ASN.1 Data Format [Introduction to ASN.1](https://www.itu.int/en/ITU-T/asn1/Pages/introduction.aspx) is a Camel Frameworks’s data format implementation based on Bouncy Castle’s bcprov-jdk18on library and jASN.1’s java compiler for the formal notation used for describing data transmitted by telecommunications protocols, regardless of language implementation and physical representation of these data, whatever the application, whether complex or very simple. Messages can be unmarshalled (conversion to simple Java POJO(s)) to plain Java objects. By the help of Camel’s routing engine and data transformations you can then play with POJO(s) and apply customised formatting and call other Camel Component’s to convert and send messages to upstream systems.
7.1. ASN.1 Data Format Options
The ASN.1 File dataformat supports 3 options, which are listed below.
Name | Default | Java Type | Description |
---|---|---|---|
usingIterator |
|
| If the asn1 file has more then one entry, the setting this option to true, allows to work with the splitter EIP, to split the data using an iterator in a streaming mode. |
clazzName |
| Name of class to use when unmarshalling | |
contentTypeHeader |
|
| Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. |
7.2. Spring Boot Auto-Configuration
The component supports 4 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.dataformat.asn1.clazz-name | Name of class to use when unmarshalling | String | |
camel.dataformat.asn1.content-type-header | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. | false | Boolean |
camel.dataformat.asn1.enabled | Whether to enable auto configuration of the asn1 data format. This is enabled by default. | Boolean | |
camel.dataformat.asn1.using-iterator | If the asn1 file has more then one entry, the setting this option to true, allows to work with the splitter EIP, to split the data using an iterator in a streaming mode. | false | Boolean |
ND
7.3. Unmarshal
There are 3 different ways to unmarshal ASN.1 structured messages. (Usually binary files)
In this first example we unmarshal BER file payload to OutputStream and send it to mock endpoint.
from("direct:unmarshal").unmarshal(asn1).to("mock:unmarshal");
In the second example we unmarshal BER file payload to byte array using Split EIP. The reason for applying Split EIP is that usually each BER file or (ASN.1 structured file) contains multiple records to process and Split EIP helps us to get each record in a file as byte arrays which is actually ASN1Primitive’s instance (by the use of Bouncy Castle’s ASN.1 support in bcprov-jdk18on library) Byte arrays then may be converted to ASN1Primitive by the help of public static method in (ASN1Primitive.fromByteArray) In such example, note that you need to set usingIterator=true
from("direct:unmarshal").unmarshal(asn1).split(body(Iterator.class)).streaming().to("mock:unmarshal");
In the last example we unmarshal BER file payload to plain old Java Objects using Split EIP. The reason for applying Split EIP is already mentioned in the previous example. Please note and keep in mind that reason. In such example we also need to set the fully qualified name of the class or <YourObject>.class reference through data format. The important thing to note here is that your object should have been generated by jasn1 compiler which is a nice tool to generate java object representations of your ASN.1 structure. For the reference usage of jasn1 compiler see [JASN.1 Project Page](https://www.openmuc.org/asn1/) and please also see how the compiler is invoked with the help of maven’s exec plugin. For example, in this data format’s unit tests an example ASN.1 structure(TestSMSBerCdr.asn1) is added in src/test/resources/asn1_structure
. jasn1 compiler is invoked and java object’s representations are generated in ${basedir}/target/generated/src/test/java
The nice thing about this example, you will get POJO instance at the mock endpoint or at whatever your endpoint is.
from("direct:unmarshaldsl") .unmarshal() .asn1("org.apache.camel.dataformat.asn1.model.testsmscbercdr.SmsCdr") .split(body(Iterator.class)).streaming() .to("mock:unmarshaldsl");
7.4. Dependencies
To use ASN.1 data format in your camel routes you need to add a dependency on camel-asn1 which implements this data format.
If you use Maven you can 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-asn1</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
Chapter 8. AS2 Component
The camel-as2
component for Karaf is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production.
These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process. For more information about the support scope of Red Hat Technology Preview features, see https://access.redhat.com/support/offerings/techpreview.
Available as of Camel version 2.22
The AS2 component provides transport of EDI messages using the HTTP transfer protocol as specified in RFC4130.
This component is currently a work in progress. Expect URI options and path and query parameters to change in future versions of this component.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-as2</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
8.1. URI format
as2://apiName/methodName
apiName can be one of:
- client
- server
8.2. AS2 Options
The AS2 component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (common) | To use the shared configuration | AS2Configuration | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The AS2 endpoint is configured using URI syntax:
as2:apiName
with the following path and query parameters:
8.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
apiName | Required What kind of operation to perform | AS2ApiName |
8.2.2. Query Parameters (30 parameters):
Name | Description | Default | Type |
---|---|---|---|
as2From (common) | The value of the AS2From header of AS2 message. | String | |
as2MessageStructure (common) | The structure of AS2 Message. One of: PLAIN - No encryption, no signature, SIGNED - No encryption, signature, ENCRYPTED - Encryption, no signature, ENCRYPTED_SIGNED - Encryption, signature | AS2MessageStructure | |
as2To (common) | The value of the AS2To header of AS2 message. | String | |
as2Version (common) | The version of the AS2 protocol. | 1.1 | String |
clientFqdn (common) | The Client Fully Qualified Domain Name (FQDN). Used in message ids sent by endpoint. | camel.apache.org | String |
dispositionNotificationTo (common) | The value of the Disposition-Notification-To header. Assigning a value to this parameter requests a message disposition notification (MDN) for the AS2 message. | String | |
ediMessageTransferEncoding (common) | The transfer encoding of EDI message. | String | |
ediMessageType (common) | The content type of EDI message. One of application/edifact, application/edi-x12, application/edi-consent | ContentType | |
encryptingAlgorithm (common) | The algorithm used to encrypt EDI message. | AS2EncryptionAlgorithm | |
encryptingCertificateChain (common) | The chain of certificates used to encrypt EDI message. | Certificate[] | |
encryptingPrivateKey (common) | The key used to encrypt the EDI message. | PrivateKey | |
from (common) | The value of the From header of AS2 message. | String | |
inBody (common) | Sets the name of a parameter to be passed in the exchange In Body | String | |
methodName (common) | Required What sub operation to use for the selected operation | String | |
requestUri (common) | The request URI of EDI message. | / | String |
server (common) | The value included in the Server message header identifying the AS2 Server. | Camel AS2 Server Endpoint | String |
serverFqdn (common) | The Server Fully Qualified Domain Name (FQDN). Used in message ids sent by endpoint. | camel.apache.org | String |
serverPortNumber (common) | The port number of server. | Integer | |
signedReceiptMicAlgorithms (common) | The list of algorithms, in order of preference, requested to generate a message integrity check (MIC) returned in message dispostion notification (MDN) | String[] | |
signingAlgorithm (common) | The algorithm used to sign EDI message. | AS2SignatureAlgorithm | |
signingCertificateChain (common) | The chain of certificates used to sign EDI message. | Certificate[] | |
signingPrivateKey (common) | The key used to sign the EDI message. | PrivateKey | |
subject (common) | The value of Subject header of AS2 message. | String | |
targetHostname (common) | The host name (IP or DNS name) of target host. | String | |
targetPortNumber (common) | The port number of target host. -1 indicates the scheme default port. | Integer | |
userAgent (common) | The value included in the User-Agent message header identifying the AS2 user agent. | Camel AS2 Client Endpoint | 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 |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
8.3. Spring Boot Auto-Configuration
The component supports 28 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.as2.configuration.api-name | What kind of operation to perform | AS2ApiName | |
camel.component.as2.configuration.as2-from | The value of the AS2From header of AS2 message. | String | |
camel.component.as2.configuration.as2-message-structure | The structure of AS2 Message. One of: PLAIN - No encryption, no signature, SIGNED - No encryption, signature, ENCRYPTED - Encryption, no signature, ENCRYPTED_SIGNED - Encryption, signature | AS2MessageStructure | |
camel.component.as2.configuration.as2-to | The value of the AS2To header of AS2 message. | String | |
camel.component.as2.configuration.as2-version | The version of the AS2 protocol. | 1.1 | String |
camel.component.as2.configuration.client-fqdn | The Client Fully Qualified Domain Name (FQDN). Used in message ids sent by endpoint. | camel.apache.org | String |
camel.component.as2.configuration.disposition-notification-to | The value of the Disposition-Notification-To header. Assigning a value to this parameter requests a message disposition notification (MDN) for the AS2 message. | String | |
camel.component.as2.configuration.edi-message-transfer-encoding | The transfer encoding of EDI message. | String | |
camel.component.as2.configuration.edi-message-type | The content type of EDI message. One of application/edifact, application/edi-x12, application/edi-consent | ContentType | |
camel.component.as2.configuration.encrypting-algorithm | The algorithm used to encrypt EDI message. | AS2EncryptionAlgorithm | |
camel.component.as2.configuration.encrypting-certificate-chain | The chain of certificates used to encrypt EDI message. | Certificate[] | |
camel.component.as2.configuration.encrypting-private-key | The key used to encrypt the EDI message. | PrivateKey | |
camel.component.as2.configuration.from | The value of the From header of AS2 message. | String | |
camel.component.as2.configuration.method-name | What sub operation to use for the selected operation | String | |
camel.component.as2.configuration.request-uri | The request URI of EDI message. | / | String |
camel.component.as2.configuration.server | The value included in the Server message header identifying the AS2 Server. | Camel AS2 Server Endpoint | String |
camel.component.as2.configuration.server-fqdn | The Server Fully Qualified Domain Name (FQDN). Used in message ids sent by endpoint. | camel.apache.org | String |
camel.component.as2.configuration.server-port-number | The port number of server. | Integer | |
camel.component.as2.configuration.signed-receipt-mic-algorithms | The list of algorithms, in order of preference, requested to generate a message integrity check (MIC) returned in message dispostion notification (MDN) | String[] | |
camel.component.as2.configuration.signing-algorithm | The algorithm used to sign EDI message. | AS2SignatureAlgorithm | |
camel.component.as2.configuration.signing-certificate-chain | The chain of certificates used to sign EDI message. | Certificate[] | |
camel.component.as2.configuration.signing-private-key | The key used to sign the EDI message. | PrivateKey | |
camel.component.as2.configuration.subject | The value of Subject header of AS2 message. | String | |
camel.component.as2.configuration.target-hostname | The host name (IP or DNS name) of target host. | String | |
camel.component.as2.configuration.target-port-number | The port number of target host. -1 indicates the scheme default port. | Integer | |
camel.component.as2.configuration.user-agent | The value included in the User-Agent message header identifying the AS2 user agent. | Camel AS2 Client Endpoint | String |
camel.component.as2.enabled | Whether to enable auto configuration of the as2 component. This is enabled by default. | Boolean | |
camel.component.as2.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
8.4. Client Endpoints:
Client endpoints use the endpoint prefix client
followed by the name of a method and associated options described next. The endpoint URI MUST contain the prefix client
.
as2://client/method?[options]
Endpoint options that are not mandatory are denoted by []. When there are no mandatory options for an endpoint, one of the set of [] options MUST be provided. Producer endpoints can also use a special option inBody
that in turn should contain the name of the endpoint option whose value will be contained in the Camel Exchange In message.
Any of the endpoint options can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format CamelAS2.<option>
. Note that the inBody
option overrides message header, i.e. the endpoint option inBody=option
would override a CamelAS2.option
header.
If a value is not provided for the option defaultRequest either in the endpoint URI or in a message header, it will be assumed to be null
. Note that the null
value will only be used if other options do not satisfy matching endpoints.
In case of AS2 API errors the endpoint will throw a RuntimeCamelException with a org.apache.http.HttpException derived exception cause.
Method | Options | Result Body Type |
---|---|---|
send | ediMessage, requestUri, subject, from, as2From, as2To, as2MessageStructure, ediMessageContentType, ediMessageTransferEncoding, dispositionNotificationTo, signedReceiptMicAlgorithms | org.apache.http.protocol.HttpCoreContext |
URI Options for client
Name | Type |
---|---|
ediMessage | String |
requestUri | String |
subject | String |
from | String |
as2From | String |
as2To | String |
as2MessageStructure | org.apache.camel.component.as2.api.AS2MessageStructure |
ediMessageContentType | String |
ediMessageTransferEncoding | String |
dispositionNotificationTo | String |
signedReceiptMicAlgorithms | String[] |
8.5. Server Endpoints:
Server endpoints use the endpoint prefix server
followed by the name of a method and associated options described next. The endpoint URI MUST contain the prefix server
.
as2://server/method?[options]
Endpoint options that are not mandatory are denoted by []. When there are no mandatory options for an endpoint, one of the set of [] options MUST be provided. Producer endpoints can also use a special option inBody
that in turn should contain the name of the endpoint option whose value will be contained in the Camel Exchange In message.
Any of the endpoint options can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format CamelAS2.<option>
. Note that the inBody
option overrides message header, i.e. the endpoint option inBody=option
would override a CamelAS2.option
header.
If a value is not provided for the option defaultRequest either in the endpoint URI or in a message header, it will be assumed to be null
. Note that the null
value will only be used if other options do not satisfy matching endpoints.
In case of AS2 API errors the endpoint will throw a RuntimeCamelException with a org.apache.http.HttpException derived exception cause.
Method | Options | Result Body Type |
---|---|---|
listen | requestUriPattern | org.apache.http.protocol.HttpCoreContext |
URI Options for server
Name | Type |
---|---|
requestUriPattern | String |
Chapter 9. Asterisk Component
Available as of Camel version 2.18
The asterisk: component allows you to work easily with an Asterisk PBX Server http://www.asterisk.org/ using asterisk-java
This component help to interface with Asterisk Manager Interface
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-asterisk</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
9.1. URI format
asterisk:name[?options]
9.2. Options
The Asterisk component has no options.
The Asterisk endpoint is configured using URI syntax:
asterisk:name
with the following path and query parameters:
9.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
name | Required Logical name | String |
9.2.2. Query Parameters (8 parameters):
Name | Description | Default | Type |
---|---|---|---|
hostname (common) | Required The hostname of the asterisk server | String | |
password (common) | Required Login password | String | |
username (common) | Required Login username | 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 |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
action (producer) | What action to perform such as getting queue status, sip peers or extension state. | AsteriskAction | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
9.3. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.asterisk.enabled | Enable asterisk component | true | Boolean |
camel.component.asterisk.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
9.4. Action
Supported actions are:
- QUEUE_STATUS, Queue Status
- SIP_PEERS, List SIP Peers
- EXTENSION_STATE, Check Extension Status
Chapter 10. Atmos Component
Available as of Camel version 2.15
Camel-Atmos is an Apache Camel component that allows you to work with ViPR object data services using the Atmos Client.
from("atmos:foo/get?remotePath=/path").to("mock:test");
10.1. Options
The Atmos component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
fullTokenId (security) | The token id to pass to the Atmos client | String | |
secretKey (security) | The secret key to pass to the Atmos client | String | |
uri (advanced) | The URI of the server for the Atmos client to connect to | String | |
sslValidation (security) | Whether the Atmos client should perform SSL validation | false | boolean |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Atmos endpoint is configured using URI syntax:
atmos:name/operation
with the following path and query parameters:
10.1.1. Path Parameters (2 parameters):
Name | Description | Default | Type |
---|---|---|---|
name | Atmos name | String | |
operation | Required Operation to perform | AtmosOperation |
10.1.2. Query Parameters (12 parameters):
Name | Description | Default | Type |
---|---|---|---|
enableSslValidation (common) | Atmos SSL validation | false | boolean |
fullTokenId (common) | Atmos client fullTokenId | String | |
localPath (common) | Local path to put files | String | |
newRemotePath (common) | New path on Atmos when moving files | String | |
query (common) | Search query on Atmos | String | |
remotePath (common) | Where to put files on Atmos | String | |
secretKey (common) | Atmos shared secret | String | |
uri (common) | Atomos server uri | 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 |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
10.2. Spring Boot Auto-Configuration
The component supports 6 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.atmos.enabled | Enable atmos component | true | Boolean |
camel.component.atmos.full-token-id | The token id to pass to the Atmos client | String | |
camel.component.atmos.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.atmos.secret-key | The secret key to pass to the Atmos client | String | |
camel.component.atmos.ssl-validation | Whether the Atmos client should perform SSL validation | false | Boolean |
camel.component.atmos.uri | The URI of the server for the Atmos client to connect to | String |
10.3. Dependencies
To use Atmos in your camel routes you need to add the dependency on camel-atmos 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-atmos</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
10.4. Integrations
When you look at atmos integrations, there is one type of consumer, GetConsumer, which is a type of ScheduledPollConsumer.
-
Get
Whereas there are 4 types of producers which are
-
Get
-
Del
-
Move
-
Put
10.5. Examples
These example are taken from tests:
from("atmos:foo/get?remotePath=/path").to("mock:test");
Here, this is a consumer example. remotePath
represents the path from where the data will be read and passes the camel exchange to regarding producer Underneath, this component uses atmos client API for this and every other operations.
from("direct:start") .to("atmos://get?remotePath=/dummy/dummy.txt") .to("mock:result");
Here, this a producer sample. remotePath
represents the path where the operations occur on ViPR object data service. In producers, operations(Get
,Del
, Move
,Put
) run on ViPR object data services and results are set on headers of camel exchange.
Regarding the operations, the following headers are set on camel exhange
DOWNLOADED_FILE, DOWNLOADED_FILES, UPLOADED_FILE, UPLOADED_FILES, FOUND_FILES, DELETED_PATH, MOVED_PATH;
10.6. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 11. Atlasmap Component
Only producer is supported.
You can use the AtlasMap component to process data mapping using an AtlasMap data mapping definition. When you export the AtlasMap mapping from the AtlasMap Data Mapper UI, it is packaged as an ADM archive file.
NOTE: Although it is possible to load a mapping definition JSON file that is not packaged into an ADM archive file, some features will not work. We recommend that you always use the ADM archive file for production purposes.
To use the component with Maven, add the following dependency to your pom.xml
:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-atlasmap</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
Optionally, you can include the Apache Daffodil module DFDL module:
<dependency> <groupId>io.atlasmap</groupId> <artifactId>atlas-dfdl-module</artifactId> <version>x.x.x</version> <!-- use the same version as atlasmap-core in camel-atlasmap --> </dependency>
11.1. URI format
atlas:mappingName[?options]
The mappingName is the classpath-local URI of the AtlasMap mapping definition to process, either an ADM archive file (preferably) or a mapping definition JSON file.
11.2. Configuring Options
Camel components are configured on two separate levels:
- component level
- endpoint level
11.2.1. Configuring Component Level Options
The component level is the highest configuration level. It contains general and common configurations for all endpoints.
You can configure components with the Component DSL, in a configuration file (application.properties|yaml), or directly with Java code.
Some components only have a few options, and others may have many. A component may have security settings, credentials for authentication, URLs for network connection, and so on.
Components typically have preconfigured defaults for the most common cases, so you may not need to configure any options, or only configure a few.
11.2.2. Component Options
The AtlasMap component supports 4 options:
Name | Description | Comment | Default | Type |
---|---|---|---|---|
lazyStartProducer (producer) | Lazy start of the producer. The producer starts on the first message. | Allows CamelContext and routes to start in situations where a producer fails to start and causes the route to fail. When lazy start is enabled, you can handle failures during routing messages via Camel’s routing error handlers. When the first message is processed then creating and starting the producer may prolong the total processing time. | false | boolean |
atlasContextFactory (advanced) | To use the AtlasContextFactory, otherwise a new engine is created. | AtlasContextFactory | 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 configuration of JDBC data sources, JMS connection factories, AWS Clients, and so on. | true | boolean | propertiesFile (advanced) | The URI of the properties file used for AtlasContextFactory initialization. |
11.2.3. Configuring Endpoint Level Options
At the endpoint level contains configurations for the endpoints themselves.
You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and Data Format DSL as type safe ways of configuring endpoints in Java.
Endpoints often have many options that configure what you need the endpoint to do.
Endpoint options are categorized by their use, either as a consumer (from
) or producer (to
), or both.
A good practice when configuring options is to use Property Placeholders instead of hardcoded settings for urls, port numbers, and sensitive information.
Use placeholders to externalize the configuration from your code to make it more flexible and reusable.
11.2.4. Endpoint Options
The Apache Camel Component Reference endpoint is configured using URI syntax, with path and query parameters:
atlas:resourceUri
11.2.4.1. Path Parameters (1 parameters)
Name | Description | Default | Type |
resourceUri (producer) |
Required Path to the resource. You can prefix with:
The prefix |
| String |
11.2.4.2. Query Parameters (7 parameters)
Name | Description | Comments | Default | Type |
allowContextMapAll (producer) | Allow access to all context map details. By default, only access to message body and headers is allowed. |
When enabled, | false | boolean |
contentCache (producer) | Use the resource content cache. | false | boolean | |
forceReload (producer) | Use force reload mode. This loads the ADM from a file on every Exchange. | By default, the ADM file is loaded from a file only on a first Exchange, and AtlasContext will be reused until the endpoint is recreated. | false | boolean |
lazyStartProducer (producer)(advanced) | Lazy start of the producer. The producer starts on the first message. | Allows CamelContext and routes to start in situations where a producer fails to start and causes the route to fail. When lazy start is enabled, you can handle failures during routing messages via Camel’s routing error handlers. When the first message is processed, creating and starting the producer may prolong the total processing time. | false | boolean |
sourceMapName (producer) |
The Exchange property name for a source message map which holds a | AtlasMap consumes Message bodies as source documents, as well as message headers as source properties where the scope is equal to the Document ID. | String | |
targetMapMode (producer) |
Enum values: * MAP * MESSAGE_HEADER * EXCHANGE_PROPERTY |
|
| TargetMapMode |
11.3. Examples
11.3.1. Producer Example
The following example shows an export of and ADM archive file from AtlasMap Data Mapper UI:
from("activemq:My.Queue"). to("atlas:atlasmap-mapping.adm");
The Apache Camel Component Reference endpoint has no path parameters.
Chapter 12. Atmosphere Websocket Component
Available as of Camel version 2.14
The atmosphere-websocket: component provides Websocket based endpoints for a servlet communicating with external clients over Websocket (as a servlet accepting websocket connections from external clients).
The component uses the SERVLET component and uses the Atmosphere library to support the Websocket transport in various Servlet containers (e..g., Jetty, Tomcat, …).
Unlike the Websocket component that starts the embedded Jetty server, this component uses the servlet provider of the container.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-atmosphere-websocket</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
12.1. Atmosphere-Websocket Options
The Atmosphere Websocket component supports 9 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
servletName (consumer) | Default name of servlet to use. The default name is CamelServlet. | CamelServlet | String |
httpRegistry (consumer) | To use a custom org.apache.camel.component.servlet.HttpRegistry. | HttpRegistry | |
attachmentMultipart Binding (consumer) | Whether to automatic bind multipart/form-data as attachments on the Camel Exchange. The options attachmentMultipartBinding=true and disableStreamCache=false cannot work together. Remove disableStreamCache to use AttachmentMultipartBinding. This is turn off by default as this may require servlet specific configuration to enable this when using Servlet’s. | false | boolean |
fileNameExtWhitelist (consumer) | Whitelist of accepted filename extensions for accepting uploaded files. Multiple extensions can be separated by comma, such as txt,xml. | String | |
httpBinding (advanced) | To use a custom HttpBinding to control the mapping between Camel message and HttpClient. | HttpBinding | |
httpConfiguration (advanced) | To use the shared HttpConfiguration as base configuration. | HttpConfiguration | |
allowJavaSerialized Object (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 |
headerFilterStrategy (filter) | To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message. | HeaderFilterStrategy | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Atmosphere Websocket endpoint is configured using URI syntax:
atmosphere-websocket:servicePath
with the following path and query parameters:
12.1.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
servicePath | Required Name of websocket endpoint | String |
12.1.2. Query Parameters (38 parameters):
Name | Description | Default | Type |
---|---|---|---|
chunked (common) | 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/http4 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 | |
sendToAll (common) | Whether to send to all (broadcast) or send to a single receiver. | false | boolean |
transferException (common) | 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 |
useStreaming (common) | To enable streaming to send data as multiple text fragments. | false | boolean |
httpBinding (common) | To use a custom HttpBinding to control the mapping between Camel message and HttpClient. | HttpBinding | |
async (consumer) | Configure the consumer to work in async mode | 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 |
httpMethodRestrict (consumer) | Used to only allow consuming if the HttpMethod matches, such as GET/POST/PUT etc. Multiple methods can be specified separated by comma. | String | |
matchOnUriPrefix (consumer) | Whether or not the consumer should try to find a target consumer by matching the URI prefix if no exact match is found. | false | boolean |
responseBufferSize (consumer) | To use a custom buffer size on the javax.servlet.ServletResponse. | Integer | |
servletName (consumer) | Name of the servlet to use | CamelServlet | String |
attachmentMultipartBinding (consumer) | Whether to automatic bind multipart/form-data as attachments on the Camel Exchange. The options attachmentMultipartBinding=true and disableStreamCache=false cannot work together. Remove disableStreamCache to use AttachmentMultipartBinding. This is turn off by default as this may require servlet specific configuration to enable this when using Servlet’s. | false | boolean |
eagerCheckContentAvailable (consumer) | Whether to eager check whether the HTTP requests has content if the content-length header is 0 or not present. This can be turned on in case HTTP clients do not send streamed data. | false | boolean |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
fileNameExtWhitelist (consumer) | Whitelist of accepted filename extensions for accepting uploaded files. Multiple extensions can be separated by comma, such as txt,xml. | String | |
optionsEnabled (consumer) | Specifies whether to enable HTTP OPTIONS for this Servlet consumer. By default OPTIONS is turned off. | false | boolean |
traceEnabled (consumer) | Specifies whether to enable HTTP TRACE for this Servlet consumer. By default TRACE is turned off. | false | boolean |
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 |
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 |
httpMethod (producer) | Configure the HTTP method to use. The HttpMethod header cannot override this option if set. | HttpMethods | |
ignoreResponseBody (producer) | If this option is true, The http producer won’t read response body and cache the input stream | 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 |
cookieHandler (producer) | Configure a cookie handler to maintain a HTTP session | CookieHandler | |
okStatusCodeRange (producer) | 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 |
urlRewrite (producer) | Deprecated Refers to a custom org.apache.camel.component.http.UrlRewrite which allows you to rewrite urls when you bridge/proxy endpoints. See more details at http://camel.apache.org/urlrewrite.html | UrlRewrite | |
mapHttpMessageBody (advanced) | If this option is true then IN exchange Body of the exchange will be mapped to HTTP body. Setting this to false will avoid the HTTP mapping. | true | boolean |
mapHttpMessageFormUrl EncodedBody (advanced) | If this option is true then IN exchange Form Encoded body of the exchange will be mapped to HTTP. Setting this to false will avoid the HTTP Form Encoded body mapping. | true | boolean |
mapHttpMessageHeaders (advanced) | If this option is true then IN exchange Headers of the exchange will be mapped to HTTP headers. Setting this to false will avoid the HTTP Headers mapping. | true | boolean |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
proxyAuthScheme (proxy) | Proxy authentication scheme to use | String | |
proxyHost (proxy) | Proxy hostname to use | String | |
proxyPort (proxy) | Proxy port to use | int | |
authHost (security) | Authentication host to use with NTML | String |
12.2. Spring Boot Auto-Configuration
The component supports 10 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.atmosphere-websocket.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.atmosphere-websocket.attachment-multipart-binding | Whether to automatic bind multipart/form-data as attachments on the Camel Exchange. The options attachmentMultipartBinding=true and disableStreamCache=false cannot work together. Remove disableStreamCache to use AttachmentMultipartBinding. This is turn off by default as this may require servlet specific configuration to enable this when using Servlet’s. | false | Boolean |
camel.component.atmosphere-websocket.enabled | Enable atmosphere-websocket component | true | Boolean |
camel.component.atmosphere-websocket.file-name-ext-whitelist | Whitelist of accepted filename extensions for accepting uploaded files. Multiple extensions can be separated by comma, such as txt,xml. | String | |
camel.component.atmosphere-websocket.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. | String | |
camel.component.atmosphere-websocket.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. | String | |
camel.component.atmosphere-websocket.http-configuration | To use the shared HttpConfiguration as base configuration. The option is a org.apache.camel.http.common.HttpConfiguration type. | String | |
camel.component.atmosphere-websocket.http-registry | To use a custom org.apache.camel.component.servlet.HttpRegistry. The option is a org.apache.camel.component.servlet.HttpRegistry type. | String | |
camel.component.atmosphere-websocket.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.atmosphere-websocket.servlet-name | Default name of servlet to use. The default name is CamelServlet. | CamelServlet | String |
12.3. URI Format
atmosphere-websocket:///relative path[?options]
12.4. Reading and Writing Data over Websocket
An atmopshere-websocket endpoint can either write data to the socket or read from the socket, depending on whether the endpoint is configured as the producer or the consumer, respectively.
12.5. Configuring URI to Read or Write Data
In the route below, Camel will read from the specified websocket connection.
from("atmosphere-websocket:///servicepath") .to("direct:next");
And the equivalent Spring sample:
<camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="atmosphere-websocket:///servicepath"/> <to uri="direct:next"/> </route> </camelContext>
In the route below, Camel will read from the specified websocket connection.
from("direct:next") .to("atmosphere-websocket:///servicepath");
And the equivalent Spring sample:
<camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="direct:next"/> <to uri="atmosphere-websocket:///servicepath"/> </route> </camelContext>
12.6. See Also
Chapter 13. Atom Component
Available as of Camel version 1.2
The atom: component is used for polling Atom feeds.
Camel will poll the feed every 60 seconds by default.
Note: The component currently only supports polling (consuming) feeds.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-atom</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
13.1. URI format
atom://atomUri[?options]
Where atomUri is the URI to the Atom feed to poll.
13.2. Options
The Atom component has no options.
The Atom endpoint is configured using URI syntax:
atom:feedUri
with the following path and query parameters:
13.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
feedUri | Required The URI to the feed to poll. | String |
13.2.2. Query Parameters (27 parameters):
Name | Description | Default | Type |
---|---|---|---|
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 |
feedHeader (consumer) | Sets whether to add the feed object as a header | true | boolean |
filter (consumer) | Sets whether to use filtering or not of the entries. | true | boolean |
lastUpdate (consumer) | Sets the timestamp to be used for filtering entries from the atom feeds. This options is only in conjunction with the splitEntries. | Date | |
password (consumer) | Sets the password to be used for basic authentication when polling from a HTTP feed | 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 |
sortEntries (consumer) | Sets whether to sort entries by published date. Only works when splitEntries = true. | false | boolean |
splitEntries (consumer) | Sets whether or not entries should be sent individually or whether the entire feed should be sent as a single message | true | boolean |
throttleEntries (consumer) | Sets whether all entries identified in a single feed poll should be delivered immediately. If true, only one entry is processed per consumer.delay. Only applicable when splitEntries = true. | true | boolean |
username (consumer) | Sets the username to be used for basic authentication when polling from a HTTP feed | String | |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
pollStrategy (consumer) | 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. | PollingConsumerPoll Strategy | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 1000 | 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. | 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. | ScheduledExecutor Service | |
scheduler (scheduler) | To use a cron scheduler from either camel-spring or camel-quartz2 component | none | ScheduledPollConsumer Scheduler |
schedulerProperties (scheduler) | To configure additional properties when using a custom scheduler or any of the Quartz2, Spring based scheduler. | Map | |
startScheduler (scheduler) | Whether the scheduler should be auto started. | true | boolean |
timeUnit (scheduler) | Time unit for initialDelay and delay options. | MILLISECONDS | TimeUnit |
useFixedDelay (scheduler) | Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean |
13.3. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.atom.enabled | Enable atom component | true | Boolean |
camel.component.atom.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
You can append query options to the URI in the following format, ?option=value&option=value&…
13.4. Exchange data format
Camel will set the In body on the returned Exchange
with the entries. Depending on the splitEntries
flag Camel will either return one Entry
or a List<Entry>
.
Option | Value | Behavior |
---|---|---|
|
|
Only a single entry from the currently being processed feed is set: |
|
|
The entire list of entries from the feed is set: |
Camel can set the Feed
object on the In header (see feedHeader
option to disable this):
13.5. Message Headers
Camel atom uses these headers.
Header | Description |
---|---|
|
When consuming the |
13.6. Samples
In this sample we poll James Strachan’s blog.
from("atom://http://macstrac.blogspot.com/feeds/posts/default").to("seda:feeds");
In this sample we want to filter only good blogs we like to a SEDA queue. The sample also shows how to setup Camel standalone, not running in any Container or using Spring.
13.7. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- RSS
Chapter 14. Atomix Map Component
Available as of Camel version 2.20
The camel atomix-map component allows you to work with Atomix’s Distributed Map collection.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-atomix</artifactId> <version>${camel-version}</version> </dependency>
14.1. URI format
atomix-map:mapName
14.2. Options
The Atomix Map component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (common) | The shared component configuration | AtomixMapConfiguration | |
atomix (common) | The shared AtomixClient instance | AtomixClient | |
nodes (common) | The nodes the AtomixClient should connect to | List | |
configurationUri (common) | The path to the AtomixClient configuration | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Atomix Map endpoint is configured using URI syntax:
atomix-map:resourceName
with the following path and query parameters:
14.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
resourceName | Required The distributed resource name | String |
14.2.2. Query Parameters (18 parameters):
Name | Description | Default | Type |
---|---|---|---|
atomix (common) | The Atomix instance to use | Atomix | |
configurationUri (common) | The Atomix configuration uri. | String | |
defaultAction (common) | The default action. | PUT | Action |
key (common) | The key to use if none is set in the header or to listen for events for a specific key. | Object | |
nodes (common) | The address of the nodes composing the cluster. | String | |
resultHeader (common) | The header that wil carry the result. | String | |
transport (common) | Sets the Atomix transport. | io.atomix.catalyst.transport.netty.NettyTransport | Transport |
ttl (common) | The resource ttl. | long | |
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) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
defaultResourceConfig (advanced) | The cluster wide default resource configuration. | Properties | |
defaultResourceOptions (advanced) | The local default resource options. | Properties | |
ephemeral (advanced) | Sets if the local member should join groups as PersistentMember or not. If set to ephemeral the local member will receive an auto generated ID thus the local one is ignored. | false | boolean |
readConsistency (advanced) | The read consistency level. | ReadConsistency | |
resourceConfigs (advanced) | Cluster wide resources configuration. | Map | |
resourceOptions (advanced) | Local resources configurations | Map | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
14.3. Spring Boot Auto-Configuration
The component supports 9 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.atomix-map.atomix | The shared AtomixClient instance. The option is a io.atomix.AtomixClient type. | String | |
camel.component.atomix-map.configuration-uri | The path to the AtomixClient configuration | String | |
camel.component.atomix-map.configuration.default-action | The default action. | AtomixMap$Action | |
camel.component.atomix-map.configuration.key | The key to use if none is set in the header or to listen for events for a specific key. | Object | |
camel.component.atomix-map.configuration.result-header | The header that wil carry the result. | String | |
camel.component.atomix-map.configuration.ttl | The resource ttl. | Long | |
camel.component.atomix-map.enabled | Whether to enable auto configuration of the atomix-map component. This is enabled by default. | Boolean | |
camel.component.atomix-map.nodes | The nodes the AtomixClient should connect to | List | |
camel.component.atomix-map.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
14.4. Headers
Name | Type | Values | Description |
---|---|---|---|
CamelAtomixResourceAction | AtomixMap.Action |
| The action to perform |
CamelAtomixResourceKey | Object | - | The key to operate on |
CamelAtomixResourceValue | Object | - | The value, if missing In Body is used |
CamelAtomixResourceOldValue | Object | - | The old value |
CamelAtomixResourceTTL | String / long | - | The entry TTL |
CamelAtomixResourceReadConsistency | ReadConsistency |
| The read consistency level |
14.5. Configuring the component to connect to an Atomix cluster
The nodes of the Atomix cluster you want to join can be se at Endpoint or component level (recommended), below some examples:
Endpoint:
<beans xmlns="..."> <camelContext xmlns="http://camel.apache.org/schema/spring"> <from uri="direct:start"/> <to uri="atomix-map:myMap?nodes=node-1.atomix.cluster:8700,node-2.atomix.cluster:8700"/> </route> </camelContext> </beans>
Component:
<beans xmlns="..."> <bean id="atomix-map" class="org.apache.camel.component.atomix.client.map.AtomixMapComponent"> <property name="nodes" value="nodes=node-1.atomix.cluster:8700,node-2.atomix.cluster:8700"/> </bean> <camelContext xmlns="http://camel.apache.org/schema/spring"> <from uri="direct:start"/> <to uri="atomix-map:myMap"/> </route> </camelContext> </beans>
14.6. Usage examples:
PUT an element with TTL of 1 second:
FluentProducerTemplate.on(context) .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixMap.Action.PUT) .withHeader(AtomixClientConstants.RESOURCE_KEY, key) .withHeader(AtomixClientConstants.RESOURCE_TTL, "1s") .withBody(val) .to("direct:start") .send();
Chapter 15. Atomix Messaging Component
Available as of Camel version 2.20
The camel atomix-messaging component allows you to work with Atomix’s Group Messaging.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-atomix</artifactId> <version>${camel-version}</version> </dependency>
15.1. URI format
atomix-messaging:group
The Atomix Messaging component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (common) | The shared component configuration | AtomixMessaging Configuration | |
atomix (common) | The shared AtomixClient instance | AtomixClient | |
nodes (common) | The nodes the AtomixClient should connect to | List | |
configurationUri (common) | The path to the AtomixClient configuration | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Atomix Messaging endpoint is configured using URI syntax:
atomix-messaging:resourceName
with the following path and query parameters:
15.1.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
resourceName | Required The distributed resource name | String |
15.1.2. Query Parameters (19 parameters):
Name | Description | Default | Type |
---|---|---|---|
atomix (common) | The Atomix instance to use | Atomix | |
broadcastType (common) | The broadcast type. | ALL | BroadcastType |
channelName (common) | The messaging channel name | String | |
configurationUri (common) | The Atomix configuration uri. | String | |
defaultAction (common) | The default action. | DIRECT | Action |
memberName (common) | The Atomix Group member name | String | |
nodes (common) | The address of the nodes composing the cluster. | String | |
resultHeader (common) | The header that wil carry the result. | String | |
transport (common) | Sets the Atomix transport. | io.atomix.catalyst.transport.netty.NettyTransport | Transport |
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) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
defaultResourceConfig (advanced) | The cluster wide default resource configuration. | Properties | |
defaultResourceOptions (advanced) | The local default resource options. | Properties | |
ephemeral (advanced) | Sets if the local member should join groups as PersistentMember or not. If set to ephemeral the local member will receive an auto generated ID thus the local one is ignored. | false | boolean |
readConsistency (advanced) | The read consistency level. | ReadConsistency | |
resourceConfigs (advanced) | Cluster wide resources configuration. | Map | |
resourceOptions (advanced) | Local resources configurations | Map | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
15.2. Spring Boot Auto-Configuration
The component supports 10 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.atomix-messaging.atomix | The shared AtomixClient instance. The option is a io.atomix.AtomixClient type. | String | |
camel.component.atomix-messaging.configuration-uri | The path to the AtomixClient configuration | String | |
camel.component.atomix-messaging.configuration.broadcast-type | The broadcast type. | AtomixMessaging$ BroadcastType | |
camel.component.atomix-messaging.configuration.channel-name | The messaging channel name | String | |
camel.component.atomix-messaging.configuration.default-action | The default action. | AtomixMessaging$Action | |
camel.component.atomix-messaging.configuration.member-name | The Atomix Group member name | String | |
camel.component.atomix-messaging.configuration.result-header | The header that wil carry the result. | String | |
camel.component.atomix-messaging.enabled | Whether to enable auto configuration of the atomix-messaging component. This is enabled by default. | Boolean | |
camel.component.atomix-messaging.nodes | The nodes the AtomixClient should connect to | List | |
camel.component.atomix-messaging.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
Chapter 16. Atomix MultiMap Component
Available as of Camel version 2.20
The camel atomix-multimap component allows you to work with Atomix’s Distributed MultiMap collection.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-atomix</artifactId> <version>${camel-version}</version> </dependency>
16.1. URI format
atomix-multimap:multiMapName
The Atomix MultiMap component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (consumer) | The shared component configuration | AtomixMultiMap Configuration | |
atomix (consumer) | The shared AtomixClient instance | AtomixClient | |
nodes (consumer) | The nodes the AtomixClient should connect to | List | |
configurationUri (consumer) | The path to the AtomixClient configuration | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Atomix MultiMap endpoint is configured using URI syntax:
atomix-multimap:resourceName
with the following path and query parameters:
16.1.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
resourceName | Required The distributed resource name | String |
16.1.2. Query Parameters (18 parameters):
Name | Description | Default | Type |
---|---|---|---|
atomix (consumer) | The Atomix instance to use | Atomix | |
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 |
configurationUri (consumer) | The Atomix configuration uri. | String | |
defaultAction (consumer) | The default action. | PUT | Action |
key (consumer) | The key to use if none is set in the header or to listen for events for a specific key. | Object | |
nodes (consumer) | The address of the nodes composing the cluster. | String | |
resultHeader (consumer) | The header that wil carry the result. | String | |
transport (consumer) | Sets the Atomix transport. | io.atomix.catalyst.transport.netty.NettyTransport | Transport |
ttl (consumer) | The resource ttl. | long | |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
defaultResourceConfig (advanced) | The cluster wide default resource configuration. | Properties | |
defaultResourceOptions (advanced) | The local default resource options. | Properties | |
ephemeral (advanced) | Sets if the local member should join groups as PersistentMember or not. If set to ephemeral the local member will receive an auto generated ID thus the local one is ignored. | false | boolean |
readConsistency (advanced) | The read consistency level. | ReadConsistency | |
resourceConfigs (advanced) | Cluster wide resources configuration. | Map | |
resourceOptions (advanced) | Local resources configurations | Map | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
16.2. Spring Boot Auto-Configuration
The component supports 9 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.atomix-multimap.atomix | The shared AtomixClient instance. The option is a io.atomix.AtomixClient type. | String | |
camel.component.atomix-multimap.configuration-uri | The path to the AtomixClient configuration | String | |
camel.component.atomix-multimap.configuration.default-action | The default action. | AtomixMultiMap$Action | |
camel.component.atomix-multimap.configuration.key | The key to use if none is set in the header or to listen for events for a specific key. | Object | |
camel.component.atomix-multimap.configuration.result-header | The header that wil carry the result. | String | |
camel.component.atomix-multimap.configuration.ttl | The resource ttl. | Long | |
camel.component.atomix-multimap.enabled | Whether to enable auto configuration of the atomix-multimap component. This is enabled by default. | Boolean | |
camel.component.atomix-multimap.nodes | The nodes the AtomixClient should connect to | List | |
camel.component.atomix-multimap.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
Chapter 17. Atomix Queue Component
Available as of Camel version 2.20
The camel atomix-queue component allows you to work with Atomix’s Distributed Queue collection.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-atomix</artifactId> <version>${camel-version}</version> </dependency>
17.1. URI format
atomix-queue:queueName
The Atomix Queue component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (common) | The shared component configuration | AtomixQueue Configuration | |
atomix (common) | The shared AtomixClient instance | AtomixClient | |
nodes (common) | The nodes the AtomixClient should connect to | List | |
configurationUri (common) | The path to the AtomixClient configuration | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Atomix Queue endpoint is configured using URI syntax:
atomix-queue:resourceName
with the following path and query parameters:
17.1.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
resourceName | Required The distributed resource name | String |
17.1.2. Query Parameters (16 parameters):
Name | Description | Default | Type |
---|---|---|---|
atomix (common) | The Atomix instance to use | Atomix | |
configurationUri (common) | The Atomix configuration uri. | String | |
defaultAction (common) | The default action. | ADD | Action |
nodes (common) | The address of the nodes composing the cluster. | String | |
resultHeader (common) | The header that wil carry the result. | String | |
transport (common) | Sets the Atomix transport. | io.atomix.catalyst.transport.netty.NettyTransport | Transport |
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) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
defaultResourceConfig (advanced) | The cluster wide default resource configuration. | Properties | |
defaultResourceOptions (advanced) | The local default resource options. | Properties | |
ephemeral (advanced) | Sets if the local member should join groups as PersistentMember or not. If set to ephemeral the local member will receive an auto generated ID thus the local one is ignored. | false | boolean |
readConsistency (advanced) | The read consistency level. | ReadConsistency | |
resourceConfigs (advanced) | Cluster wide resources configuration. | Map | |
resourceOptions (advanced) | Local resources configurations | Map | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
17.2. Spring Boot Auto-Configuration
The component supports 7 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.atomix-queue.atomix | The shared AtomixClient instance. The option is a io.atomix.AtomixClient type. | String | |
camel.component.atomix-queue.configuration-uri | The path to the AtomixClient configuration | String | |
camel.component.atomix-queue.configuration.default-action | The default action. | AtomixQueue$Action | |
camel.component.atomix-queue.configuration.result-header | The header that wil carry the result. | String | |
camel.component.atomix-queue.enabled | Whether to enable auto configuration of the atomix-queue component. This is enabled by default. | Boolean | |
camel.component.atomix-queue.nodes | The nodes the AtomixClient should connect to | List | |
camel.component.atomix-queue.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
Chapter 18. Atomix Set Component
Available as of Camel version 2.20
The camel atomix-set component allows you to work with Atomix’s Distributed Set collection.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-atomix</artifactId> <version>${camel-version}</version> </dependency>
18.1. URI format
atomix-set:setName
The Atomix Set component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (common) | The shared component configuration | AtomixSetConfiguration | |
atomix (common) | The shared AtomixClient instance | AtomixClient | |
nodes (common) | The nodes the AtomixClient should connect to | List | |
configurationUri (common) | The path to the AtomixClient configuration | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Atomix Set endpoint is configured using URI syntax:
atomix-set:resourceName
with the following path and query parameters:
18.1.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
resourceName | Required The distributed resource name | String |
18.1.2. Query Parameters (17 parameters):
Name | Description | Default | Type |
---|---|---|---|
atomix (common) | The Atomix instance to use | Atomix | |
configurationUri (common) | The Atomix configuration uri. | String | |
defaultAction (common) | The default action. | ADD | Action |
nodes (common) | The address of the nodes composing the cluster. | String | |
resultHeader (common) | The header that wil carry the result. | String | |
transport (common) | Sets the Atomix transport. | io.atomix.catalyst.transport.netty.NettyTransport | Transport |
ttl (common) | The resource ttl. | long | |
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) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
defaultResourceConfig (advanced) | The cluster wide default resource configuration. | Properties | |
defaultResourceOptions (advanced) | The local default resource options. | Properties | |
ephemeral (advanced) | Sets if the local member should join groups as PersistentMember or not. If set to ephemeral the local member will receive an auto generated ID thus the local one is ignored. | false | boolean |
readConsistency (advanced) | The read consistency level. | ReadConsistency | |
resourceConfigs (advanced) | Cluster wide resources configuration. | Map | |
resourceOptions (advanced) | Local resources configurations | Map | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
18.2. Spring Boot Auto-Configuration
The component supports 8 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.atomix-set.atomix | The shared AtomixClient instance. The option is a io.atomix.AtomixClient type. | String | |
camel.component.atomix-set.configuration-uri | The path to the AtomixClient configuration | String | |
camel.component.atomix-set.configuration.default-action | The default action. | AtomixSet$Action | |
camel.component.atomix-set.configuration.result-header | The header that wil carry the result. | String | |
camel.component.atomix-set.configuration.ttl | The resource ttl. | Long | |
camel.component.atomix-set.enabled | Whether to enable auto configuration of the atomix-set component. This is enabled by default. | Boolean | |
camel.component.atomix-set.nodes | The nodes the AtomixClient should connect to | List | |
camel.component.atomix-set.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
Chapter 19. Atomix Value Component
Available as of Camel version 2.20
The camel atomix-value component allows you to work with Atomix’s Distributed Value.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-atomix</artifactId> <version>${camel-version}</version> </dependency>
19.1. URI format
atomix-value:valueName
The Atomix Value component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (common) | The shared component configuration | AtomixValue Configuration | |
atomix (common) | The shared AtomixClient instance | AtomixClient | |
nodes (common) | The nodes the AtomixClient should connect to | List | |
configurationUri (common) | The path to the AtomixClient configuration | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Atomix Value endpoint is configured using URI syntax:
atomix-value:resourceName
with the following path and query parameters:
19.1.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
resourceName | Required The distributed resource name | String |
19.1.2. Query Parameters (17 parameters):
Name | Description | Default | Type |
---|---|---|---|
atomix (common) | The Atomix instance to use | Atomix | |
configurationUri (common) | The Atomix configuration uri. | String | |
defaultAction (common) | The default action. | SET | Action |
nodes (common) | The address of the nodes composing the cluster. | String | |
resultHeader (common) | The header that wil carry the result. | String | |
transport (common) | Sets the Atomix transport. | io.atomix.catalyst.transport.netty.NettyTransport | Transport |
ttl (common) | The resource ttl. | long | |
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) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
defaultResourceConfig (advanced) | The cluster wide default resource configuration. | Properties | |
defaultResourceOptions (advanced) | The local default resource options. | Properties | |
ephemeral (advanced) | Sets if the local member should join groups as PersistentMember or not. If set to ephemeral the local member will receive an auto generated ID thus the local one is ignored. | false | boolean |
readConsistency (advanced) | The read consistency level. | ReadConsistency | |
resourceConfigs (advanced) | Cluster wide resources configuration. | Map | |
resourceOptions (advanced) | Local resources configurations | Map | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
19.2. Spring Boot Auto-Configuration
The component supports 8 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.atomix-value.atomix | The shared AtomixClient instance. The option is a io.atomix.AtomixClient type. | String | |
camel.component.atomix-value.configuration-uri | The path to the AtomixClient configuration | String | |
camel.component.atomix-value.configuration.default-action | The default action. | AtomixValue$Action | |
camel.component.atomix-value.configuration.result-header | The header that wil carry the result. | String | |
camel.component.atomix-value.configuration.ttl | The resource ttl. | Long | |
camel.component.atomix-value.enabled | Whether to enable auto configuration of the atomix-value component. This is enabled by default. | Boolean | |
camel.component.atomix-value.nodes | The nodes the AtomixClient should connect to | List | |
camel.component.atomix-value.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
Chapter 20. Avro Component
Available as of Camel version 2.10
This component provides a dataformat for avro, which allows serialization and deserialization of messages using Apache Avro’s binary dataformat. Moreover, it provides support for Apache Avro’s rpc, by providing producers and consumers endpoint for using avro over netty or http.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-avro</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
20.1. Apache Avro Overview
Avro allows you to define message types and a protocol using a json like format and then generate java code for the specified types and messages. An example of how a schema looks like is below.
{"namespace": "org.apache.camel.avro.generated", "protocol": "KeyValueProtocol", "types": [ {"name": "Key", "type": "record", "fields": [ {"name": "key", "type": "string"} ] }, {"name": "Value", "type": "record", "fields": [ {"name": "value", "type": "string"} ] } ], "messages": { "put": { "request": [{"name": "key", "type": "Key"}, {"name": "value", "type": "Value"} ], "response": "null" }, "get": { "request": [{"name": "key", "type": "Key"}], "response": "Value" } } }
You can easily generate classes from a schema, using maven, ant etc. More details can be found at the Apache Avro documentation.
However, it doesn’t enforce a schema first approach and you can create schema for your existing classes. Since 2.12 you can use existing protocol interfaces to make RCP calls. You should use interface for the protocol itself and POJO beans or primitive/String classes for parameter and result types. Here is an example of the class that corresponds to schema above:
package org.apache.camel.avro.reflection; public interface KeyValueProtocol { void put(String key, Value value); Value get(String key); } class Value { private String value; public String getValue() { return value; } public void setValue(String value) { this.value = value; } }
Note: Existing classes can be used only for RPC (see below), not in data format.
20.2. Using the Avro data format
Using the avro data format is as easy as specifying that the class that you want to marshal or unmarshal in your route.
<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 ref="avro"/> <to uri="log:out"/> </route> </camelContext>
In the same manner you can umarshal using the avro data format.
20.3. Using Avro RPC in Camel
As mentioned above Avro also provides RPC support over multiple transports such as http and netty. Camel provides consumers and producers for these two transports.
avro:[transport]:[host]:[port][?options]
The supported transport values are currently http or netty.
Since 2.12 you can specify message name right in the URI:
avro:[transport]:[host]:[port][/messageName][?options]
For consumers this allows you to have multiple routes attached to the same socket. Dispatching to correct route will be done by the avro component automatically. Route with no messageName specified (if any) will be used as default.
When using camel producers for avro ipc, the "in" message body needs to contain the parameters of the operation specified in the avro protocol. The response will be added in the body of the "out" message.
In a similar manner when using camel avro consumers for avro ipc, the requests parameters will be placed inside the "in" message body of the created exchange and once the exchange is processed the body of the "out" message will be send as a response.
Note: By default consumer parameters are wrapped into array. If you’ve got only one parameter, since 2.12 you can use singleParameter
URI option to receive it direcly in the "in" message body without array wrapping.
20.4. Avro RPC URI Options
The Avro component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | To use a shared AvroConfiguration to configure options once | AvroConfiguration | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Avro endpoint is configured using URI syntax:
avro:transport:host:port/messageName
with the following path and query parameters:
20.4.1. Path Parameters (4 parameters):
Name | Description | Default | Type |
---|---|---|---|
transport | Required Transport to use, can be either http or netty | AvroTransport | |
port | Required Port number to use | int | |
host | Required Hostname to use | String | |
messageName | The name of the message to send. | String |
20.4.2. Query Parameters (10 parameters):
Name | Description | Default | Type |
---|---|---|---|
protocol (common) | Avro protocol to use | Protocol | |
protocolClassName (common) | Avro protocol to use defined by the FQN class name | String | |
protocolLocation (common) | Avro protocol location | String | |
reflectionProtocol (common) | If protocol object provided is reflection protocol. Should be used only with protocol parameter because for protocolClassName protocol type will be auto detected | false | boolean |
singleParameter (common) | If true, consumer parameter won’t be wrapped into array. Will fail if protocol specifies more then 1 parameter for the message | false | boolean |
uriAuthority (common) | Authority to use (username and password) | 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 |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
20.5. Spring Boot Auto-Configuration
The component supports 15 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.avro.configuration.host | Hostname to use | String | |
camel.component.avro.configuration.message-name | The name of the message to send. | String | |
camel.component.avro.configuration.port | Port number to use | Integer | |
camel.component.avro.configuration.protocol | Avro protocol to use | Protocol | |
camel.component.avro.configuration.protocol-class-name | Avro protocol to use defined by the FQN class name | String | |
camel.component.avro.configuration.protocol-location | Avro protocol location | String | |
camel.component.avro.configuration.reflection-protocol | If protocol object provided is reflection protocol. Should be used only with protocol parameter because for protocolClassName protocol type will be auto detected | false | Boolean |
camel.component.avro.configuration.single-parameter | If true, consumer parameter won’t be wrapped into array. Will fail if protocol specifies more then 1 parameter for the message | false | Boolean |
camel.component.avro.configuration.transport | Transport to use, can be either http or netty | AvroTransport | |
camel.component.avro.configuration.uri-authority | Authority to use (username and password) | String | |
camel.component.avro.enabled | Enable avro component | true | Boolean |
camel.component.avro.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.dataformat.avro.content-type-header | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. | false | Boolean |
camel.dataformat.avro.enabled | Enable avro dataformat | true | Boolean |
camel.dataformat.avro.instance-class-name | Class name to use for marshal and unmarshalling | String |
20.6. Avro RPC Headers
Name | Description |
---|---|
| The name of the message to send. In consumer overrides message name from URI (if any) |
20.7. Examples
An example of using camel avro producers via http:
<route> <from uri="direct:start"/> <to uri="avro:http:localhost:{{avroport}}?protocolClassName=org.apache.camel.avro.generated.KeyValueProtocol"/> <to uri="log:avro"/> </route>
In the example above you need to fill CamelAvroMessageName
header. Since 2.12 you can use following syntax to call constant messages:
<route> <from uri="direct:start"/> <to uri="avro:http:localhost:{{avroport}}/put?protocolClassName=org.apache.camel.avro.generated.KeyValueProtocol"/> <to uri="log:avro"/> </route>
An example of consuming messages using camel avro consumers via netty:
<route> <from uri="avro:netty:localhost:{{avroport}}?protocolClassName=org.apache.camel.avro.generated.KeyValueProtocol"/> <choice> <when> <el>${in.headers.CamelAvroMessageName == 'put'}</el> <process ref="putProcessor"/> </when> <when> <el>${in.headers.CamelAvroMessageName == 'get'}</el> <process ref="getProcessor"/> </when> </choice> </route>
Since 2.12 you can set up two distinct routes to perform the same task:
<route> <from uri="avro:netty:localhost:{{avroport}}/put?protocolClassName=org.apache.camel.avro.generated.KeyValueProtocol"> <process ref="putProcessor"/> </route> <route> <from uri="avro:netty:localhost:{{avroport}}/get?protocolClassName=org.apache.camel.avro.generated.KeyValueProtocol&singleParameter=true"/> <process ref="getProcessor"/> </route>
In the example above, get takes only one parameter, so singleParameter
is used and getProcessor
will receive Value class directly in body, while putProcessor
will receive an array of size 2 with String key and Value value filled as array contents.
Chapter 21. Avro DataFormat
Available as of Camel version 2.14
This component provides a dataformat for avro, which allows serialization and deserialization of messages using Apache Avro’s binary dataformat. Moreover, it provides support for Apache Avro’s rpc, by providing producers and consumers endpoint for using avro over netty or http.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-avro</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
21.1. Apache Avro Overview
Avro allows you to define message types and a protocol using a json like format and then generate java code for the specified types and messages. An example of how a schema looks like is below.
{"namespace": "org.apache.camel.avro.generated", "protocol": "KeyValueProtocol", "types": [ {"name": "Key", "type": "record", "fields": [ {"name": "key", "type": "string"} ] }, {"name": "Value", "type": "record", "fields": [ {"name": "value", "type": "string"} ] } ], "messages": { "put": { "request": [{"name": "key", "type": "Key"}, {"name": "value", "type": "Value"} ], "response": "null" }, "get": { "request": [{"name": "key", "type": "Key"}], "response": "Value" } } }
You can easily generate classes from a schema, using maven, ant etc. More details can be found at the Apache Avro documentation.
However, it doesn’t enforce a schema first approach and you can create schema for your existing classes. Since 2.12 you can use existing protocol interfaces to make RCP calls. You should use interface for the protocol itself and POJO beans or primitive/String classes for parameter and result types. Here is an example of the class that corresponds to schema above:
package org.apache.camel.avro.reflection; public interface KeyValueProtocol { void put(String key, Value value); Value get(String key); } class Value { private String value; public String getValue() { return value; } public void setValue(String value) { this.value = value; } }
Note: Existing classes can be used only for RPC (see below), not in data format.
21.2. Using the Avro data format
Using the avro data format is as easy as specifying that the class that you want to marshal or unmarshal in your route.
<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 ref="avro"/> <to uri="log:out"/> </route> </camelContext>
In the same manner you can umarshal using the avro data format.
21.3. Avro Dataformat Options
The Avro dataformat supports 2 options, which are listed below.
Name | Default | Java Type | Description |
---|---|---|---|
instanceClassName |
| Class name to use for marshal and unmarshalling | |
contentTypeHeader |
|
| Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. |
21.4. Spring Boot Auto-Configuration
The component supports 15 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.avro.configuration.host | Hostname to use | String | |
camel.component.avro.configuration.message-name | The name of the message to send. | String | |
camel.component.avro.configuration.port | Port number to use | Integer | |
camel.component.avro.configuration.protocol | Avro protocol to use | Protocol | |
camel.component.avro.configuration.protocol-class-name | Avro protocol to use defined by the FQN class name | String | |
camel.component.avro.configuration.protocol-location | Avro protocol location | String | |
camel.component.avro.configuration.reflection-protocol | If protocol object provided is reflection protocol. Should be used only with protocol parameter because for protocolClassName protocol type will be auto detected | false | Boolean |
camel.component.avro.configuration.single-parameter | If true, consumer parameter won’t be wrapped into array. Will fail if protocol specifies more then 1 parameter for the message | false | Boolean |
camel.component.avro.configuration.transport | Transport to use, can be either http or netty | AvroTransport | |
camel.component.avro.configuration.uri-authority | Authority to use (username and password) | String | |
camel.component.avro.enabled | Enable avro component | true | Boolean |
camel.component.avro.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.dataformat.avro.content-type-header | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. | false | Boolean |
camel.dataformat.avro.enabled | Enable avro dataformat | true | Boolean |
camel.dataformat.avro.instance-class-name | Class name to use for marshal and unmarshalling | String |
ND
Chapter 22. AWS CloudWatch Component
Available as of Camel version 2.11
The CW 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 are available at Amazon CloudWatch.
22.1. URI Format
aws-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&…
22.2. URI Options
The AWS CloudWatch component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | The AWS CW default configuration | CwConfiguration | |
accessKey (producer) | Amazon AWS Access Key | String | |
secretKey (producer) | Amazon AWS Secret Key | String | |
region (producer) | The region in which CW client needs to work | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The AWS CloudWatch endpoint is configured using URI syntax:
aws-cw:namespace
with the following path and query parameters:
22.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
namespace | Required The metric namespace | String |
22.2.2. Query Parameters (11 parameters):
Name | Description | Default | Type |
---|---|---|---|
amazonCwClient (producer) | To use the AmazonCloudWatch as the client | AmazonCloudWatch | |
name (producer) | The metric name | String | |
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 | |
region (producer) | The region in which CW client needs to work | String | |
timestamp (producer) | The metric timestamp | Date | |
unit (producer) | The metric unit | String | |
value (producer) | The metric value | Double | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
accessKey (security) | Amazon AWS Access Key | String | |
secretKey (security) | Amazon AWS Secret Key | String |
22.3. Spring Boot Auto-Configuration
The component supports 16 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.aws-cw.access-key | Amazon AWS Access Key | String | |
camel.component.aws-cw.configuration.access-key | Amazon AWS Access Key | String | |
camel.component.aws-cw.configuration.amazon-cw-client | To use the AmazonCloudWatch as the client | AmazonCloudWatch | |
camel.component.aws-cw.configuration.name | The metric name | String | |
camel.component.aws-cw.configuration.namespace | The metric namespace | String | |
camel.component.aws-cw.configuration.proxy-host | To define a proxy host when instantiating the CW client | String | |
camel.component.aws-cw.configuration.proxy-port | To define a proxy port when instantiating the CW client | Integer | |
camel.component.aws-cw.configuration.region | The region in which CW client needs to work | String | |
camel.component.aws-cw.configuration.secret-key | Amazon AWS Secret Key | String | |
camel.component.aws-cw.configuration.timestamp | The metric timestamp | Date | |
camel.component.aws-cw.configuration.unit | The metric unit | String | |
camel.component.aws-cw.configuration.value | The metric value | Double | |
camel.component.aws-cw.enabled | Enable aws-cw component | true | Boolean |
camel.component.aws-cw.region | The region in which CW client needs to work | String | |
camel.component.aws-cw.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.aws-cw.secret-key | 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.
22.4. Usage
22.4.1. Message headers evaluated by the CW producer
Header | Type | Description |
---|---|---|
|
| The Amazon CW metric name. |
|
| The Amazon CW metric value. |
|
| The Amazon CW metric unit. |
|
| The Amazon CW metric namespace. |
|
| The Amazon CW metric timestamp. |
|
| Camel 2.12: The Amazon CW metric dimension name. |
|
| Camel 2.12: The Amazon CW metric dimension value. |
|
| Camel 2.12: A map of dimension names and dimension values. |
22.4.2. Advanced AmazonCloudWatch configuration
If you need more control over the AmazonCloudWatch
instance configuration you can create your own instance and refer to it from the URI:
from("direct:start") .to("aws-cw://namepsace?amazonCwClient=#client");
The #client
refers to a AmazonCloudWatch
in the Registry.
For example if your Camel Application is running behind a firewall:
AWSCredentials awsCredentials = new BasicAWSCredentials("myAccessKey", "mySecretKey"); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setProxyHost("http://myProxyHost"); clientConfiguration.setProxyPort(8080); AmazonCloudWatch client = new AmazonCloudWatchClient(awsCredentials, clientConfiguration); registry.bind("client", client);
22.5. Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.10 or higher).
22.6. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 23. AWS DynamoDB Component
Available as of Camel version 2.10
The DynamoDB component supports storing and retrieving data from/to Amazon’s DynamoDB service.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon DynamoDB. More information are available at Amazon DynamoDB.
23.1. URI Format
aws-ddb://domainName[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
23.2. URI Options
The AWS DynamoDB component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | The AWS DDB default configuration | DdbConfiguration | |
accessKey (producer) | Amazon AWS Access Key | String | |
secretKey (producer) | Amazon AWS Secret Key | String | |
region (producer) | The region in which DDB client needs to work | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The AWS DynamoDB endpoint is configured using URI syntax:
aws-ddb:tableName
with the following path and query parameters:
23.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
tableName | Required The name of the table currently worked with. | String |
23.2.2. Query Parameters (13 parameters):
Name | Description | Default | Type |
---|---|---|---|
amazonDDBClient (producer) | To use the AmazonDynamoDB as the client | AmazonDynamoDB | |
consistentRead (producer) | Determines whether or not strong consistency should be enforced when data is read. | false | boolean |
keyAttributeName (producer) | Attribute name when creating table | String | |
keyAttributeType (producer) | Attribute type when creating table | String | |
operation (producer) | What operation to perform | PutItem | DdbOperations |
proxyHost (producer) | To define a proxy host when instantiating the DDB client | String | |
proxyPort (producer) | To define a proxy port when instantiating the DDB client | Integer | |
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 | |
writeCapacity (producer) | The provisioned throughput to reserved for writing resources to your table | Long | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
accessKey (security) | Amazon AWS Access Key | String | |
secretKey (security) | Amazon AWS Secret Key | String |
23.3. Spring Boot Auto-Configuration
The component supports 18 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.aws-ddb.access-key | Amazon AWS Access Key | String | |
camel.component.aws-ddb.configuration.access-key | Amazon AWS Access Key | String | |
camel.component.aws-ddb.configuration.amazon-d-d-b-client | To use the AmazonDynamoDB as the client | AmazonDynamoDB | |
camel.component.aws-ddb.configuration.consistent-read | Determines whether or not strong consistency should be enforced when data is read. | false | Boolean |
camel.component.aws-ddb.configuration.key-attribute-name | Attribute name when creating table | String | |
camel.component.aws-ddb.configuration.key-attribute-type | Attribute type when creating table | String | |
camel.component.aws-ddb.configuration.operation | What operation to perform | DdbOperations | |
camel.component.aws-ddb.configuration.proxy-host | To define a proxy host when instantiating the DDB client | String | |
camel.component.aws-ddb.configuration.proxy-port | To define a proxy port when instantiating the DDB client | Integer | |
camel.component.aws-ddb.configuration.read-capacity | The provisioned throughput to reserve for reading resources from your table | Long | |
camel.component.aws-ddb.configuration.region | The region in which DDB client needs to work | String | |
camel.component.aws-ddb.configuration.secret-key | Amazon AWS Secret Key | String | |
camel.component.aws-ddb.configuration.table-name | The name of the table currently worked with. | String | |
camel.component.aws-ddb.configuration.write-capacity | The provisioned throughput to reserved for writing resources to your table | Long | |
camel.component.aws-ddb.enabled | Enable aws-ddb component | true | Boolean |
camel.component.aws-ddb.region | The region in which DDB client needs to work | String | |
camel.component.aws-ddb.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.aws-ddb.secret-key | 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.
23.4. Usage
23.4.1. Message headers evaluated by the DDB producer
Header | Type | Description |
---|---|---|
|
| A map of the table name and corresponding items to get by primary key. |
|
| Table Name for this operation. |
|
| The primary key that uniquely identifies each item in a table. From Camel 2.16.0 the type of this header is Map<String, AttributeValue> and not Key |
|
| 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). |
|
| Designates an attribute for a conditional modification. |
|
| If attribute names are not specified then all attributes will be returned. |
|
| If set to true, then a consistent read is issued, otherwise eventually consistent is used. |
|
| If set will be used as Secondary Index for Query operation. |
|
| A map of the attributes for the item, and must include the primary key values that define the item. |
|
| 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. From Camel 2.16.0 this header doesn’t exist anymore. |
|
| From Camel 2.16.0. This header specify the selection criteria for the query, and merge together the two old headers CamelAwsDdbHashKeyValue and CamelAwsDdbScanRangeKeyCondition |
|
| Primary key of the item from which to continue an earlier query. |
|
| Value of the hash component of the composite primary key. From Camel 2.16.0 this header doesn’t exist anymore. |
|
| The maximum number of items to return. |
|
| A container for the attribute values and comparison operators to use for the query.From Camel 2.16.0 this header doesn’t exist anymore. |
|
| Specifies forward or backward traversal of the index. |
|
| Evaluates the scan results and returns only the desired values. |
|
| Map of attribute name to the new value and action for the update. |
23.4.2. Message headers set during BatchGetItems operation
Header | Type | Description |
---|---|---|
|
| Table names and the respective item attributes from the tables. |
|
| Contains a map of tables and their respective keys that were not processed with the current response. |
23.4.3. Message headers set during DeleteItem operation
Header | Type | Description |
---|---|---|
|
| The list of attributes returned by the operation. |
23.4.4. Message headers set during DeleteTable operation
Header | Type | Description |
---|---|---|
| ||
| The value of the ProvisionedThroughput property for this table | |
|
| Creation DateTime of this table. |
|
| Item count for this table. |
|
| 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 |
|
| The table name. |
|
| The table size in bytes. |
|
| The status of the table: CREATING, UPDATING, DELETING, ACTIVE |
23.4.5. Message headers set during DescribeTable operation
Header | Type | Description |
---|---|---|
| {{ProvisionedThroughputDescription}} | The value of the ProvisionedThroughput property for this table |
|
| Creation DateTime of this table. |
|
| Item count for this table. |
| {{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 |
|
| The table name. |
|
| The table size in bytes. |
|
| The status of the table: CREATING, UPDATING, DELETING, ACTIVE |
|
| ReadCapacityUnits property of this table. |
|
| WriteCapacityUnits property of this table. |
23.4.6. Message headers set during GetItem operation
Header | Type | Description |
---|---|---|
|
| The list of attributes returned by the operation. |
23.4.7. Message headers set during PutItem operation
Header | Type | Description |
---|---|---|
|
| The list of attributes returned by the operation. |
23.4.8. Message headers set during Query operation
Header | Type | Description |
---|---|---|
|
| The list of attributes returned by the operation. |
|
| Primary key of the item where the query operation stopped, inclusive of the previous result set. |
|
| The number of Capacity Units of the provisioned throughput of the table consumed during the operation. |
|
| Number of items in the response. |
23.4.9. Message headers set during Scan operation
Header | Type | Description |
---|---|---|
|
| The list of attributes returned by the operation. |
|
| Primary key of the item where the query operation stopped, inclusive of the previous result set. |
|
| The number of Capacity Units of the provisioned throughput of the table consumed during the operation. |
|
| Number of items in the response. |
|
| Number of items in the complete scan before any filters are applied. |
23.4.10. Message headers set during UpdateItem operation
Header | Type | Description |
---|---|---|
|
| The list of attributes returned by the operation. |
23.4.11. 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("aws-ddb://domainName?amazonDDBClient=#client");
The #client
refers to a AmazonDynamoDB
in the Registry.
For example if your Camel Application is running behind a firewall:
AWSCredentials awsCredentials = new BasicAWSCredentials("myAccessKey", "mySecretKey"); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setProxyHost("http://myProxyHost"); clientConfiguration.setProxyPort(8080); AmazonDynamoDB client = new AmazonDynamoDBClient(awsCredentials, clientConfiguration); registry.bind("client", client);
23.5. Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.10 or higher).
23.6. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 24. AWS DynamoDB Streams Component
Available as of Camel version 2.17
The DynamoDB Stream component supports receiving messages from Amazon DynamoDB Stream service.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon DynamoDB Streams. More information are available at AWS DynamoDB
24.1. URI Format
aws-ddbstream://table-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&…
24.2. URI Options
The AWS DynamoDB Streams component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | The AWS DDB stream default configuration | DdbStreamConfiguration | |
accessKey (consumer) | Amazon AWS Access Key | String | |
secretKey (consumer) | Amazon AWS Secret Key | String | |
region (consumer) | Amazon AWS Region | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The AWS DynamoDB Streams endpoint is configured using URI syntax:
aws-ddbstream:tableName
with the following path and query parameters:
24.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
tableName | Required Name of the dynamodb table | String |
24.2.2. Query Parameters (28 parameters):
Name | Description | Default | Type |
---|---|---|---|
amazonDynamoDbStreams Client (consumer) | Amazon DynamoDB client to use for all requests for this endpoint | AmazonDynamoDBStreams | |
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 DynaboDB stream to start getting records. Note that using TRIM_HORIZON can cause a significant delay before the stream has caught up to real-time. if AT,AFTER_SEQUENCE_NUMBER are used, then a sequenceNumberProvider MUST be supplied. | LATEST | ShardIteratorType |
maxResultsPerRequest (consumer) | Maximum number of records that will be fetched in each poll | int | |
proxyHost (consumer) | To define a proxy host when instantiating the DDBStreams client | String | |
proxyPort (consumer) | To define a proxy port when instantiating the DDBStreams client | Integer | |
region (consumer) | The region in which DDBStreams client needs to work | 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 |
sequenceNumberProvider (consumer) | Provider for the sequence number when using one of the two ShardIteratorType.AT,AFTER_SEQUENCE_NUMBER iterator types. Can be a registry reference or a literal sequence number. | SequenceNumberProvider | |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
pollStrategy (consumer) | 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. | PollingConsumerPoll Strategy | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 1000 | 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. | 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. | ScheduledExecutor Service | |
scheduler (scheduler) | To use a cron scheduler from either camel-spring or camel-quartz2 component | none | ScheduledPollConsumer Scheduler |
schedulerProperties (scheduler) | To configure additional properties when using a custom scheduler or any of the Quartz2, Spring based scheduler. | Map | |
startScheduler (scheduler) | Whether the scheduler should be auto started. | true | boolean |
timeUnit (scheduler) | Time unit for initialDelay and delay options. | 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 |
24.3. Spring Boot Auto-Configuration
The component supports 15 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.aws-ddbstream.access-key | Amazon AWS Access Key | String | |
camel.component.aws-ddbstream.configuration.access-key | Amazon AWS Access Key | String | |
camel.component.aws-ddbstream.configuration.amazon-dynamo-db-streams-client | Amazon DynamoDB client to use for all requests for this endpoint | AmazonDynamoDBStreams | |
camel.component.aws-ddbstream.configuration.iterator-type | Defines where in the DynaboDB stream to start getting records. Note that using TRIM_HORIZON can cause a significant delay before the stream has caught up to real-time. if AT,AFTER_SEQUENCE_NUMBER are used, then a sequenceNumberProvider MUST be supplied. | ShardIteratorType | |
camel.component.aws-ddbstream.configuration.max-results-per-request | Maximum number of records that will be fetched in each poll | Integer | |
camel.component.aws-ddbstream.configuration.proxy-host | To define a proxy host when instantiating the DDBStreams client | String | |
camel.component.aws-ddbstream.configuration.proxy-port | To define a proxy port when instantiating the DDBStreams client | Integer | |
camel.component.aws-ddbstream.configuration.region | The region in which DDBStreams client needs to work | String | |
camel.component.aws-ddbstream.configuration.secret-key | Amazon AWS Secret Key | String | |
camel.component.aws-ddbstream.configuration.sequence-number-provider | Provider for the sequence number when using one of the two ShardIteratorType.AT,AFTER_SEQUENCE_NUMBER iterator types. Can be a registry reference or a literal sequence number. | SequenceNumberProvider | |
camel.component.aws-ddbstream.configuration.table-name | Name of the dynamodb table | String | |
camel.component.aws-ddbstream.enabled | Enable aws-ddbstream component | true | Boolean |
camel.component.aws-ddbstream.region | Amazon AWS Region | String | |
camel.component.aws-ddbstream.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.aws-ddbstream.secret-key | Amazon AWS Secret Key | String |
Required DynampDBStream component options
You have to provide the amazonDynamoDbStreamsClient in the Registry with proxies and relevant credentials configured.
24.4. Sequence Numbers
You can provide a literal string as the sequence number or provide a bean in the registry. An example of using the bean would be to save your current position in the change feed and restore it on Camel startup.
It is an error to provide a sequence number that is greater than the largest sequence number in the describe-streams result, as this will lead to the AWS call returning an HTTP 400.
24.5. 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.
24.6. Usage
24.6.1. AmazonDynamoDBStreamsClient configuration
You will need to create an instance of AmazonDynamoDBStreamsClient and bind it to the registry
ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setProxyHost("http://myProxyHost"); clientConfiguration.setProxyPort(8080); Region region = Region.getRegion(Regions.fromName(region)); region.createClient(AmazonDynamoDBStreamsClient.class, null, clientConfiguration); // the 'null' here is the AWSCredentialsProvider which defaults to an instance of DefaultAWSCredentialsProviderChain registry.bind("kinesisClient", client);
24.6.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(…).
24.7. Coping with Downtime
24.7.1. AWS DynamoDB Streams outage of less than 24 hours
The consumer will resume from the last seen sequence number (as implemented for CAMEL-9515), so you should receive a flood of events in quick succession, as long as the outage did not also include DynamoDB itself.
24.7.2. AWS DynamoDB Streams outage of more than 24 hours
Given that AWS only retain 24 hours worth of changes, you will have missed change events no matter what mitigations are in place.
24.8. Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.7 or higher).
24.9. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
-
AWS Component
+
Chapter 25. AWS EC2 Component
Available as of Camel version 2.16
The EC2 component supports create, run, start, stop and terminate AWS EC2 instances.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon EC2. More information are available at Amazon EC2.
25.1. URI Format
aws-ec2://label[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
25.2. URI Options
The AWS EC2 component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | The AWS EC2 default configuration | EC2Configuration | |
region (producer) | The region in which EC2 client needs to work | String | |
accessKey (producer) | Amazon AWS Access Key | String | |
secretKey (producer) | Amazon AWS Secret Key | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The AWS EC2 endpoint is configured using URI syntax:
aws-ec2:label
with the following path and query parameters:
25.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
label | Required Logical name | String |
25.2.2. Query Parameters (8 parameters):
Name | Description | Default | Type |
---|---|---|---|
accessKey (producer) | Amazon AWS Access Key | String | |
amazonEc2Client (producer) | To use a existing configured AmazonEC2Client as client | AmazonEC2Client | |
operation (producer) | Required The operation to perform. It can be createAndRunInstances, startInstances, stopInstances, terminateInstances, describeInstances, describeInstancesStatus, rebootInstances, monitorInstances, unmonitorInstances, createTags or deleteTags | EC2Operations | |
proxyHost (producer) | To define a proxy host when instantiating the EC2 client | String | |
proxyPort (producer) | To define a proxy port when instantiating the EC2 client | Integer | |
region (producer) | The region in which EC2 client needs to work | String | |
secretKey (producer) | Amazon AWS Secret Key | String | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
25.3. Spring Boot Auto-Configuration
The component supports 12 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.aws-ec2.access-key | Amazon AWS Access Key | String | |
camel.component.aws-ec2.configuration.access-key | Amazon AWS Access Key | String | |
camel.component.aws-ec2.configuration.amazon-ec2-client | To use a existing configured AmazonEC2Client as client | AmazonEC2Client | |
camel.component.aws-ec2.configuration.operation | The operation to perform. It can be createAndRunInstances, startInstances, stopInstances, terminateInstances, describeInstances, describeInstancesStatus, rebootInstances, monitorInstances, unmonitorInstances, createTags or deleteTags | EC2Operations | |
camel.component.aws-ec2.configuration.proxy-host | To define a proxy host when instantiating the EC2 client | String | |
camel.component.aws-ec2.configuration.proxy-port | To define a proxy port when instantiating the EC2 client | Integer | |
camel.component.aws-ec2.configuration.region | The region in which EC2 client needs to work | String | |
camel.component.aws-ec2.configuration.secret-key | Amazon AWS Secret Key | String | |
camel.component.aws-ec2.enabled | Enable aws-ec2 component | true | Boolean |
camel.component.aws-ec2.region | The region in which EC2 client needs to work | String | |
camel.component.aws-ec2.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.aws-ec2.secret-key | Amazon AWS Secret Key | String |
Required EC2 component options
You have to provide the amazonEc2Client in the Registry or your accessKey and secretKey to access the Amazon EC2 service.
25.4. Usage
25.4.1. Message headers evaluated by the EC2 producer
Header | Type | Description |
---|---|---|
|
| An image ID of the AWS marketplace |
| com.amazonaws.services.ec2.model.InstanceType | The instance type we want to create and run |
|
| The operation we want to perform |
|
| The mininum number of instances we want to run. |
|
| The maximum number of instances we want to run. |
| Boolean | Define if we want the running instances to be monitored |
|
| Define if the creating instance is optimized for EBS I/O. |
| Collection | The security groups to associate to the instances |
|
| A collection of instances IDS to execute start, stop, describe and terminate operations on. |
|
| A collection of tags to add or remove from EC2 resources |
Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.16 or higher).
25.5. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 26. AWS IAM Component
Available as of Camel version 2.23
The KMS component supports create, run, start, stop and terminate AWS IAM instances.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon IAM. More information are available at Amazon IAM.
26.1. URI Format
aws-kms://label[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
26.2. URI Options
The AWS IAM component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | The AWS IAM default configuration | IAMConfiguration | |
accessKey (producer) | Amazon AWS Access Key | String | |
secretKey (producer) | Amazon AWS Secret Key | String | |
region (producer) | The region in which IAM client needs to work | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The AWS IAM endpoint is configured using URI syntax:
aws-iam:label
with the following path and query parameters:
26.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
label | Required Logical name | String |
26.2.2. Query Parameters (8 parameters):
Name | Description | Default | Type |
---|---|---|---|
accessKey (producer) | Amazon AWS Access Key | String | |
iamClient (producer) | To use a existing configured AWS IAM as client | AmazonIdentity ManagementClient | |
operation (producer) | Required The operation to perform | IAMOperations | |
proxyHost (producer) | To define a proxy host when instantiating the KMS client | String | |
proxyPort (producer) | To define a proxy port when instantiating the KMS client | Integer | |
region (producer) | The region in which KMS client needs to work | String | |
secretKey (producer) | Amazon AWS Secret Key | String | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
26.3. Spring Boot Auto-Configuration
The component supports 12 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.aws-iam.access-key | Amazon AWS Access Key | String | |
camel.component.aws-iam.configuration.access-key | Amazon AWS Access Key | String | |
camel.component.aws-iam.configuration.iam-client | To use a existing configured AWS IAM as client | AmazonIdentity ManagementClient | |
camel.component.aws-iam.configuration.operation | The operation to perform | IAMOperations | |
camel.component.aws-iam.configuration.proxy-host | To define a proxy host when instantiating the KMS client | String | |
camel.component.aws-iam.configuration.proxy-port | To define a proxy port when instantiating the KMS client | Integer | |
camel.component.aws-iam.configuration.region | The region in which KMS client needs to work | String | |
camel.component.aws-iam.configuration.secret-key | Amazon AWS Secret Key | String | |
camel.component.aws-iam.enabled | Whether to enable auto configuration of the aws-iam component. This is enabled by default. | Boolean | |
camel.component.aws-iam.region | The region in which IAM client needs to work | String | |
camel.component.aws-iam.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.aws-iam.secret-key | Amazon AWS Secret Key | String |
Required IAM component options
You have to provide the amazonKmsClient in the Registry or your accessKey and secretKey to access the Amazon IAM service.
26.4. Usage
26.4.1. Message headers evaluated by the IAM producer
Header | Type | Description |
---|---|---|
|
| The operation we want to perform |
|
| The username for the user you want to manage |
|
| The accessKey you want to manage |
|
| The Status of the AccessKey you want to set, possible value are active and inactive |
26.4.2. IAM Producer operations
Camel-AWS IAM component provides the following operation on the producer side:
- listAccessKeys
- createUser
- deleteUser
- listUsers
- getUser
- createAccessKey
- deleteAccessKey
- updateAccessKey
Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.16 or higher).
26.5. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 27. AWS Kinesis Component
Available as of Camel version 2.17
The Kinesis component supports receiving messages from and sending messages to Amazon Kinesis service.
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
27.1. URI Format
aws-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&…
27.2. URI Options
The AWS Kinesis component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | The AWS S3 default configuration | KinesisConfiguration | |
accessKey (common) | Amazon AWS Access Key | String | |
secretKey (common) | Amazon AWS Secret Key | String | |
region (common) | Amazon AWS Region | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The AWS Kinesis endpoint is configured using URI syntax:
aws-kinesis:streamName
with the following path and query parameters:
27.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
streamName | Required Name of the stream | String |
27.2.2. Query Parameters (30 parameters):
Name | Description | Default | Type |
---|---|---|---|
amazonKinesisClient (common) | Amazon Kinesis client to use for all requests for this endpoint | AmazonKinesis | |
proxyHost (common) | To define a proxy host when instantiating the DDBStreams client | String | |
proxyPort (common) | To define a proxy port when instantiating the DDBStreams client | Integer | |
region (common) | The region in which Kinesis client needs to work | 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 |
iteratorType (consumer) | Defines where in the Kinesis stream to start getting records | TRIM_HORIZON | ShardIteratorType |
maxResultsPerRequest (consumer) | Maximum number of records that will be fetched in each poll | 1 | int |
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 | ignore | KinesisShardClosed StrategyEnum |
shardId (consumer) | Defines which shardId in the Kinesis stream to get records from | String | |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
pollStrategy (consumer) | 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. | PollingConsumerPoll Strategy | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 1000 | 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. | 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. | ScheduledExecutor Service | |
scheduler (scheduler) | To use a cron scheduler from either camel-spring or camel-quartz2 component | none | ScheduledPollConsumer Scheduler |
schedulerProperties (scheduler) | To configure additional properties when using a custom scheduler or any of the Quartz2, Spring based scheduler. | Map | |
startScheduler (scheduler) | Whether the scheduler should be auto started. | true | boolean |
timeUnit (scheduler) | Time unit for initialDelay and delay options. | 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 |
27.3. Spring Boot Auto-Configuration
The component supports 17 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.aws-kinesis.access-key | Amazon AWS Access Key | String | |
camel.component.aws-kinesis.configuration.access-key | Amazon AWS Access Key | String | |
camel.component.aws-kinesis.configuration.amazon-kinesis-client | Amazon Kinesis client to use for all requests for this endpoint | AmazonKinesis | |
camel.component.aws-kinesis.configuration.iterator-type | Defines where in the Kinesis stream to start getting records | ShardIteratorType | |
camel.component.aws-kinesis.configuration.max-results-per-request | Maximum number of records that will be fetched in each poll | 1 | Integer |
camel.component.aws-kinesis.configuration.proxy-host | To define a proxy host when instantiating the DDBStreams client | String | |
camel.component.aws-kinesis.configuration.proxy-port | To define a proxy port when instantiating the DDBStreams client | Integer | |
camel.component.aws-kinesis.configuration.region | The region in which Kinesis client needs to work | String | |
camel.component.aws-kinesis.configuration.secret-key | Amazon AWS Secret Key | String | |
camel.component.aws-kinesis.configuration.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.aws-kinesis.configuration.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 | KinesisShardClosed StrategyEnum | |
camel.component.aws-kinesis.configuration.shard-id | Defines which shardId in the Kinesis stream to get records from | String | |
camel.component.aws-kinesis.configuration.stream-name | Name of the stream | String | |
camel.component.aws-kinesis.enabled | Enable aws-kinesis component | true | Boolean |
camel.component.aws-kinesis.region | Amazon AWS Region | String | |
camel.component.aws-kinesis.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.aws-kinesis.secret-key | Amazon AWS Secret Key | String |
Required Kinesis component options
You have to provide the amazonKinesisClient in the Registry with proxies and relevant credentials configured.
27.4. 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.
27.5. Usage
27.5.1. Message headers set by the Kinesis consumer
Header | Type | Description |
---|---|---|
|
| The sequence number of the record. This is represented as a String as it size is not defined by the API. If it is to be used as a numerical type then use |
|
| The time AWS assigned as the arrival time of the record. |
|
| Identifies which shard in the stream the data record is assigned to. |
27.5.2. AmazonKinesis configuration
You will need to create an instance of AmazonKinesisClient and bind it to the registry
ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setProxyHost("http://myProxyHost"); clientConfiguration.setProxyPort(8080); Region region = Region.getRegion(Regions.fromName(region)); region.createClient(AmazonKinesisClient.class, null, clientConfiguration); // the 'null' here is the AWSCredentialsProvider which defaults to an instance of DefaultAWSCredentialsProviderChain registry.bind("kinesisClient", client);
You then have to reference the AmazonKinesisClient in the amazonKinesisClient
URI option.
from("aws-kinesis://mykinesisstream?amazonKinesisClient=#kinesisClient") .to("log:out?showAll=true");
27.5.3. 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(…).
27.5.4. Message headers used by the Kinesis producer to write to Kinesis. The producer expects that the message body is a byte[]
.
Header | Type | Description |
---|---|---|
|
| The PartitionKey to pass to Kinesis to store this record. |
|
| Optional paramter to indicate the sequence number of this record. |
27.5.5. Message headers set by the Kinesis producer on successful storage of a Record
Header | Type | Description |
---|---|---|
|
| The sequence number of the record, as defined in Response Syntax |
|
| The shard ID of where the Record was stored |
27.6. Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.17 or higher).
27.7. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 28. AWS Kinesis Firehose Component
Available as of Camel version 2.19
The Kinesis Firehose component supports sending messages to Amazon Kinesis Firehose service.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon Kinesis Firehose. More information are available at AWS Kinesis Firehose
28.1. URI Format
aws-kinesis-firehose://delivery-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&…
28.2. URI Options
The AWS Kinesis Firehose component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | The AWS Kinesis Firehose default configuration | KinesisFirehose Configuration | |
accessKey (producer) | Amazon AWS Access Key | String | |
secretKey (producer) | Amazon AWS Secret Key | String | |
region (producer) | Amazon AWS Region | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The AWS Kinesis Firehose endpoint is configured using URI syntax:
aws-kinesis-firehose:streamName
with the following path and query parameters:
28.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
streamName | Required Name of the stream | String |
28.2.2. Query Parameters (7 parameters):
Name | Description | Default | Type |
---|---|---|---|
amazonKinesisFirehoseClient (producer) | Amazon Kinesis Firehose client to use for all requests for this endpoint | AmazonKinesisFirehose | |
proxyHost (producer) | To define a proxy host when instantiating the DDBStreams client | String | |
proxyPort (producer) | To define a proxy port when instantiating the DDBStreams client | Integer | |
region (producer) | The region in which Kinesis client needs to work | String | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
accessKey (security) | Amazon AWS Access Key | String | |
secretKey (security) | Amazon AWS Secret Key | String |
28.3. Spring Boot Auto-Configuration
The component supports 12 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.aws-kinesis-firehose.access-key | Amazon AWS Access Key | String | |
camel.component.aws-kinesis-firehose.configuration.access-key | Amazon AWS Access Key | String | |
camel.component.aws-kinesis-firehose.configuration.amazon-kinesis-firehose-client | Amazon Kinesis Firehose client to use for all requests for this endpoint | AmazonKinesisFirehose | |
camel.component.aws-kinesis-firehose.configuration.proxy-host | To define a proxy host when instantiating the DDBStreams client | String | |
camel.component.aws-kinesis-firehose.configuration.proxy-port | To define a proxy port when instantiating the DDBStreams client | Integer | |
camel.component.aws-kinesis-firehose.configuration.region | The region in which Kinesis client needs to work | String | |
camel.component.aws-kinesis-firehose.configuration.secret-key | Amazon AWS Secret Key | String | |
camel.component.aws-kinesis-firehose.configuration.stream-name | Name of the stream | String | |
camel.component.aws-kinesis-firehose.enabled | Enable aws-kinesis-firehose component | true | Boolean |
camel.component.aws-kinesis-firehose.region | Amazon AWS Region | String | |
camel.component.aws-kinesis-firehose.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.aws-kinesis-firehose.secret-key | Amazon AWS Secret Key | String |
Required Kinesis Firehose component options
You have to provide the amazonKinesisClient in the Registry with proxies and relevant credentials configured.
28.4. Usage
28.4.1. Amazon Kinesis Firehose configuration
You will need to create an instance of AmazonKinesisClient and bind it to the registry
ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setProxyHost("http://myProxyHost"); clientConfiguration.setProxyPort(8080); Region region = Region.getRegion(Regions.fromName(region)); region.createClient(AmazonKinesisClient.class, null, clientConfiguration); // the 'null' here is the AWSCredentialsProvider which defaults to an instance of DefaultAWSCredentialsProviderChain registry.bind("kinesisFirehoseClient", client);
You then have to reference the AmazonKinesisFirehoseClient in the amazonKinesisFirehoseClient
URI option.
from("aws-kinesis-firehose://mykinesisdeliverystream?amazonKinesisFirehoseClient=#kinesisClient") .to("log:out?showAll=true");
28.4.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(…).
28.4.3. Message headers set by the Kinesis producer on successful storage of a Record
Header | Type | Description |
---|---|---|
|
| The record ID, as defined in Response Syntax |
28.5. Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.19 or higher).
28.6. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 29. AWS KMS Component
Available as of Camel version 2.21
The KMS component supports create, run, start, stop and terminate AWS KMS instances.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon KMS. More information are available at Amazon KMS.
29.1. URI Format
aws-kms://label[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
29.2. URI Options
The AWS KMS component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | The AWS KMS default configuration | KMSConfiguration | |
accessKey (producer) | Amazon AWS Access Key | String | |
secretKey (producer) | Amazon AWS Secret Key | String | |
region (producer) | The region in which KMS client needs to work | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The AWS KMS endpoint is configured using URI syntax:
aws-kms:label
with the following path and query parameters:
29.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
label | Required Logical name | String |
29.2.2. Query Parameters (8 parameters):
Name | Description | Default | Type |
---|---|---|---|
accessKey (producer) | Amazon AWS Access Key | String | |
kmsClient (producer) | To use a existing configured AWS KMS as client | AWSKMS | |
operation (producer) | Required The operation to perform | KMSOperations | |
proxyHost (producer) | To define a proxy host when instantiating the KMS client | String | |
proxyPort (producer) | To define a proxy port when instantiating the KMS client | Integer | |
region (producer) | The region in which KMS client needs to work | String | |
secretKey (producer) | Amazon AWS Secret Key | String | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
29.3. Spring Boot Auto-Configuration
The component supports 12 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.aws-kms.access-key | Amazon AWS Access Key | String | |
camel.component.aws-kms.configuration.access-key | Amazon AWS Access Key | String | |
camel.component.aws-kms.configuration.kms-client | To use a existing configured AWS KMS as client | AWSKMS | |
camel.component.aws-kms.configuration.operation | The operation to perform | KMSOperations | |
camel.component.aws-kms.configuration.proxy-host | To define a proxy host when instantiating the KMS client | String | |
camel.component.aws-kms.configuration.proxy-port | To define a proxy port when instantiating the KMS client | Integer | |
camel.component.aws-kms.configuration.region | The region in which KMS client needs to work | String | |
camel.component.aws-kms.configuration.secret-key | Amazon AWS Secret Key | String | |
camel.component.aws-kms.enabled | Whether to enable auto configuration of the aws-kms component. This is enabled by default. | Boolean | |
camel.component.aws-kms.region | The region in which KMS client needs to work | String | |
camel.component.aws-kms.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.aws-kms.secret-key | Amazon AWS Secret Key | String |
Required KMS component options
You have to provide the amazonKmsClient in the Registry or your accessKey and secretKey to access the Amazon KMS service.
29.4. Usage
29.4.1. Message headers evaluated by the MQ producer
Header | Type | Description |
---|---|---|
|
| The limit number of keys to return while performing a listKeys operation |
|
| The operation we want to perform |
|
| A key description to use while performing a createKey operation |
|
| The key Id |
29.4.2. KMS Producer operations
Camel-AWS KMS component provides the following operation on the producer side:
- listKeys
- createKey
- disableKey
- scheduleKeyDeletion
- describeKey
- enableKey
Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.16 or higher).
29.5. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 30. AWS Lambda Component
Available as of Camel version 2.20
The 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 are available at Amazon Lambda.
When creating a Lambda function, you need to specify a IAM role which has at least the AWSLambdaBasicExecuteRole policy attached.
Warning
Lambda is regional service. Unlike S3 bucket, Lambda function created in a given region is not available on other regions.
30.1. URI Format
aws-lambda://functionName[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
30.2. URI Options
The AWS Lambda component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | The AWS Lambda default configuration | LambdaConfiguration | |
accessKey (producer) | Amazon AWS Access Key | String | |
secretKey (producer) | Amazon AWS Secret Key | String | |
region (producer) | Amazon AWS Region | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The AWS Lambda endpoint is configured using URI syntax:
aws-lambda:function
with the following path and query parameters:
30.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
function | Required Name of the Lambda function. | String |
30.2.2. Query Parameters (8 parameters):
Name | Description | Default | Type |
---|---|---|---|
operation (producer) | Required The operation to perform. It can be listFunctions, getFunction, createFunction, deleteFunction or invokeFunction | LambdaOperations | |
region (producer) | Amazon AWS Region | String | |
awsLambdaClient (advanced) | To use a existing configured AwsLambdaClient as client | AWSLambda | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
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 | |
accessKey (security) | Amazon AWS Access Key | String | |
secretKey (security) | Amazon AWS Secret Key | String |
30.3. Spring Boot Auto-Configuration
The component supports 13 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.aws-lambda.access-key | Amazon AWS Access Key | String | |
camel.component.aws-lambda.configuration.access-key | Amazon AWS Access Key | String | |
camel.component.aws-lambda.configuration.aws-lambda-client | To use a existing configured AwsLambdaClient as client | AWSLambda | |
camel.component.aws-lambda.configuration.function | Name of the Lambda function. | String | |
camel.component.aws-lambda.configuration.operation | The operation to perform. It can be listFunctions, getFunction, createFunction, deleteFunction or invokeFunction | LambdaOperations | |
camel.component.aws-lambda.configuration.proxy-host | To define a proxy host when instantiating the Lambda client | String | |
camel.component.aws-lambda.configuration.proxy-port | To define a proxy port when instantiating the Lambda client | Integer | |
camel.component.aws-lambda.configuration.region | Amazon AWS Region | String | |
camel.component.aws-lambda.configuration.secret-key | Amazon AWS Secret Key | String | |
camel.component.aws-lambda.enabled | Whether to enable auto configuration of the aws-lambda component. This is enabled by default. | Boolean | |
camel.component.aws-lambda.region | Amazon AWS Region | String | |
camel.component.aws-lambda.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.aws-lambda.secret-key | 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.
30.4. Usage
30.4.1. Message headers evaluated by the Lambda producer
Operation | Header | Type | Description | Required |
---|---|---|---|---|
All |
|
| The operation we want to perform. Override operation passed as query parameter | Yes |
createFunction |
|
| 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 |
|
| The Amazon S3 object (the deployment package) key name you want to upload. | No |
createFunction |
| String | The Amazon S3 object (the deployment package) version you want to upload. | No |
createFunction |
|
| The local path of the zip file (the deployment package). Content of zip file can also be put in Message body. | No |
createFunction |
|
| 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 |
| 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 |
|
| 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 |
|
| The user-provided description. | No |
createFunction |
|
| The parent object that contains the target ARN (Amazon Resource Name) of an Amazon SQS queue or Amazon SNS topic. | No |
createFunction |
|
| The memory size, in MB, you configured for the function. Must be a multiple of 64 MB. | No |
createFunction |
|
| 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 |
|
| 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 |
|
| The function execution time at which Lambda should terminate the function. The default is 3 seconds. | No |
createFunction |
|
| Your function’s tracing settings (Active or PassThrough). | No |
createFunction |
|
| The key-value pairs that represent your environment’s configuration settings. | No |
createFunction |
|
| The list of tags (key-value pairs) assigned to the new function. | No |
createFunction |
|
| If your Lambda function accesses resources in a VPC, a list of one or more security groups IDs in your VPC. | No |
createFunction |
|
| If your Lambda function accesses resources in a VPC, a list of one or more subnet IDs in your VPC. | No |
30.5. List of Avalaible Operations
- listFunctions
- getFunction,
- createFunction
- deleteFunction
- invokeFunction
- updateFunction
- createEventSourceMapping
- deleteEventSourceMapping
- listEventSourceMapping
30.6. Example
To have a full understanding of how the component works, you may have a look at this integration test
30.7. Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.16 or higher).
30.8. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 31. AWS MQ Component
Available as of Camel version 2.21
The EC2 component supports create, run, start, stop and terminate AWS MQ instances.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon MQ. More information are available at Amazon MQ.
31.1. URI Format
aws-mq://label[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
31.2. URI Options
The AWS MQ component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | The AWS MQ default configuration | MQConfiguration | |
accessKey (producer) | Amazon AWS Access Key | String | |
secretKey (producer) | Amazon AWS Secret Key | String | |
region (producer) | The region in which MQ client needs to work | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The AWS MQ endpoint is configured using URI syntax:
aws-mq:label
with the following path and query parameters:
31.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
label | Required Logical name | String |
31.2.2. Query Parameters (8 parameters):
Name | Description | Default | Type |
---|---|---|---|
accessKey (producer) | Amazon AWS Access Key | String | |
amazonMqClient (producer) | To use a existing configured AmazonMQClient as client | AmazonMQ | |
operation (producer) | Required The operation to perform. It can be listBrokers,createBroker,deleteBroker | MQOperations | |
proxyHost (producer) | To define a proxy host when instantiating the MQ client | String | |
proxyPort (producer) | To define a proxy port when instantiating the MQ client | Integer | |
region (producer) | The region in which MQ client needs to work | String | |
secretKey (producer) | Amazon AWS Secret Key | String | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
31.3. Spring Boot Auto-Configuration
The component supports 12 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.aws-mq.access-key | Amazon AWS Access Key | String | |
camel.component.aws-mq.configuration.access-key | Amazon AWS Access Key | String | |
camel.component.aws-mq.configuration.amazon-mq-client | To use a existing configured AmazonMQClient as client | AmazonMQ | |
camel.component.aws-mq.configuration.operation | The operation to perform. It can be listBrokers,createBroker,deleteBroker | MQOperations | |
camel.component.aws-mq.configuration.proxy-host | To define a proxy host when instantiating the MQ client | String | |
camel.component.aws-mq.configuration.proxy-port | To define a proxy port when instantiating the MQ client | Integer | |
camel.component.aws-mq.configuration.region | The region in which MQ client needs to work | String | |
camel.component.aws-mq.configuration.secret-key | Amazon AWS Secret Key | String | |
camel.component.aws-mq.enabled | Whether to enable auto configuration of the aws-mq component. This is enabled by default. | Boolean | |
camel.component.aws-mq.region | The region in which MQ client needs to work | String | |
camel.component.aws-mq.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.aws-mq.secret-key | Amazon AWS Secret Key | String |
Required EC2 component options
You have to provide the amazonEc2Client in the Registry or your accessKey and secretKey to access the Amazon EC2 service.
31.4. Usage
31.4.1. Message headers evaluated by the MQ producer
Header | Type | Description |
---|---|---|
|
| The number of results that must be retrieved from listBrokers operation |
|
| The broker name |
|
| The operation we want to perform |
|
| The broker id |
|
| The deployment mode for the broker in the createBroker operation |
|
| The instance type for the EC2 machine in the createBroker operation |
|
| The Broker Engine for MQ. Default is ACTIVEMQ |
|
| The Broker Engine Version for MQ. Currently you can choose between 5.15.6 and 5.15.0 of ACTIVEMQ |
|
| The list of users for MQ |
|
| If the MQ instance must be publicly available or not. Default is false. |
Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.16 or higher).
31.5. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 32. AWS S3 Storage Service Component
Available as of Camel version 2.8
The S3 component supports storing and retrieving objetcs 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 are available at Amazon S3.
32.1. URI Format
aws-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&…
For example in order to read file hello.txt
from bucket helloBucket
, use the following snippet:
from("aws-s3:helloBucket?accessKey=yourAccessKey&secretKey=yourSecretKey&prefix=hello.txt") .to("file:/var/downloaded");
32.2. URI Options
The AWS S3 Storage Service component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | The AWS S3 default configuration | S3Configuration | |
accessKey (common) | Amazon AWS Access Key | String | |
secretKey (common) | Amazon AWS Secret Key | String | |
region (common) | The region where the bucket is located. This option is used in the com.amazonaws.services.s3.model.CreateBucketRequest. | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The AWS S3 Storage Service endpoint is configured using URI syntax:
aws-s3:bucketNameOrArn
with the following path and query parameters:
32.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
bucketNameOrArn | Required Bucket name or ARN | String |
32.2.2. Query Parameters (50 parameters):
Name | Description | Default | Type |
---|---|---|---|
amazonS3Client (common) | Reference to a com.amazonaws.services.sqs.AmazonS3 in the link:https://camel.apache.org/registry.htmlRegistry. | AmazonS3 | |
pathStyleAccess (common) | Whether or not the S3 client should use path style access | 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 | |
region (common) | The region in which S3 client needs to work | String | |
useIAMCredentials (common) | Set whether the S3 client should expect to load credentials on an EC2 instance or to expect static credentials to be passed in. | false | boolean |
encryptionMaterials (common) | The encryption materials to use in case of Symmetric/Asymmetric client usage | EncryptionMaterials | |
useEncryption (common) | Define if encryption must be used or not | 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 |
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 S3Constants#BUCKET_NAME and S3Constants#KEY headers, or only the S3Constants#KEY header. | true | boolean |
fileName (consumer) | To get the object from the bucket with the given file name | String | |
includeBody (consumer) | If it is true, the exchange body will be set to a stream to the contents of the file. If false, the headers will be set with the S3 object metadata, but the body will be null. This option is strongly related to autocloseBody option. In case of setting includeBody to true 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 |
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. Is default unlimited, but use 0 or negative number to disable it as unlimited. | 10 | int |
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) | If this option is true and includeBody is true, 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 true 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) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
pollStrategy (consumer) | 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. | PollingConsumerPoll Strategy | |
deleteAfterWrite (producer) | Delete file object after the S3 file has been uploaded | 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 |
operation (producer) | The operation to do in case the user don’t want to do only an upload | S3Operations | |
partSize (producer) | Setup the partSize which is used in multi part upload, the default size is 25M. | 26214400 | long |
serverSideEncryption (producer) | Sets the server-side encryption algorithm when encrypting the object using AWS-managed keys. For example use AES256. | String | |
storageClass (producer) | The storage class to set in the com.amazonaws.services.s3.model.PutObjectRequest request. | String | |
awsKMSKeyId (producer) | Define the id of KMS key to use in case KMS is enabled | String | |
useAwsKMS (producer) | Define if KMS must be used or not | false | boolean |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
accelerateModeEnabled ( advanced) | Define if Accelerate Mode enabled is true or false | false | boolean |
chunkedEncodingDisabled ( advanced) | Define if disabled Chunked Encoding is true or false | false | boolean |
dualstackEnabled ( advanced) | Define if Dualstack enabled is true or false | false | boolean |
forceGlobalBucketAccess Enabled ( advanced) | Define if Force Global Bucket Access enabled is true or false | false | boolean |
payloadSigningEnabled ( advanced) | Define if Payload Signing enabled is true or false | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 1000 | 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. | 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. | ScheduledExecutor Service | |
scheduler (scheduler) | To use a cron scheduler from either camel-spring or camel-quartz2 component | none | ScheduledPollConsumer Scheduler |
schedulerProperties (scheduler) | To configure additional properties when using a custom scheduler or any of the Quartz2, Spring based scheduler. | Map | |
startScheduler (scheduler) | Whether the scheduler should be auto started. | true | boolean |
timeUnit (scheduler) | Time unit for initialDelay and delay options. | 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 |
32.3. Spring Boot Auto-Configuration
The component supports 34 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.aws-s3.access-key | Amazon AWS Access Key | String | |
camel.component.aws-s3.configuration.accelerate-mode-enabled | Define if Accelerate Mode enabled is true or false | false | Boolean |
camel.component.aws-s3.configuration.access-key | Amazon AWS Access Key | String | |
camel.component.aws-s3.configuration.amazon-s3-client | Reference to a com.amazonaws.services.sqs.AmazonS3 in the link:https://camel.apache.org/registry.htmlRegistry. | AmazonS3 | |
camel.component.aws-s3.configuration.autoclose-body | If this option is true and includeBody is true, 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 true 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.aws-s3.configuration.aws-k-m-s-key-id | Define the id of KMS key to use in case KMS is enabled | String | |
camel.component.aws-s3.configuration.bucket-name | Name of the bucket. The bucket will be created if it doesn’t already exists. | String | |
camel.component.aws-s3.configuration.chunked-encoding-disabled | Define if disabled Chunked Encoding is true or false | false | Boolean |
camel.component.aws-s3.configuration.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 S3Constants#BUCKET_NAME and S3Constants#KEY headers, or only the S3Constants#KEY header. | true | Boolean |
camel.component.aws-s3.configuration.delete-after-write | Delete file object after the S3 file has been uploaded | false | Boolean |
camel.component.aws-s3.configuration.dualstack-enabled | Define if Dualstack enabled is true or false | false | Boolean |
camel.component.aws-s3.configuration.encryption-materials | The encryption materials to use in case of Symmetric/Asymmetric client usage | EncryptionMaterials | |
camel.component.aws-s3.configuration.file-name | To get the object from the bucket with the given file name | String | |
camel.component.aws-s3.configuration.force-global-bucket-access-enabled | Define if Force Global Bucket Access enabled is true or false | false | Boolean |
camel.component.aws-s3.configuration.include-body | If it is true, the exchange body will be set to a stream to the contents of the file. If false, the headers will be set with the S3 object metadata, but the body will be null. This option is strongly related to autocloseBody option. In case of setting includeBody to true 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.aws-s3.configuration.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.aws-s3.configuration.operation | The operation to do in case the user don’t want to do only an upload | S3Operations | |
camel.component.aws-s3.configuration.part-size | Setup the partSize which is used in multi part upload, the default size is 25M. | 26214400 | Long |
camel.component.aws-s3.configuration.path-style-access | Whether or not the S3 client should use path style access | false | Boolean |
camel.component.aws-s3.configuration.payload-signing-enabled | Define if Payload Signing enabled is true or false | false | Boolean |
camel.component.aws-s3.configuration.policy | The policy for this queue to set in the com.amazonaws.services.s3.AmazonS3#setBucketPolicy() method. | String | |
camel.component.aws-s3.configuration.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.aws-s3.configuration.proxy-host | To define a proxy host when instantiating the SQS client | String | |
camel.component.aws-s3.configuration.proxy-port | Specify a proxy port to be used inside the client definition. | Integer | |
camel.component.aws-s3.configuration.region | The region in which S3 client needs to work | String | |
camel.component.aws-s3.configuration.secret-key | Amazon AWS Secret Key | String | |
camel.component.aws-s3.configuration.server-side-encryption | Sets the server-side encryption algorithm when encrypting the object using AWS-managed keys. For example use AES256. | String | |
camel.component.aws-s3.configuration.storage-class | The storage class to set in the com.amazonaws.services.s3.model.PutObjectRequest request. | String | |
camel.component.aws-s3.configuration.use-aws-k-m-s | Define if KMS must be used or not | false | Boolean |
camel.component.aws-s3.configuration.use-encryption | Define if encryption must be used or not | false | Boolean |
camel.component.aws-s3.enabled | Enable aws-s3 component | true | Boolean |
camel.component.aws-s3.region | The region where the bucket is located. This option is used in the com.amazonaws.services.s3.model.CreateBucketRequest. | String | |
camel.component.aws-s3.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.aws-s3.secret-key | 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.
32.4. 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.
32.5. Usage
32.5.1. Message headers evaluated by the S3 producer
Header | Type | Description |
---|---|---|
|
| The bucket Name which this object will be stored or which will be used for the current operation |
|
| Camel 2.18: The bucket Destination Name which will be used for the current operation |
|
| The content length of this object. |
|
| The content type of this object. |
|
| Camel 2.8.2: The content control of this object. |
|
| Camel 2.8.2: The content disposition of this object. |
|
| Camel 2.8.2: The content encoding of this object. |
|
| Camel 2.8.2: The md5 checksum of this object. |
|
| Camel 2.18:The Destination key which will be used for the current operation |
|
| The key under which this object will be stored or which will be used for the current operation |
|
| Camel 2.8.2: The last modified timestamp of this object. |
|
| Camel 2.18: The operation to perform. Permitted values are copyObject, deleteObject, listBuckets, deleteBucket, downloadLink, listObjects |
|
| Camel 2.8.4: The storage class of this object. |
|
|
Camel 2.11.0: The canned acl that will be applied to the object. see |
|
|
Camel 2.11.0: a well constructed Amazon S3 Access Control List object. see |
|
| Camel 2.15.0: support to get or set custom objectMetadata headers. |
| String | Camel 2.16: Sets the server-side encryption algorithm when encrypting the object using AWS-managed keys. For example use AES256. |
|
| The version Id of the object to be stored or returned from the current operation |
32.5.2. Message headers set by the S3 producer
Header | Type | Description |
---|---|---|
|
| The ETag value for the newly uploaded object. |
|
| The optional version ID of the newly uploaded object. |
|
| The expiration (millis) of URL download link. The link will be stored into CamelAwsS3DownloadLink response header. |
32.5.3. Message headers set by the S3 consumer
Header | Type | Description |
---|---|---|
|
| The key under which this object is stored. |
|
| The name of the bucket in which this object is contained. |
|
| 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. |
|
| The value of the Last-Modified header, indicating the date and time at which Amazon S3 last recorded a modification to the associated object. |
|
| 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. |
|
| 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. |
|
| 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. |
|
| The Content-Length HTTP header indicating the size of the associated object in bytes. |
|
| 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. |
|
| The optional Content-Disposition HTTP header, which specifies presentational information such as the recommended filename for the object to be saved as. |
|
| The optional Cache-Control HTTP header which allows the user to specify caching behavior along the HTTP request/reply chain. |
| String | Camel 2.16: The server-side encryption algorithm when encrypting the object using AWS-managed keys. |
32.5.4. S3 Producer operations
Camel-AWS s3 component provides the following operation on the producer side:
- copyObject
- deleteObject
- listBuckets
- deleteBucket
- downloadLink
- listObjects
32.5.5. Advanced AmazonS3 configuration
If your Camel Application is running behind a firewall or if you need to have more control over the AmazonS3
instance configuration, you can create your own instance:
AWSCredentials awsCredentials = new BasicAWSCredentials("myAccessKey", "mySecretKey"); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setProxyHost("http://myProxyHost"); clientConfiguration.setProxyPort(8080); AmazonS3 client = new AmazonS3Client(awsCredentials, clientConfiguration); registry.bind("client", client);
and refer to it in your Camel aws-s3 component configuration:
from("aws-s3://MyBucket?amazonS3Client=#client&delay=5000&maxMessagesPerPoll=5") .to("mock:result");
32.5.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("aws-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.
32.5.7. Use "useIAMCredentials" with the s3 component
To use AWS IAM credentials, you must first verify that the EC2 in which you are launching the Camel application on has an IAM role associated with it containing the appropriate policies attached to run effectively. Keep in mind that this feature should only be set to "true" on remote instances. To clarify even further, you must still use static credentials locally since IAM is an AWS specific component, but AWS environments should now be easier to manage. After this is implemented and understood, you can set the query parameter "useIAMCredentials" to "true" for AWS environments! To effectively toggle this on and off based on local and remote environments, you can consider enabling this query parameter with system environment variables. For example, your code could set the "useIAMCredentials" query parameter to "true", when the system environment variable called "isRemote" is set to true (there are many other ways to do this and this should act as a simple example). Although it doesn’t take away the need for static credentials completely, using IAM credentials on AWS environments takes away the need to refresh on remote environments and adds a major security boost (IAM credentials are refreshed automatically every 6 hours and update when their policies are updated). This is the AWS recommended way to manage credentials and therefore should be used as often as possible.
32.6. Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.8 or higher).
32.7. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 33. AWS SimpleDB Component
Available as of Camel version 2.9
The sdb component supports storing and retrieving data from/to Amazon’s SDB service.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon SDB. More information are available at Amazon SDB.
33.1. URI Format
aws-sdb://domainName[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
33.2. URI Options
The AWS SimpleDB component has no options.
The AWS SimpleDB endpoint is configured using URI syntax:
aws-sdb:domainName
with the following path and query parameters:
33.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
domainName | Required The name of the domain currently worked with. | String |
33.2.2. Query Parameters (10 parameters):
Name | Description | Default | Type |
---|---|---|---|
accessKey (producer) | Amazon AWS Access Key | String | |
amazonSDBClient (producer) | To use the AmazonSimpleDB as the client | AmazonSimpleDB | |
consistentRead (producer) | Determines whether or not strong consistency should be enforced when data is read. | false | boolean |
maxNumberOfDomains (producer) | The maximum number of domain names you want returned. The range is 1 to 100. | Integer | |
operation (producer) | Operation to perform | PutAttributes | SdbOperations |
proxyHost (producer) | To define a proxy host when instantiating the SDB client | String | |
proxyPort (producer) | To define a proxy port when instantiating the SDB client | Integer | |
region (producer) | The region in which SDB client needs to work | String | |
secretKey (producer) | Amazon AWS Secret Key | String | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
33.3. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.aws-sdb.enabled | Enable aws-sdb component | true | Boolean |
camel.component.aws-sdb.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
Required SDB component options
You have to provide the amazonSDBClient in the Registry or your accessKey and secretKey to access the Amazon’s SDB.
33.4. Usage
33.4.1. Message headers evaluated by the SDB producer
Header | Type | Description |
---|---|---|
|
| List of attributes to be acted upon. |
|
| The names of the attributes to be retrieved. |
|
| Determines whether or not strong consistency should be enforced when data is read. |
|
| A list of items on which to perform the delete operation in a batch. |
|
| The name of the domain currently worked with. |
|
| The unique key for this item |
|
| The maximum number of domain names you want returned. The range is 1 * to 100. |
|
| A string specifying where to start the next list of domain/item names. |
|
| To override the operation from the URI options. |
|
| List of attributes to put in an Item. |
|
| A list of items to put in a Domain. |
|
| The expression used to query the domain. |
|
| The update condition which, if specified, determines whether the specified attributes will be updated/deleted or not. |
33.4.2. Message headers set during DomainMetadata operation
Header | Type | Description |
---|---|---|
|
| The data and time when metadata was calculated, in Epoch (UNIX) seconds. |
|
| The number of all items in the domain. |
|
| The number of unique attribute names in the domain. |
|
| The number of all attribute name/value pairs in the domain. |
|
| The total size of all unique attribute names in the domain, in bytes. |
|
| The total size of all attribute values in the domain, in bytes. |
|
| The total size of all item names in the domain, in bytes. |
33.4.3. Message headers set during GetAttributes operation
Header | Type | Description |
---|---|---|
|
| The list of attributes returned by the operation. |
33.4.4. Message headers set during ListDomains operation
Header | Type | Description |
---|---|---|
|
| A list of domain names that match the expression. |
|
| An opaque token indicating that there are more domains than the specified MaxNumberOfDomains still available. |
33.4.5. Message headers set during Select operation
Header | Type | Description |
---|---|---|
|
| A list of items that match the select expression. |
|
| An opaque token indicating that more items than MaxNumberOfItems were matched, the response size exceeded 1 megabyte, or the execution time exceeded 5 seconds. |
33.4.6. Advanced AmazonSimpleDB configuration
If you need more control over the AmazonSimpleDB
instance configuration you can create your own instance and refer to it from the URI:
from("direct:start") .to("aws-sdb://domainName?amazonSDBClient=#client");
The #client
refers to a AmazonSimpleDB
in the Registry.
For example if your Camel Application is running behind a firewall:
AWSCredentials awsCredentials = new BasicAWSCredentials("myAccessKey", "mySecretKey"); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setProxyHost("http://myProxyHost"); clientConfiguration.setProxyPort(8080); AmazonSimpleDB client = new AmazonSimpleDBClient(awsCredentials, clientConfiguration); registry.bind("client", client);
33.5. Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.8.4 or higher).
33.6. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 34. AWS Simple Email Service Component
Available as of Camel version 2.9
The ses component supports sending emails with Amazon’s SES service.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon SES. More information are available at Amazon SES.
34.1. URI Format
aws-ses://from[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
34.2. URI Options
The AWS Simple Email Service component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | The AWS SES default configuration | SesConfiguration | |
accessKey (producer) | Amazon AWS Access Key | String | |
secretKey (producer) | Amazon AWS Secret Key | String | |
region (producer) | The region in which SES client needs to work | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The AWS Simple Email Service endpoint is configured using URI syntax:
aws-ses:from
with the following path and query parameters:
34.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
from | Required The sender’s email address. | String |
34.2.2. Query Parameters (11 parameters):
Name | Description | Default | Type |
---|---|---|---|
amazonSESClient (producer) | To use the AmazonSimpleEmailService as the client | AmazonSimpleEmail Service | |
proxyHost (producer) | To define a proxy host when instantiating the SES client | String | |
proxyPort (producer) | To define a proxy port when instantiating the SES client | Integer | |
region (producer) | The region in which SES client needs to work | String | |
replyToAddresses (producer) | List of reply-to email address(es) for the message, override it using 'CamelAwsSesReplyToAddresses' header. | List | |
returnPath (producer) | The email address to which bounce notifications are to be forwarded, override it using 'CamelAwsSesReturnPath' header. | String | |
subject (producer) | The subject which is used if the message header 'CamelAwsSesSubject' is not present. | String | |
to (producer) | List of destination email address. Can be overriden with 'CamelAwsSesTo' header. | List | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
accessKey (security) | Amazon AWS Access Key | String | |
secretKey (security) | Amazon AWS Secret Key | String |
34.3. Spring Boot Auto-Configuration
The component supports 16 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.aws-ses.access-key | Amazon AWS Access Key | String | |
camel.component.aws-ses.configuration.access-key | Amazon AWS Access Key | String | |
camel.component.aws-ses.configuration.amazon-s-e-s-client | To use the AmazonSimpleEmailService as the client | AmazonSimpleEmail Service | |
camel.component.aws-ses.configuration.from | The sender’s email address. | String | |
camel.component.aws-ses.configuration.proxy-host | To define a proxy host when instantiating the SES client | String | |
camel.component.aws-ses.configuration.proxy-port | To define a proxy port when instantiating the SES client | Integer | |
camel.component.aws-ses.configuration.region | The region in which SES client needs to work | String | |
camel.component.aws-ses.configuration.reply-to-addresses | List of reply-to email address(es) for the message, override it using 'CamelAwsSesReplyToAddresses' header. | List | |
camel.component.aws-ses.configuration.return-path | The email address to which bounce notifications are to be forwarded, override it using 'CamelAwsSesReturnPath' header. | String | |
camel.component.aws-ses.configuration.secret-key | Amazon AWS Secret Key | String | |
camel.component.aws-ses.configuration.subject | The subject which is used if the message header 'CamelAwsSesSubject' is not present. | String | |
camel.component.aws-ses.configuration.to | List of destination email address. Can be overriden with 'CamelAwsSesTo' header. | List | |
camel.component.aws-ses.enabled | Enable aws-ses component | true | Boolean |
camel.component.aws-ses.region | The region in which SES client needs to work | String | |
camel.component.aws-ses.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.aws-ses.secret-key | Amazon AWS Secret Key | String |
Required SES component options
You have to provide the amazonSESClient in the Registry or your accessKey and secretKey to access the Amazon’s SES.
34.4. Usage
34.4.1. Message headers evaluated by the SES producer
Header | Type | Description |
---|---|---|
|
| The sender’s email address. |
|
| The destination(s) for this email. |
|
| The subject of the message. |
|
| The reply-to email address(es) for the message. |
|
| The email address to which bounce notifications are to be forwarded. |
|
| Since Camel 2.12.3 The flag to show if email content is HTML. |
34.4.2. Message headers set by the SES producer
Header | Type | Description |
---|---|---|
|
| The Amazon SES message ID. |
34.4.3. Advanced AmazonSimpleEmailService configuration
If you need more control over the AmazonSimpleEmailService
instance configuration you can create your own instance and refer to it from the URI:
from("direct:start") .to("aws-ses://example@example.com?amazonSESClient=#client");
The #client
refers to a AmazonSimpleEmailService
in the Registry.
For example if your Camel Application is running behind a firewall:
AWSCredentials awsCredentials = new BasicAWSCredentials("myAccessKey", "mySecretKey"); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setProxyHost("http://myProxyHost"); clientConfiguration.setProxyPort(8080); AmazonSimpleEmailService client = new AmazonSimpleEmailServiceClient(awsCredentials, clientConfiguration); registry.bind("client", client);
34.5. Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.8.4 or higher).
34.6. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 35. AWS Simple Notification System Component
Available as of Camel version 2.8
The 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 are available at Amazon SNS.
35.1. URI Format
aws-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&…
35.2. URI Options
The AWS Simple Notification System component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | The AWS SNS default configuration | SnsConfiguration | |
accessKey (producer) | Amazon AWS Access Key | String | |
secretKey (producer) | Amazon AWS Secret Key | String | |
region (producer) | The region in which SNS client needs to work | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The AWS Simple Notification System endpoint is configured using URI syntax:
aws-sns:topicNameOrArn
with the following path and query parameters:
35.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
topicNameOrArn | Required Topic name or ARN | String |
35.2.2. Query Parameters (11 parameters):
Name | Description | Default | Type |
---|---|---|---|
amazonSNSClient (producer) | To use the AmazonSNS as the client | AmazonSNS | |
headerFilterStrategy (producer) | To use a custom HeaderFilterStrategy to map headers to/from Camel. | HeaderFilterStrategy | |
messageStructure (producer) | The message structure to use such as json | String | |
policy (producer) | The policy for this queue | 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 | |
region (producer) | The region in which SNS client needs to work | String | |
subject (producer) | The subject which is used if the message header 'CamelAwsSnsSubject' is not present. | String | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
accessKey (security) | Amazon AWS Access Key | String | |
secretKey (security) | Amazon AWS Secret Key | String |
35.3. Spring Boot Auto-Configuration
The component supports 16 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.aws-sns.access-key | Amazon AWS Access Key | String | |
camel.component.aws-sns.configuration.access-key | Amazon AWS Access Key | String | |
camel.component.aws-sns.configuration.amazon-s-n-s-client | To use the AmazonSNS as the client | AmazonSNS | |
camel.component.aws-sns.configuration.message-structure | The message structure to use such as json | String | |
camel.component.aws-sns.configuration.policy | The policy for this queue | String | |
camel.component.aws-sns.configuration.proxy-host | To define a proxy host when instantiating the SNS client | String | |
camel.component.aws-sns.configuration.proxy-port | To define a proxy port when instantiating the SNS client | Integer | |
camel.component.aws-sns.configuration.region | The region in which SNS client needs to work | String | |
camel.component.aws-sns.configuration.secret-key | Amazon AWS Secret Key | String | |
camel.component.aws-sns.configuration.subject | The subject which is used if the message header 'CamelAwsSnsSubject' is not present. | String | |
camel.component.aws-sns.configuration.topic-arn | The Amazon Resource Name (ARN) assigned to the created topic. | String | |
camel.component.aws-sns.configuration.topic-name | The name of the topic | String | |
camel.component.aws-sns.enabled | Enable aws-sns component | true | Boolean |
camel.component.aws-sns.region | The region in which SNS client needs to work | String | |
camel.component.aws-sns.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.aws-sns.secret-key | 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.
35.4. Usage
35.4.1. Message headers evaluated by the SNS producer
Header | Type | Description |
---|---|---|
|
|
The Amazon SNS message subject. If not set, the subject from the |
35.4.2. Message headers set by the SNS producer
Header | Type | Description |
---|---|---|
|
| The Amazon SNS message ID. |
35.4.3. Advanced AmazonSNS configuration
If you need more control over the AmazonSNS
instance configuration you can create your own instance and refer to it from the URI:
from("direct:start") .to("aws-sns://MyTopic?amazonSNSClient=#client");
The #client
refers to a AmazonSNS
in the Registry.
For example if your Camel Application is running behind a firewall:
AWSCredentials awsCredentials = new BasicAWSCredentials("myAccessKey", "mySecretKey"); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setProxyHost("http://myProxyHost"); clientConfiguration.setProxyPort(8080); AmazonSNS client = new AmazonSNSClient(awsCredentials, clientConfiguration); registry.bind("client", client);
35.5. Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.8 or higher).
35.6. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 36. AWS Simple Queue Service Component
Available as of Camel version 2.6
The 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 are available at Amazon SQS.
36.1. URI Format
aws-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&…
36.2. URI Options
The AWS Simple Queue Service component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | The AWS SQS default configuration | SqsConfiguration | |
accessKey (common) | Amazon AWS Access Key | String | |
secretKey (common) | Amazon AWS Secret Key | String | |
region (common) | Specify the queue region which could be used with queueOwnerAWSAccountId to build the service URL. | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The AWS Simple Queue Service endpoint is configured using URI syntax:
aws-sqs:queueNameOrArn
with the following path and query parameters:
36.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
queueNameOrArn | Required Queue name or ARN | String |
36.2.2. Query Parameters (49 parameters):
Name | Description | Default | Type |
---|---|---|---|
amazonAWSHost (common) | The hostname of the Amazon AWS cloud. | amazonaws.com | String |
amazonSQSClient (common) | To use the AmazonSQS as client | AmazonSQS | |
headerFilterStrategy (common) | To use a custom HeaderFilterStrategy to map headers to/from Camel. | HeaderFilterStrategy | |
queueOwnerAWSAccountId (common) | Specify the queue owner aws account id when you need to connect the queue with different account owner. | String | |
region (common) | Specify the queue region which could be used with queueOwnerAWSAccountId to build the service URL. | String | |
useIAMCredentials (common) | Set whether the SQS client should expect to load credentials on an EC2 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 an exchange fails to get through a filter. If 'false' and exchange does not make it through a Camel filter upstream in the route, then don’t send DeleteMessage. | 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 |
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 |
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) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
pollStrategy (consumer) | 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. | PollingConsumerPoll Strategy | |
delaySeconds (producer) | Delay sending messages for a number of seconds. | Integer | |
messageDeduplicationId Strategy (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. | useExchangeId | MessageDeduplicationId Strategy |
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. | MessageGroupIdStrategy | |
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 | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 1000 | 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. | 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. | ScheduledExecutor Service | |
scheduler (scheduler) | To use a cron scheduler from either camel-spring or camel-quartz2 component | none | ScheduledPollConsumer Scheduler |
schedulerProperties (scheduler) | To configure additional properties when using a custom scheduler or any of the Quartz2, Spring based scheduler. | Map | |
startScheduler (scheduler) | Whether the scheduler should be auto started. | true | boolean |
timeUnit (scheduler) | Time unit for initialDelay and delay options. | MILLISECONDS | TimeUnit |
useFixedDelay (scheduler) | Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean |
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 | String | |
receiveMessageWaitTime Seconds (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 |
36.3. Spring Boot Auto-Configuration
The component supports 31 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.aws-sqs.access-key | Amazon AWS Access Key | String | |
camel.component.aws-sqs.configuration.access-key | Amazon AWS Access Key | String | |
camel.component.aws-sqs.configuration.amazon-a-w-s-host | The hostname of the Amazon AWS cloud. | amazonaws.com | String |
camel.component.aws-sqs.configuration.amazon-s-q-s-client | To use the AmazonSQS as client | AmazonSQS | |
camel.component.aws-sqs.configuration.attribute-names | A list of attribute names to receive when consuming. Multiple names can be separated by comma. | String | |
camel.component.aws-sqs.configuration.concurrent-consumers | Allows you to use multiple threads to poll the sqs queue to increase throughput | 1 | Integer |
camel.component.aws-sqs.configuration.default-visibility-timeout | The default visibility timeout (in seconds) | Integer | |
camel.component.aws-sqs.configuration.delay-queue | Define if you want to apply delaySeconds option to the queue or on single messages | false | Boolean |
camel.component.aws-sqs.configuration.delay-seconds | Delay sending messages for a number of seconds. | Integer | |
camel.component.aws-sqs.configuration.delete-after-read | Delete message from SQS after it has been read | true | Boolean |
camel.component.aws-sqs.configuration.delete-if-filtered | Whether or not to send the DeleteMessage to the SQS queue if an exchange fails to get through a filter. If 'false' and exchange does not make it through a Camel filter upstream in the route, then don’t send DeleteMessage. | true | Boolean |
camel.component.aws-sqs.configuration.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.aws-sqs.configuration.maximum-message-size | The maximumMessageSize (in bytes) an SQS message can contain for this queue. | Integer | |
camel.component.aws-sqs.configuration.message-attribute-names | A list of message attribute names to receive when consuming. Multiple names can be separated by comma. | String | |
camel.component.aws-sqs.configuration.message-retention-period | The messageRetentionPeriod (in seconds) a message will be retained by SQS for this queue. | Integer | |
camel.component.aws-sqs.configuration.policy | The policy for this queue | String | |
camel.component.aws-sqs.configuration.proxy-host | To define a proxy host when instantiating the SQS client | String | |
camel.component.aws-sqs.configuration.proxy-port | To define a proxy port when instantiating the SQS client | Integer | |
camel.component.aws-sqs.configuration.queue-name | Name of queue. The queue will be created if they don’t already exists. | String | |
camel.component.aws-sqs.configuration.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.aws-sqs.configuration.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.aws-sqs.configuration.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.aws-sqs.configuration.redrive-policy | Specify the policy that send message to DeadLetter queue. See detail at Amazon docs. | String | |
camel.component.aws-sqs.configuration.region | Specify the queue region which could be used with queueOwnerAWSAccountId to build the service URL. | String | |
camel.component.aws-sqs.configuration.secret-key | Amazon AWS Secret Key | String | |
camel.component.aws-sqs.configuration.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.aws-sqs.configuration.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 | |
camel.component.aws-sqs.enabled | Enable aws-sqs component | true | Boolean |
camel.component.aws-sqs.region | Specify the queue region which could be used with queueOwnerAWSAccountId to build the service URL. | String | |
camel.component.aws-sqs.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.aws-sqs.secret-key | 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.
36.4. 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.
36.5. Usage
36.5.1. Message headers set by the SQS producer
Header | Type | Description |
---|---|---|
|
| The MD5 checksum of the Amazon SQS message. |
|
| The Amazon SQS message ID. |
|
| Since Camel 2.11, the delay seconds that the Amazon SQS message can be see by others. |
36.5.2. Message headers set by the SQS consumer
Header | Type | Description |
---|---|---|
|
| The MD5 checksum of the Amazon SQS message. |
|
| The Amazon SQS message ID. |
|
| The Amazon SQS message receipt handle. |
|
| The Amazon SQS message attributes. |
36.5.3. Advanced AmazonSQS configuration
If your Camel Application is running behind a firewall or if you need to have more control over the AmazonSQS instance configuration, you can create your own instance:
AWSCredentials awsCredentials = new BasicAWSCredentials("myAccessKey", "mySecretKey"); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setProxyHost("http://myProxyHost"); clientConfiguration.setProxyPort(8080); AmazonSQS client = new AmazonSQSClient(awsCredentials, clientConfiguration); registry.bind("client", client);
and refer to it in your Camel aws-sqs component configuration:
from("aws-sqs://MyQueue?amazonSQSClient=#client&delay=5000&maxMessagesPerPoll=5") .to("mock:result");
36.5.4. 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("aws-sqs://MyQueue?amazonSQSClient=#client&delay=5000&maxMessagesPerPoll=5") .to("mock:result");
In this example if the MyQueue queue is not already created on AWS, 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.
36.5.5. DelayQueue VS Delay for Single message
From 2.23.0 the component has a new option: delayQueue. When the option 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.
36.5.6. Using AWS IAM credentials with the SQS component
To use AWS IAM credentials, you must first confirm that the EC2 instance on which you are launching the Camel application has an IAM role associated with it and that the appropriate policies are attached.
This feature should only be set to true
on remote instances. Additionally, you must also use static credentials locally as IAM is an AWS specific component.
To implement this feature set useIAMCredentials
to true
.
To toggle this feature on and off based on local and remote environments, you could consider enabling this query parameter with system environment variables. For example, your code could set the useIAMCredentials
query parameter to true
if a system environment variable named isRemote
is set to true
.
Although this feature does not eliminate the need for static credentials completely, using IAM credentials on AWS environments does remove the need to refresh on remote environments and is more secure as IAM credentials are refreshed automatically every six hours and are also updated when EC2 security policies are updated.
This is the AWS recommended way to manage credentials and therefore should be used as often as possible.
36.6. Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.6 or higher).
36.7. 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("aws-sqs://MyQueue?amazonSQSClient=#client&defaultVisibilityTimeout=5000&deleteIfFiltered=false") .filter("${header.login} == true") .to("mock:result");
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 miliseconds, the message will become visible to other consumers.
36.8. 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("aws-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)®ion=EU_WEST_1");
As result you’ll get an exchange containing a DeleteMessageResult
instance, that you can use to check if the message was deleted or not.
36.9. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 37. AWS Simple Workflow Component
Available as of Camel version 2.13
The Simple Workflow component supports managing workflows from Amazon’s Simple Workflow service.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon Simple Workflow. More information are available at Amazon Simple Workflow.
37.1. URI Format
aws-swf://<workflow|activity>[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
37.2. URI Options
The AWS Simple Workflow component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | The AWS SWF default configuration | SWFConfiguration | |
accessKey (common) | Amazon AWS Access Key. | String | |
secretKey (common) | Amazon AWS Secret Key. | String | |
region (common) | Amazon AWS Region. | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The AWS Simple Workflow endpoint is configured using URI syntax:
aws-swf:type
with the following path and query parameters:
37.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
type | Required Activity or workflow | String |
37.2.2. Query Parameters (30 parameters):
Name | Description | Default | Type |
---|---|---|---|
amazonSWClient (common) | To use the given AmazonSimpleWorkflowClient as client | AmazonSimpleWorkflow Client | |
dataConverter (common) | An instance of com.amazonaws.services.simpleworkflow.flow.DataConverter to use for serializing/deserializing the data. | DataConverter | |
domainName (common) | The workflow domain to use. | String | |
eventName (common) | The workflow or activity event name to use. | String | |
region (common) | Amazon AWS Region. | String | |
version (common) | The workflow or activity event version to use. | 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 |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
clientConfiguration Parameters (advanced) | To configure the ClientConfiguration using the key/values from the Map. | Map | |
startWorkflowOptions Parameters (advanced) | To configure the StartWorkflowOptions using the key/values from the Map. | Map | |
sWClientParameters (advanced) | To configure the AmazonSimpleWorkflowClient using the key/values from the Map. | Map | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
activityList (activity) | The list name to consume activities from. | String | |
activitySchedulingOptions (activity) | Activity scheduling options | ActivityScheduling Options | |
activityThreadPoolSize (activity) | Maximum number of threads in work pool for activity. | 100 | int |
activityTypeExecution Options (activity) | Activity execution options | ActivityTypeExecution Options | |
activityTypeRegistration Options (activity) | Activity registration options | ActivityType RegistrationOptions | |
childPolicy (workflow) | The policy to use on child workflows when terminating a workflow. | String | |
executionStartToClose Timeout (workflow) | Set the execution start to close timeout. | 3600 | String |
operation (workflow) | Workflow operation | START | String |
signalName (workflow) | The name of the signal to send to the workflow. | String | |
stateResultType (workflow) | The type of the result when a workflow state is queried. | String | |
taskStartToCloseTimeout (workflow) | Set the task start to close timeout. | 600 | String |
terminationDetails (workflow) | Details for terminating a workflow. | String | |
terminationReason (workflow) | The reason for terminating a workflow. | String | |
workflowList (workflow) | The list name to consume workflows from. | String | |
workflowTypeRegistration Options (workflow) | Workflow registration options | WorkflowType RegistrationOptions | |
accessKey (security) | Amazon AWS Access Key. | String | |
secretKey (security) | Amazon AWS Secret Key. | String |
37.3. Spring Boot Auto-Configuration
The component supports 32 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.aws-swf.access-key | Amazon AWS Access Key. | String | |
camel.component.aws-swf.configuration.access-key | Amazon AWS Access Key. | String | |
camel.component.aws-swf.configuration.activity-list | The list name to consume activities from. | String | |
camel.component.aws-swf.configuration.activity-scheduling-options | Activity scheduling options | ActivityScheduling Options | |
camel.component.aws-swf.configuration.activity-thread-pool-size | Maximum number of threads in work pool for activity. | 100 | Integer |
camel.component.aws-swf.configuration.activity-type-execution-options | Activity execution options | ActivityTypeExecution Options | |
camel.component.aws-swf.configuration.activity-type-registration-options | Activity registration options | ActivityType RegistrationOptions | |
camel.component.aws-swf.configuration.amazon-s-w-client | To use the given AmazonSimpleWorkflowClient as client | AmazonSimpleWorkflow Client | |
camel.component.aws-swf.configuration.child-policy | The policy to use on child workflows when terminating a workflow. | String | |
camel.component.aws-swf.configuration.client-configuration-parameters | To configure the ClientConfiguration using the key/values from the Map. | Map | |
camel.component.aws-swf.configuration.data-converter | An instance of com.amazonaws.services.simpleworkflow.flow.DataConverter to use for serializing/deserializing the data. | DataConverter | |
camel.component.aws-swf.configuration.domain-name | The workflow domain to use. | String | |
camel.component.aws-swf.configuration.event-name | The workflow or activity event name to use. | String | |
camel.component.aws-swf.configuration.execution-start-to-close-timeout | Set the execution start to close timeout. | 3600 | String |
camel.component.aws-swf.configuration.operation | Workflow operation | START | String |
camel.component.aws-swf.configuration.region | Amazon AWS Region. | String | |
camel.component.aws-swf.configuration.s-w-client-parameters | To configure the AmazonSimpleWorkflowClient using the key/values from the Map. | Map | |
camel.component.aws-swf.configuration.secret-key | Amazon AWS Secret Key. | String | |
camel.component.aws-swf.configuration.signal-name | The name of the signal to send to the workflow. | String | |
camel.component.aws-swf.configuration.start-workflow-options-parameters | To configure the StartWorkflowOptions using the key/values from the Map. | Map | |
camel.component.aws-swf.configuration.state-result-type | The type of the result when a workflow state is queried. | String | |
camel.component.aws-swf.configuration.task-start-to-close-timeout | Set the task start to close timeout. | 600 | String |
camel.component.aws-swf.configuration.termination-details | Details for terminating a workflow. | String | |
camel.component.aws-swf.configuration.termination-reason | The reason for terminating a workflow. | String | |
camel.component.aws-swf.configuration.type | Activity or workflow | String | |
camel.component.aws-swf.configuration.version | The workflow or activity event version to use. | String | |
camel.component.aws-swf.configuration.workflow-list | The list name to consume workflows from. | String | |
camel.component.aws-swf.configuration.workflow-type-registration-options | Workflow registration options | WorkflowType RegistrationOptions | |
camel.component.aws-swf.enabled | Enable aws-swf component | true | Boolean |
camel.component.aws-swf.region | Amazon AWS Region. | String | |
camel.component.aws-swf.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.aws-swf.secret-key | Amazon AWS Secret Key. | String |
Required SWF component options
You have to provide the amazonSWClient in the Registry or your accessKey and secretKey to access the Amazon’s Simple Workflow Service.
37.4. Usage
37.4.1. Message headers evaluated by the SWF Workflow Producer
A workflow producer allows interacting with a workflow. It can start a new workflow execution, query its state, send signals to a running workflow, or terminate and cancel it.
Header | Type | Description |
---|---|---|
|
|
The operation to perform on the workflow. Supported operations are: |
|
| A workflow ID to use. |
|
| A worfklow run ID to use. |
|
| The type of the result when a workflow state is queried. |
|
| The workflow or activity event name to use. |
|
| The workflow or activity event version to use. |
|
| The reason for terminating a workflow. |
|
| Details for terminating a workflow. |
|
| The policy to use on child workflows when terminating a workflow. |
37.4.2. Message headers set by the SWF Workflow Producer
Header | Type | Description |
---|---|---|
|
| The worfklow ID used or newly generated. |
|
| The worfklow run ID used or generated. |
37.4.3. Message headers set by the SWF Workflow Consumer
A workflow consumer represents the workflow logic. When it is started, it will start polling workflow decision tasks and process them. In addition to processing decision tasks, a workflow consumer route, will also receive signals (send from a workflow producer) or state queries. The primary purpose of a workflow consumer is to schedule activity tasks for execution using activity producers. Actually activity tasks can be scheduled only from a thread started by a workflow consumer.
Header | Type | Description |
---|---|---|
|
| Indicates what type is the current event: CamelSWFActionExecute, CamelSWFSignalReceivedAction or CamelSWFGetStateAction. |
|
| Indicates whether the current decision task is a replay or not. |
|
| The time of the start event for this decision task. |
37.4.4. Message headers set by the SWF Activity Producer
An activity producer allows scheduling activity tasks. An activity producer can be used only from a thread started by a workflow consumer ie, it can process synchronous exchanges started by a workflow consumer.
Header | Type | Description |
---|---|---|
|
| The activity name to schedule. |
|
| The activity version to schedule. |
37.4.5. Message headers set by the SWF Activity Consumer
Header | Type | Description |
---|---|---|
|
| The task token that is required to report task completion for manually completed tasks. |
37.4.6. Advanced amazonSWClient configuration
If you need more control over the AmazonSimpleWorkflowClient instance configuration you can create your own instance and refer to it from the URI:
The #client
refers to a AmazonSimpleWorkflowClient in the Registry.
For example if your Camel Application is running behind a firewall:
AWSCredentials awsCredentials = new BasicAWSCredentials("myAccessKey", "mySecretKey"); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setProxyHost("http://myProxyHost"); clientConfiguration.setProxyPort(8080); AmazonSimpleWorkflowClient client = new AmazonSimpleWorkflowClient(awsCredentials, clientConfiguration); registry.bind("client", client);
37.5. Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.13 or higher).
37.6. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
AWS Component
Chapter 38. AWS XRay Component
Available as of Camel 2.21
The camel-aws-xray component is used for tracing and timing incoming and outgoing Camel messages using AWS XRay.
Events (subsegments) are captured for incoming and outgoing messages being sent to/from Camel.
38.1. Dependency
In order to include AWS XRay support into Camel, the archive containing the Camel related AWS XRay related classes need to be added to the project. In addition to that, AWS XRay libraries also need to be available.
To include both, AWS XRay and Camel, dependencies use the following Maven imports:
<dependencyManagement> <dependencies> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-xray-recorder-sdk-bom</artifactId> <version>1.3.1</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws-xray</artifactId> </dependency> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-xray-recorder-sdk-core</artifactId> </dependency> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-xray-recorder-sdk-aws-sdk</artifactId> </dependency> <dependencies>
38.2. Configuration
The configuration properties for the AWS XRay tracer are:
Option | Default | Description |
---|---|---|
addExcludePatterns |
| Sets exclude pattern(s) that will disable tracing for Camel messages that matches the pattern. The content is a Set<String> where the key is a pattern matching routeId’s. The pattern uses the rules from Intercept. |
setTracingStrategy | NoopTracingStrategy |
Allows a custom Camel |
There is currently only one way an AWS XRay tracer can be configured to provide distributed tracing for a Camel application:
38.2.1. Explicit
Include the camel-aws-xray
component in your POM, along with any specific dependencies associated with the AWS XRay Tracer.
To explicitly configure AWS XRay support, instantiate the XRayTracer
and initialize the camel context. You can optionally specify a Tracer
, or alternatively it can be implicitly discovered using the Registry
or ServiceLoader
.
XRayTracer xrayTracer = new XRayTracer(); // By default it uses a NoopTracingStrategy, but you can override it with a specific InterceptStrategy implementation. xrayTracer.setTracingStrategy(...); // And then initialize the context xrayTracer.init(camelContext);
To use XRayTracer in XML, all you need to do is to define the AWS XRay tracer bean. Camel will automatically discover and use it.
<bean id="tracingStrategy" class="..."/> <bean id="aws-xray-tracer" class="org.apache.camel.component.aws.xray.XRayTracer" /> <property name="tracer" ref="tracingStrategy"/> </bean>
In case of the default NoopTracingStrategy
only the creation and deletion of exchanges is tracked but not the invocation of certain beans or EIP patterns.
38.2.2. Tracking of comprehensive route execution
In order to track the execution of an exchange among multiple routes, on exchange creation a unique trace ID is generated and stored in the headers if no corresponding value was yet available. This trace ID is copied over to new exchanges in order to keep a consistent view of the processed exchange.
As AWS XRay traces work on a thread-local basis the current sub/segment should be copied over to the new thread and set as explained in in the AWS XRay documentation. The Camel AWS XRay component therefore provides an additional header field that the component will use in order to set the passed AWS XRay Entity
to the new thread and thus keep the tracked data to the route rather than exposing a new segment which seems uncorrelated with any of the executed routes.
The component will use the following constants found in the headers of the exchange:
Header | Description |
---|---|
Camel-AWS-XRay-Trace-ID |
Contains a reference to the AWS XRay |
Camel-AWS-XRay-Trace-Entity |
Contains a reference to the actual AWS XRay |
Note that the AWS XRay Entity
(i.e., Segment
and Subsegment
) are not serializable and therefore should not get passed to other JVM processes.
38.3. Example
You can find an example demonstrating the way to configure AWS XRay tracing within the tests accompanying this project.
Chapter 39. Camel Components for Windows Azure Services
The Camel Components for Windows Azure Services provide connectivity to Azure services from Camel.
Azure Service | Camel Component | Camel Version | Component Description |
---|---|---|---|
2.9.0 | Supports storing and retrieving of blobs | ||
2.9.0 | Supports storing and retrieving of messages in the queues |
Chapter 40. Azure Storage Blob Service Component
Available as of Camel version 2.19
The Azure Blob component supports storing and retrieving the blobs to/from Azure Storage Blob service.
Prerequisites
You must have a valid Windows Azure Storage account. More information is available at Azure Documentation Portal.
40.1. URI Format
azure-blob://accountName/containerName[/blobName][?options]
In most cases a blobName is required and 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&…
For example in order to download a blob content from the public block blob blockBlob
located on the container1
in the camelazure
storage account, use the following snippet:
from("azure-blob:/camelazure/container1/blockBlob"). to("file://blobdirectory");
40.2. URI Options
The Azure Storage Blob Service component has no options.
The Azure Storage Blob Service endpoint is configured using URI syntax:
azure-blob:containerOrBlobUri
with the following path and query parameters:
40.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
containerOrBlobUri | Required Container or Blob compact Uri | String |
40.2.2. Query Parameters (19 parameters):
Name | Description | Default | Type |
---|---|---|---|
azureBlobClient (common) | The blob service client | CloudBlob | |
blobOffset (common) | Set the blob offset for the upload or download operations, default is 0 | 0 | Long |
blobType (common) | Set a blob type, 'blockblob' is default | blockblob | BlobType |
closeStreamAfterRead (common) | Close the stream after read or keep it open, default is true | true | boolean |
credentials (common) | Set the storage credentials, required in most cases | StorageCredentials | |
dataLength (common) | Set the data length for the download or page blob upload operations | Long | |
fileDir (common) | Set the file directory where the downloaded blobs will be saved to | String | |
publicForRead (common) | Storage resources can be public for reading their content, if this property is enabled then the credentials do not have to be set | false | boolean |
streamReadSize (common) | Set the minimum read size in bytes when reading the blob content | int | |
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) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
blobMetadata (producer) | Set the blob meta-data | Map | |
blobPrefix (producer) | Set a prefix which can be used for listing the blobs | String | |
closeStreamAfterWrite (producer) | Close the stream after write or keep it open, default is true | true | boolean |
operation (producer) | Blob service operation hint to the producer | listBlobs | BlobServiceOperations |
streamWriteSize (producer) | Set the size of the buffer for writing block and page blocks | int | |
useFlatListing (producer) | Specify if the flat or hierarchical blob listing should be used | true | boolean |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
40.3. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.azure-blob.enabled | Enable azure-blob component | true | Boolean |
camel.component.azure-blob.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
Required Azure Storage Blob Service component options
You have to provide the containerOrBlob name and the credentials if the private blob needs to be accessed.
40.4. Usage
40.4.1. Message headers evaluated by the Azure Storage Blob Service producer
Header | Type | Description |
---|---|---|
40.4.2. Message headers set by the Azure Storage Blob Service producer
Header | Type | Description |
---|---|---|
|
| The file name for the downloaded blob content. |
40.4.3. Message headers set by the Azure Storage Blob Service producer consumer
Header | Type | Description |
---|---|---|
|
| The file name for the downloaded blob content. |
40.4.4. Azure Blob Service operations
Operations common to all block types
Operation | Description |
---|---|
| Get the content of the blob. You can restrict the output of this operation to a blob range. |
| Delete the blob. |
| List the blobs. |
Block blob operations
Operation | Description |
---|---|
| Put block blob content that either creates a new block blob or overwrites the existing block blob content. |
|
Upload block blob content, by first generating a sequence of blob blocks and then committing them to a blob. If you enable the message CommitBlockListLater property, you can execute the commit later with the |
|
Commit a sequence of blob blocks to the block list that you previously uploaded to the blob service (by using the |
| Get the block blob list. |
Append blob operations
Operation | Description |
---|---|
|
Create an append block. By default, if the block already exists then it is not reset. Note that you can alternately create an append blob by enabling the message AppendBlobCreated property and using the |
| Append the new content to the blob. This operation also creates the blob if it does not already exist and if you enabled a message AppendBlobCreated property. |
Page Block operations
Operation | Description |
---|---|
|
Create a page block. By default, if the block already exists then it is not reset. Note that you can also create a page blob (and set its contents) by enabling a message PageBlobCreated property and by using the |
| Create a page block (unless you enable a message PageBlobCreated property and the identically named block already exists) and set the content of this blob. |
| Resize the page blob. |
| Clear the page blob. |
| Get the page blob page ranges. |
40.4.5. Azure Blob Client configuration
If your Camel Application is running behind a firewall or if you need to have more control over the Azure Blob Client configuration, you can create your own instance:
StorageCredentials credentials = new StorageCredentialsAccountAndKey("camelazure", "thekey"); CloudBlob client = new CloudBlob("camelazure", credentials); registry.bind("azureBlobClient", client);
and refer to it in your Camel azure-blob component configuration:
from("azure-blob:/camelazure/container1/blockBlob?azureBlobClient=#client") .to("mock:result");
40.5. Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-azure</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.19.0 or higher).
40.6. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- Azure Component
Chapter 41. Azure Storage Queue Service Component
Available as of Camel version 2.19
The Azure Queue component supports storing and retrieving the messages to/from Azure Storage Queue service.
Prerequisites
You must have a valid Microsoft Azure account. More information is available at Azure Portal.
41.1. URI Format
azure-queue://accountName/queueName[?options]
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&…
For example in order to get a message content from the queue messageQueue
in the camelazure
storage account and, use the following snippet:
from("azure-queue:/camelazure/messageQueue"). to("file://queuedirectory");
41.2. URI Options
The Azure Storage Queue Service component has no options.
The Azure Storage Queue Service endpoint is configured using URI syntax:
azure-queue:containerAndQueueUri
with the following path and query parameters:
41.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
containerAndQueueUri | Required Container Queue compact Uri | String |
41.2.2. Query Parameters (10 parameters):
Name | Description | Default | Type |
---|---|---|---|
azureQueueClient (common) | The queue service client | CloudQueue | |
credentials (common) | Set the storage credentials, required in most cases | StorageCredentials | |
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) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
messageTimeToLive (producer) | Message Time To Live in seconds | int | |
messageVisibilityDelay (producer) | Message Visibility Delay in seconds | int | |
operation (producer) | The operation to do in case the user does not want to send only a message. There are three enums options and the value can be one of the following: sendBatchMessage, deleteMessage, listQueues | listQueues | QueueServiceOperations |
queuePrefix (producer) | Set a prefix which can be used for listing the queues | String | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
41.3. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.azure-queue.enabled | Enable azure-queue component | true | Boolean |
camel.component.azure-queue.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
Required Azure Storage Queue Service component options
You have to provide the containerAndQueue URI and the credentials.
41.4. Usage
41.4.1. Message headers evaluated by the Azure Storage Queue Service producer
Header | Type | Description |
---|---|---|
41.4.2. Message headers set by the Azure Storage Queue Service producer
Header | Type | Description |
---|---|---|
41.4.3. Message headers set by the Azure Storage Queue Service producer consumer
Header | Type | Description |
---|---|---|
41.4.4. Azure Queue Service operations
Operation | Description |
---|---|
| List the queues. |
| Create the queue. |
| Delete the queue. |
| Add a message to the queue. |
| Retrieve a message from the queue. |
| View the message inside the queue, for example, to determine whether the message arrived at the correct queue. |
| Update the message in the queue. |
| Delete the message in the queue. |
41.4.5. Azure Queue Client configuration
If your Camel Application is running behind a firewall or if you need to have more control over the Azure Queue Client configuration, you can create your own instance:
StorageCredentials credentials = new StorageCredentialsAccountAndKey("camelazure", "thekey"); CloudQueue client = new CloudQueue("camelazure", credentials); registry.bind("azureQueueClient", client);
and refer to it in your Camel azure-queue component configuration:
from("azure-queue:/camelazure/messageQueue?azureQueueClient=#client") .to("mock:result");
41.5. Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-azure</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.19.0 or higher).
41.6. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- Azure Component
Chapter 42. Barcode DataFormat
Available as of Camel version 2.14
The barcode data format is based on the zxing library. The goal of this component is to create a barcode image from a String (marshal) and a String from a barcode image (unmarshal). You’re free to use all features that zxing offers.
42.1. Dependencies
To use the barcode data format in your camel routes you need to add the a dependency on camel-barcode 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-barcode</artifactId> <version>x.x.x</version> </dependency>
42.2. Barcode Options
The Barcode dataformat supports 5 options, which are listed below.
Name | Default | Java Type | Description |
---|---|---|---|
width |
| Width of the barcode | |
height |
| Height of the barcode | |
imageType |
| Image type of the barcode such as png | |
barcodeFormat |
| Barcode format such as QR-Code | |
contentTypeHeader |
|
| Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. |
42.3. Spring Boot Auto-Configuration
The component supports 6 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.dataformat.barcode.barcode-format | Barcode format such as QR-Code | String | |
camel.dataformat.barcode.content-type-header | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. | false | Boolean |
camel.dataformat.barcode.enabled | Enable barcode dataformat | true | Boolean |
camel.dataformat.barcode.height | Height of the barcode | Integer | |
camel.dataformat.barcode.image-type | Image type of the barcode such as png | String | |
camel.dataformat.barcode.width | Width of the barcode | Integer |
ND
42.4. Using the Java DSL
First you have to initialize the barcode data fomat class. You can use the default constructor, or one of parameterized (see JavaDoc). The default values are:
Parameter | Default Value |
---|---|
image type (BarcodeImageType) | PNG |
width | 100 px |
height | 100 px |
encoding | UTF-8 |
barcode format (BarcodeFormat) | QR-Code |
// QR-Code default DataFormat code = new BarcodeDataFormat();
If you want to use zxing hints, you can use the 'addToHintMap' method of your BarcodeDataFormat instance:
code.addToHintMap(DecodeHintType.TRY_HARDER, Boolean.true);
For possible hints, please consult the xzing documentation.
42.4.1. Marshalling
from("direct://code") .marshal(code) .to("file://barcode_out");
You can call the route from a test class with:
template.sendBody("direct://code", "This is a testmessage!");
You should find inside the 'barcode_out' folder this image:
42.4.2. Unmarshalling
The unmarshaller is generic. For unmarshalling you can use any BarcodeDataFormat instance. If you’ve two instances, one for (generating) QR-Code and one for PDF417, it doesn’t matter which one will be used.
from("file://barcode_in?noop=true") .unmarshal(code) // for unmarshalling, the instance doesn't matter .to("mock:out");
If you’ll paste the QR-Code image above into the 'barcode_in' folder, you should find ‘This is a testmessage!’ inside the mock. You can find the barcode data format as header variable:
Name | Type | Description |
---|---|---|
BarcodeFormat | String | Value of com.google.zxing.BarcodeFormat. |
Chapter 43. Base64 DataFormat
Available as of Camel version 2.11
The Base64 data format is used for base64 encoding and decoding.
43.1. Options
The Base64 dataformat supports 4 options, which are listed below.
Name | Default | Java Type | Description |
---|---|---|---|
lineLength |
|
| To specific a maximum line length for the encoded data. By default 76 is used. |
lineSeparator |
| The line separators to use. Uses new line characters (CRLF) by default. | |
urlSafe |
|
| Instead of emitting '' and '/' we emit '-' and '_' respectively. urlSafe is only applied to encode operations. Decoding seamlessly handles both modes. Is by default false. |
contentTypeHeader |
|
| Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. |
43.2. Spring Boot Auto-Configuration
The component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.dataformat.base64.content-type-header | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. | false | Boolean |
camel.dataformat.base64.enabled | Enable base64 dataformat | true | Boolean |
camel.dataformat.base64.line-length | To specific a maximum line length for the encoded data. By default 76 is used. | 76 | Integer |
camel.dataformat.base64.line-separator | The line separators to use. Uses new line characters (CRLF) by default. | String | |
camel.dataformat.base64.url-safe | Instead of emitting '' and '/' we emit '-' and '_' respectively. urlSafe is only applied to encode operations. Decoding seamlessly handles both modes. Is by default false. | false | Boolean |
ND
In Spring DSL, you configure the data format using this tag:
<camelContext> <dataFormats> <!-- for a newline character (\n), use the HTML entity notation coupled with the ASCII code. --> <base64 lineSeparator=" " id="base64withNewLine" /> <base64 lineLength="64" id="base64withLineLength64" /> </dataFormats> ... </camelContext>
Then you can use it later by its reference:
<route> <from uri="direct:startEncode" /> <marshal ref="base64withLineLength64" /> <to uri="mock:result" /> </route>
Most of the time, you won’t need to declare the data format if you use the default options. In that case, you can declare the data format inline as shown below.
43.3. Marshal
In this example we marshal the file content to base64 object.
from("file://data.bin") .marshal().base64() .to("jms://myqueue");
In Spring DSL:
<from uri="file://data.bin"> <marshal> <base64/> </marshal> <to uri="jms://myqueue"/>
43.4. Unmarshal
In this example we unmarshal the payload from the JMS queue to a byte[] object, before its processed by the newOrder processor.
from("jms://queue/order") .unmarshal().base64() .process("newOrder");
In Spring DSL:
<from uri="jms://queue/order"> <unmarshal> <base64/> </unmarshal> <to uri="bean:newOrder"/>
43.5. Dependencies
To use Base64 in your Camel routes you need to add a dependency on camel-base64 which implements this data format.
If you use Maven you can just add the following to your pom.xml:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-base64</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
Chapter 44. Bean Component
Available as of Camel version 1.0
The bean: component binds beans to Camel message exchanges.
44.1. URI format
bean:beanName[?options]
Where beanID can be any string which is used to look up the bean in the Registry
44.2. Options
The Bean component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
cache (advanced) | If enabled, Camel will cache the result of the first Registry look-up. Cache can be enabled if the bean in the Registry is defined as a singleton scope. | Boolean | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Bean endpoint is configured using URI syntax:
bean:beanName
with the following path and query parameters:
44.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
beanName | Required Sets the name of the bean to invoke | String |
44.2.2. Query Parameters (5 parameters):
Name | Description | Default | Type |
---|---|---|---|
method (producer) | Sets the name of the method to invoke on the bean | String | |
cache (advanced) | If enabled, Camel will cache the result of the first Registry look-up. Cache can be enabled if the bean in the Registry is defined as a singleton scope. | Boolean | |
multiParameterArray (advanced) | Deprecated How to treat the parameters which are passed from the message body; if it is true, the message body should be an array of parameters. Note: This option is used internally by Camel, and is not intended for end users to use. Deprecation note: This option is used internally by Camel, and is not intended for end users to use. | false | boolean |
parameters (advanced) | Used for configuring additional properties on the bean | Map | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
You can append query options to the URI in the following format, ?option=value&option=value&…
44.3. Using
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, spring.xml
; or if you don’t use Spring, by registering the bean in JNDI.
Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20
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 BeanExchanges and send them to any endpoint:
And the same route using Spring DSL:
<route> <from uri="direct:hello"> <to uri="bean:bye"/> </route>
44.4. Bean as endpoint
Camel also supports invoking Bean as an Endpoint. In the route below:
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.
44.5. Java DSL bean syntax
Java DSL comes with syntactic sugar for the Bean 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").beanRef("beanName"); // Send message to the bean endpoint // and invoke given method. from("direct:start").beanRef("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);
44.6. 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.
44.7. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- Class component
- Bean Binding
- Bean Integration
Chapter 45. BeanIO DataFormat
Available as of Camel version 2.10
The BeanIO Data Format uses BeanIO to handle flat payloads (such as XML, CSV, delimited, or fixed length formats).
BeanIO is configured using a mappings XML file where you define the mapping from the flat format to Objects (POJOs). This mapping file is mandatory to use.
45.1. Options
The BeanIO dataformat supports 9 options, which are listed below.
Name | Default | Java Type | Description |
---|---|---|---|
mapping |
| The BeanIO mapping file. Is by default loaded from the classpath. You can prefix with file:, http:, or classpath: to denote from where to load the mapping file. | |
streamName |
| The name of the stream to use. | |
ignoreUnidentifiedRecords |
|
| Whether to ignore unidentified records. |
ignoreUnexpectedRecords |
|
| Whether to ignore unexpected records. |
ignoreInvalidRecords |
|
| Whether to ignore invalid records. |
encoding |
| The charset to use. Is by default the JVM platform default charset. | |
beanReaderErrorHandlerType |
| To use a custom org.apache.camel.dataformat.beanio.BeanIOErrorHandler as error handler while parsing. Configure the fully qualified class name of the error handler. Notice the options ignoreUnidentifiedRecords, ignoreUnexpectedRecords, and ignoreInvalidRecords may not be in use when you use a custom error handler. | |
unmarshalSingleObject |
|
| This options controls whether to unmarshal as a list of objects or as a single object only. The former is the default mode, and the latter is only intended in special use-cases where beanio maps the Camel message to a single POJO bean. |
contentTypeHeader |
|
| Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. |
45.2. Spring Boot Auto-Configuration
The component supports 10 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.dataformat.beanio.bean-reader-error-handler-type | To use a custom org.apache.camel.dataformat.beanio.BeanIOErrorHandler as error handler while parsing. Configure the fully qualified class name of the error handler. Notice the options ignoreUnidentifiedRecords, ignoreUnexpectedRecords, and ignoreInvalidRecords may not be in use when you use a custom error handler. | String | |
camel.dataformat.beanio.content-type-header | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. | false | Boolean |
camel.dataformat.beanio.enabled | Enable beanio dataformat | true | Boolean |
camel.dataformat.beanio.encoding | The charset to use. Is by default the JVM platform default charset. | String | |
camel.dataformat.beanio.ignore-invalid-records | Whether to ignore invalid records. | false | Boolean |
camel.dataformat.beanio.ignore-unexpected-records | Whether to ignore unexpected records. | false | Boolean |
camel.dataformat.beanio.ignore-unidentified-records | Whether to ignore unidentified records. | false | Boolean |
camel.dataformat.beanio.mapping | The BeanIO mapping file. Is by default loaded from the classpath. You can prefix with file:, http:, or classpath: to denote from where to load the mapping file. | String | |
camel.dataformat.beanio.stream-name | The name of the stream to use. | String | |
camel.dataformat.beanio.unmarshal-single-object | This options controls whether to unmarshal as a list of objects or as a single object only. The former is the default mode, and the latter is only intended in special use-cases where beanio maps the Camel message to a single POJO bean. | false | Boolean |
ND
45.3. Usage
An example of a mapping file is here.
45.3.1. Using Java DSL
To use the BeanIODataFormat
you need to configure the data format with the mapping file, as well the name of the stream.
In Java DSL this can be done as shown below. The streamName is "employeeFile".
Then we have two routes. The first route is for transforming CSV data into a List<Employee> Java objects. Which we then split, so the mock endpoint
receives a message for each row.
The 2nd route is for the reverse operation, to transform a List<Employee> into a stream of CSV data.
The CSV data could for example be as below:
45.3.2. Using XML DSL
To use the BeanIO data format in XML, you need to configure it using the <beanio> XML tag as shown below. The routes is similar to the example above.
45.4. Dependencies
To use BeanIO in your Camel routes you need to add a dependency on camel-beanio which implements this data format.
If you use Maven you can 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-beanio</artifactId> <version>2.10.0</version> </dependency>
Chapter 46. Beanstalk Component
Available as of Camel version 2.15
camel-beanstalk project provides a Camel component for job retrieval and post-processing of Beanstalk jobs.
You can find the detailed explanation of Beanstalk job lifecycle at Beanstalk protocol.
46.1. Dependencies
Maven users need to add the following dependency to their pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-beanstalk</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.15.0 or higher).
46.2. URI format
beanstalk://[host[:port]][/tube][?options]
You may omit either port
or both host
and port
: for the Beanstalk defaults to be used (“localhost” and 11300). If you omit tube
, Beanstalk component will use the tube with name “default”.
When listening, you may probably want to watch for jobs from several tubes. Just separate them with plus sign, e.g.
beanstalk://localhost:11300/tube1+tube2
Tube name will be URL decoded, so if your tube names include special characters like + or ?, you need to URL-encode them appropriately, or use the RAW syntax, see more details here.
By the way, you cannot specify several tubes when you are writing jobs into Beanstalk.
46.3. Beanstalk options
The Beanstalk component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
connectionSettings Factory (common) | Custom ConnectionSettingsFactory. Specify which ConnectionSettingsFactory to use to make connections to Beanstalkd. Especially useful for unit testing without beanstalkd daemon (you can mock ConnectionSettings) | ConnectionSettings Factory | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Beanstalk endpoint is configured using URI syntax:
beanstalk:connectionSettings
with the following path and query parameters:
46.3.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
connectionSettings | Connection settings host:port/tube | String |
46.3.2. Query Parameters (26 parameters):
Name | Description | Default | Type |
---|---|---|---|
command (common) | put means to put the job into Beanstalk. Job body is specified in the Camel message body. Job ID will be returned in beanstalk.jobId message header. delete, release, touch or bury expect Job ID in the message header beanstalk.jobId. Result of the operation is returned in beanstalk.result message header kick expects the number of jobs to kick in the message body and returns the number of jobs actually kicked out in the message header beanstalk.result. | BeanstalkCommand | |
jobDelay (common) | Job delay in seconds. | 0 | int |
jobPriority (common) | Job priority. (0 is the highest, see Beanstalk protocol) | 1000 | long |
jobTimeToRun (common) | Job time to run in seconds. (when 0, the beanstalkd daemon raises it to 1 automatically, see Beanstalk protocol) | 60 | int |
awaitJob (consumer) | Whether to wait for job to complete before ack the job from beanstalk | true | 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 |
onFailure (consumer) | Command to use when processing failed. | BeanstalkCommand | |
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 |
useBlockIO (consumer) | Whether to use blockIO. | true | boolean |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
pollStrategy (consumer) | 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. | PollingConsumerPoll Strategy | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 1000 | 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. | 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. | ScheduledExecutor Service | |
scheduler (scheduler) | To use a cron scheduler from either camel-spring or camel-quartz2 component | none | ScheduledPollConsumer Scheduler |
schedulerProperties (scheduler) | To configure additional properties when using a custom scheduler or any of the Quartz2, Spring based scheduler. | Map | |
startScheduler (scheduler) | Whether the scheduler should be auto started. | true | boolean |
timeUnit (scheduler) | Time unit for initialDelay and delay options. | MILLISECONDS | TimeUnit |
useFixedDelay (scheduler) | Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean |
46.4. Spring Boot Auto-Configuration
The component supports 3 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.beanstalk.connection-settings-factory | Custom ConnectionSettingsFactory. Specify which ConnectionSettingsFactory to use to make connections to Beanstalkd. Especially useful for unit testing without beanstalkd daemon (you can mock ConnectionSettings). The option is a org.apache.camel.component.beanstalk.ConnectionSettingsFactory type. | String | |
camel.component.beanstalk.enabled | Enable beanstalk component | true | Boolean |
camel.component.beanstalk.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
Producer behavior is affected by the command
parameter which tells what to do with the job, it can be
The consumer may delete the job immediately after reserving it or wait until Camel routes process it. While the first scenario is more like a “message queue”, the second is similar to “job queue”. This behavior is controlled by consumer.awaitJob
parameter, which equals true
by default (following Beanstalkd nature).
When synchronous, the consumer calls delete
on successful job completion and calls bury
on failure. You can choose which command to execute in the case of failure by specifying consumer.onFailure
parameter in the URI. It can take values of bury
, delete
or release
.
There is a boolean parameter consumer.useBlockIO
which corresponds to the same parameter in JavaBeanstalkClient library. By default it is true
.
Be careful when specifying release
, as the failed job will immediately become available in the same tube and your consumer will try to acquire it again. You can release
and specify jobDelay though.
The beanstalk consumer is a Scheduled Polling Consumer which means there is more options you can configure, such as how frequent the consumer should poll. For more details see Polling Consumer.
46.5. Consumer Headers
The consumer stores a number of job headers in the Exchange message:
Property | Type | Description |
---|---|---|
beanstalk.jobId | long | Job ID |
beanstalk.tube | string | the name of the tube that contains this job |
beanstalk.state | string | “ready” or “delayed” or “reserved” or “buried” (must be “reserved”) |
beanstalk.priority | long | the priority value set |
beanstalk.age | int | the time in seconds since the put command that created this job |
beanstalk.time-left | int | the number of seconds left until the server puts this job into the ready queue |
beanstalk.timeouts | int | the number of times this job has timed out during a reservation |
beanstalk.releases | int | the number of times a client has released this job from a reservation |
beanstalk.buries | int | the number of times this job has been buried |
beanstalk.kicks | int | the number of times this job has been kicked |
46.6. Examples
This Camel component lets you both request the jobs for processing and supply them to Beanstalkd daemon. Our simple demo routes may look like
from("beanstalk:testTube"). log("Processing job #${property.beanstalk.jobId} with body ${in.body}"). process(new Processor() { @Override public void process(Exchange exchange) { // try to make integer value out of body exchange.getIn().setBody( Integer.valueOf(exchange.getIn().getBody(classOf[String])) ); } }). log("Parsed job #${property.beanstalk.jobId} to body ${in.body}");
from("timer:dig?period=30seconds"). setBody(constant(10)).log("Kick ${in.body} buried/delayed tasks"). to("beanstalk:testTube?command=kick");
In the first route we are listening for new jobs in tube “testTube”. When they are arriving, we are trying to parse integer value from the message body. If done successful, we log it and this successful exchange completion makes Camel component to delete this job from Beanstalk automatically. Contrary, when we cannot parse the job data, the exchange failed and the Camel component buries it by default, so that it can be processed later or probably we are going to inspect failed jobs manually.
So the second route periodically requests Beanstalk to kick 10 jobs out of buried and/or delayed state to the normal queue.
46.7. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 47. Bean Validator Component
Available as of Camel version 2.3
The Validator component performs bean validation of the message body using the Java Bean Validation API (JSR 303). Camel uses the reference implementation, which is Hibernate Validator.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-bean-validator</artifactId> <version>x.y.z</version> <!-- use the same version as your Camel core version --> </dependency>
47.1. URI format
bean-validator:label[?options]
or
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&…
47.2. URI Options
The Bean Validator component has no options.
The Bean Validator endpoint is configured using URI syntax:
bean-validator:label
with the following path and query parameters:
47.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
label | Required Where label is an arbitrary text value describing the endpoint | String |
47.2.2. Query Parameters (6 parameters):
Name | Description | Default | Type |
---|---|---|---|
constraintValidatorFactory (producer) | To use a custom ConstraintValidatorFactory | ConstraintValidator Factory | |
group (producer) | To use a custom validation group | javax.validation.groups.Default | String |
messageInterpolator (producer) | To use a custom MessageInterpolator | MessageInterpolator | |
traversableResolver (producer) | To use a custom TraversableResolver | TraversableResolver | |
validationProviderResolver (producer) | To use a a custom ValidationProviderResolver | ValidationProvider Resolver | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
47.3. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.bean-validator.enabled | Enable bean-validator component | true | Boolean |
camel.component.bean-validator.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
47.4. 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. Keep in mind that you can use HibernateValidationProviderResolver
starting from the Camel 2.13.0.
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.
47.5. 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
<?xml version="1.0" encoding="UTF-8"?> <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
<?xml version="1.0" encoding="UTF-8"?> <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 where OrderedChecks can be https://github.com/apache/camel/blob/master/components/camel-bean-validator/src/test/java/org/apache/camel/component/bean/validator/OrderedChecks.java
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>
47.6. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 48. Binding Component (deprecated)
Available as of Camel version 2.11
In Camel terms a binding is a way of wrapping an Endpoint in a contract; such as a Data Format, a Content Enricher or validation step. Bindings are completely optional and you can choose to use them on any camel endpoint.
Bindings are inspired by the work of SwitchYard project adding service contracts to various technologies like Camel and many others. But rather than the SwitchYard approach of wrapping Camel in SCA, Camel Bindings provide a way of wrapping Camel endpoints with contracts inside the Camel framework itself; so you can use them easily inside any Camel route.
48.1. Options
The Binding component has no options.
The Binding endpoint is configured using URI syntax:
binding:bindingName:delegateUri
with the following path and query parameters:
48.1.1. Path Parameters (2 parameters):
Name | Description | Default | Type |
---|---|---|---|
bindingName | Required Name of the binding to lookup in the Camel registry. | String | |
delegateUri | Required Uri of the delegate endpoint. | String |
48.1.2. Query Parameters (4 parameters):
Name | Description | Default | Type |
---|---|---|---|
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/ERROR level and ignored. | false | boolean |
exceptionHandler (consumer) | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions, that will be logged at WARN/ERROR level and ignored. | ExceptionHandler | |
exchangePattern (consumer) | Sets the default exchange pattern when creating an exchange. | ExchangePattern | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
48.2. Using Bindings
A Binding is currently a bean which defines the contract (though we’ll hopefully add bindings to the Camel DSL).
There are a few approaches to defining a bound endpoint (i.e. an endpoint bound with a Binding).
48.3. Using the binding URI
You can prefix any endpoint URI with binding:nameOfBinding: where nameOfBinding is the name of the Binding bean in your registry.
from("binding:jaxb:activemq:myQueue").to("binding:jaxb:activemq:anotherQueue")
Here we are using the "jaxb" binding which may, for example, use the JAXB Data Format to marshal and unmarshal messages.
48.4. Using a BindingComponent
There is a Component called BindingComponent which can be configured in your Registry by dependency injection which allows the creation of endpoints which are already bound to some binding.
For example if you registered a new component called "jsonmq" in your registry using code like this
JacksonDataFormat format = new JacksonDataFormat(MyBean.class); context.bind("jsonmq", new BindingComponent(new DataFormatBinding(format), "activemq:foo."));
Then you could use the endpoint as if it were any other endpoint.
from("jsonmq:myQueue").to("jsonmq:anotherQueue")
which would be using the queueus "foo.myQueue" and "foo.anotherQueue" and would use the given Jackson Data Format to marshal on and off the queue.
48.5. When to use Bindings
If you only use an endpoint once in a single route; a binding may actually be more complex and more work than just using the 'raw' endpoint directly and using explicit marshalling and validation in the camel route as normal.
However bindings can help when you are composing many routes together; or using a single route as a 'template' that is configured input and output endpoints; bindings then provide a nice way to wrap up a contract and endpoint together.
Another good use case for bindings is when you are using many endpoints which use the same binding; rather than always having to mention a specific data format or validation rule, you can just use the BindingComponent to wrap the endpoints in the binding of your choice.
So bindings are a composition tool really; only use them when they make sense - the extra complexity may not be worth it unless you have lots of routes or endpoints.
Chapter 49. Bindy DataFormat
Available as of Camel version 2.0
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.
Type | Format Type | Pattern example | Link |
---|---|---|---|
Date | DateFormat |
| http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html |
Decimal* | Decimalformat |
| http://java.sun.com/j2se/1.5.0/docs/api/java/text/DecimalFormat.html |
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*
If you use multiple models, each model has to be placed in it’s own package to prevent unpredictable results.
From Camel 2.16 onwards this is no longer the case, as you can safely have multiple models in the same package, as you configure bindy using class names instead of package names now.
49.1. Options
The Bindy dataformat supports 5 options, which are listed below.
Name | Default | Java Type | Description |
---|---|---|---|
type |
| Whether to use csv, fixed or key value pairs mode. The default value is either Csv or KeyValue depending on chosen dataformat. | |
classType |
| Name of model class to use. | |
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 | |
unwrapSingleInstance |
|
| When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List. |
contentTypeHeader |
|
| Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. |
49.2. Spring Boot Auto-Configuration
The component supports 18 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.dataformat.bindy-csv.class-type | Name of model class to use. | String | |
camel.dataformat.bindy-csv.content-type-header | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. | false | Boolean |
camel.dataformat.bindy-csv.enabled | Enable bindy-csv dataformat | true | 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 key value pairs mode. | BindyType | |
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.class-type | Name of model class to use. | String | |
camel.dataformat.bindy-fixed.content-type-header | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. | false | Boolean |
camel.dataformat.bindy-fixed.enabled | Enable bindy-fixed dataformat | true | 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 key value pairs mode. | BindyType | |
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.class-type | Name of model class to use. | String | |
camel.dataformat.bindy-kvp.content-type-header | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. | false | Boolean |
camel.dataformat.bindy-kvp.enabled | Enable bindy-kvp dataformat | true | 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 key value pairs mode. | BindyType | |
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 |
ND
49.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 (since 2.18.0),
- FormatFactories (since 2.18.0)
This section will describe them :
49.4. 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 name | Record type | Level |
---|---|---|
CsvRecord | csv | Class |
Parameter name | type | Info |
---|---|---|
separator | string | 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, than you have to mask it, like '|' |
skipFirstLine | boolean | optional - default value = false - allow to skip the first line of the CSV file |
crlf | string | optional - possible values = WINDOWS,UNIX,MAC, or custom; default value. WINDOWS - 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) |
generateHeaderColumns | boolean | optional - default value = false - uses to generate the header columns of the CSV generates |
autospanLine | boolean | Camel 2.13/2.12.2: optional - default value = false - 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. |
isOrdered | boolean | optional - default value = false - allow to change the order of the fields when CSV is generated |
quote | String | Camel 2.8.3/2.9: option - 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 | *Camel 2.11:*optional - default value = false - Indicate if the values (and headers) must be quoted when marshaling when CSV is generated. |
endWithLineBreak | boolean | Camel 2.21: optional - default value = true - Indicate if the CSV generated file should end with a line break. |
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 whould 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 simple or double quotes
as delimiter (e.g : '10', 'Street 10, NY', 'USA' or "10", "Street 10, NY", "USA").
Remark : In this case, the first and last character of the line which are a simple or double quotes will removed by bindy
"10","J","Pauline"," M","XD12345678","Fortis Dynamic 15,15" 2500","USD","08-01-2009"
@CsvRecord( separator = "\",\"" ) public Class Order { }
From Camel 2.8.3/2.9 or never bindy will automatic detect 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 simple do as below:
"10","J","Pauline"," M","XD12345678","Fortis Dynamic 15,15" 2500","USD","08-01-2009"
@CsvRecord( separator = "," ) public Class Order { }
Notice 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, than 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; }
Remark : pos is used to parse the file, stream while positions is used to generate the CSV
49.5. 2. Link
The link annotation will allow to link objects together.
Annotation name | Record type | Level |
---|---|---|
Link | all | Class & Property |
Parameter name | type | Info |
---|---|---|
linkType | LinkType | optional - by default the value is LinkType.oneToOne - so you are not obliged to mention it |
Only one-to-one relation is allowed.
e.g : If the model Class Client is linked to the Order class, then use annotation Link in the Order class like this :
Property Link
@CsvRecord(separator = ",") public class Order { @DataField(pos = 1) private int orderNr; @Link private Client client; }
AND for the class Client :
Class Link
@Link public class Client { }
49.6. 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 name | Record type | Level |
---|---|---|
DataField | all | Property |
Parameter name | type | Info |
---|---|---|
pos | int | mandatory - The input position of the field. digit number starting from 1 to … - See the position parameter. |
pattern | string | optional - default value = "" - will be used to format Decimal, Date, |
length | int | optional - represents the length of the field for fixed length format |
precision | int | optional - represents the precision to be used when the Decimal number will be formatted/parsed |
pattern | string | optional - default value = "" - is used by the Java formatter (SimpleDateFormat by example) to format/validate data. 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. Notice that "default" requires Camel 2.14/2.13.3/2.12.5. |
position | int | optional - 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. |
required | boolean | optional - default value = "false" |
trim | boolean | optional - default value = "false" |
defaultValue | string | Camel 2.10: optional - default value = "" - defines the field’s default value when the respective CSV field is empty/not available |
impliedDecimalSeparator | boolean | Camel 2.11: optional - default value = "false" - Indicates if there is a decimal point implied at a specified location |
lengthPos | int | Camel 2.11: optional - can be used to identify a data field in a fixed-length record that defines the fixed length for this field |
align | string | optional - default value = "R" - Align the text to the right or left within a fixed-length field. Use values 'R' or 'L' |
delimiter | string | Camel 2.11: optional - can be used to demarcate the end of a variable-length field within a fixed-length record |
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) than 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' setted 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, than 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' setted 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; }
This attribute is only applicable to optional fields.
49.7. 4. FixedLengthRecord
The FixedLengthRecord annotation is used to identifiy the root class of the model. It represents a record which is "a line of a file/message containing data fixed length formatted" and can be linked to several child model classes. This format is 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 name | Record type | Level |
---|---|---|
FixedLengthRecord | fixed | Class |
Parameter name | type | Required | Default value | Info |
---|---|---|---|---|
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 | Indicates that the record(s) of this type may be preceded by a single header record at the beginning of in the file. | |||
ignoreMissingChars | Indicates whether too short lines will be ignored | |||
ignoreTrailingChars | 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 by default. | |
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 shows how to define the alignment for a field and how to assign a padding character which, in this case, is ' '
:
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 a 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, in the model, you can use 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. In the following example, 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 or 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 defines 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 }
49.8. 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)
*"FIX information"*
More information about FIX can be found on this web site : http://www.fixprotocol.org/. 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 http://www.quickfixj.org/.
Annotation name | Record type | Level |
---|---|---|
Message | key value pair | Class |
Parameter name | type | Info |
---|---|---|
pairSeparator | string | mandatory - can be '=' or ';' or 'anything' |
keyValuePairSeparair | string | mandatory - can be '\u0001', '\u0009', '#' or 'anything' |
crlf | string | optional - possible values = WINDOWS,UNIX,MAC, or custom; default value = WINDOWS - 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) |
type | string | optional - define the type of message (e.g. FIX, EMX, …) |
version | string | optional - version of the message (e.g. 4.1) |
isOrdered | boolean | optional - default value = false - allow to change the order of the fields when FIX message is generated. This annotation is associated to the message class of the model and must be declared one time. |
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 (src\test\data\fix\fix.txt) and the Order, Trailer, Header classes (src\test\java\org\apache\camel\dataformat\bindy\model\fix\simple\Order.java)
49.9. 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 name | Record type | Level |
---|---|---|
KeyValuePairField | Key Value Pair - FIX | Property |
Parameter name | type | Info |
---|---|---|
tag | int | mandatory - digit number identifying the field in the message - must be unique |
pattern | string | optional - default value = "" - will be used to format Decimal, Date, … |
precision | int | optional - digit number - represents the precision to be used when the Decimal number will be formatted/parsed |
position | int | optional - must be used when the position of the key/tag in the FIX message must be different |
required | boolean | optional - default value = "false" |
impliedDecimalSeparator | boolean | Camel 2.11: optional - default value = "false" - Indicates if there is a decimal point implied at a specified location |
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; }
49.10. 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 name | Record type | Level |
---|---|---|
Section | FIX | Class |
Parameter name | type | Info |
---|---|---|
number | int | digit number identifying the section position |
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; }
49.11. 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.
*Restrictions 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 name | Record type | Level |
---|---|---|
OneToMany | all | property |
Parameter name | type | Info |
---|---|---|
mappedTo | string | optional - 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
Remark : 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; }
Very simple isn’t it !!!
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; }
49.12. 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(); } }
49.13. 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); } }; } }
49.14. 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 (java 8, since 2.18.0)
- LocalDateTime (java 8, since 2.18.0)
- LocalTime (java 8, since 2.18.0)
- Long
- Short
- String
The DefaultFormatFactory can be overridden by providing an instance of FactoryRegistry in the registry in use (e.g. spring or JNDI).
49.15. Using the Java DSL
The next step consists in instantiating the DataFormat bindy class associated with this record type and providing Java package name(s) as parameter.
For example the following uses the class BindyCsvDataFormat
(who correspond to the class associated with the CSV record type) which is configured with com.acme.model
package name to initialize the model objects configured in this package.
// Camel 2.15 or older (configure by package name) DataFormat bindy = new BindyCsvDataFormat("com.acme.model"); // Camel 2.16 onwards (configure by class name) DataFormat bindy = new BindyCsvDataFormat(com.acme.model.MyModel.class);
49.15.1. Setting locale
Bindy supports configuring the locale on the dataformat, such as
// Camel 2.15 or older (configure by package name) BindyCsvDataFormat bindy = new BindyCsvDataFormat("com.acme.model"); // Camel 2.16 onwards (configure by class name) 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. Notice this requires Camel 2.14/2.13.3/2.12.5.
// Camel 2.15 or older (configure by package name) BindyCsvDataFormat bindy = new BindyCsvDataFormat("com.acme.model"); // Camel 2.16 onwards (configure by class name) BindyCsvDataFormat bindy = new BindyCsvDataFormat(com.acme.model.MyModel.class); bindy.setLocale("default");
for older releases you can set it using Java code as shown
// Camel 2.15 or older (configure by package name) BindyCsvDataFormat bindy = new BindyCsvDataFormat("com.acme.model"); // Camel 2.16 onwards (configure by class name) BindyCsvDataFormat bindy = new BindyCsvDataFormat(com.acme.model.MyModel.class); bindy.setLocale(Locale.getDefault().getISO3Country());
49.15.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");
49.15.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")
49.16. 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. The example above is for using Camel 2.16 onwards.
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>
Please verify that your model classes implements serializable otherwise the queue manager will raise an error
49.17. 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>x.x.x</version> </dependency>
Chapter 50. Using OSGi blueprint with Camel
A custom XML namespace for Blueprint has been created to let you leverage the nice XML dialect. Given Blueprint custom namespaces are not standardized yet, this namespace can only be used on the Apache Aries Blueprint implementation, which is the one used by Apache Karaf.
50.1. Overview
The XML schema is mostly the same as the one for Spring, so all the xml snippets throughout the documentation referring to Spring XML also apply to Blueprint routes.
Here is a very simple route definition using blueprint:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <camelContext xmlns="http://camel.apache.org/schema/blueprint"> <route> <from uri="timer:test" /> <to uri="log:test" /> </route> </camelContext> </blueprint>
There are a few limitations at this point about the supported xml elements (compared to the Spring xml syntax):
- beanPostProcessor are specific to Spring and aren’t allowed
However, using blueprint when you deploy your applications in an OSGi enviroment has several advantages:
- when upgrading to a new camel version, you don’t have to change the namespace, as the correct version will be selected based on the camel packages that are imported by your bundle
- no startup ordering issue with respect to the custom namespaces and your bundles
- you can use Blueprint property placeholders
50.2. Using camel-blueprint
To leverage camel-blueprint in OSGi, you only need the Aries Blueprint bundle and the camel-blueprint bundle, in addition to camel-core and its dependencies.
If you use Karaf, you can use the feature named camel-blueprint which will install all the required bundles.
Chapter 51. Bonita Component
Available as of Camel version 2.19
Used for communicating with a remote Bonita BPM process engine.
51.1. URI format
bonita://[operation]?[options]
Where operation is the specific action to perform on Bonita.
51.2. General Options
The Bonita component has no options.
The Bonita endpoint is configured using URI syntax:
bonita:operation
with the following path and query parameters:
51.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
operation | Required Operation to use | BonitaOperation |
51.2.2. Query Parameters (9 parameters):
Name | Description | Default | Type |
---|---|---|---|
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 |
hostname (consumer) | Hostname where Bonita engine runs | localhost | String |
port (consumer) | Port of the server hosting Bonita engine | 8080 | String |
processName (consumer) | Name of the process involved in the operation | String | |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
password (security) | Password to authenticate to Bonita engine. | String | |
username (security) | Username to authenticate to Bonita engine. | String |
51.3. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.bonita.enabled | Enable bonita component | true | Boolean |
camel.component.bonita.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
51.4. Body content
For the startCase operation, the input variables are retrieved from the body message. This one has to contains a Map<String,Serializable>.
51.5. Examples
The following example start a new case in Bonita:
from("direct:start").to("bonita:startCase?hostname=localhost&port=8080&processName=TestProcess&username=install&password=install")
51.6. Dependencies
To use Bonita in your Camel routes you need to add a dependency on camel-bonita, which implements the component.
If you use Maven you can just add the following to your pom.xml, substituting the version number for the latest and greatest release (see the download page for the latest versions).
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-bonita</artifactId> <version>x.x.x</version> </dependency>
Chapter 52. Boon DataFormat
Available as of Camel version 2.16
Boon is a Data Format which uses the Boon JSON marshalling library to unmarshal an JSON payload into Java objects or to marshal Java objects into an JSON payload. Boon aims to be a simple and fast parser than other common parsers currently used.
52.1. Options
The Boon dataformat supports 3 options, which are listed below.
Name | Default | Java Type | Description |
---|---|---|---|
unmarshalTypeName |
| Class name of the java type to use when unarmshalling | |
useList |
|
| To unarmshal to a List of Map or a List of Pojo. |
contentTypeHeader |
|
| Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. |
52.2. Spring Boot Auto-Configuration
The component supports 4 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.dataformat.boon.content-type-header | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. | false | Boolean |
camel.dataformat.boon.enabled | Enable boon dataformat | true | Boolean |
camel.dataformat.boon.unmarshal-type-name | Class name of the java type to use when unarmshalling | String | |
camel.dataformat.boon.use-list | To unarmshal to a List of Map or a List of Pojo. | false | Boolean |
ND
52.3. Using the Java DSL
DataFormat boonDataFormat = new BoonDataFormat("com.acme.model.Person"); from("activemq:My.Queue") .unmarshal(boonDataFormat) .to("mqseries:Another.Queue");
52.4. Using Blueprint XML
<bean id="boonDataFormat" class="org.apache.camel.component.boon.BoonDataFormat"> <argument value="com.acme.model.Person"/> </bean> <camelContext id="camel" xmlns="http://camel.apache.org/schema/blueprint"> <route> <from uri="activemq:My.Queue"/> <unmarshal ref="boonDataFormat"/> <to uri="mqseries:Another.Queue"/> </route> </camelContext>
52.5. Dependencies
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-boon</artifactId> <version>x.x.x</version> </dependency>
Chapter 53. Box Component
Available as of Camel version 2.14
The Box component provides access to all of the Box.com APIs accessible using https://github.com/box/box-java-sdk. It allows producing messages to upload and download files, create, edit, and manage folders, etc. It also supports APIs that allow polling for updates to user accounts and even changes to enterprise accounts, etc.
Box.com requires the use of OAuth2.0 for all client application authentication. In order to use camel-box with your account, you’ll need to create a new application within Box.com at https://developer.box.com. The Box application’s client id and secret will allow access to Box APIs which require a current user. A user access token is generated and managed by the API for an end user.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-box</artifactId> <version>${camel-version}</version> </dependency>
53.1. Connection Authentication Types
The Box component supports three different types of authenticated connections.
53.1.1. Standard Authentication
Standard Authentication uses the OAuth 2.0 three-legged authentication process to authenticate its connections with Box.com. This type of authentication enables Box managed users and external users to access, edit, and save their Box content through the Box component.
53.1.2. App Enterprise Authentication
App Enterprise Authentication uses the OAuth 2.0 with JSON Web Tokens (JWT) to authenticate its connections as a Service Account for a Box Application. This type of authentication enables a service account to access, edit, and save the Box content of its Box Application through the Box component.
53.1.3. App User Authentication
App User Authentication uses the OAuth 2.0 with JSON Web Tokens (JWT) to authenticate its connections as an App User for a Box Application. This type of authentication enables app users to access, edit, and save their Box content in its Box Application through the Box component.
53.2. Box Options
The Box component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (common) | To use the shared configuration | BoxConfiguration | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Box endpoint is configured using URI syntax:
box:apiName/methodName
with the following path and query parameters:
53.2.1. Path Parameters (2 parameters):
Name | Description | Default | Type |
---|---|---|---|
apiName | Required What kind of operation to perform | BoxApiName | |
methodName | Required What sub operation to use for the selected operation | String |
53.2.2. Query Parameters (20 parameters):
Name | Description | Default | Type |
---|---|---|---|
clientId (common) | Box application client ID | String | |
enterpriseId (common) | The enterprise ID to use for an App Enterprise. | String | |
inBody (common) | Sets the name of a parameter to be passed in the exchange In Body | String | |
userId (common) | The user ID to use for an App User. | 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 |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
httpParams (advanced) | Custom HTTP params for settings like proxy host | Map | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
accessTokenCache (security) | Custom Access Token Cache for storing and retrieving access tokens. | IAccessTokenCache | |
clientSecret (security) | Box application client secret | String | |
encryptionAlgorithm (security) | The type of encryption algorithm for JWT. Supported Algorithms: RSA_SHA_256 RSA_SHA_384 RSA_SHA_512 | RSA_SHA_256 | EncryptionAlgorithm |
maxCacheEntries (security) | The maximum number of access tokens in cache. | 100 | int |
authenticationType (authentication) | The type of authentication for connection. Types of Authentication: STANDARD_AUTHENTICATION - OAuth 2.0 (3-legged) SERVER_AUTHENTICATION - OAuth 2.0 with JSON Web Tokens | APP_USER_AUTHENTICATION | String |
privateKeyFile (security) | The private key for generating the JWT signature. | String | |
privateKeyPassword (security) | The password for the private key. | String | |
publicKeyId (security) | The ID for public key for validating the JWT signature. | String | |
sslContextParameters (security) | To configure security using SSLContextParameters. | SSLContextParameters | |
userName (security) | Box user name, MUST be provided | String | |
userPassword (security) | Box user password, MUST be provided if authSecureStorage is not set, or returns null on first call | String |
53.3. Spring Boot Auto-Configuration
The component supports 17 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.box.configuration.access-token-cache | Custom Access Token Cache for storing and retrieving access tokens. | IAccessTokenCache | |
camel.component.box.configuration.api-name | What kind of operation to perform | BoxApiName | |
camel.component.box.configuration.authentication-type | The type of authentication for connection. Types of Authentication: STANDARD_AUTHENTICATION - OAuth 2.0 (3-legged) SERVER_AUTHENTICATION - OAuth 2.0 with JSON Web Tokens | APP_USER_AUTHENTICATION | String |
camel.component.box.configuration.client-id | Box application client ID | String | |
camel.component.box.configuration.client-secret | Box application client secret | String | |
camel.component.box.configuration.enterprise-id | The enterprise ID to use for an App Enterprise. | String | |
camel.component.box.configuration.http-params | Custom HTTP params for settings like proxy host | Map | |
camel.component.box.configuration.method-name | What sub operation to use for the selected operation | String | |
camel.component.box.configuration.private-key-file | The private key for generating the JWT signature. | String | |
camel.component.box.configuration.private-key-password | The password for the private key. | String | |
camel.component.box.configuration.public-key-id | The ID for public key for validating the JWT signature. | String | |
camel.component.box.configuration.ssl-context-parameters | To configure security using SSLContextParameters. | SSLContextParameters | |
camel.component.box.configuration.user-id | The user ID to use for an App User. | String | |
camel.component.box.configuration.user-name | Box user name, MUST be provided | String | |
camel.component.box.configuration.user-password | Box user password, MUST be provided if authSecureStorage is not set, or returns null on first call | String | |
camel.component.box.enabled | Enable box component | true | Boolean |
camel.component.box.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
53.4. URI format
box:apiName/methodName
apiName can be one of:
- collaborations
- comments
- event-logs
- files
- folders
- groups
- events
- search
- tasks
- users
53.5. Producer Endpoints:
Producer endpoints can use endpoint prefixes followed by endpoint names and associated options described next. A shorthand alias can be used for some endpoints. The endpoint URI MUST contain a prefix.
Endpoint options that are not mandatory are denoted by []. When there are no mandatory options for an endpoint, one of the set of [] options MUST be provided. Producer endpoints can also use a special option inBody
that in turn should contain the name of the endpoint option whose value will be contained in the Camel Exchange In message.
Any of the endpoint options can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format CamelBox.<option>
. Note that the inBody
option overrides message header, i.e. the endpoint option inBody=option
would override a CamelBox.option
header.
If a value is not provided for the option defaultRequest either in the endpoint URI or in a message header, it will be assumed to be null
. Note that the null
value will only be used if other options do not satisfy matching endpoints.
In case of Box API errors the endpoint will throw a RuntimeCamelException with a com.box.sdk.BoxAPIException derived exception cause.
53.5.1. Endpoint Prefix collaborations
For more information on Box collaborations see https://developer.box.com/reference#collaboration-object. The following endpoints can be invoked with the prefix collaborations
as follows:
box:collaborations/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
addFolderCollaboration | add | folderId, collaborator, role | com.box.sdk.BoxCollaboration |
addFolderCollaborationByEmail | addByEmail | folderId, email, role | com.box.sdk.BoxCollaboration |
deleteCollaboration | delete | collaborationId | |
getFolderCollaborations | collaborations | folderId | java.util.Collection |
getPendingCollaborations | pendingCollaborations | java.util.Collection | |
getCollaborationInfo | info | collaborationId | com.box.sdk.BoxCollaboration.Info |
updateCollaborationInfo | updateInfo | collaborationId, info | com.box.sdk.BoxCollaboration |
URI Options for collaborations
Name | Type |
---|---|
collaborationId | String |
collaborator | com.box.sdk.BoxCollaborator |
role | com.box.sdk.BoxCollaboration.Role |
folderId | String |
| String |
info | com.box.sdk.BoxCollaboration.Info |
53.5.2. Endpoint Prefix comments
For more information on Box comments see https://developer.box.com/reference#comment-object. The following endpoints can be invoked with the prefix comments
as follows:
box:comments/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
addFileComment | add | fileId, message | com.box.sdk.BoxFile |
changeCommentMessage | updateMessage | commentId, message | com.box.sdk.BoxComment |
deleteComment | delete | commentId | |
getCommentInfo | info | commentId | com.box.sdk.BoxComment.Info |
getFileComments | comments | fileId | java.util.List |
replyToComment | reply | commentId, message | com.box.sdk.BoxComment |
URI Options for collaborations
Name | Type |
---|---|
commentId | String |
fileId | String |
message | String |
53.5.3. Endpoint Prefix events-logs
For more information on Box event logs see https://developer.box.com/reference#events. The following endpoints can be invoked with the prefix event-logs
as follows:
box:event-logs/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
getEnterpriseEvents | events | position, after, before, [types] | java.util.List |
URI Options for event-logs
Name | Type |
---|---|
position | String |
after | Date |
before | Date |
types | com.box.sdk.BoxEvent.Types[] |
53.5.4. Endpoint Prefix files
For more information on Box files see https://developer.box.com/reference#file-object. The following endpoints can be invoked with the prefix files
as follows.
box:files/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
uploadFile | upload | parentFolderId, content, fileName, [created], [modified], [size], [listener] | com.box.sdk.BoxFile |
downloadFile | download | fileId, output, [rangeStart], [rangeEnd], [listener] | java.io.OutputStream |
copyFile | copy | fileId, destinationFolderId, [newName] | com.box.sdk.BoxFile |
moveFile | move | fileId, destinationFolderId, [newName] | com.box.sdk.BoxFile |
renameFile | rename | fileId, newFileName | com.box.sdk.BoxFile |
createFileSharedLink | link | fileId, access, [unshareDate], [permissions] | com.box.sdk.BoxSharedLink |
deleteFile | delete | fileId | |
uploadNewFileVersion | uploadVersion | fileId, fileContent, [modified], [fileSize], [listener] | com.box.boxsdk.BoxFile |
promoteFileVersion | promoteVersion | fileId, version | com.box.sdk.BoxFileVersion |
getFileVersions | versions | fileId | java.util.Collection |
downloadPreviousFileVersions | downloadVersion | fileId, version, output, [listener] | java.io.OutputStream |
deleteFileVersion | deleteVersion | fileId, version | |
getFileInfo | info | fileId, fields | com.box.sdk.BoxFile.Info |
updateFileInfo | updateInfo | fileId, info | com.box.sdk.BoxFile |
createFileMetadata | createMetadata | fileId, metadata, [typeName] | com.box.sdk.Metadata |
getFileMetadata | metadata | fileId, [typeName] | com.box.sdk.Metadata |
updateFileMetadata | updateMetadata | fileId, metadata | com.box.sdk.Metadata |
deleteFileMetadata | deleteMetadata | fileId | |
getDownloadUrl | url | fileId | java.net.URL |
getPreviewLink | preview | fileId | java.net.URL |
getFileThumbnail | thumbnail | fileId, fileType, minWidth, minHeight, maxWidth, maxHeight | byte[] |
URI Options for files
Name | Type |
---|---|
parentFolderId | String |
content | java.io.InputStream |
fileName | String |
created | Date |
modified | Date |
size | Long |
listener | com.box.sdk.ProgressListener |
output | java.io.OutputStream |
rangeStart | Long |
rangeEnd | Long |
outputStreams | java.io.OutputStream[] |
destinationFolderId | String |
newName | String |
fields | String[] |
info | com.box.sdk.BoxFile.Info |
fileSize | Long |
version | Integer |
access | com.box.sdk.BoxSharedLink.Access |
unshareDate | Date |
permissions | com.box.sdk.BoxSharedLink.Permissions |
fileType | com.box.sdk.BoxFile.ThumbnailFileType |
minWidth | Integer |
minHeight | Integer |
maxWidth | Integer |
maxHeight | Integer |
metadata | com.box.sdk.Metadata |
typeName | String |
53.5.5. Endpoint Prefix folders
For more information on Box folders see https://developer.box.com/reference#folder-object. The following endpoints can be invoked with the prefix folders
as follows.
box:folders/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
getRootFolder | root | com.box.sdk.BoxFolder | |
createFolder | create | parentFolderId, folderName | com.box.sdk.BoxFolder |
createFolder | create | parentFolderId, path | com.box.sdk.BoxFolder |
copyFolder | copy | folderId, destinationfolderId, [newName] | com.box.sdk.BoxFolder |
moveFolder | move | folderId, destinationFolderId, newName | com.box.sdk.BoxFolder |
renameFolder | rename | folderId, newFolderName | com.box.sdk.BoxFolder |
createFolderSharedLink | link | folderId, access, [unsharedDate], [permissions] | java.util.List |
deleteFolder | delete | folderId | |
getFolder | folder | path | com.box.sdk.BoxFolder |
getFolderInfo | info | folderId, fields | com.box.sdk.BoxFolder.Info |
getFolderItems | items | folderId, offset, limit, fields | java.util.List |
updateFolderInfo | updateInfo | folderId, info | com.box.sdk.BoxFolder |
URI Options for folders
Name | Type |
---|---|
path | String[] |
folderId | String |
offset | Long |
limit | Long |
fields | String[] |
parentFolderId | String |
folderName | String |
destinationFolderId | String |
newName | String |
newFolderName | String |
info | String |
access | com.box.sdk.BoxSharedLink.Access |
unshareDate | Date |
permissions | com.box.sdk.BoxSharedLink.Permissions |
53.5.6. Endpoint Prefix groups
For more information on Box groups see https://developer.box.com/reference#group-object. The following endpoints can be invoked with the prefix groups
as follows:
box:groups/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
createGroup | create | name, [provenance, externalSyncIdentifier, description, invitabilityLevel, memberViewabilityLevel] | com.box.sdk.BoxGroup |
addGroupMembership | createMembership | groupId, userId, role | com.box.sdk.BoxGroupMembership |
deleteGroup | delete | groupId | |
getAllGroups | groups | java.util.Collection | |
getGroupInfo | info | groupId | com.box.sdk.BoxGroup.Info |
updateGroupInfo | updateInfo | groupId, groupInfo | com.box.sdk.BoxGroup |
addGroupMembership | addMembership | groupId, userId, role | com.box.sdk.BoxGroupMembership |
deleteGroupMembership | deleteMembership | groupMembershipId | |
getGroupMemberships | memberships | groupId | java.uti.Collection |
getGroupMembershipInfo | membershipInfo | groupMemebershipId | com.box.sdk.BoxGroup.Info |
updateGroupMembershipInfo | updateMembershipInfo | groupMemebershipId, info | com.box.sdk.BoxGroupMembership |
URI Options for groups
Name | Type |
---|---|
name | String |
groupId | String |
userId | String |
role | com.box.sdk.BoxGroupMembership.Role |
groupMembershipId | String |
info | com.box.sdk.BoxGroupMembership.Info |
53.5.7. Endpoint Prefix search
For more information on Box search API see https://developer.box.com/reference#searching-for-content. The following endpoints can be invoked with the prefix search
as follows:
box:search/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
searchFolder | search | folderId, query | java.util.Collection |
URI Options for search
Name | Type |
---|---|
folderId | String |
query | String |
53.5.8. Endpoint Prefix tasks
For information on Box tasks see https://developer.box.com/reference#task-object-1. The following endpoints can be invoked with the prefix tasks
as follows:
box:tasks/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
addFileTask | add | fileId, action, dueAt, [message] | com.box.sdk.BoxUser |
deleteTask | delete | taskId | |
getFileTasks | tasks | fileId | java.util.List |
getTaskInfo | info | taskId | com.box.sdk.BoxTask.Info |
updateTaskInfo | updateInfo | taskId, info | com.box.sdk.BoxTask |
addAssignmentToTask | addAssignment | taskId, assignTo | com.box.sdk.BoxTask |
deleteTaskAssignment | deleteAssignment | taskAssignmentId | |
getTaskAssignments | assignments | taskId | java.util.List |
getTaskAssignmentInfo | assignmentInfo | taskAssignmentId | com.box.sdk.BoxTaskAssignment.Info |
URI Options for tasks
Name | Type |
---|---|
fileId | String |
action | com.box.sdk.BoxTask.Action |
dueAt | Date |
message | String |
taskId | String |
info | com.box.sdk.BoxTask.Info |
assignTo | com.box.sdk.BoxUser |
taskAssignmentId | String |
53.5.9. Endpoint Prefix users
For information on Box users see https://developer.box.com/reference#user-object. The following endpoints can be invoked with the prefix users
as follows:
box:users/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
getCurrentUser | currentUser | com.box.sdk.BoxUser | |
getAllEnterpriseOrExternalUsers | users | filterTerm, [fields] | com.box.sdk.BoxUser |
createAppUser | create | name, [params] | com.box.sdk.BoxUser |
createEnterpriseUser | create | login, name, [params] | com.box.sdk.BoxUser |
deleteUser | delete | userId, notifyUser, force | |
getUserEmailAlias | emailAlias | userId | com.box.sdk.BoxUser |
deleteUserEmailAlias | deleteEmailAlias | userId, emailAliasId | java.util.List |
getUserInfo | info | userId | com.box.sdk.BoxUser.Info |
updateUserInfo | updateInfo | userId, info | com.box.sdk.BoxUser |
moveFolderToUser | - | userId, sourceUserId | com.box.sdk.BoxFolder.Info |
URI Options for users
Name | Type |
---|---|
defaultRequest | com.box.restclientv2.requestsbase.BoxDefaultRequestObject |
emailAliasRequest | com.box.boxjavalibv2.requests.requestobjects.BoxEmailAliasRequestObject |
emailId | String |
filterTerm | String |
folderId | String |
simpleUserRequest | com.box.boxjavalibv2.requests.requestobjects.BoxSimpleUserRequestObject |
userDeleteRequest | com.box.boxjavalibv2.requests.requestobjects.BoxUserDeleteRequestObject |
userId | String |
userRequest | com.box.boxjavalibv2.requests.requestobjects.BoxUserRequestObject |
userUpdateLoginRequest | com.box.boxjavalibv2.requests.requestobjects.BoxUserUpdateLoginRequestObject |
53.6. Consumer Endpoints:
For more information on Box events see https://developer.box.com/reference#events. Consumer endpoints can only use the endpoint prefix events as shown in the example next.
box:events/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
events | [startingPosition] | com.box.sdk.BoxEvent |
URI Options for events
Name | Type |
---|---|
startingPosition | Long |
53.7. Message header
Any of the options can be provided in a message header for producer endpoints with CamelBox. prefix.
53.8. Message body
All result message bodies utilize objects provided by the Box Java SDK. Producer endpoints can specify the option name for incoming message body in the inBody endpoint parameter.
53.9. Configure the component and enable authentication
For authentication with Box, set the authentication properties on the component as demonstrated in the following example:
BoxConfiguration configuration = new BoxConfiguration(); configuration.setClientId("clientId"); configuration.setClientSecret("clientSecret"); configuration.setUserName("userName"); configuration.setUserPassword("userPassword"); // add BoxComponent to Camel context BoxComponent component = new BoxComponent(context); component.setConfiguration(configuration); context.addComponent("box", component);
53.10. Samples
The following route uploads new files to the user’s root folder:
from("file:...") .to("box://files/upload/inBody=fileUploadRequest");
The following route polls user’s account for updates:
from("box://events/listen?startingPosition=-1") .to("bean:blah");
The following route uses a producer with dynamic header options. The fileId property has the Box file id and the output property has the output stream of the file contents, so they are assigned to the CamelBox.fileId header and CamelBox.output header respectively as follows:
from("direct:foo") .setHeader("CamelBox.fileId", header("fileId")) .setHeader("CamelBox.output", header("output")) .to("box://files/download") .to("file://...");
Chapter 54. Braintree Component
Available as of Camel version 2.17
The Braintree component provides access to Braintree Payments trough through theirs Java SDK.
All client applications need API credential in order to process payments. In order to use camel-braintree with your account, you’ll need to create a new Sandbox or Production account.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-braintree</artifactId> <version>${camel-version}</version> </dependency>
54.1. Braintree Options
The Braintree component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (common) | To use the shared configuration | BraintreeConfiguration | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Braintree endpoint is configured using URI syntax:
braintree:apiName/methodName
with the following path and query parameters:
54.1.1. Path Parameters (2 parameters):
Name | Description | Default | Type |
---|---|---|---|
apiName | Required What kind of operation to perform | BraintreeApiName | |
methodName | What sub operation to use for the selected operation | String |
54.1.2. Query Parameters (14 parameters):
Name | Description | Default | Type |
---|---|---|---|
environment (common) | The environment Either SANDBOX or PRODUCTION | String | |
inBody (common) | Sets the name of a parameter to be passed in the exchange In Body | String | |
merchantId (common) | The merchant id provided by Braintree. | String | |
privateKey (common) | The private key provided by Braintree. | String | |
publicKey (common) | The public key provided by Braintree. | 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 |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
accessToken (advanced) | The access token granted by a merchant to another in order to process transactions on their behalf. Used in place of environment, merchant id, public key and private key fields. | String | |
httpReadTimeout (advanced) | Set read timeout for http calls. | Integer | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
httpLogLevel (logging) | Set logging level for http calls, see java.util.logging.Level | String | |
proxyHost (proxy) | The proxy host | String | |
proxyPort (proxy) | The proxy port | Integer |
54.2. Spring Boot Auto-Configuration
The component supports 14 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.braintree.configuration.access-token | The access token granted by a merchant to another in order to process transactions on their behalf. Used in place of environment, merchant id, public key and private key fields. | String | |
camel.component.braintree.configuration.api-name | What kind of operation to perform | BraintreeApiName | |
camel.component.braintree.configuration.environment | The environment Either SANDBOX or PRODUCTION | String | |
camel.component.braintree.configuration.http-log-level | Set logging level for http calls, see java.util.logging.Level | Level | |
camel.component.braintree.configuration.http-log-name | Set log category to use to log http calls, default "Braintree" | String | |
camel.component.braintree.configuration.http-read-timeout | Set read timeout for http calls. | Integer | |
camel.component.braintree.configuration.merchant-id | The merchant id provided by Braintree. | String | |
camel.component.braintree.configuration.method-name | What sub operation to use for the selected operation | String | |
camel.component.braintree.configuration.private-key | The private key provided by Braintree. | String | |
camel.component.braintree.configuration.proxy-host | The proxy host | String | |
camel.component.braintree.configuration.proxy-port | The proxy port | Integer | |
camel.component.braintree.configuration.public-key | The public key provided by Braintree. | String | |
camel.component.braintree.enabled | Enable braintree component | true | Boolean |
camel.component.braintree.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
54.3. URI format
braintree://endpoint-prefix/endpoint?[options]
Endpoint prefix can be one of:
- addOn
- address
- clientToken
- creditCardverification
- customer
- discount
- dispute
- documentUpload
- merchantAccount
- paymentmethod
- paymentmethodNonce
- plan
- report
- settlementBatchSummary
- subscription
- transaction
- webhookNotification
54.4. BraintreeComponent
The Braintree Component can be configured with the options below. These options can be provided using the component’s bean property configuration of type org.apache.camel.component.braintree.BraintreeConfiguration.
Option | Type | Description |
---|---|---|
environment | String | Value that specifies where requests should be directed – sandbox or production |
merchantId | String | A unique identifier for your gateway account, which is different than your merchant account ID |
publicKey | String | User-specific public identifier |
privateKey | String | User-specific secure identifier that should not be shared – even with us! |
accessToken | String | Token granted to a merchant using Braintree Auth allowing them to process transactions on another’s behalf. Used in place of the environment, merchantId, publicKey and privateKey options. |
All the options above are provided by Braintree Payments
54.5. Producer Endpoints:
Producer endpoints can use endpoint prefixes followed by endpoint names and associated options described next. A shorthand alias can be used for some endpoints. The endpoint URI MUST contain a prefix.
Endpoint options that are not mandatory are denoted by []. When there are no mandatory options for an endpoint, one of the set of [] options MUST be provided. Producer endpoints can also use a special option inBody that in turn should contain the name of the endpoint option whose value will be contained in the Camel Exchange In message.
Any of the endpoint options can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format CamelBraintree.<option>. Note that the inBody option overrides message header, i.e. the endpoint option inBody=option would override a CamelBraintree.option header.
For more information on the endpoints and options see Braintree references at https://developers.braintreepayments.com/reference/overview
54.5.1. Endpoint prefix addOn
The following endpoints can be invoked with the prefix addOn as follows:
braintree://addOn/endpoint
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
all | List<com.braintreegateway.Addon> |
54.5.2. Endpoint prefix address
The following endpoints can be invoked with the prefix address as follows:
braintree://address/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
create | customerId, request | com.braintreegateway.Result<com.braintreegateway.Address> | |
delete | customerId, id | com.braintreegateway.Result<com.braintreegateway.Address> | |
find | customerId, id | com.braintreegateway.Address | |
update | customerId, id, request | com.braintreegateway.Result<com.braintreegateway.Address> |
URI Options for address
Name | Type |
---|---|
customerId | String |
request | com.braintreegateway.AddressRequest |
id | String |
54.5.3. Endpoint prefix clientToken
The following endpoints can be invoked with the prefix clientToken as follows:
braintree://clientToken/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
generate | request | String |
URI Options for clientToken
Name | Type |
---|---|
request | com.braintreegateway.ClientTokenrequest |
54.5.4. Endpoint prefix creditCardVerification
The following endpoints can be invoked with the prefix creditCardverification as follows:
braintree://creditCardVerification/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
find | id | com.braintreegateway.CreditCardVerification | |
search | query | com.braintreegateway.ResourceCollection<com.braintreegateway.CreditCardVerification> |
URI Options for creditCardVerification
Name | Type |
---|---|
id | String |
query | com.braintreegateway.CreditCardVerificationSearchRequest |
54.5.5. Endpoint prefix customer
The following endpoints can be invoked with the prefix customer as follows:
braintree://customer/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
all | |||
create | request | com.braintreegateway.Result<com.braintreegateway.Customer> | |
delete | id | com.braintreegateway.Result<com.braintreegateway.Customer> | |
find | id | com.braintreegateway.Customer | |
search | query | com.braintreegateway.ResourceCollection<com.braintreegateway.Customer> | |
update | id, request | com.braintreegateway.Result<com.braintreegateway.Customer> |
URI Options for customer
Name | Type |
---|---|
id | String |
request | com.braintreegateway.CustomerRequest |
query | com.braintreegateway.CustomerSearchRequest |
54.5.6. Endpoint prefix discount
The following endpoints can be invoked with the prefix discount as follows:
braintree://discount/endpoint
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
all |
| List<com.braintreegateway.Discount> |
+
+
54.5.7. Endpoint prefix dispute
The following endpoints can be invoked with the prefix dispute as follows:
braintree://dispute/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
accept |
| id | com.braintreegateway.Result |
addFileEvidence |
| disputeId, documentId | com.braintreegateway.Result<DisputeEvidence> |
addFileEvidence |
| disputeId, fileEvidenceRequest | com.braintreegateway.Result<DisputeEvidence> |
addTextEvidence |
| disputeId, content | com.braintreegateway.Result<DisputeEvidence> |
addTextEvidence |
| disputeId, textEvidenceRequest | com.braintreegateway.Result<DisputeEvidence> |
finalize |
| id | com.braintreegateway.Result |
find |
| id | com.braintreegateway.Dispute |
removeEvidence |
| id | com.braintreegateway.Result |
search |
| disputeSearchRequest | com.braintreegateway.PaginatedCollection<com.braintreegateway.Dispute> |
URI Options for dispute
Name | Type |
---|---|
id | String |
disputeId | String |
documentId | String |
fileEvidenceRequest | com.braintreegateway.FileEvidenceRequest |
content | String |
textEvidenceRequest | |
com.braintreegateway.TextEvidenceRequest | disputeSearchRequest |
54.5.8. Endpoint prefix documentUpload
The following endpoints can be invoked with the prefix documentUpload as follows:
braintree://documentUpload/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
create |
| request | com.braintreegateway.Result<com.braintreegateway.DocumentUpload> |
URI Options for documentUpload
Name | Type |
---|---|
request | com.braintreegateway.DocumentUploadRequest |
54.5.9. Endpoint prefix merchantAccount
The following endpoints can be invoked with the prefix merchantAccount as follows:
braintree://merchantAccount/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
create |
| request | com.braintreegateway.Result<com.braintreegateway.MerchantAccount> |
createForCurrency | currencyRequest | com.braintreegateway.Result<com.braintreegateway.MerchantAccount> | |
find |
| id | com.braintreegateway.MerchantAccount |
update |
| id, request | com.braintreegateway.Result<com.braintreegateway.MerchantAccount> |
URI Options for merchantAccount
Name | Type |
---|---|
id | String |
request | com.braintreegateway.MerchantAccountRequest |
currencyRequest | com.braintreegateway.MerchantAccountCreateForCurrencyRequest |
54.5.10. Endpoint prefix paymentMethod
The following endpoints can be invoked with the prefix paymentMethod as follows:
braintree://paymentMethod/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
create |
| request | com.braintreegateway.Result<com.braintreegateway.PaymentMethod> |
delete |
| token, deleteRequest | com.braintreegateway.Result<com.braintreegateway.PaymentMethod> |
find |
| token | com.braintreegateway.PaymentMethod |
update |
| token, request | com.braintreegateway.Result<com.braintreegateway.PaymentMethod> |
URI Options for paymentMethod
Name | Type |
---|---|
token | String |
request | com.braintreegateway.PaymentMethodRequest |
deleteRequest | com.braintreegateway.PaymentMethodDeleteRequest |
54.5.11. Endpoint prefix paymentMethodNonce
The following endpoints can be invoked with the prefix paymentMethodNonce as follows:
braintree://paymentMethodNonce/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
create |
| paymentMethodToken | com.braintreegateway.Result<com.braintreegateway.PaymentMethodNonce> |
find |
| paymentMethodNonce | com.braintreegateway.PaymentMethodNonce |
URI Options for paymentMethodNonce
Name | Type |
---|---|
paymentMethodToken | String |
paymentMethodNonce | String |
54.5.12. Endpoint prefix plan
The following endpoints can be invoked with the prefix plan as follows:
braintree://plan/endpoint
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
all |
|
| List<com.braintreegateway.Plan> |
54.5.13. Endpoint prefix report
The following endpoints can be invoked with the prefix report as follows:
braintree://plan/report?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
transactionLevelFees |
| request | com.braintreegateway.Result<com.braintreegateway.TransactionLevelFeeReport> |
URI Options for report
Name | Type |
---|---|
request | com.braintreegateway.TransactionLevelFeeReportRequest |
54.5.14. Endpoint prefix settlementBatchSummary
The following endpoints can be invoked with the prefix settlementBatchSummary as follows:
braintree://settlementBatchSummary/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
generate |
| request | com.braintreegateway.Result<com.braintreegateway.SettlementBatchSummary> |
URI Options for settlementBatchSummary
Name | Type |
---|---|
settlementDate | Calendar |
groupByCustomField | String |
54.5.15. Endpoint prefix subscription
The following endpoints can be invoked with the prefix subscription as follows:
braintree://subscription/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
cancel |
| id | com.braintreegateway.Result<com.braintreegateway.Subscription> |
create |
| request | com.braintreegateway.Result<com.braintreegateway.Subscription> |
delete |
| customerId, id | com.braintreegateway.Result<com.braintreegateway.Subscription> |
find |
| id | com.braintreegateway.Subscription |
retryCharge |
| subscriptionId, amount | com.braintreegateway.Result<com.braintreegateway.Transaction> |
search |
| searchRequest | com.braintreegateway.ResourceCollection<com.braintreegateway.Subscription> |
update |
| id, request | com.braintreegateway.Result<com.braintreegateway.Subscription> |
URI Options for subscription
Name | Type |
---|---|
id | String |
request | com.braintreegateway.SubscriptionRequest |
customerId | String |
subscriptionId | String |
amount | BigDecimal |
searchRequest | com.braintreegateway.SubscriptionSearchRequest. |
54.5.16. Endpoint prefix transaction
The following endpoints can be invoked with the prefix transaction as follows:
braintree://transaction/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
cancelRelease |
| id | com.braintreegateway.Result<com.braintreegateway.Transaction> |
cloneTransaction |
| id, cloneRequest | com.braintreegateway.Result<com.braintreegateway.Transaction> |
credit |
| request | com.braintreegateway.Result<com.braintreegateway.Transaction> |
find |
| id | com.braintreegateway.Transaction |
holdInEscrow |
| id | com.braintreegateway.Result<com.braintreegateway.Transaction> |
releaseFromEscrow |
| id | com.braintreegateway.Result<com.braintreegateway.Transaction> |
refund |
| id, amount, refundRequest | com.braintreegateway.Result<com.braintreegateway.Transaction> |
sale |
| request | com.braintreegateway.Result<com.braintreegateway.Transaction> |
search |
| query | com.braintreegateway.ResourceCollection<com.braintreegateway.Transaction> |
submitForPartialSettlement |
| id, amount | com.braintreegateway.Result<com.braintreegateway.Transaction> |
submitForSettlement |
| id, amount, request | com.braintreegateway.Result<com.braintreegateway.Transaction> |
voidTransaction |
| id | com.braintreegateway.Result<com.braintreegateway.Transaction> |
URI Options for transaction
Name | Type |
---|---|
id | String |
request | com.braintreegateway.TransactionCloneRequest |
cloneRequest | com.braintreegateway.TransactionCloneRequest |
refundRequest | com.braintreegateway.TransactionRefundRequest |
amount | BigDecimal |
query | com.braintreegateway.TransactionSearchRequest |
54.5.17. Endpoint prefix webhookNotification
The following endpoints can be invoked with the prefix webhookNotification as follows:
braintree://webhookNotification/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
parse |
| signature, payload | com.braintreegateway.WebhookNotification |
verify |
| challenge | String |
URI Options for webhookNotification
Name | Type |
---|---|
signature | String |
payload | String |
challenge | String |
54.6. Consumer Endpoints
Any of the producer endpoints can be used as a consumer endpoint. Consumer endpoints can use Scheduled Poll Consumer Options with a consumer. prefix to schedule endpoint invocation. By default Consumer endpoints that return an array or collection will generate one exchange per element, and their routes will be executed once for each exchange. To change this behavior use the property consumer.splitResults=true to return a single exchange for the entire list or array.
54.7. Message Headers
Any URI option can be provided in a message header for producer endpoints with a CamelBraintree. prefix.
54.8. Message body
All result message bodies utilize objects provided by the Braintree Java SDK. Producer endpoints can specify the option name for incoming message body in the inBody endpoint parameter.
54.9. Examples
Blueprint
<?xml version="1.0"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0" xsi:schemaLocation=" http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd"> <cm:property-placeholder id="placeholder" persistent-id="camel.braintree"> </cm:property-placeholder> <bean id="braintree" class="org.apache.camel.component.braintree.BraintreeComponent"> <property name="configuration"> <bean class="org.apache.camel.component.braintree.BraintreeConfiguration"> <property name="environment" value="${environment}"/> <property name="merchantId" value="${merchantId}"/> <property name="publicKey" value="${publicKey}"/> <property name="privateKey" value="${privateKey}"/> </bean> </property> </bean> <camelContext trace="true" xmlns="http://camel.apache.org/schema/blueprint" id="braintree-example-context"> <route id="braintree-example-route"> <from uri="direct:generateClientToken"/> <to uri="braintree://clientToken/generate"/> <to uri="stream:out"/> </route> </camelContext> </blueprint>
54.10. See Also
* Configuring Camel * Component * Endpoint * Getting Started
Chapter 55. Browse Component
Available as of Camel version 1.3
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.
55.1. URI format
browse:someName[?options]
Where someName can be any string to uniquely identify the endpoint.
55.2. Options
The Browse component has no options.
The Browse endpoint is configured using URI syntax:
browse:name
with the following path and query parameters:
55.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
name | Required A name which can be any string to uniquely identify the endpoint | String |
55.2.2. Query Parameters (4 parameters):
Name | Description | Default | Type |
---|---|---|---|
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/ERROR level and ignored. | false | boolean |
exceptionHandler (consumer) | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions, that will be logged at WARN/ERROR level and ignored. | ExceptionHandler | |
exchangePattern (consumer) | Sets the default exchange pattern when creating an exchange. | ExchangePattern | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
55.3. 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 inspectRecievedOrders() { 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 } }
55.4. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 56. EHCache Component (deprecated)
Available as of Camel version 2.1
The cache component enables you to perform caching operations using EHCache as the Cache Implementation. The cache itself is created on demand or if a cache of that name already exists then it is simply utilized with its original settings.
This component supports producer and event based consumer endpoints.
The Cache consumer is an event based consumer and can be used to listen and respond to specific cache activities. If you need to perform selections from a pre-existing cache, use the processors defined for the cache component.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-cache</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
56.1. URI format
cache://cacheName[?options]
You can append query options to the URI in the following format, ?option=value&option=#beanRef&…
56.2. Options
The EHCache component supports 4 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
cacheManagerFactory (advanced) | To use the given CacheManagerFactory for creating the CacheManager. By default the DefaultCacheManagerFactory is used. | CacheManagerFactory | |
configuration (common) | Sets the Cache configuration | CacheConfiguration | |
configurationFile (common) | Sets the location of the ehcache.xml file to load from classpath or file system. By default the file is loaded from classpath:ehcache.xml | classpath:ehcache.xml | String |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The EHCache endpoint is configured using URI syntax:
cache:cacheName
with the following path and query parameters:
56.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
cacheName | Required Name of the cache | String |
56.2.2. Query Parameters (19 parameters):
Name | Description | Default | Type |
---|---|---|---|
diskExpiryThreadInterval Seconds (common) | The number of seconds between runs of the disk expiry thread. | long | |
diskPersistent (common) | Whether the disk store persists between restarts of the application. | false | boolean |
diskStorePath (common) | Deprecated This parameter is ignored. CacheManager sets it using setter injection. | String | |
eternal (common) | Sets whether elements are eternal. If eternal, timeouts are ignored and the element never expires. | false | boolean |
key (common) | The default key to use. If a key is provided in the message header, then the key from the header takes precedence. | String | |
maxElementsInMemory (common) | The number of elements that may be stored in the defined cache in memory. | 1000 | int |
memoryStoreEvictionPolicy (common) | Which eviction strategy to use when maximum number of elements in memory is reached. The strategy defines which elements to be removed. LRU - Lest Recently Used LFU - Lest Frequently Used FIFO - First In First Out | LFU | MemoryStoreEviction Policy |
objectCache (common) | Whether to turn on allowing to store non serializable objects in the cache. If this option is enabled then overflow to disk cannot be enabled as well. | false | boolean |
operation (common) | The default cache operation to use. If an operation in the message header, then the operation from the header takes precedence. | String | |
overflowToDisk (common) | Specifies whether cache may overflow to disk | true | boolean |
timeToIdleSeconds (common) | The maximum amount of time between accesses before an element expires | 300 | long |
timeToLiveSeconds (common) | The maximum time between creation time and when an element expires. Is used only if the element is not eternal | 300 | long |
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) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
cacheLoaderRegistry (advanced) | To configure cache loader using the CacheLoaderRegistry | CacheLoaderRegistry | |
cacheManagerFactory (advanced) | To use a custom CacheManagerFactory for creating the CacheManager to be used by this endpoint. By default the CacheManagerFactory configured on the component is used. | CacheManagerFactory | |
eventListenerRegistry (advanced) | To configure event listeners using the CacheEventListenerRegistry | CacheEventListener Registry | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
56.3. Spring Boot Auto-Configuration
The component supports 17 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.cache.cache-manager-factory | To use the given CacheManagerFactory for creating the CacheManager. By default the DefaultCacheManagerFactory is used. The option is a org.apache.camel.component.cache.CacheManagerFactory type. | String | |
camel.component.cache.configuration-file | Sets the location of the ehcache.xml file to load from classpath or file system. By default the file is loaded from classpath:ehcache.xml | classpath:ehcache.xml | String |
camel.component.cache.configuration.cache-loader-registry | To configure cache loader using the CacheLoaderRegistry | CacheLoaderRegistry | |
camel.component.cache.configuration.cache-name | Name of the cache | String | |
camel.component.cache.configuration.disk-expiry-thread-interval-seconds | The number of seconds between runs of the disk expiry thread. | Long | |
camel.component.cache.configuration.disk-persistent | Whether the disk store persists between restarts of the application. | false | Boolean |
camel.component.cache.configuration.eternal | Sets whether elements are eternal. If eternal, timeouts are ignored and the element never expires. | false | Boolean |
camel.component.cache.configuration.event-listener-registry | To configure event listeners using the CacheEventListenerRegistry | CacheEventListener Registry | |
camel.component.cache.configuration.max-elements-in-memory | The number of elements that may be stored in the defined cache in memory. | 1000 | Integer |
camel.component.cache.configuration.memory-store-eviction-policy | Which eviction strategy to use when maximum number of elements in memory is reached. The strategy defines which elements to be removed. LRU - Lest Recently Used LFU - Lest Frequently Used FIFO - First In First Out | MemoryStoreEviction Policy | |
camel.component.cache.configuration.object-cache | Whether to turn on allowing to store non serializable objects in the cache. If this option is enabled then overflow to disk cannot be enabled as well. | false | Boolean |
camel.component.cache.configuration.overflow-to-disk | Specifies whether cache may overflow to disk | true | Boolean |
camel.component.cache.configuration.time-to-idle-seconds | The maximum amount of time between accesses before an element expires | 300 | Long |
camel.component.cache.configuration.time-to-live-seconds | The maximum time between creation time and when an element expires. Is used only if the element is not eternal | 300 | Long |
camel.component.cache.enabled | Enable cache component | true | Boolean |
camel.component.cache.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.cache.configuration.disk-store-path | This parameter is ignored. CacheManager sets it using setter injection. | String |
56.4. Sending/Receiving Messages to/from the cache
56.4.1. Message Headers up to Camel 2.7
Header | Description |
---|---|
| The operation to be performed on the cache. Valid options are
* GET * CHECK * ADD * UPDATE * DELETE * DELETEALL |
| The cache key used to store the Message in the cache. The cache key is optional if the CACHE_OPERATION is DELETEALL |
56.4.2. Message Headers Camel 2.8+
Header changes in Camel 2.8
The header names and supported values have changed to be prefixed with 'CamelCache' and use mixed case. This makes them easier to identify and keep separate from other headers. The CacheConstants variable names remain unchanged, just their values have been changed. Also, these headers are now removed from the exchange after the cache operation is performed.
Header | Description |
---|---|
| The operation to be performed on the cache. The valid options are * CamelCacheGet * CamelCacheCheck * CamelCacheAdd * CamelCacheUpdate * CamelCacheDelete * CamelCacheDeleteAll |
| The cache key used to store the Message in the cache. The cache key is optional if the CamelCacheOperation is CamelCacheDeleteAll |
The CamelCacheAdd
and CamelCacheUpdate
operations support additional headers:
Header | Type | Description |
---|---|---|
|
| Camel 2.11: Time to live in seconds. |
|
| Camel 2.11: Time to idle in seconds. |
|
| Camel 2.11: Whether the content is eternal. |
56.4.3. Cache Producer
Sending data to the cache involves the ability to direct payloads in exchanges to be stored in a pre-existing or created-on-demand cache. The mechanics of doing this involve
- setting the Message Exchange Headers shown above.
- ensuring that the Message Exchange Body contains the message directed to the cache
56.4.4. Cache Consumer
Receiving data from the cache involves the ability of the CacheConsumer to listen on a pre-existing or created-on-demand Cache using an event Listener and receive automatic notifications when any cache activity take place (i.e CamelCacheGet/CamelCacheUpdate/CamelCacheDelete/CamelCacheDeleteAll). Upon such an activity taking place
- an exchange containing Message Exchange Headers and a Message Exchange Body containing the just added/updated payload is placed and sent.
- in case of a CamelCacheDeleteAll operation, the Message Exchange Header CamelCacheKey and the Message Exchange Body are not populated.
56.4.5. Cache Processors
There are a set of nice processors with the ability to perform cache lookups and selectively replace payload content at the
- body
- token
- xpath level
56.5. Cache Usage Samples
56.5.1. Example 1: Configuring the cache
from("cache://MyApplicationCache" + "?maxElementsInMemory=1000" + "&memoryStoreEvictionPolicy=" + "MemoryStoreEvictionPolicy.LFU" + "&overflowToDisk=true" + "&eternal=true" + "&timeToLiveSeconds=300" + "&timeToIdleSeconds=true" + "&diskPersistent=true" + "&diskExpiryThreadIntervalSeconds=300")
56.5.2. Example 2: Adding keys to the cache
RouteBuilder builder = new RouteBuilder() { public void configure() { from("direct:start") .setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_ADD)) .setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")) .to("cache://TestCache1") } };
56.5.3. Example 2: Updating existing keys in a cache
RouteBuilder builder = new RouteBuilder() { public void configure() { from("direct:start") .setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_UPDATE)) .setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")) .to("cache://TestCache1") } };
56.5.4. Example 3: Deleting existing keys in a cache
RouteBuilder builder = new RouteBuilder() { public void configure() { from("direct:start") .setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_DELETE)) .setHeader(CacheConstants.CACHE_KEY", constant("Ralph_Waldo_Emerson")) .to("cache://TestCache1") } };
56.5.5. Example 4: Deleting all existing keys in a cache
RouteBuilder builder = new RouteBuilder() { public void configure() { from("direct:start") .setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_DELETEALL)) .to("cache://TestCache1"); } };
56.5.6. Example 5: Notifying any changes registering in a Cache to Processors and other Producers
RouteBuilder builder = new RouteBuilder() { public void configure() { from("cache://TestCache1") .process(new Processor() { public void process(Exchange exchange) throws Exception { String operation = (String) exchange.getIn().getHeader(CacheConstants.CACHE_OPERATION); String key = (String) exchange.getIn().getHeader(CacheConstants.CACHE_KEY); Object body = exchange.getIn().getBody(); // Do something } }) } };
56.5.7. Example 6: Using Processors to selectively replace payload with cache values
RouteBuilder builder = new RouteBuilder() { public void configure() { //Message Body Replacer from("cache://TestCache1") .filter(header(CacheConstants.CACHE_KEY).isEqualTo("greeting")) .process(new CacheBasedMessageBodyReplacer("cache://TestCache1","farewell")) .to("direct:next"); //Message Token replacer from("cache://TestCache1") .filter(header(CacheConstants.CACHE_KEY).isEqualTo("quote")) .process(new CacheBasedTokenReplacer("cache://TestCache1","novel","#novel#")) .process(new CacheBasedTokenReplacer("cache://TestCache1","author","#author#")) .process(new CacheBasedTokenReplacer("cache://TestCache1","number","#number#")) .to("direct:next"); //Message XPath replacer from("cache://TestCache1"). .filter(header(CacheConstants.CACHE_KEY).isEqualTo("XML_FRAGMENT")) .process(new CacheBasedXPathReplacer("cache://TestCache1","book1","/books/book1")) .process (new CacheBasedXPathReplacer("cache://TestCache1","book2","/books/book2")) .to("direct:next"); } };
56.5.8. Example 7: Getting an entry from the Cache
from("direct:start") // Prepare headers .setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_GET)) .setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")). .to("cache://TestCache1"). // Check if entry was not found .choice().when(header(CacheConstants.CACHE_ELEMENT_WAS_FOUND).isNull()). // If not found, get the payload and put it to cache .to("cxf:bean:someHeavyweightOperation"). .setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_ADD)) .setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")) .to("cache://TestCache1") .end() .to("direct:nextPhase");
56.5.9. Example 8: Checking for an entry in the Cache
Note: The CHECK command tests existence of an entry in the cache but doesn’t place a message in the body.
from("direct:start") // Prepare headers .setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_CHECK)) .setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")). .to("cache://TestCache1"). // Check if entry was not found .choice().when(header(CacheConstants.CACHE_ELEMENT_WAS_FOUND).isNull()). // If not found, get the payload and put it to cache .to("cxf:bean:someHeavyweightOperation"). .setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_ADD)) .setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")) .to("cache://TestCache1") .end();
56.6. Management of EHCache
EHCache has its own statistics and management from JMX.
Here’s a snippet on how to expose them via JMX in a Spring application context:
<bean id="ehCacheManagementService" class="net.sf.ehcache.management.ManagementService" init-method="init" lazy-init="false"> <constructor-arg> <bean class="net.sf.ehcache.CacheManager" factory-method="getInstance"/> </constructor-arg> <constructor-arg> <bean class="org.springframework.jmx.support.JmxUtils" factory-method="locateMBeanServer"/> </constructor-arg> <constructor-arg value="true"/> <constructor-arg value="true"/> <constructor-arg value="true"/> <constructor-arg value="true"/> </bean>
Of course you can do the same thing in straight Java:
ManagementService.registerMBeans(CacheManager.getInstance(), mbeanServer, true, true, true, true);
You can get cache hits, misses, in-memory hits, disk hits, size stats this way. You can also change CacheConfiguration parameters on the fly.
56.7. Cache replication Camel 2.8
The Camel Cache component is able to distribute a cache across server nodes using several different replication mechanisms including: RMI, JGroups, JMS and Cache Server.
There are two different ways to make it work:
1. You can configure ehcache.xml
manually
OR
2. You can configure these three options:
- cacheManagerFactory
- eventListenerRegistry
- cacheLoaderRegistry
Configuring Camel Cache replication using the first option is a bit of hard work as you have to configure all caches separately. So in a situation when the all names of caches are not known, using ehcache.xml
is not a good idea.
The second option is much better when you want to use many different caches as you do not need to define options per cache. This is because replication options are set per CacheManager
and per CacheEndpoint
. Also it is the only way when cache names are not know at the development phase.
Note: It might be useful to read the EHCache manual to get a better understanding of the Camel Cache replication mechanism.
56.7.1. Example: JMS cache replication
JMS replication is the most powerful and secured replication method. Used together with Camel Cache replication makes it also rather simple. An example is available on a separate page.
Chapter 57. Caffeine Cache Component
Available as of Camel version 2.20
The caffeine-cache component enables you to perform caching operations using the simple cache from Caffeine.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-caffeine</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
57.1. URI format
caffeine-cache://cacheName[?options]
You can append query options to the URI in the following format, ?option=value&option=#beanRef&…
57.2. Options
The Caffeine Cache component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | Sets the global component configuration | CaffeineConfiguration | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Caffeine Cache endpoint is configured using URI syntax:
caffeine-cache:cacheName
with the following path and query parameters:
57.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
cacheName | Required the cache name | String |
57.2.2. Query Parameters (19 parameters):
Name | Description | Default | Type |
---|---|---|---|
createCacheIfNotExist (common) | Configure if a cache need to be created if it does exist or can’t be pre-configured. | true | 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) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
action (producer) | To configure the default cache action. If an action is set in the message header, then the operation from the header takes precedence. | String | |
cache (producer) | To configure an already instantiated cache to be used | Cache | |
cacheLoader (producer) | To configure a CacheLoader in case of a LoadCache use | CacheLoader | |
evictionType (producer) | Set the eviction Type for this cache | SIZE_BASED | EvictionType |
expireAfterAccessTime (producer) | Set the expire After Access Time in case of time based Eviction (in seconds) | 300 | int |
expireAfterWriteTime (producer) | Set the expire After Access Write in case of time based Eviction (in seconds) | 300 | int |
initialCapacity (producer) | Set the initial Capacity for the cache | 10000 | int |
key (producer) | To configure the default action key. If a key is set in the message header, then the key from the header takes precedence. | Object | |
maximumSize (producer) | Set the maximum size for the cache | 10000 | int |
removalListener (producer) | Set a specific removal Listener for the cache | RemovalListener | |
statsCounter (producer) | Set a specific Stats Counter for the cache stats | StatsCounter | |
statsEnabled (producer) | To enable stats on the cache | false | boolean |
keyType (advanced) | The cache key type, default java.lang.Object | java.lang.Object | String |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
valueType (advanced) | The cache value type, default java.lang.Object | java.lang.Object | String |
57.3. Spring Boot Auto-Configuration
The component supports 17 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.caffeine-cache.configuration.action | To configure the default cache action. If an action is set in the message header, then the operation from the header takes precedence. | String | |
camel.component.caffeine-cache.configuration.cache | To configure an already instantiated cache to be used | Cache | |
camel.component.caffeine-cache.configuration.cache-loader | To configure a CacheLoader in case of a LoadCache use | CacheLoader | |
camel.component.caffeine-cache.configuration.create-cache-if-not-exist | Configure if a cache need to be created if it does exist or can’t be pre-configured. | true | Boolean |
camel.component.caffeine-cache.configuration.eviction-type | Set the eviction Type for this cache | EvictionType | |
camel.component.caffeine-cache.configuration.expire-after-access-time | Set the expire After Access Time in case of time based Eviction (in seconds) | 300 | Integer |
camel.component.caffeine-cache.configuration.expire-after-write-time | Set the expire After Access Write in case of time based Eviction (in seconds) | 300 | Integer |
camel.component.caffeine-cache.configuration.initial-capacity | Set the initial Capacity for the cache | 10000 | Integer |
camel.component.caffeine-cache.configuration.key | To configure the default action key. If a key is set in the message header, then the key from the header takes precedence. | Object | |
camel.component.caffeine-cache.configuration.key-type | The cache key type, default java.lang.Object | java.lang.Object | String |
camel.component.caffeine-cache.configuration.maximum-size | Set the maximum size for the cache | 10000 | Integer |
camel.component.caffeine-cache.configuration.removal-listener | Set a specific removal Listener for the cache | RemovalListener | |
camel.component.caffeine-cache.configuration.stats-counter | Set a specific Stats Counter for the cache stats | StatsCounter | |
camel.component.caffeine-cache.configuration.stats-enabled | To enable stats on the cache | false | Boolean |
camel.component.caffeine-cache.configuration.value-type | The cache value type, default java.lang.Object | java.lang.Object | String |
camel.component.caffeine-cache.enabled | Whether to enable auto configuration of the caffeine-cache component. This is enabled by default. | Boolean | |
camel.component.caffeine-cache.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
57.4. Examples
You can use your cache with the following code:
@Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() { from("direct://start") .toF("caffeine-cache://%s?cache=#cache&action=PUT&key=1", "test") .toF("caffeine-cache://%s?cache=#cache&key=1&action=GET", "test") .log("Test! ${body}") .to("mock:result"); } }; }
In this way you’ll work always on the same cache in the registry.
57.5. Check operation result
Each time you’ll use an operation on the cache you’ll have two different headers to check for status:
CaffeineConstants.ACTION_HAS_RESULT CaffeineConstants.ACTION_SUCCEEDED
Chapter 58. Caffeine LoadCache Component
Available as of Camel version 2.20
The caffeine-loadcache component enables you to perform caching operations using The Load cache from Caffeine.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-caffeine</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
58.1. URI format
caffeine-loadcache://cacheName[?options]
You can append query options to the URI in the following format, ?option=value&option=#beanRef&…
58.2. Options
The Caffeine LoadCache component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | Sets the global component configuration | CaffeineConfiguration | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Caffeine LoadCache endpoint is configured using URI syntax:
caffeine-loadcache:cacheName
with the following path and query parameters:
58.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
cacheName | Required the cache name | String |
58.2.2. Query Parameters (19 parameters):
Name | Description | Default | Type |
---|---|---|---|
createCacheIfNotExist (common) | Configure if a cache need to be created if it does exist or can’t be pre-configured. | true | 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) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
action (producer) | To configure the default cache action. If an action is set in the message header, then the operation from the header takes precedence. | String | |
cache (producer) | To configure an already instantiated cache to be used | Cache | |
cacheLoader (producer) | To configure a CacheLoader in case of a LoadCache use | CacheLoader | |
evictionType (producer) | Set the eviction Type for this cache | SIZE_BASED | EvictionType |
expireAfterAccessTime (producer) | Set the expire After Access Time in case of time based Eviction (in seconds) | 300 | int |
expireAfterWriteTime (producer) | Set the expire After Access Write in case of time based Eviction (in seconds) | 300 | int |
initialCapacity (producer) | Set the initial Capacity for the cache | 10000 | int |
key (producer) | To configure the default action key. If a key is set in the message header, then the key from the header takes precedence. | Object | |
maximumSize (producer) | Set the maximum size for the cache | 10000 | int |
removalListener (producer) | Set a specific removal Listener for the cache | RemovalListener | |
statsCounter (producer) | Set a specific Stats Counter for the cache stats | StatsCounter | |
statsEnabled (producer) | To enable stats on the cache | false | boolean |
keyType (advanced) | The cache key type, default java.lang.Object | java.lang.Object | String |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
valueType (advanced) | The cache value type, default java.lang.Object | java.lang.Object | String |
58.3. Spring Boot Auto-Configuration
The component supports 17 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.caffeine-loadcache.configuration.action | To configure the default cache action. If an action is set in the message header, then the operation from the header takes precedence. | String | |
camel.component.caffeine-loadcache.configuration.cache | To configure an already instantiated cache to be used | Cache | |
camel.component.caffeine-loadcache.configuration.cache-loader | To configure a CacheLoader in case of a LoadCache use | CacheLoader | |
camel.component.caffeine-loadcache.configuration.create-cache-if-not-exist | Configure if a cache need to be created if it does exist or can’t be pre-configured. | true | Boolean |
camel.component.caffeine-loadcache.configuration.eviction-type | Set the eviction Type for this cache | EvictionType | |
camel.component.caffeine-loadcache.configuration.expire-after-access-time | Set the expire After Access Time in case of time based Eviction (in seconds) | 300 | Integer |
camel.component.caffeine-loadcache.configuration.expire-after-write-time | Set the expire After Access Write in case of time based Eviction (in seconds) | 300 | Integer |
camel.component.caffeine-loadcache.configuration.initial-capacity | Set the initial Capacity for the cache | 10000 | Integer |
camel.component.caffeine-loadcache.configuration.key | To configure the default action key. If a key is set in the message header, then the key from the header takes precedence. | Object | |
camel.component.caffeine-loadcache.configuration.key-type | The cache key type, default java.lang.Object | java.lang.Object | String |
camel.component.caffeine-loadcache.configuration.maximum-size | Set the maximum size for the cache | 10000 | Integer |
camel.component.caffeine-loadcache.configuration.removal-listener | Set a specific removal Listener for the cache | RemovalListener | |
camel.component.caffeine-loadcache.configuration.stats-counter | Set a specific Stats Counter for the cache stats | StatsCounter | |
camel.component.caffeine-loadcache.configuration.stats-enabled | To enable stats on the cache | false | Boolean |
camel.component.caffeine-loadcache.configuration.value-type | The cache value type, default java.lang.Object | java.lang.Object | String |
camel.component.caffeine-loadcache.enabled | Whether to enable auto configuration of the caffeine-loadcache component. This is enabled by default. | Boolean | |
camel.component.caffeine-loadcache.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
Chapter 59. Castor DataFormat (deprecated)
Available as of Camel version 2.1
Castor is a Data Format which uses the Castor XML library to unmarshal an XML payload into Java objects or to marshal Java objects into an XML payload.
As usually you can use either Java DSL or Spring XML to work with Castor Data Format.
59.1. Using the Java DSL
from("direct:order"). marshal().castor(). to("activemq:queue:order");
For example the following uses a named DataFormat of Castor which uses default Castor data binding features.
CastorDataFormat castor = new CastorDataFormat (); from("activemq:My.Queue"). unmarshal(castor). to("mqseries:Another.Queue");
If you prefer to use a named reference to a data format which can then be defined in your Registry such as via your Spring XML file. e.g.
from("activemq:My.Queue"). unmarshal("mycastorType"). to("mqseries:Another.Queue");
If you want to override default mapping schema by providing a mapping file you can set it as follows.
CastorDataFormat castor = new CastorDataFormat (); castor.setMappingFile("mapping.xml");
Also if you want to have more control on Castor Marshaller and Unmarshaller you can access them as below.
castor.getMarshaller(); castor.getUnmarshaller();
59.2. Using Spring XML
The following example shows how to use Castor to unmarshal using Spring configuring the castor data type
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="direct:start"/> <unmarshal> <castor validation="true" /> </unmarshal> <to uri="mock:result"/> </route> </camelContext>
This example shows how to configure the data type just once and reuse it on multiple routes. You have to set the <castor> element directly in <camelContext>.
<camelContext> <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <dataFormats> <castor id="myCastor"/> </dataFormats> <route> <from uri="direct:start"/> <marshal ref="myCastor"/> <to uri="direct:marshalled"/> </route> <route> <from uri="direct:marshalled"/> <unmarshal ref="myCastor"/> <to uri="mock:result"/> </route> </camelContext>
59.3. Options
The Castor dataformat supports 9 options, which are listed below.
Name | Default | Java Type | Description |
---|---|---|---|
mappingFile |
| Path to a Castor mapping file to load from the classpath. | |
whitelistEnabled |
|
| Define if Whitelist feature is enabled or not |
allowedUnmarshallObjects |
| Define the allowed objects to be unmarshalled. You can specify the FQN class name of allowed objects, and you can use comma to separate multiple entries. It is also possible to use wildcards and regular expression which is based on the pattern defined by link org.apache.camel.util.EndpointHelper#matchPattern(String, String). Denied objects takes precedence over allowed objects. | |
deniedUnmarshallObjects |
| Define the denied objects to be unmarshalled. You can specify the FQN class name of deined objects, and you can use comma to separate multiple entries. It is also possible to use wildcards and regular expression which is based on the pattern defined by link org.apache.camel.util.EndpointHelper#matchPattern(String, String). Denied objects takes precedence over allowed objects. | |
validation |
|
| Whether validation is turned on or off. Is by default true. |
encoding |
|
| Encoding to use when marshalling an Object to XML. Is by default UTF-8 |
packages |
| Add additional packages to Castor XmlContext | |
classes |
| Add additional class names to Castor XmlContext | |
contentTypeHeader |
|
| Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. |
59.4. Spring Boot Auto-Configuration
The component supports 10 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.dataformat.castor.allowed-unmarshall-objects | Define the allowed objects to be unmarshalled. You can specify the FQN class name of allowed objects, and you can use comma to separate multiple entries. It is also possible to use wildcards and regular expression which is based on the pattern defined by link org.apache.camel.util.EndpointHelper#matchPattern(String, String). Denied objects takes precedence over allowed objects. | String | |
camel.dataformat.castor.classes | Add additional class names to Castor XmlContext | String[] | |
camel.dataformat.castor.content-type-header | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. | false | Boolean |
camel.dataformat.castor.denied-unmarshall-objects | Define the denied objects to be unmarshalled. You can specify the FQN class name of deined objects, and you can use comma to separate multiple entries. It is also possible to use wildcards and regular expression which is based on the pattern defined by link org.apache.camel.util.EndpointHelper#matchPattern(String, String). Denied objects takes precedence over allowed objects. | String | |
camel.dataformat.castor.enabled | Enable castor dataformat | true | Boolean |
camel.dataformat.castor.encoding | Encoding to use when marshalling an Object to XML. Is by default UTF-8 | UTF-8 | String |
camel.dataformat.castor.mapping-file | Path to a Castor mapping file to load from the classpath. | String | |
camel.dataformat.castor.packages | Add additional packages to Castor XmlContext | String[] | |
camel.dataformat.castor.validation | Whether validation is turned on or off. Is by default true. | true | Boolean |
camel.dataformat.castor.whitelist-enabled | Define if Whitelist feature is enabled or not | true | Boolean |
ND
59.5. Dependencies
To use Castor in your camel routes you need to add the a dependency on camel-castor 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-castor</artifactId> <version>x.x.x</version> </dependency>
Chapter 60. Camel CDI
The Camel CDI component provides auto-configuration for Apache Camel using CDI as dependency injection framework based on convention-over-configuration. It auto-detects Camel routes available in the application and provides beans for common Camel primitives like Endpoint
, FluentProducerTemplate
, ProducerTemplate
or TypeConverter
. It implements standard Camel bean integration so that Camel annotations like @Consume
, @Produce
and @PropertyInject
can be used seamlessly in CDI beans. Besides, it bridges Camel events (e.g. RouteAddedEvent
, CamelContextStartedEvent
, ExchangeCompletedEvent
, …) as CDI events and provides a CDI events endpoint that can be used to consume / produce CDI events from / to Camel routes.
While the Camel CDI component is available as of Camel 2.10, it’s been rewritten in Camel 2.17 to better fit into the CDI programming model. Hence some of the features like the Camel events to CDI events bridge and the CDI events endpoint only apply starting Camel 2.17.
More details on how to test Camel CDI applications are available in Camel CDI testing.
camel-cdi is deprecated in OSGi and not supported. Use OSGi Blueprint if using Camel with OSGi.
60.1. Auto-configured Camel context
Camel CDI automatically deploys and configures a CamelContext
bean. That CamelContext
bean is automatically instantiated, configured and started (resp. stopped) when the CDI container initializes (resp. shuts down). It can be injected in the application, e.g.:
@Inject CamelContext context;
That default CamelContext
bean is qualified with the built-in @Default
qualifier, is scoped @ApplicationScoped
and is of type DefaultCamelContext
.
Note that this bean can be customized programmatically and other Camel context beans can be deployed in the application as well.
60.2. Auto-detecting Camel routes
Camel CDI automatically collects all the RoutesBuilder
beans in the application, instantiates and add them to the CamelContext
bean instance when the CDI container initializes. For example, adding a Camel route is as simple as declaring a class, e.g.:
class MyRouteBean extends RouteBuilder { @Override public void configure() { from("jms:invoices").to("file:/invoices"); } }
Note that you can declare as many RoutesBuilder
beans as you want. Besides, RouteContainer
beans are also automatically collected, instantiated and added to the CamelContext
bean instance managed by Camel CDI when the container initializes.
Available as of Camel 2.19
In some situations, it may be necessary to disable the auto-configuration of the RouteBuilder
and RouteContainer
beans. That can be achieved by observing for the CdiCamelConfiguration
event, e.g.:
static void configuration(@Observes CdiCamelConfiguration configuration) { configuration.autoConfigureRoutes(false); }
Similarly, it is possible to deactivate the automatic starting of the configured CamelContext
beans, e.g.:
static void configuration(@Observes CdiCamelConfiguration configuration) { configuration.autoStartContexts(false); }
60.3. Auto-configured Camel primitives
Camel CDI provides beans for common Camel primitives that can be injected in any CDI beans, e.g.:
@Inject @Uri("direct:inbound") ProducerTemplate producerTemplate; @Inject @Uri("direct:inbound") FluentProducerTemplate fluentProducerTemplate; @Inject MockEndpoint outbound; // URI defaults to the member name, i.e. mock:outbound @Inject @Uri("direct:inbound") Endpoint endpoint; @Inject TypeConverter converter;
60.4. Camel context configuration
If you just want to change the name of the default CamelContext
bean, you can used the @ContextName
qualifier provided by Camel CDI, e.g.:
@ContextName("camel-context") class MyRouteBean extends RouteBuilder { @Override public void configure() { from("jms:invoices").to("file:/invoices"); } }
Else, if more customization is needed, any CamelContext
class can be used to declare a custom Camel context bean. Then, the @PostConstruct
and @PreDestroy
lifecycle callbacks can be done to do the customization, e.g.:
@ApplicationScoped class CustomCamelContext extends DefaultCamelContext { @PostConstruct void customize() { // Set the Camel context name setName("custom"); // Disable JMX disableJMX(); } @PreDestroy void cleanUp() { // ... } }
Producer and disposer methods can also be used as well to customize the Camel context bean, e.g.:
class CamelContextFactory { @Produces @ApplicationScoped CamelContext customize() { DefaultCamelContext context = new DefaultCamelContext(); context.setName("custom"); return context; } void cleanUp(@Disposes CamelContext context) { // ... } }
Similarly, producer fields can be used, e.g.:
@Produces @ApplicationScoped CamelContext context = new CustomCamelContext(); class CustomCamelContext extends DefaultCamelContext { CustomCamelContext() { setName("custom"); } }
This pattern can be used for example to avoid having the Camel context routes started automatically when the container initializes by calling the setAutoStartup
method, e.g.:
@ApplicationScoped class ManualStartupCamelContext extends DefaultCamelContext { @PostConstruct void manual() { setAutoStartup(false); } }
60.5. Multiple Camel contexts
Any number of CamelContext
beans can actually be declared in the application as documented above. In that case, the CDI qualifiers declared on these CamelContext
beans are used to bind the Camel routes and other Camel primitives to the corresponding Camel contexts. From example, if the following beans get declared:
@ApplicationScoped @ContextName("foo") class FooCamelContext extends DefaultCamelContext { } @ApplicationScoped @BarContextQualifier class BarCamelContext extends DefaultCamelContext { } @ContextName("foo") class RouteAddedToFooCamelContext extends RouteBuilder { @Override public void configure() { // ... } } @BarContextQualifier class RouteAddedToBarCamelContext extends RouteBuilder { @Override public void configure() { // ... } } @ContextName("baz") class RouteAddedToBazCamelContext extends RouteBuilder { @Override public void configure() { // ... } } @MyOtherQualifier class RouteNotAddedToAnyCamelContext extends RouteBuilder { @Override public void configure() { // ... } }
The RoutesBuilder
beans qualified with @ContextName
are automatically added to the corresponding CamelContext
beans by Camel CDI. If no such CamelContext
bean exists, it gets automatically created, as for the RouteAddedToBazCamelContext
bean. Note this only happens for the @ContextName
qualifier provided by Camel CDI. Hence the RouteNotAddedToAnyCamelContext
bean qualified with the user-defined @MyOtherQualifier
qualifier does not get added to any Camel contexts. That may be useful, for example, for Camel routes that may be required to be added later during the application execution.
Since Camel version 2.17.0, Camel CDI is capable of managing any kind of CamelContext
beans (e.g. DefaultCamelContext
). In previous versions, it is only capable of managing beans of type CdiCamelContext
so it is required to extend it.
The CDI qualifiers declared on the CamelContext
beans are also used to bind the corresponding Camel primitives, e.g.:
@Inject @ContextName("foo") @Uri("direct:inbound") ProducerTemplate producerTemplate; @Inject @ContextName("foo") @Uri("direct:inbound") FluentProducerTemplate fluentProducerTemplate; @Inject @BarContextQualifier MockEndpoint outbound; // URI defaults to the member name, i.e. mock:outbound @Inject @ContextName("baz") @Uri("direct:inbound") Endpoint endpoint;
60.6. Configuration properties
To configure the sourcing of the configuration properties used by Camel to resolve properties placeholders, you can declare a PropertiesComponent
bean qualified with @Named("properties")
, e.g.:
@Produces @ApplicationScoped @Named("properties") PropertiesComponent propertiesComponent() { Properties properties = new Properties(); properties.put("property", "value"); PropertiesComponent component = new PropertiesComponent(); component.setInitialProperties(properties); component.setLocation("classpath:placeholder.properties"); return component; }
If you want to use DeltaSpike configuration mechanism you can declare the following PropertiesComponent
bean:
@Produces @ApplicationScoped @Named("properties") PropertiesComponent properties(PropertiesParser parser) { PropertiesComponent component = new PropertiesComponent(); component.setPropertiesParser(parser); return component; } // PropertiesParser bean that uses DeltaSpike to resolve properties static class DeltaSpikeParser extends DefaultPropertiesParser { @Override public String parseProperty(String key, String value, Properties properties) { return ConfigResolver.getPropertyValue(key); } }
You can see the camel-example-cdi-properties
example for a working example of a Camel CDI application using DeltaSpike configuration mechanism.
60.7. Auto-configured type converters
CDI beans annotated with the @Converter
annotation are automatically registered into the deployed Camel contexts, e.g.:
@Converter public class MyTypeConverter { @Converter public Output convert(Input input) { //... } }
Note that CDI injection is supported within the type converters.
60.8. Camel bean integration
60.8.1. Camel annotations
As part of the Camel bean integration, Camel comes with a set of annotations that are seamlessly supported by Camel CDI. So you can use any of these annotations in your CDI beans, e.g.:
Camel annotation | CDI equivalent | |
---|---|---|
Configuration property |
@PropertyInject("key") String value; | If using DeltaSpike configuration mechanism: @Inject @ConfigProperty(name = "key") String value; See configuration properties for more details. |
Producer template injection (default Camel context) |
@Produce(uri = "mock:outbound") ProducerTemplate producer; @Produce(uri = "mock:outbound") FluentProducerTemplate producer; |
@Inject @Uri("direct:outbound") ProducerTemplate producer; @Produce(uri = "direct:outbound") FluentProducerTemplate producer; |
Endpoint injection (default Camel context) |
@EndpointInject(uri = "direct:inbound") Endpoint endpoint; |
@Inject @Uri("direct:inbound") Endpoint endpoint; |
Endpoint injection (Camel context by name) |
@EndpointInject(uri = "direct:inbound", context = "foo") Endpoint contextEndpoint; |
@Inject @ContextName("foo") @Uri("direct:inbound") Endpoint contextEndpoint; |
Bean injection (by type) |
@BeanInject MyBean bean; |
@Inject MyBean bean; |
Bean injection (by name) |
@BeanInject("foo") MyBean bean; |
@Inject @Named("foo") MyBean bean; |
POJO consuming |
@Consume(uri = "seda:inbound") void consume(@Body String body) { //... } |
60.8.2. Bean component
You can refer to CDI beans, either by type or name, From the Camel DSL, e.g. with the Java Camel DSL:
class MyBean { //... } from("direct:inbound").bean(MyBean.class);
Or to lookup a CDI bean by name from the Java DSL:
@Named("foo") class MyNamedBean { //... } from("direct:inbound").bean("foo");
60.8.3. Referring beans from Endpoint URIs
When configuring endpoints using the URI syntax you can refer to beans in the Registry using the #
notation. If the URI parameter value starts with a #
sign then Camel CDI will lookup for a bean of the given type by name, e.g.:
from("jms:queue:{{destination}}?transacted=true&transactionManager=#jtaTransactionManager").to("...");
Having the following CDI bean qualified with @Named("jtaTransactionManager")
:
@Produces @Named("jtaTransactionManager") PlatformTransactionManager createTransactionManager(TransactionManager transactionManager, UserTransaction userTransaction) { JtaTransactionManager jtaTransactionManager = new JtaTransactionManager(); jtaTransactionManager.setUserTransaction(userTransaction); jtaTransactionManager.setTransactionManager(transactionManager); jtaTransactionManager.afterPropertiesSet(); return jtaTransactionManager; }
60.9. Camel events to CDI events
Available as of Camel 2.17
Camel provides a set of management events that can be subscribed to for listening to Camel context, service, route and exchange events. Camel CDI seamlessly translates these Camel events into CDI events that can be observed using CDI observer methods, e.g.:
void onContextStarting(@Observes CamelContextStartingEvent event) { // Called before the default Camel context is about to start }
As of Camel 2.18, it is possible to observe events for a particular route (RouteAddedEvent
, RouteStartedEvent
, RouteStoppedEvent
and RouteRemovedEvent
) should it have an explicit defined, e.g.:
from("...").routeId("foo").to("..."); void onRouteStarted(@Observes @Named("foo") RouteStartedEvent event) { // Called after the route "foo" has started }
When multiple Camel contexts exist in the CDI container, the Camel context bean qualifiers, like @ContextName
, can be used to refine the observer method resolution to a particular Camel context as specified in observer resolution, e.g.:
void onRouteStarted(@Observes @ContextName("foo") RouteStartedEvent event) { // Called after the route 'event.getRoute()' for the Camel context 'foo' has started } void onContextStarted(@Observes @Manual CamelContextStartedEvent event) { // Called after the Camel context qualified with '@Manual' has started }
Similarly, the @Default
qualifier can be used to observe Camel events for the default Camel context if multiples contexts exist, e.g.:
void onExchangeCompleted(@Observes @Default ExchangeCompletedEvent event) { // Called after the exchange 'event.getExchange()' processing has completed }
In that example, if no qualifier is specified, the @Any
qualifier is implicitly assumed, so that corresponding events for all the Camel contexts get received.
Note that the support for Camel events translation into CDI events is only activated if observer methods listening for Camel events are detected in the deployment, and that per Camel context.
60.10. CDI events endpoint
Available as of Camel 2.17
The CDI event endpoint bridges the CDI events with the Camel routes so that CDI events can be seamlessly observed / consumed (resp. produced / fired) from Camel consumers (resp. by Camel producers).
The CdiEventEndpoint<T>
bean provided by Camel CDI can be used to observe / consume CDI events whose event type is T
, for example:
@Inject CdiEventEndpoint<String> cdiEventEndpoint; from(cdiEventEndpoint).log("CDI event received: ${body}");
This is equivalent to writing:
@Inject @Uri("direct:event") ProducerTemplate producer; void observeCdiEvents(@Observes String event) { producer.sendBody(event); } from("direct:event").log("CDI event received: ${body}");
Conversely, the CdiEventEndpoint<T>
bean can be used to produce / fire CDI events whose event type is T
, for example:
@Inject CdiEventEndpoint<String> cdiEventEndpoint; from("direct:event").to(cdiEventEndpoint).log("CDI event sent: ${body}");
This is equivalent to writing:
@Inject Event<String> event; from("direct:event").process(new Processor() { @Override public void process(Exchange exchange) { event.fire(exchange.getBody(String.class)); } }).log("CDI event sent: ${body}");
Or using a Java 8 lambda expression:
@Inject Event<String> event; from("direct:event") .process(exchange -> event.fire(exchange.getIn().getBody(String.class))) .log("CDI event sent: ${body}");
The type variable T
(resp. the qualifiers) of a particular CdiEventEndpoint<T>
injection point are automatically translated into the parameterized event type (resp. into the event qualifiers) e.g.:
@Inject @FooQualifier CdiEventEndpoint<List<String>> cdiEventEndpoint; from("direct:event").to(cdiEventEndpoint); void observeCdiEvents(@Observes @FooQualifier List<String> event) { logger.info("CDI event: {}", event); }
When multiple Camel contexts exist in the CDI container, the Camel context bean qualifiers, like @ContextName
, can be used to qualify the CdiEventEndpoint<T>
injection points, e.g.:
@Inject @ContextName("foo") CdiEventEndpoint<List<String>> cdiEventEndpoint; // Only observes / consumes events having the @ContextName("foo") qualifier from(cdiEventEndpoint).log("Camel context (foo) > CDI event received: ${body}"); // Produces / fires events with the @ContextName("foo") qualifier from("...").to(cdiEventEndpoint); void observeCdiEvents(@Observes @ContextName("foo") List<String> event) { logger.info("Camel context (foo) > CDI event: {}", event); }
Note that the CDI event Camel endpoint dynamically adds an observer method for each unique combination of event type and event qualifiers and solely relies on the container typesafe observer resolution, which leads to an implementation as efficient as possible.
Besides, as the impedance between the typesafe nature of CDI and the dynamic nature of the Camel component model is quite high, it is not possible to create an instance of the CDI event Camel endpoint via URIs. Indeed, the URI format for the CDI event component is:
cdi-event://PayloadType<T1,...,Tn>[?qualifiers=QualifierType1[,...[,QualifierTypeN]...]]
With the authority PayloadType
(resp. the QualifierType
) being the URI escaped fully qualified name of the payload (resp. qualifier) raw type followed by the type parameters section delimited by angle brackets for payload parameterized type. Which leads to unfriendly URIs, e.g.:
cdi-event://org.apache.camel.cdi.example.EventPayload%3Cjava.lang.Integer%3E?qualifiers=org.apache.camel.cdi.example.FooQualifier%2Corg.apache.camel.cdi.example.BarQualifier
But more fundamentally, that would prevent efficient binding between the endpoint instances and the observer methods as the CDI container doesn’t have any ways of discovering the Camel context model during the deployment phase.
60.11. Camel XML configuration import
Available as of Camel 2.18
While CDI favors a typesafe dependency injection mechanism, it may be useful to reuse existing Camel XML configuration files into a Camel CDI application. In other use cases, it might be handy to rely on the Camel XML DSL to configure its Camel context(s).
You can use the @ImportResource
annotation that’s provided by Camel CDI on any CDI beans and Camel CDI will automatically load the Camel XML configuration at the specified locations, e.g.:
@ImportResource("camel-context.xml") class MyBean { }
Camel CDI will load the resources at the specified locations from the classpath (other protocols may be added in the future).
Every CamelContext
elements and other Camel primitives from the imported resources are automatically deployed as CDI beans during the container bootstrap so that they benefit from the auto-configuration provided by Camel CDI and become available for injection at runtime. If such an element has an explicit id
attribute set, the corresponding CDI bean is qualified with the @Named
qualifier, e.g., given the following Camel XML configuration:
<camelContext id="foo"> <endpoint id="bar" uri="seda:inbound"> <property key="queue" value="#queue"/> <property key="concurrentConsumers" value="10"/> </endpoint> <camelContext/>
The corresponding CDI beans are automatically deployed and can be injected, e.g.:
@Inject @ContextName("foo") CamelContext context; @Inject @Named("bar") Endpoint endpoint;
Note that the CamelContext
beans are automatically qualified with both the @Named
and @ContextName
qualifiers. If the imported CamelContext
element doesn’t have an id
attribute, the corresponding bean is deployed with the built-in @Default
qualifier.
Conversely, CDI beans deployed in the application can be referred to from the Camel XML configuration, usually using the ref
attribute, e.g., given the following bean declared:
@Produces @Named("baz") Processor processor = exchange -> exchange.getIn().setHeader("qux", "quux");
A reference to that bean can be declared in the imported Camel XML configuration, e.g.:
<camelContext id="foo"> <route> <from uri="..."/> <process ref="baz"/> </route> <camelContext/>
60.12. Transaction support
Available as of Camel 2.19
Camel CDI provides support for Camel transactional client using JTA.
That support is optional hence you need to have JTA in your application classpath, e.g., by explicitly add JTA as a dependency when using Maven:
<dependency> <groupId>javax.transaction</groupId> <artifactId>javax.transaction-api</artifactId> <scope>runtime</scope> </dependency>
You’ll have to have your application deployed in a JTA capable container or provide a standalone JTA implementation.
Note that, for the time being, the transaction manager is looked up as JNDI resource with the java:/TransactionManager
key.
More flexible strategies will be added in the future to support a wider range of deployment scenarios.
60.12.1. Transaction policies
Camel CDI provides implementation for the typically supported Camel TransactedPolicy
as CDI beans. It is possible to have these policies looked up by name using the transacted EIP, e.g.:
class MyRouteBean extends RouteBuilder { @Override public void configure() { from("activemq:queue:foo") .transacted("PROPAGATION_REQUIRED") .bean("transformer") .to("jpa:my.application.entity.Bar") .log("${body.id} inserted"); } }
This would be equivalent to:
class MyRouteBean extends RouteBuilder { @Inject @Named("PROPAGATION_REQUIRED") Policy required; @Override public void configure() { from("activemq:queue:foo") .policy(required) .bean("transformer") .to("jpa:my.application.entity.Bar") .log("${body.id} inserted"); } }
The list of supported transaction policy names is:
-
PROPAGATION_NEVER
, -
PROPAGATION_NOT_SUPPORTED
, -
PROPAGATION_SUPPORTS
, -
PROPAGATION_REQUIRED
, -
PROPAGATION_REQUIRES_NEW
, -
PROPAGATION_NESTED
, -
PROPAGATION_MANDATORY
.
60.12.2. Transactional error handler
Camel CDI provides a transactional error handler that extends the redelivery error handler, forces a rollback whenever an exception occurs and creates a new transaction for each redelivery.
Camel CDI provides the CdiRouteBuilder
class that exposes the transactionErrorHandler
helper method to enable quick access to the configuration, e.g.:
class MyRouteBean extends CdiRouteBuilder { @Override public void configure() { errorHandler(transactionErrorHandler() .setTransactionPolicy("PROPAGATION_SUPPORTS") .maximumRedeliveries(5) .maximumRedeliveryDelay(5000) .collisionAvoidancePercent(10) .backOffMultiplier(1.5)); } }
60.13. Auto-configured OSGi integration
Available as of Camel 2.17
The Camel context beans are automatically adapted by Camel CDI so that they are registered as OSGi services and the various resolvers (like ComponentResolver
and DataFormatResolver
) integrate with the OSGi registry. That means that the Karaf Camel commands can be used to operate the Camel contexts auto-configured by Camel CDI, e.g.:
karaf@root()> camel:context-list Context Status Total # Failed # Inflight # Uptime ------- ------ ------- -------- ---------- ------ camel-cdi Started 1 0 0 1 minute
See the camel-example-cdi-osgi
example for a working example of the Camel CDI OSGi integration.
60.14. Lazy Injection / Programmatic Lookup
While the CDI programmatic model favors a typesafe resolution mechanism that occurs at application initialization time, it is possible to perform dynamic / lazy injection later during the application execution using the programmatic lookup mechanism.
Camel CDI provides for convenience the annotation literals corresponding to the CDI qualifiers that you can use for standard injection of Camel primitives. These annotation literals can be used in conjunction with the javax.enterprise.inject.Instance
interface which is the CDI entry point to perform lazy injection / programmatic lookup.
For example, you can use the provided annotation literal for the @Uri
qualifier to lazily lookup for Camel primitives, e.g. for ProducerTemplate
beans:
@Any @Inject Instance<ProducerTemplate> producers; ProducerTemplate inbound = producers .select(Uri.Literal.of("direct:inbound")) .get();
Or for Endpoint
beans, e.g.:
@Any @Inject Instance<Endpoint> endpoints; MockEndpoint outbound = endpoints .select(MockEndpoint.class, Uri.Literal.of("mock:outbound")) .get();
Similarly, you can use the provided annotation literal for the @ContextName
qualifier to lazily lookup for CamelContext
beans, e.g.:
@Any @Inject Instance<CamelContext> contexts; CamelContext context = contexts .select(ContextName.Literal.of("foo")) .get();
You can also refined the selection based on the Camel context type, e.g.:
@Any @Inject Instance<CamelContext> contexts; // Refine the selection by type Instance<DefaultCamelContext> context = contexts.select(DefaultCamelContext.class); // Check if such a bean exists then retrieve a reference if (!context.isUnsatisfied()) context.get();
Or even iterate over a selection of Camel contexts, e.g.:
@Any @Inject Instance<CamelContext> contexts; for (CamelContext context : contexts) context.setUseBreadcrumb(true);
60.15. Maven Archetype
Among the available Camel Maven archetypes, you can use the provided camel-archetype-cdi
to generate a Camel CDI Maven project, e.g.:
mvn archetype:generate -DarchetypeGroupId=org.apache.camel.archetypes -DarchetypeArtifactId=camel-archetype-cdi
60.16. Supported containers
The Camel CDI component is compatible with any CDI 1.0, CDI 1.1 and CDI 1.2 compliant runtime. It’s been successfully tested against the following runtimes:
Container | Version | Runtime |
---|---|---|
Weld SE |
| CDI 1.0 / Java SE 7 |
OpenWebBeans |
| CDI 1.0 / Java SE 7 |
Weld SE |
| CDI 1.2 / Java SE 7 |
OpenWebBeans |
| CDI 1.2 / Java SE 7 |
WildFly |
| CDI 1.2 / Java EE 7 |
WildFly |
| CDI 1.2 / Java EE 7 |
WildFly |
| CDI 1.2 / Java EE 7 |
60.17. Examples
The following examples are available in the examples
directory of the Camel project:
Example | Description |
---|---|
| Illustrates how to work with Camel using CDI to configure components, endpoints and beans |
| Illustrates the integration between Camel, CDI and Kubernetes |
| Illustrates the integration between Camel, Dropwizard Metrics and CDI |
| Illustrates the integration between Camel, DeltaSpike and CDI for configuration properties |
| A CDI application using the SJMS component that can be executed inside an OSGi container using PAX CDI |
| Illustrates the Camel REST DSL being used in a Web application that uses CDI as dependency injection framework |
| Demonstrates the testing features that are provided as part of the integration between Camel and CDI |
| Illustrates the use of Camel XML configuration files into a Camel CDI application |
| An example using REST DSL and OpenAPI Java with CDI |
| An example using REST DSL and Swagger Java with CDI |
| The Widget and Gadget use-case from the EIP book implemented in Java with CDI dependency Injection |
60.18. See Also
- Camel CDI testing
- CDI specification Web site
- CDI ecosystem
- Weld home page
- OpenWebBeans home page
- Going further with CDI and Camel (See Camel CDI section)
60.19. Camel CDI for EAR deployments on WildFly-Camel
Camel CDI EAR deployments on WildFly-Camel have some differences in class and resource loading behaviour, compared to standard WAR or JAR deployments.
WildFly bootstraps Weld using the EAR deployment ClassLoader. WildFly also mandates that only a single CDI extension is created and shared by all EAR sub-deployments.
This results in the 'Auto-configured' CDI Camel Context using the EAR deployment ClassLoader to dynamically load classes and resources. By default, this ClassLoader does not have access to resources within EAR sub-deployments.
For EAR deployments, it is recommended that usage of the 'Auto-configured' CDI Camel Context is avoided and that RouteBuilder
classes are annotated with @ContextName
, or that a CamelContext
is created via the @ImportResource
annotation or through CDI producer methods and fields. This helps WildFly-Camel to determine the correct ClassLoader to use with Camel.
Chapter 61. Chronicle Engine Component
Available as of Camel version 2.18
The camel chronicle-engine component let you leverage the power of OpenHFT’s Chronicle-Engine
61.1. URI Format
chronicle-engine:addresses/path[?options]
61.2. URI Options
The Chronicle Engine component has no options.
The Chronicle Engine endpoint is configured using URI syntax:
chronicle-engine:addresses/path
with the following path and query parameters:
61.2.1. Path Parameters (2 parameters):
Name | Description | Default | Type |
---|---|---|---|
addresses | Required Engine addresses. Multiple addresses can be separated by comma. | String | |
path | Required Engine path | String |
61.2.2. Query Parameters (12 parameters):
Name | Description | Default | Type |
---|---|---|---|
action (common) | The default action to perform, valid values are: - PUBLISH - PPUBLISH_AND_INDEX - PPUT - PGET_AND_PUT - PPUT_ALL - PPUT_IF_ABSENT - PGET - PGET_AND_REMOVE - PREMOVE - PIS_EMPTY - PSIZE | String | |
clusterName (common) | Cluster name for queue | String | |
filteredMapEvents (common) | A comma separated list of Map event type to filer, valid values are: INSERT, UPDATE, REMOVE. | String | |
persistent (common) | Enable/disable data persistence | true | boolean |
subscribeMapEvents (common) | Set if consumer should subscribe to Map events, default true. | true | boolean |
subscribeTopicEvents (common) | Set if consumer should subscribe to TopicEvents,d efault false. | false | boolean |
subscribeTopologicalEvents (common) | Set if consumer should subscribe to TopologicalEvents,d efault false. | false | boolean |
wireType (common) | The Wire type to use, default to binary wire. | BINARY | 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 |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
61.3. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.chronicle-engine.enabled | Enable chronicle-engine component | true | Boolean |
camel.component.chronicle-engine.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
Chapter 62. Chunk Component
Available as of Camel version 2.15
The chunk: component allows for processing a message using a Chunk template. This can be ideal when using Templating to generate responses for requests.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-chunk</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
62.1. URI format
chunk:templateName[?options]
Where templateName is the classpath-local URI of the template to invoke.
You can append query options to the URI in the following format, ?option=value&option=value&…
62.2. Options
The Chunk component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
allowContextMapAll (producer) | Sets whether the context map should allow access to all details. By default only the message body and headers can be accessed. This option can be enabled for full access to the current Exchange and CamelContext. Doing so imposes a potential security risk as this opens access to the full power of CamelContext API. | false | boolean |
allowTemplateFromHeader (producer) | Whether to allow to use resource template from header or not (default false). Enabling this option has security ramifications. For example, if the header contains untrusted or user derived content, this can ultimately impact on the confidentility and integrity of your end application, so use this option with caution. | false | boolean |
The Chunk endpoint is configured using URI syntax:
chunk:resourceUri
with the following path and query parameters:
62.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
resourceUri | Required Path to the resource. You can prefix with: classpath, file, http, ref, or bean. classpath, file and http loads the resource using these protocols (classpath is default). ref will lookup the resource in the registry. bean will call a method on a bean to be used as the resource. For bean you can specify the method name after dot, eg bean:myBean.myMethod. | String |
62.2.2. Query Parameters (9 parameters):
Name | Description | Default | Type |
---|---|---|---|
allowContextMapAll (producer) | Sets whether the context map should allow access to all details. By default only the message body and headers can be accessed. This option can be enabled for full access to the current Exchange and CamelContext. Doing so imposes a potential security risk as this opens access to the full power of CamelContext API. | false | boolean |
allowTemplateFromHeader (producer) | Whether to allow to use resource template from header or not (default false). Enabling this option has security ramifications. For example, if the header contains untrusted or user derived content, this can ultimately impact on the confidentility and integrity of your end application, so use this option with caution. | false | boolean |
contentCache (producer) | Sets whether to use resource content cache or not | false | boolean |
encoding (producer) | Define the encoding of the body | String | |
extension (producer) | Define the file extension of the template | String | |
themeFolder (producer) | Define the themes folder to scan | String | |
themeLayer (producer) | Define the theme layer to elaborate | String | |
themeSubfolder (producer) | Define the themes subfolder to scan | String | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
62.3. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.chunk.enabled | Enable chunk component | true | Boolean |
camel.component.chunk.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
Chunk component will look for a specific template in themes folder with extensions .chtml or _.cxml. _If you need to specify a different folder or extensions, you will need to use the specific options listed above.
62.4. Chunk Context
Camel will provide exchange information in the Chunk context (just a Map
). The Exchange
is transferred as:
key | value |
---|---|
|
The |
|
The |
| The headers of the In message. |
| The Camel Context. |
| The In message. |
| The In message body. |
| The Out message (only for InOut message exchange pattern). |
62.5. Dynamic templates
Camel provides two headers by which you can define a different resource location for a template or the template content itself. If any of these headers is set then Camel uses this over the endpoint configured resource. This allows you to provide a dynamic template at runtime.
Header | Type | Description | Support Version |
---|---|---|---|
ChunkConstants.CHUNK_RESOURCE_URI | String | A URI for the template resource to use instead of the endpoint configured. | |
ChunkConstants.CHUNK_TEMPLATE | String | The template to use instead of the endpoint configured. |
62.6. Samples
For example you could use something like:
from("activemq:My.Queue"). to("chunk:template");
To use a Chunk template to formulate a response for a message for InOut message exchanges (where there is a JMSReplyTo
header).
If you want to use InOnly and consume the message and send it to another destination you could use:
from("activemq:My.Queue"). to("chunk:template"). to("activemq:Another.Queue");
It’s possible to specify what template the component should use dynamically via a header, so for example:
from("direct:in"). setHeader(ChunkConstants.CHUNK_RESOURCE_URI).constant("template"). to("chunk:dummy?allowTemplateFromHeader=true");
Enabling the allowTemplateFromHeader
option has security ramifications. For example, if the header contains untrusted or user derived content, this can ultimately impact on the confidentility and integrity of your end application, so use this option with caution.
An example of Chunk component options use:
from("direct:in"). to("chunk:file_example?themeFolder=template&themeSubfolder=subfolder&extension=chunk");
In this example Chunk component will look for the file file_example.chunk in the folder template/subfolder.
62.7. The Email Sample
In this sample we want to use Chunk templating for an order confirmation email. The email template is laid out in Chunk as:
Dear {$headers.lastName}, {$headers.firstName} Thanks for the order of {$headers.item}. Regards Camel Riders Bookstore {$body}
62.8. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 63. Class Component
Available as of Camel version 2.4
The class: component binds beans to Camel message exchanges. It works in the same way as the Bean component but instead of looking up beans from a Registry it creates the bean based on the class name.
63.1. URI format
class:className[?options]
Where className is the fully qualified class name to create and use as bean.
63.2. Options
The Class component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
cache (advanced) | If enabled, Camel will cache the result of the first Registry look-up. Cache can be enabled if the bean in the Registry is defined as a singleton scope. | Boolean | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Class endpoint is configured using URI syntax:
class:beanName
with the following path and query parameters:
63.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
beanName | Required Sets the name of the bean to invoke | String |
63.2.2. Query Parameters (5 parameters):
Name | Description | Default | Type |
---|---|---|---|
method (producer) | Sets the name of the method to invoke on the bean | String | |
cache (advanced) | If enabled, Camel will cache the result of the first Registry look-up. Cache can be enabled if the bean in the Registry is defined as a singleton scope. | Boolean | |
multiParameterArray (advanced) | Deprecated How to treat the parameters which are passed from the message body; if it is true, the message body should be an array of parameters. Note: This option is used internally by Camel, and is not intended for end users to use. Deprecation note: This option is used internally by Camel, and is not intended for end users to use. | false | boolean |
parameters (advanced) | Used for configuring additional properties on the bean | Map | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
63.3. Using
You simply use the class component just as the Bean component but by specifying the fully qualified classname instead.
For example to use the MyFooBean
you have to do as follows:
from("direct:start").to("class:org.apache.camel.component.bean.MyFooBean").to("mock:result");
You can also specify which method to invoke on the MyFooBean
, for example hello
:
from("direct:start").to("class:org.apache.camel.component.bean.MyFooBean?method=hello").to("mock:result");
63.4. Setting properties on the created instance
In the endpoint uri you can specify properties to set on the created instance, for example if it has a setPrefix
method:
// Camel 2.17 onwards from("direct:start") .to("class:org.apache.camel.component.bean.MyPrefixBean?bean.prefix=Bye") .to("mock:result"); // Camel 2.16 and older from("direct:start") .to("class:org.apache.camel.component.bean.MyPrefixBean?prefix=Bye") .to("mock:result");
And you can also use the #
syntax to refer to properties to be looked up in the Registry.
// Camel 2.17 onwards from("direct:start") .to("class:org.apache.camel.component.bean.MyPrefixBean?bean.cool=#foo") .to("mock:result"); // Camel 2.16 and older from("direct:start") .to("class:org.apache.camel.component.bean.MyPrefixBean?cool=#foo") .to("mock:result");
Which will lookup a bean from the Registry with the id foo
and invoke the setCool
method on the created instance of the MyPrefixBean
class.
TIP:See more details at the Bean component as the class component works in much the same way.
63.5. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- Bean
- Bean Binding
- Bean Integration
Chapter 64. CMIS Component
Available as of Camel version 2.11
The cmis component uses the Apache Chemistry client API and allows you to add/read nodes to/from a CMIS compliant content repositories.
64.1. URI Format
cmis://cmisServerUrl[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
64.2. CMIS Options
The CMIS component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
sessionFacadeFactory (common) | To use a custom CMISSessionFacadeFactory to create the CMISSessionFacade instances | CMISSessionFacade Factory | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The CMIS endpoint is configured using URI syntax:
cmis:cmsUrl
with the following path and query parameters:
64.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
cmsUrl | Required URL to the cmis repository | String |
64.2.2. Query Parameters (13 parameters):
Name | Description | Default | Type |
---|---|---|---|
pageSize (common) | Number of nodes to retrieve per page | 100 | int |
readContent (common) | If set to true, the content of document node will be retrieved in addition to the properties | false | boolean |
readCount (common) | Max number of nodes to read | int | |
repositoryId (common) | The Id of the repository to use. If not specified the first available repository is used | 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 |
query (consumer) | The cmis query to execute against the repository. If not specified, the consumer will retrieve every node from the content repository by iterating the content tree recursively | String | |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
queryMode (producer) | If true, will execute the cmis query from the message body and return result, otherwise will create a node in the cmis repository | false | boolean |
sessionFacadeFactory (advanced) | To use a custom CMISSessionFacadeFactory to create the CMISSessionFacade instances | CMISSessionFacade Factory | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
password (security) | Password for the cmis repository | String | |
username (security) | Username for the cmis repository | String |
64.3. Spring Boot Auto-Configuration
The component supports 3 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.cmis.enabled | Enable cmis component | true | Boolean |
camel.component.cmis.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.cmis.session-facade-factory | To use a custom CMISSessionFacadeFactory to create the CMISSessionFacade instances. The option is a org.apache.camel.component.cmis.CMISSessionFacadeFactory type. | String |
64.4. Usage
64.4.1. Message headers evaluated by the producer
Header | Default Value | Description |
---|---|---|
|
| The current folder to use during the execution. If not specified will use the root folder |
|
|
In |
|
| Max number of nodes to read. |
|
|
If |
|
|
If |
|
| The type of the node |
|
| The mimetype to set for a document |
64.4.2. Message headers set during querying Producer operation
Header | Type | Description |
---|---|---|
|
| Number of nodes returned from the query. |
The message body will contain a list of maps, where each entry in the map is cmis property and its value. If CamelCMISRetrieveContent
header is set to true, one additional entry in the map with key CamelCMISContent
will contain InputStream
of the document type of nodes.
64.5. Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-cmis</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.11 or higher).
64.6. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 65. CM SMS Gateway Component
Available as of Camel version 2.18
Camel-Cm-Sms is an Apache Camel component for the [CM SMS Gateway](https://www.cmtelecom.com).
It allows to integrate CM SMS APIin an application as a camel component.
You must have a valid account. More information are available at CM Telecom.
cm-sms://sgw01.cm.nl/gateway.ashx?defaultFrom=DefaultSender&defaultMaxNumberOfParts=8&productToken=xxxxx
Maven users will need to add the following dependency to their pom.xml for this component:
--- <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-cm-sms</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency> ---
65.1. Options
The CM SMS Gateway component has no options.
The CM SMS Gateway endpoint is configured using URI syntax:
cm-sms:host
with the following path and query parameters:
65.1.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
host | Required SMS Provider HOST with scheme | String |
65.1.2. Query Parameters (5 parameters):
Name | Description | Default | Type |
---|---|---|---|
defaultFrom (producer) | This is the sender name. The maximum length is 11 characters. | String) | |
defaultMaxNumberOfParts (producer) | If it is a multipart message forces the max number. Message can be truncated. Technically the gateway will first check if a message is larger than 160 characters, if so, the message will be cut into multiple 153 characters parts limited by these parameters. | 8 | Max(8L)::Int) |
productToken (producer) | Required The unique token to use | String) | |
testConnectionOnStartup (producer) | Whether to test the connection to the SMS Gateway on startup | false | boolean |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
65.2. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.cm-sms.enabled | Enable cm-sms component | true | Boolean |
camel.component.cm-sms.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
65.3. Sample
You can try this project to see how camel-cm-sms can be integrated in a camel route.
Chapter 66. CoAP Component
Available as of Camel version 2.16
Camel-CoAP is an Apache Camel component that allows you to work with CoAP, a lightweight REST-type protocol for machine-to-machine operation. CoAP, Constrained Application Protocol is a specialized web transfer protocol for use with constrained nodes and constrained networks and it is based on RFC 7252.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-coap</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
66.1. Options
The CoAP component has no options.
The CoAP endpoint is configured using URI syntax:
coap:uri
with the following path and query parameters:
66.1.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
uri | The URI for the CoAP endpoint | URI |
66.1.2. Query Parameters (5 parameters):
Name | Description | Default | Type |
---|---|---|---|
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 |
coapMethodRestrict (consumer) | Comma separated list of methods that the CoAP consumer will bind to. The default is to bind to all methods (DELETE, GET, POST, PUT). | String | |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
66.2. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.coap.enabled | Enable coap component | true | Boolean |
camel.component.coap.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
66.3. Message Headers
Name | Type | Description |
---|---|---|
|
| The request method that the CoAP producer should use when calling the target CoAP server URI. Valid options are DELETE, GET, PING, POST & PUT. |
|
| The CoAP response code sent by the external server. See RFC 7252 for details of what each code means. |
|
| The URI of a CoAP server to call. Will override any existing URI configured directly on the endpoint. |
66.3.1. Configuring the CoAP producer request method
The following rules determine which request method the CoAP producer will use to invoke the target URI:
-
The value of the
CamelCoapMethod
header - GET if a query string is provided on the target CoAP server URI.
- POST if the message exchange body is not null.
- GET otherwise.
Chapter 67. Constant Language
Available as of Camel version 1.5
The Constant Expression Language is really just a way to specify constant strings as a type of expression.
This is a fixed constant value that is only set once during starting up the route, do not use this if you want dynamic values during routing.
67.1. Constant Options
The Constant language supports 1 options, which are listed below.
Name | Default | Java Type | Description |
---|---|---|---|
trim |
|
| Whether to trim the value to remove leading and trailing whitespaces and line breaks |
67.2. Example usage
The setHeader element of the Spring DSL can utilize a constant expression like:
<route> <from uri="seda:a"/> <setHeader headerName="theHeader"> <constant>the value</constant> </setHeader> <to uri="mock:b"/> </route>
in this case, the Message coming from the seda:a Endpoint will have 'theHeader' header set to the constant value 'the value'.
And the same example using Java DSL:
from("seda:a") .setHeader("theHeader", constant("the value")) .to("mock:b");
67.3. Dependencies
The Constant language is part of camel-core.
Chapter 68. CometD Component
Available as of Camel version 2.0
The cometd: component is a transport for working with the jetty implementation of the cometd/bayeux protocol.
Using this component in combination with the dojo toolkit library it’s possible to push Camel messages directly into the browser using an AJAX based mechanism.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-cometd</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
68.1. URI format
cometd://host:port/channelName[?options]
The channelName represents a topic that can be subscribed to by the Camel endpoints.
68.2. Examples
cometd://localhost:8080/service/mychannel cometds://localhost:8443/service/mychannel
where cometds:
represents an SSL configured endpoint.
68.3. Options
The CometD component supports 8 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
sslKeyPassword (security) | The password for the keystore when using SSL. | String | |
sslPassword (security) | The password when using SSL. | String | |
sslKeystore (security) | The path to the keystore. | String | |
securityPolicy (security) | To use a custom configured SecurityPolicy to control authorization | SecurityPolicy | |
extensions (common) | To use a list of custom BayeuxServer.Extension that allows modifying incoming and outgoing requests. | List | |
sslContextParameters (security) | To configure security using SSLContextParameters | SSLContextParameters | |
useGlobalSslContext Parameters (security) | Enable usage of global SSL context parameters. | false | boolean |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The CometD endpoint is configured using URI syntax:
cometd:host:port/channelName
with the following path and query parameters:
68.3.1. Path Parameters (3 parameters):
Name | Description | Default | Type |
---|---|---|---|
host | Required Hostname | String | |
port | Required Host port number | int | |
channelName | Required The channelName represents a topic that can be subscribed to by the Camel endpoints. | String |
68.3.2. Query Parameters (16 parameters):
Name | Description | Default | Type |
---|---|---|---|
allowedOrigins (common) | The origins domain that support to cross, if the crosssOriginFilterOn is true | * | String |
baseResource (common) | The root directory for the web resources or classpath. Use the protocol file: or classpath: depending if you want that the component loads the resource from file system or classpath. Classpath is required for OSGI deployment where the resources are packaged in the jar | String | |
crossOriginFilterOn (common) | If true, the server will support for cross-domain filtering | false | boolean |
filterPath (common) | The filterPath will be used by the CrossOriginFilter, if the crosssOriginFilterOn is true | String | |
interval (common) | The client side poll timeout in milliseconds. How long a client will wait between reconnects | int | |
jsonCommented (common) | If true, the server will accept JSON wrapped in a comment and will generate JSON wrapped in a comment. This is a defence against Ajax Hijacking. | true | boolean |
logLevel (common) | Logging level. 0=none, 1=info, 2=debug. | 1 | int |
maxInterval (common) | The max client side poll timeout in milliseconds. A client will be removed if a connection is not received in this time. | 30000 | int |
multiFrameInterval (common) | The client side poll timeout, if multiple connections are detected from the same browser. | 1500 | int |
timeout (common) | The server side poll timeout in milliseconds. This is how long the server will hold a reconnect request before responding. | 240000 | int |
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 |
sessionHeadersEnabled (consumer) | Whether to include the server session headers in the Camel message when creating a Camel Message for incoming requests. | false | boolean |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
disconnectLocalSession (producer) | Whether to disconnect local sessions after publishing a message to its channel. Disconnecting local session is needed as they are not swept by default by CometD, and therefore you can run out of memory. | false | boolean |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
68.4. Spring Boot Auto-Configuration
The component supports 9 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.cometd.enabled | Enable cometd component | true | Boolean |
camel.component.cometd.extensions | To use a list of custom BayeuxServer.Extension that allows modifying incoming and outgoing requests. | List | |
camel.component.cometd.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.cometd.security-policy | To use a custom configured SecurityPolicy to control authorization. The option is a org.cometd.bayeux.server.SecurityPolicy type. | String | |
camel.component.cometd.ssl-context-parameters | To configure security using SSLContextParameters. The option is a org.apache.camel.util.jsse.SSLContextParameters type. | String | |
camel.component.cometd.ssl-key-password | The password for the keystore when using SSL. | String | |
camel.component.cometd.ssl-keystore | The path to the keystore. | String | |
camel.component.cometd.ssl-password | The password when using SSL. | String | |
camel.component.cometd.use-global-ssl-context-parameters | Enable usage of global SSL context parameters. | false | Boolean |
You can append query options to the URI in the following format, ?option=value&option=value&…
Here is some examples on How to pass the parameters
For file (for webapp resources located in the Web Application directory -→ cometd://localhost:8080?resourceBase=file./webapp
For classpath (when by example the web resources are packaged inside the webapp folder -→ cometd://localhost:8080?resourceBase=classpath:webapp
68.5. Authentication
Available as of Camel 2.8
You can configure custom SecurityPolicy
and Extension’s to the `CometdComponent
which allows you to use authentication as documented here
68.6. Setting up SSL for Cometd Component
68.6.1. Using the JSSE Configuration Utility
As of Camel 2.9, the Cometd 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 Cometd component. You need to configure SSL on the CometdComponent.
Programmatic configuration of the component
KeyStoreParameters ksp = new KeyStoreParameters(); ksp.setResource("/users/home/server/keystore.jks"); ksp.setPassword("keystorePassword"); KeyManagersParameters kmp = new KeyManagersParameters(); kmp.setKeyStore(ksp); kmp.setKeyPassword("keyPassword"); TrustManagersParameters tmp = new TrustManagersParameters(); tmp.setKeyStore(ksp); SSLContextParameters scp = new SSLContextParameters(); scp.setKeyManagers(kmp); scp.setTrustManagers(tmp); CometdComponent commetdComponent = getContext().getComponent("cometds", CometdComponent.class); commetdComponent.setSslContextParameters(scp);
Spring DSL based configuration of endpoint
... <camel:sslContextParameters id="sslContextParameters"> <camel:keyManagers keyPassword="keyPassword"> <camel:keyStore resource="/users/home/server/keystore.jks" password="keystorePassword"/> </camel:keyManagers> <camel:trustManagers> <camel:keyStore resource="/users/home/server/keystore.jks" password="keystorePassword"/> </camel:keyManagers> </camel:sslContextParameters>... <bean id="cometd" class="org.apache.camel.component.cometd.CometdComponent"> <property name="sslContextParameters" ref="sslContextParameters"/> </bean> ... <to uri="cometds://127.0.0.1:443/service/test?baseResource=file:./target/test-classes/webapp&timeout=240000&interval=0&maxInterval=30000&multiFrameInterval=1500&jsonCommented=true&logLevel=2"/>...
68.7. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 69. Consul Component
Available as of Camel version 2.18
The Consul component is a component for integrating your application with Consul.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-consul</artifactId> <version>${camel-version}</version> </dependency>
69.1. URI format
consul://domain?[options]
You can append query options to the URI in the following format:
?option=value&option=value&...
69.2. Options
The Consul component supports 9 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
url (common) | The Consul agent URL | String | |
datacenter (common) | The data center | String | |
sslContextParameters (common) | SSL configuration using an org.apache.camel.util.jsse.SSLContextParameters instance. | SSLContextParameters | |
useGlobalSslContext Parameters (security) | Enable usage of global SSL context parameters. | false | boolean |
aclToken (common) | Sets the ACL token to be used with Consul | String | |
userName (common) | Sets the username to be used for basic authentication | String | |
password (common) | Sets the password to be used for basic authentication | String | |
configuration (advanced) | Sets the common configuration shared among endpoints | ConsulConfiguration | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Consul endpoint is configured using URI syntax:
consul:apiEndpoint
with the following path and query parameters:
69.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
apiEndpoint | Required The API endpoint | String |
69.2.2. Query Parameters (4 parameters):
Name | Description | Default | Type |
---|---|---|---|
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) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
69.3. Spring Boot Auto-Configuration
The component supports 90 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.consul.acl-token | Sets the ACL token to be used with Consul | String | |
camel.component.consul.cluster.service.acl-token | String | ||
camel.component.consul.cluster.service.attributes | Custom service attributes. | Map | |
camel.component.consul.cluster.service.block-seconds | Integer | ||
camel.component.consul.cluster.service.connect-timeout-millis | Long | ||
camel.component.consul.cluster.service.consistency-mode | ConsistencyMode | ||
camel.component.consul.cluster.service.datacenter | String | ||
camel.component.consul.cluster.service.enabled | Sets if the consul cluster service should be enabled or not, default is false. | false | Boolean |
camel.component.consul.cluster.service.first-index | BigInteger | ||
camel.component.consul.cluster.service.id | Cluster Service ID | String | |
camel.component.consul.cluster.service.near-node | String | ||
camel.component.consul.cluster.service.node-meta | List | ||
camel.component.consul.cluster.service.order | Service lookup order/priority. | Integer | |
camel.component.consul.cluster.service.password | String | ||
camel.component.consul.cluster.service.ping-instance | Boolean | ||
camel.component.consul.cluster.service.read-timeout-millis | Long | ||
camel.component.consul.cluster.service.recursive | Boolean | ||
camel.component.consul.cluster.service.root-path | String | ||
camel.component.consul.cluster.service.session-lock-delay | Integer | ||
camel.component.consul.cluster.service.session-refresh-interval | Integer | ||
camel.component.consul.cluster.service.session-ttl | Integer | ||
camel.component.consul.cluster.service.ssl-context-parameters | SSLContextParameters | ||
camel.component.consul.cluster.service.tags | Set | ||
camel.component.consul.cluster.service.url | String | ||
camel.component.consul.cluster.service.user-name | String | ||
camel.component.consul.cluster.service.write-timeout-millis | Long | ||
camel.component.consul.configuration.acl-token | Sets the ACL token to be used with Consul | String | |
camel.component.consul.configuration.action | The default action. Can be overridden by CamelConsulAction | String | |
camel.component.consul.configuration.block-seconds | The second to wait for a watch event, default 10 seconds | Integer | |
camel.component.consul.configuration.connect-timeout-millis | Connect timeout for OkHttpClient | Long | |
camel.component.consul.configuration.consistency-mode | The consistencyMode used for queries, default ConsistencyMode.DEFAULT | ConsistencyMode | |
camel.component.consul.configuration.consul-client |
Reference to a | Consul | |
camel.component.consul.configuration.datacenter | The data center | String | |
camel.component.consul.configuration.first-index | The first index for watch for, default 0 | BigInteger | |
camel.component.consul.configuration.key | The default key. Can be overridden by CamelConsulKey | String | |
camel.component.consul.configuration.near-node | The near node to use for queries. | String | |
camel.component.consul.configuration.node-meta | The note meta-data to use for queries. | List | |
camel.component.consul.configuration.password | Sets the password to be used for basic authentication | String | |
camel.component.consul.configuration.ping-instance | Configure if the AgentClient should attempt a ping before returning the Consul instance | Boolean | |
camel.component.consul.configuration.read-timeout-millis | Read timeout for OkHttpClient | Long | |
camel.component.consul.configuration.recursive | Recursively watch, default false | Boolean | |
camel.component.consul.configuration.ssl-context-parameters | SSL configuration using an org.apache.camel.util.jsse.SSLContextParameters instance. | SSLContextParameters | |
camel.component.consul.configuration.tags | Set tags. You can separate multiple tags by comma. | Set | |
camel.component.consul.configuration.url | The Consul agent URL | String | |
camel.component.consul.configuration.user-name | Sets the username to be used for basic authentication | String | |
camel.component.consul.configuration.value-as-string | Default to transform values retrieved from Consul i.e. on KV endpoint to string. | Boolean | |
camel.component.consul.configuration.write-timeout-millis | Write timeout for OkHttpClient | Long | |
camel.component.consul.datacenter | The data center | String | |
camel.component.consul.enabled | Enable consul component | true | Boolean |
camel.component.consul.health.check.repository.checks | Define the checks to include. | List | |
camel.component.consul.health.check.repository.configurations | Health check configurations. | Map | |
camel.component.consul.health.check.repository.enabled | Boolean | ||
camel.component.consul.health.check.repository.failure-threshold | Integer | ||
camel.component.consul.health.check.repository.interval | String | ||
camel.component.consul.password | Sets the password to be used for basic authentication | String | |
camel.component.consul.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.consul.service-registry.acl-token | String | ||
camel.component.consul.service-registry.attributes | Custom service attributes. | Map | |
camel.component.consul.service-registry.block-seconds | Integer | ||
camel.component.consul.service-registry.check-interval | Integer | ||
camel.component.consul.service-registry.check-ttl | Integer | ||
camel.component.consul.service-registry.connect-timeout-millis | Long | ||
camel.component.consul.service-registry.consistency-mode | ConsistencyMode | ||
camel.component.consul.service-registry.datacenter | String | ||
camel.component.consul.service-registry.deregister-after | Integer | ||
camel.component.consul.service-registry.deregister-services-on-stop | Boolean | ||
camel.component.consul.service-registry.enabled | Sets if the consul service registry should be enabled or not, default is false. | false | Boolean |
camel.component.consul.service-registry.first-index | BigInteger | ||
camel.component.consul.service-registry.id | Service Registry ID | String | |
camel.component.consul.service-registry.near-node | String | ||
camel.component.consul.service-registry.node-meta | List | ||
camel.component.consul.service-registry.order | Service lookup order/priority. | Integer | |
camel.component.consul.service-registry.override-service-host | Boolean | ||
camel.component.consul.service-registry.password | String | ||
camel.component.consul.service-registry.ping-instance | Boolean | ||
camel.component.consul.service-registry.read-timeout-millis | Long | ||
camel.component.consul.service-registry.recursive | Boolean | ||
camel.component.consul.service-registry.service-host | String | ||
camel.component.consul.service-registry.ssl-context-parameters | SSLContextParameters | ||
camel.component.consul.service-registry.tags | Set | ||
camel.component.consul.service-registry.url | String | ||
camel.component.consul.service-registry.user-name | String | ||
camel.component.consul.service-registry.write-timeout-millis | Long | ||
camel.component.consul.ssl-context-parameters | SSL configuration using an org.apache.camel.util.jsse.SSLContextParameters instance. The option is a org.apache.camel.util.jsse.SSLContextParameters type. | String | |
camel.component.consul.url | The Consul agent URL | String | |
camel.component.consul.use-global-ssl-context-parameters | Enable usage of global SSL context parameters. | false | Boolean |
camel.component.consul.user-name | Sets the username to be used for basic authentication | String | |
camel.component.consul.cluster.service.dc | String | ||
camel.component.consul.configuration.dc | The data center @deprecated replaced by {@link #setDatacenter(String)} ()} | String | |
camel.component.consul.service-registry.dc | String |
69.4. Headers
Name | Type | Description |
---|---|---|
CamelConsulAction | String | The Producer action |
CamelConsulKey | String | The Key on which the action should applied |
CamelConsulEventId | String | The event id (consumer only) |
CamelConsulEventName | String | The event name (consumer only) |
CamelConsulEventLTime | Long | The event LTime |
CamelConsulNodeFilter | String | The Node filter |
CamelConsulTagFilter | String | The tag filter |
CamelConsulSessionFilter | String | The session filter |
CamelConsulVersion | int | The data version |
CamelConsulFlags | Long | Flags associated with a value |
CamelConsulCreateIndex | Long | The internal index value that represents when the entry was created |
CamelConsulLockIndex | Long | The number of times this key has successfully been acquired in a lock |
CamelConsulModifyIndex | Long | The last index that modified this key |
CamelConsulOptions | Object | Options associated to the request |
CamelConsulResult | boolean | true if the response has a result |
CamelConsulSession | String | The session id |
CamelConsulValueAsString | boolean | To transform values retrieved from Consul i.e. on KV endpoint to string. |
Chapter 70. Control Bus Component
Available as of Camel version 2.11
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.
From Camel 2.11 onwards we have introduced a new ControlBus Component that allows you to send messages to a control bus Endpoint that reacts accordingly.
70.1. ControlBus Component
Available as of Camel 2.11
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.
70.2. Commands
Command | Description |
---|---|
|
To control routes using the |
| Allows you to specify 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. |
70.3. Options
The Control Bus component has no options.
The Control Bus endpoint is configured using URI syntax:
controlbus:command:language
with the following path and query parameters:
70.3.1. Path Parameters (2 parameters):
Name | Description | Default | Type |
---|---|---|---|
command | Required Command can be either route or language | String | |
language | 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. | Language |
70.3.2. Query Parameters (6 parameters):
Name | Description | Default | Type |
---|---|---|---|
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. | 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 |
loggingLevel (producer) | Logging level used for logging when task is done, or if any exceptions occurred during processing the task. | 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 | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
You can append query options to the URI in the following format, ?option=value&option=value&…
70.4. 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);
70.5. Getting performance statistics
Available as of Camel 2.11.1
This requires JMX to be enabled (is by default) then you can get the performance statics per route, or for the CamelContext. For example to get the statics for a route named foo, we can do:
String xml = template.requestBody("controlbus:route?routeId=foo&action=stats", null, String.class);
The returned statics is in XML format. Its the same data you can get from JMX with the dumpRouteStatsAsXml
operation on the ManagedRouteMBean
.
To get statics for the entire CamelContext you just omit the routeId parameter as shown below:
String xml = template.requestBody("controlbus:route?action=stats", null, String.class);
70.6. 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.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.
You can also use other languages such as Groovy, etc.
Chapter 71. Couchbase Component
Available as of Camel version 2.19
The couchbase: component allows you to treat CouchBase instances as a producer or consumer of messages.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-couchbase</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
71.1. URI format
couchbase:url
71.2. Options
The Couchbase component has no options.
The Couchbase endpoint is configured using URI syntax:
couchbase:protocol:hostname:port
with the following path and query parameters:
71.2.1. Path Parameters (3 parameters):
Name | Description | Default | Type |
---|---|---|---|
protocol | Required The protocol to use | String | |
hostname | Required The hostname to use | String | |
port | The port number to use | 8091 | int |
71.2.2. Query Parameters (47 parameters):
Name | Description | Default | Type |
---|---|---|---|
bucket (common) | The bucket to use | String | |
key (common) | The key to use | 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 |
consumerProcessedStrategy (consumer) | Define the consumer Processed strategy to use | none | String |
descending (consumer) | Define if this operation is descending or not | false | boolean |
designDocumentName (consumer) | The design document name to use | beer | String |
limit (consumer) | The output limit to use | -1 | int |
rangeEndKey (consumer) | Define a range for the end key | String | |
rangeStartKey (consumer) | Define a range for the start key | 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 |
skip (consumer) | Define the skip to use | -1 | int |
viewName (consumer) | The view name to use | brewery_beers | String |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
pollStrategy (consumer) | 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. | PollingConsumerPoll Strategy | |
autoStartIdForInserts (producer) | Define if we want an autostart Id when we are doing an insert operation | false | boolean |
operation (producer) | The operation to do | CCB_PUT | String |
persistTo (producer) | Where to persist the data | 0 | int |
producerRetryAttempts (producer) | Define the number of retry attempts | 2 | int |
producerRetryPause (producer) | Define the retry pause between different attempts | 5000 | int |
replicateTo (producer) | Where to replicate the data | 0 | int |
startingIdForInsertsFrom (producer) | Define the starting Id where we are doing an insert operation | long | |
additionalHosts (advanced) | The additional hosts | String | |
maxReconnectDelay (advanced) | Define the max delay during a reconnection | 30000 | long |
obsPollInterval (advanced) | Define the observation polling interval | 400 | long |
obsTimeout (advanced) | Define the observation timeout | -1 | long |
opQueueMaxBlockTime (advanced) | Define the max time an operation can be in queue blocked | 10000 | long |
opTimeOut (advanced) | Define the operation timeout | 2500 | long |
readBufferSize (advanced) | Define the buffer size | 16384 | int |
shouldOptimize (advanced) | Define if we want to use optimization or not where possible | false | boolean |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
timeoutExceptionThreshold (advanced) | Define the threshold for throwing a timeout Exception | 998 | int |
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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 1000 | 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. | 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. | ScheduledExecutor Service | |
scheduler (scheduler) | To use a cron scheduler from either camel-spring or camel-quartz2 component | none | ScheduledPollConsumer Scheduler |
schedulerProperties (scheduler) | To configure additional properties when using a custom scheduler or any of the Quartz2, Spring based scheduler. | Map | |
startScheduler (scheduler) | Whether the scheduler should be auto started. | true | boolean |
timeUnit (scheduler) | Time unit for initialDelay and delay options. | MILLISECONDS | TimeUnit |
useFixedDelay (scheduler) | Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean |
password (security) | The password to use | String | |
username (security) | The username to use | String |
71.3. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.couchbase.enabled | Enable couchbase component | true | Boolean |
camel.component.couchbase.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
Chapter 72. CouchDB Component
Available as of Camel version 2.11
The couchdb: component allows you to treat CouchDB instances as a producer or consumer of messages. Using the lightweight LightCouch API, this camel component has the following features:
- As a consumer, monitors couch changesets for inserts, updates and deletes and publishes these as messages into camel routes.
- As a producer, can save, update, from Camel 2.18 delete (by using CouchDbMethod with DELETE value) documents and from Camel 2.22 get document by id (by using CouchDbMethod with GET value) into couch.
- Can support as many endpoints as required, eg for multiple databases across multiple instances.
- Ability to have events trigger for only deletes, only inserts/updates or all (default).
- Headers set for sequenceId, document revision, document id, and HTTP method type.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-couchdb</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
72.1. URI format
couchdb:http://hostname[:port]/database?[options]
Where hostname is the hostname of the running couchdb instance. Port is optional and if not specified then defaults to 5984.
72.2. Options
The CouchDB component has no options.
The CouchDB endpoint is configured using URI syntax:
couchdb:protocol:hostname:port/database
with the following path and query parameters:
72.2.1. Path Parameters (4 parameters):
Name | Description | Default | Type |
---|---|---|---|
protocol | Required The protocol to use for communicating with the database. | String | |
hostname | Required Hostname of the running couchdb instance | String | |
port | Port number for the running couchdb instance | 5984 | int |
database | Required Name of the database to use | String |
72.2.2. Query Parameters (12 parameters):
Name | Description | Default | Type |
---|---|---|---|
createDatabase (common) | Creates the database if it does not already exist | 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 |
deletes (consumer) | Document deletes are published as events | true | boolean |
heartbeat (consumer) | How often to send an empty message to keep socket alive in millis | 30000 | long |
since (consumer) | Start tracking changes immediately after the given update sequence. The default, null, will start monitoring from the latest sequence. | String | |
style (consumer) | Specifies how many revisions are returned in the changes array. The default, main_only, will only return the current winning revision; all_docs will return all leaf revisions (including conflicts and deleted former conflicts.) | main_only | String |
updates (consumer) | Document inserts/updates are published as events | true | boolean |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
password (security) | Password for authenticated databases | String | |
username (security) | Username in case of authenticated databases | String |
72.3. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.couchdb.enabled | Enable couchdb component | true | Boolean |
camel.component.couchdb.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
72.4. Headers
The following headers are set on exchanges during message transport.
Property | Value |
---|---|
| the database the message came from |
| the couchdb changeset sequence number of the update / delete message |
| the couchdb document id |
| the couchdb document revision |
| the method (delete / update) |
Headers are set by the consumer once the message is received. The producer will also set the headers for downstream processors once the insert/update has taken place. Any headers set prior to the producer are ignored. That means for example, if you set CouchDbId as a header, it will not be used as the id for insertion, the id of the document will still be used.
72.5. Message Body
The component will use the message body as the document to be inserted. If the body is an instance of String, then it will be marshalled into a GSON object before insert. This means that the string must be valid JSON or the insert / update will fail. If the body is an instance of a com.google.gson.JsonElement then it will be inserted as is. Otherwise the producer will throw an exception of unsupported body type.
72.6. Samples
For example if you wish to consume all inserts, updates and deletes from a CouchDB instance running locally, on port 9999 then you could use the following:
from("couchdb:http://localhost:9999").process(someProcessor);
If you were only interested in deletes, then you could use the following
from("couchdb:http://localhost:9999?updates=false").process(someProcessor);
If you wanted to insert a message as a document, then the body of the exchange is used
from("someProducingEndpoint").process(someProcessor).to("couchdb:http://localhost:9999")
Chapter 73. Cassandra CQL Component
Available as of Camel version 2.15
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.
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.
Maven users will need to add the following dependency to their pom.xml
:
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-cassandraql</artifactId> <version>x.y.z</version> <!-- use the same version as your Camel core version --> </dependency>
73.1. URI format
The endpoint can initiate the Cassandra connection or use an existing one.
URI | Description |
---|---|
| Single host, default port, usual for testing |
| Multi host, default port |
| Multi host, custom port |
| Default port and keyspace |
| Provided Session reference |
| 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.
73.2. Cassandra Options
The Cassandra CQL component has no options.
The Cassandra CQL endpoint is configured using URI syntax:
cql:beanRef:hosts:port/keyspace
with the following path and query parameters:
73.2.1. Path Parameters (4 parameters):
Name | Description | Default | Type |
---|---|---|---|
beanRef | beanRef is defined using bean:id | String | |
hosts | Hostname(s) cassansdra server(s). Multiple hosts can be separated by comma. | String | |
port | Port number of cassansdra server(s) | Integer | |
keyspace | Keyspace to use | String |
73.2.2. Query Parameters (29 parameters):
Name | Description | Default | Type |
---|---|---|---|
cluster (common) | To use the Cluster instance (you would normally not use this option) | Cluster | |
clusterName (common) | Cluster name | String | |
consistencyLevel (common) | Consistency level to use | ConsistencyLevel | |
cql (common) | CQL query to perform. Can be overridden with the message header with key CamelCqlQuery. | String | |
loadBalancingPolicy (common) | To use a specific LoadBalancingPolicy | 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… | String | |
session (common) | To use the Session instance (you would normally not use this option) | Session | |
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) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
pollStrategy (consumer) | 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. | PollingConsumerPoll Strategy | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 1000 | 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. | 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. | ScheduledExecutor Service | |
scheduler (scheduler) | To use a cron scheduler from either camel-spring or camel-quartz2 component | none | ScheduledPollConsumer Scheduler |
schedulerProperties (scheduler) | To configure additional properties when using a custom scheduler or any of the Quartz2, Spring based scheduler. | Map | |
startScheduler (scheduler) | Whether the scheduler should be auto started. | true | boolean |
timeUnit (scheduler) | Time unit for initialDelay and delay options. | MILLISECONDS | TimeUnit |
useFixedDelay (scheduler) | Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean |
73.3. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.cql.enabled | Enable cql component | true | Boolean |
camel.component.cql.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
73.4. Messages
73.4.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
orRegularStatement
): CQL query either as a plain String or built using theQueryBuilder
.
73.4.2. Outgoing Message
The Camel Cassandra endpoint produces one or many a Cassandra Row objects depending on the resultSetConversionStrategy
:
-
List<Row>
ifresultSetConversionStrategy
isALL
orLIMIT_[0-9]+
-
Single` Row` if
resultSetConversionStrategy
isONE
-
Anything else, if
resultSetConversionStrategy
is a custom implementation of theResultSetConversionStrategy
73.5. 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.
73.6. 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.
Option | Default | Description |
---|---|---|
|
| Table name |
|
| Primary key columns |
|
Repository name, value used for | |
| Key time to live | |
|
Consistency level used to insert/delete key: | |
|
Consistency level used to read/check key: |
73.7. 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.
Option | Default | Description |
---|---|---|
|
| Table name |
|
| Primary key columns |
|
| Exchange Id column |
|
| Exchange content column |
|
Repository name, value used for | |
| Exchange time to live | |
|
Consistency level used to insert/delete exchange: | |
|
Consistency level used to read/check exchange: |
73.8. 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.
Chapter 74. Crypto (JCE) Component
Available as of Camel version 2.3
With Camel cryptographic endpoints and Java’s 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’s workflow and then verify the signature in a later part of the workflow.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-crypto</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
74.1. Introduction
Digital signatures make use of Asymmetric Cryptographic techniques to sign messages. From a (very) 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. One, 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 some excellent 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
74.2. URI format
As mentioned 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 constantorg.apache.camel.component.crypto.DigitalSignatureConstants.SIGNATURE
, i.e."CamelDigitalSignature"
. -
crypto:verify
will read in the contents of this header and do the verification calculation.
In order to correctly 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.
Note 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. It goes without saying that both signing and verifying should be configured identically.
74.3. Options
The Crypto (JCE) component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | To use the shared DigitalSignatureConfiguration as configuration | DigitalSignature Configuration | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Crypto (JCE) endpoint is configured using URI syntax:
crypto:cryptoOperation:name
with the following path and query parameters:
74.3.1. Path Parameters (2 parameters):
Name | Description | Default | Type |
---|---|---|---|
cryptoOperation | 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. | CryptoOperation | |
name | Required The logical name of this operation. | String |
74.3.2. Query Parameters (19 parameters):
Name | Description | Default | Type |
---|---|---|---|
algorithm (producer) | Sets the JCE name of the Algorithm that should be used for the signer. | SHA1WithDSA | 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 fond 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 fond 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 fond 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 fond 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 | |
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 | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
password (security) | Sets the password used to access an aliased PrivateKey in the KeyStore. | String |
74.4. Spring Boot Auto-Configuration
The component supports 33 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.crypto.configuration.algorithm | Sets the JCE name of the Algorithm that should be used for the signer. | SHA1WithDSA | String |
camel.component.crypto.configuration.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.configuration.buffer-size | Set the size of the buffer used to read in the Exchange payload data. | 2048 | Integer |
camel.component.crypto.configuration.certificate | Set the Certificate that should be used to verify the signature in the exchange based on its payload. | Certificate | |
camel.component.crypto.configuration.certificate-name | Sets the reference name for a PrivateKey that can be fond in the registry. | String | |
camel.component.crypto.configuration.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.crypto-operation | Set the Crypto operation from that supplied after the crypto scheme in the endpoint uri e.g. crypto:sign sets sign as the operation. | CryptoOperation | |
camel.component.crypto.configuration.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. | KeyStoreParameters | |
camel.component.crypto.configuration.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. | KeyStore | |
camel.component.crypto.configuration.keystore-name | Sets the reference name for a Keystore that can be fond in the registry. | String | |
camel.component.crypto.configuration.name | The logical name of this operation. | String | |
camel.component.crypto.configuration.password | Sets the password used to access an aliased PrivateKey in the KeyStore. | Character[] | |
camel.component.crypto.configuration.private-key | Set the PrivateKey that should be used to sign the exchange | PrivateKey | |
camel.component.crypto.configuration.private-key-name | Sets the reference name for a PrivateKey that can be fond in the registry. | String | |
camel.component.crypto.configuration.provider | Set the id of the security provider that provides the configured Signature algorithm. | String | |
camel.component.crypto.configuration.public-key | Set the PublicKey that should be used to verify the signature in the exchange. | PublicKey | |
camel.component.crypto.configuration.public-key-name | references that should be resolved when the context changes | String | |
camel.component.crypto.configuration.secure-random | Set the SecureRandom used to initialize the Signature service | SecureRandom | |
camel.component.crypto.configuration.secure-random-name | Sets the reference name for a SecureRandom that can be fond in the registry. | String | |
camel.component.crypto.configuration.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.component.crypto.enabled | Enable crypto component | true | Boolean |
camel.component.crypto.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.dataformat.crypto.algorithm | The JCE algorithm name indicating the cryptographic algorithm that will be used. Is by default DES/CBC/PKCS5Padding. | DES/CBC/PKCS5Padding | 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.buffersize | The size of the buffer used in the signature process. | Integer | |
camel.dataformat.crypto.content-type-header | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. | false | Boolean |
camel.dataformat.crypto.crypto-provider | The name of the JCE Security Provider that should be used. | String | |
camel.dataformat.crypto.enabled | Enable crypto dataformat | true | 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. | false | Boolean |
74.5. Using
74.5.1. Raw keys
The most basic way to way to sign and verify an exchange is with a KeyPair as follows.
The same can be achieved with the Spring XML Extensions using references to keys
74.5.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. This is a good example of using keytool to create a KeyStore with a self signed Cert and Private key.
The examples use a Keystore with a key and cert aliased by 'bob'. The password for the keystore and the key is 'letmein'
The following shows how to use a Keystore via the Fluent builders, it also shows how to load and initialize the keystore.
Again in Spring a ref is used to lookup an actual keystore instance.
74.5.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.
or
74.5.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
or
74.5.5. Changing the buffersize
In case you need to update the size of the buffer…
or
74.5.6. 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
-
Exchange.SIGNATURE_PRIVATE_KEY
,"CamelSignaturePrivateKey"
-
Exchange.SIGNATURE_PUBLIC_KEY_OR_CERT
,"CamelSignaturePublicKeyOrCert"
or
Even better would be to dynamically supply a keystore alias. Again the alias can be supplied in a message header
-
Exchange.KEYSTORE_ALIAS
,"CamelSignatureKeyStoreAlias"
or
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.getOut()); signed.getIn().setHeader(KEYSTORE_ALIAS, "bob"); template.send("direct:alias-verify", signed);
74.6. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 75. Crypto CMS Component
Available as of Camel version 2.20
Cryptographic Message Syntax (CMS) is a well established standard for signing and encrypting messages. The Apache Crypto CMS component supports the following parts of this standard: * Content Type "Enveloped Data" with Key Transport (asymmetric key), * Content Type "Signed Data". You can create CMS Enveloped Data instances, decrypt CMS Enveloped Data instances, create CMS Signed Data instances, and validate CMS Signed Data instances.
The component uses the Bouncy Castle libraries bcprov-jdk18on and bcpkix-jdk18on.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-crypto-cms</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
We recommend to register the Bouncy Castle security provider in your application before you call an endpoint of this component:
Security.addProvider(new BouncyCastleProvider());
If the Bouncy Castle security provider is not registered then the Crypto CMS component will register the provider.
75.1. Options
The Crypto CMS component supports 3 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
signedDataVerifier Configuration (advanced) | To configure the shared SignedDataVerifierConfiguration, which determines the uri parameters for the verify operation. | SignedDataVerifier Configuration | |
envelopedDataDecryptor Configuration (advanced) | To configure the shared EnvelopedDataDecryptorConfiguration, which determines the uri parameters for the decrypt operation. | EnvelopedDataDecryptor Configuration | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Crypto CMS endpoint is configured using URI syntax:
crypto-cms:cryptoOperation:name
with the following path and query parameters:
75.1.1. Path Parameters (2 parameters):
Name | Description | Default | Type |
---|---|---|---|
cryptoOperation | Required Set the Crypto operation from that supplied after the crypto scheme in the endpoint uri e.g. crypto-cms:sign sets sign as the operation. Possible values: sign, verify, encrypt, or decrypt. | CryptoOperation | |
name | Required The name part in the URI can be chosen by the user to distinguish between different signer/verifier/encryptor/decryptor endpoints within the camel context. | String |
75.1.2. Query Parameters (15 parameters):
Name | Description | Default | Type |
---|---|---|---|
keyStore (common) | Keystore which contains signer private keys, verifier public keys, encryptor public keys, decryptor private keys depending on the operation. Use either this parameter or the parameter 'keyStoreParameters'. | KeyStore | |
keyStoreParameters (common) | Keystore containing signer private keys, verifier public keys, encryptor public keys, decryptor private keys depending on the operation. Use either this parameter or the parameter 'keystore'. | KeyStoreParameters | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
password (decrypt) | Sets the password of the private keys. It is assumed that all private keys in the keystore have the same password. If not set then it is assumed that the password of the private keys is given by the keystore password given in the KeyStoreParameters. | Char[] | |
fromBase64 (decrypt_verify) | If true then the CMS message is base 64 encoded and must be decoded during the processing. Default value is false. | false | Boolean |
contentEncryptionAlgorithm (encrypt) | Encryption algorithm, for example DESede/CBC/PKCS5Padding. Further possible values: DESede/CBC/PKCS5Padding, AES/CBC/PKCS5Padding, Camellia/CBC/PKCS5Padding, CAST5/CBC/PKCS5Padding. | String | |
originatorInformation Provider (encrypt) | Provider for the originator info. See https://tools.ietf.org/html/rfc5652#section-6.1. The default value is null. | OriginatorInformation Provider | |
recipient (encrypt) | Recipient Info: reference to a bean which implements the interface org.apache.camel.component.crypto.cms.api.TransRecipientInfo | List | |
secretKeyLength (encrypt) | Key length for the secret symmetric key used for the content encryption. Only used if the specified content-encryption algorithm allows keys of different sizes. If contentEncryptionAlgorithm=AES/CBC/PKCS5Padding or Camellia/CBC/PKCS5Padding then 128; if contentEncryptionAlgorithm=DESede/CBC/PKCS5Padding then 192, 128; if strong encryption is enabled then for AES/CBC/PKCS5Padding and Camellia/CBC/PKCS5Padding also the key lengths 192 and 256 are possible. | int | |
unprotectedAttributes GeneratorProvider (encrypt) | Provider of the generator for the unprotected attributes. The default value is null which means no unprotected attribute is added to the Enveloped Data object. See https://tools.ietf.org/html/rfc5652#section-6.1. | AttributesGenerator Provider | |
toBase64 (encrypt_sign) | Indicates whether the Signed Data or Enveloped Data instance shall be base 64 encoded. Default value is false. | false | Boolean |
includeContent (sign) | Indicates whether the signed content should be included into the Signed Data instance. If false then a detached Signed Data instance is created in the header CamelCryptoCmsSignedData. | true | Boolean |
signer (sign) | Signer information: reference to a bean which implements org.apache.camel.component.crypto.cms.api.SignerInfo | List | |
signedDataHeaderBase64 (verify) | Indicates whether the value in the header CamelCryptoCmsSignedData is base64 encoded. Default value is false. Only relevant for detached signatures. In the detached signature case, the header contains the Signed Data object. | false | Boolean |
verifySignaturesOfAll Signers (verify) | If true then the signatures of all signers contained in the Signed Data object are verified. If false then only one signature whose signer info matches with one of the specified certificates is verified. Default value is true. | true | Boolean |
75.2. Spring Boot Auto-Configuration
The component supports 4 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.crypto-cms.enabled | Whether to enable auto configuration of the crypto-cms component. This is enabled by default. | Boolean | |
camel.component.crypto-cms.enveloped-data-decryptor-configuration | To configure the shared EnvelopedDataDecryptorConfiguration, which determines the uri parameters for the decrypt operation. The option is a org.apache.camel.component.crypto.cms.crypt. EnvelopedDataDecryptorConfiguration type. | String | |
camel.component.crypto-cms.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.crypto-cms.signed-data-verifier-configuration | To configure the shared SignedDataVerifierConfiguration, which determines the uri parameters for the verify operation. The option is a org.apache.camel.component.crypto.cms.sig.SignedDataVerifierConfiguration type. | String |
75.3. Enveloped Data
Note, that a crypto-cms:encypt
endpoint is typically defined in one route and the complimentary crypto-cms:decrypt
in another, though for simplicity in the examples they appear one after the other.
The following example shows how you can create an Enveloped Data message and how you can decrypt an Enveloped Data message.
Basic Example in Java DSL
import org.apache.camel.util.jsse.KeyStoreParameters; import org.apache.camel.component.crypto.cms.crypt.DefaultKeyTransRecipientInfo; ... KeyStoreParameters keystore = new KeyStoreParameters(); keystore.setType("JCEKS"); keystore.setResource("keystore/keystore.jceks); keystore.setPassword("some_password"); // this password will also be used for accessing the private key if not specified in the crypto-cms:decrypt endpoint DefaultKeyTransRecipientInfo recipient1 = new DefaultKeyTransRecipientInfo(); recipient1.setCertificateAlias("rsa"); // alias of the public key used for the encryption recipient1.setKeyStoreParameters(keystore); simpleReg.put("keyStoreParameters", keystore); // register keystore in the registry simpleReg.put("recipient1", recipient1); // register recipient info in the registry from("direct:start") .to("crypto-cms:encrypt://testencrpyt?toBase64=true&recipient=#recipient1&contentEncryptionAlgorithm=DESede/CBC/PKCS5Padding&secretKeyLength=128") .to("crypto-cms:decrypt://testdecrypt?fromBase64=true&keyStoreParameters=#keyStoreParameters") .to("mock:result");
Basic Example in Spring XML
<keyStoreParameters xmlns="http://camel.apache.org/schema/spring" id="keyStoreParameters1" resource="./keystore/keystore.jceks" password="some_password" type="JCEKS" /> <bean id="recipient1" class="org.apache.camel.component.crypto.cms.crypt.DefaultKeyTransRecipientInfo"> <property name="keyStoreParameters" ref="keyStoreParameters1" /> <property name="certificateAlias" value="rsa" /> </bean> ... <route> <from uri="direct:start" /> <to uri="crypto-cms:encrypt://testencrpyt?toBase64=true&recipient=#recipient1&contentEncryptionAlgorithm=DESede/CBC/PKCS5Padding&secretKeyLength=128" /> <to uri="crypto-cms:decrypt://testdecrypt?fromBase64=true&keyStoreParameters=#keyStoreParameters1" /> <to uri="mock:result" /> </route>
Two Recipients in Java DSL
import org.apache.camel.util.jsse.KeyStoreParameters; import org.apache.camel.component.crypto.cms.crypt.DefaultKeyTransRecipientInfo; ... KeyStoreParameters keystore = new KeyStoreParameters(); keystore.setType("JCEKS"); keystore.setResource("keystore/keystore.jceks); keystore.setPassword("some_password"); // this password will also be used for accessing the private key if not specified in the crypto-cms:decrypt endpoint DefaultKeyTransRecipientInfo recipient1 = new DefaultKeyTransRecipientInfo(); recipient1.setCertificateAlias("rsa"); // alias of the public key used for the encryption recipient1.setKeyStoreParameters(keystore); DefaultKeyTransRecipientInfo recipient2 = new DefaultKeyTransRecipientInfo(); recipient2.setCertificateAlias("dsa"); recipient2.setKeyStoreParameters(keystore); simpleReg.put("keyStoreParameters", keystore); // register keystore in the registry simpleReg.put("recipient1", recipient1); // register recipient info in the registry from("direct:start") .to("crypto-cms:encrypt://testencrpyt?toBase64=true&recipient=#recipient1&recipient=#recipient2&contentEncryptionAlgorithm=DESede/CBC/PKCS5Padding&secretKeyLength=128") //the decryptor will automatically choose one of the two private keys depending which one is in the decryptor keystore .to("crypto-cms:decrypt://testdecrypt?fromBase64=true&keyStoreParameters=#keyStoreParameters") .to("mock:result");
Two Recipients in Spring XML
<keyStoreParameters xmlns="http://camel.apache.org/schema/spring" id="keyStoreParameters1" resource="./keystore/keystore.jceks" password="some_password" type="JCEKS" /> <bean id="recipient1" class="org.apache.camel.component.crypto.cms.crypt.DefaultKeyTransRecipientInfo"> <property name="keyStoreParameters" ref="keyStoreParameters1" /> <property name="certificateAlias" value="rsa" /> </bean> <bean id="recipient2" class="org.apache.camel.component.crypto.cms.crypt.DefaultKeyTransRecipientInfo"> <property name="keyStoreParameters" ref="keyStoreParameters1" /> <property name="certificateAlias" value="dsa" /> </bean> ... <route> <from uri="direct:start" /> <to uri="crypto-cms:encrypt://testencrpyt?toBase64=true&recipient=#recipient1&recipient=#recipient2&contentEncryptionAlgorithm=DESede/CBC/PKCS5Padding&secretKeyLength=128" /> <!-- the decryptor will automatically choose one of the two private keys depending which one is in the decryptor keystore --> <to uri="crypto-cms:decrypt://testdecrypt?fromBase64=true&keyStoreParameters=#keyStoreParameters1" /> <to uri="mock:result" /> </route>
75.4. Signed Data
Note, that a crypto-cms:sign
endpoint is typically defined in one route and the complimentary crypto-cms:verify
in another, though for simplicity in the examples they appear one after the other.
The following example shows how you can create a Signed Data message and how you can validate a Signed Data message.
Basic Example in Java DSL
import org.apache.camel.util.jsse.KeyStoreParameters; import org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo; ... KeyStoreParameters keystore = new KeyStoreParameters(); keystore.setType("JCEKS"); keystore.setResource("keystore/keystore.jceks); keystore.setPassword("some_password"); // this password will also be used for accessing the private key if not specified in the signerInfo1 bean //Signer Information, by default the following signed attributes are included: contentType, signingTime, messageDigest, and cmsAlgorithmProtect; by default no unsigned attribute is included. // If you want to add your own signed attributes or unsigned attributes, see methods DefaultSignerInfo.setSignedAttributeGenerator and DefaultSignerInfo.setUnsignedAttributeGenerator. DefaultSignerInfo signerInfo1 = new DefaultSignerInfo(); signerInfo1.setIncludeCertificates(true); // if set to true then the certificate chain of the private key will be added to the Signed Data object signerInfo1.setSignatureAlgorithm("SHA256withRSA"); // signature algorithm; attention, the signature algorithm must fit to the signer private key. signerInfo1.setPrivateKeyAlias("rsa"); // alias of the private key used for the signing signerInfo1.setPassword("private_key_pw".toCharArray()); // optional parameter, if not set then the password of the KeyStoreParameters will be used for accessing the private key signerInfo1.setKeyStoreParameters(keystore); simpleReg.put("keyStoreParameters", keystore); //register keystore in the registry simpleReg.put("signer1", signerInfo1); //register signer info in the registry from("direct:start") .to("crypto-cms:sign://testsign?signer=#signer1&includeContent=true&toBase64=true") .to("crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters&fromBase64=true"") .to("mock:result");
Basic Example in Spring XML
<keyStoreParameters xmlns="http://camel.apache.org/schema/spring" id="keyStoreParameters1" resource="./keystore/keystore.jceks" password="some_password" type="JCEKS" /> <bean id="signer1" class="org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo"> <property name="keyStoreParameters" ref="keyStoreParameters1" /> <property name="privateKeyAlias" value="rsa" /> <property name="signatureAlgorithm" value="SHA256withRSA" /> <property name="includeCertificates" value="true" /> <!-- optional parameter 'password', if not set then the password of the KeyStoreParameters will be used for accessing the private key --> <property name="password" value="private_key_pw" /> </bean> ... <route> <from uri="direct:start" /> <to uri="crypto-cms:sign://testsign?signer=#signer1&includeContent=true&toBase64=true" /> <to uri="crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters1&fromBase64=true" /> <to uri="mock:result" /> </route>
Example with two Signers in Java DSL
import org.apache.camel.util.jsse.KeyStoreParameters; import org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo; ... KeyStoreParameters keystore = new KeyStoreParameters(); keystore.setType("JCEKS"); keystore.setResource("keystore/keystore.jceks); keystore.setPassword("some_password"); // this password will also be used for accessing the private key if not specified in the signerInfo1 bean //Signer Information, by default the following signed attributes are included: contentType, signingTime, messageDigest, and cmsAlgorithmProtect; by default no unsigned attribute is included. // If you want to add your own signed attributes or unsigned attributes, see methods DefaultSignerInfo.setSignedAttributeGenerator and DefaultSignerInfo.setUnsignedAttributeGenerator. DefaultSignerInfo signerInfo1 = new DefaultSignerInfo(); signerInfo1.setIncludeCertificates(true); // if set to true then the certificate chain of the private key will be added to the Signed Data object signerInfo1.setSignatureAlgorithm("SHA256withRSA"); // signature algorithm; attention, the signature algorithm must fit to the signer private key. signerInfo1.setPrivateKeyAlias("rsa"); // alias of the private key used for the signing signerInfo1.setPassword("private_key_pw".toCharArray()); // optional parameter, if not set then the password of the KeyStoreParameters will be used for accessing the private key signerInfo1.setKeyStoreParameters(keystore); DefaultSignerInfo signerInfo2 = new DefaultSignerInfo(); signerInfo2.setIncludeCertificates(true); signerInfo2.setSignatureAlgorithm("SHA256withDSA"); signerInfo2.setPrivateKeyAlias("dsa"); signerInfo2.setKeyStoreParameters(keystore); simpleReg.put("keyStoreParameters", keystore); //register keystore in the registry simpleReg.put("signer1", signerInfo1); //register signer info in the registry simpleReg.put("signer2", signerInfo2); //register signer info in the registry from("direct:start") .to("crypto-cms:sign://testsign?signer=#signer1&signer=#signer2&includeContent=true") .to("crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters") .to("mock:result");
Example with two Signers in Spring XML
<keyStoreParameters xmlns="http://camel.apache.org/schema/spring" id="keyStoreParameters1" resource="./keystore/keystore.jceks" password="some_password" type="JCEKS" /> <bean id="signer1" class="org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo"> <property name="keyStoreParameters" ref="keyStoreParameters1" /> <property name="privateKeyAlias" value="rsa" /> <property name="signatureAlgorithm" value="SHA256withRSA" /> <property name="includeCertificates" value="true" /> <!-- optional parameter 'password', if not set then the password of the KeyStoreParameters will be used for accessing the private key --> <property name="password" value="private_key_pw" /> </bean> <bean id="signer2" class="org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo"> <property name="keyStoreParameters" ref="keyStoreParameters1" /> <property name="privateKeyAlias" value="dsa" /> <property name="signatureAlgorithm" value="SHA256withDSA" /> <!-- optional parameter 'password', if not set then the password of the KeyStoreParameters will be used for accessing the private key --> <property name="password" value="private_key_pw2" /> </bean> ... <route> <from uri="direct:start" /> <to uri="crypto-cms:sign://testsign?signer=#signer1&signer=#signer2&includeContent=true" /> <to uri="crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters1" /> <to uri="mock:result" /> </route>
Detached Signature Example in Java DSL
import org.apache.camel.util.jsse.KeyStoreParameters; import org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo; ... KeyStoreParameters keystore = new KeyStoreParameters(); keystore.setType("JCEKS"); keystore.setResource("keystore/keystore.jceks); keystore.setPassword("some_password"); // this password will also be used for accessing the private key if not specified in the signerInfo1 bean //Signer Information, by default the following signed attributes are included: contentType, signingTime, messageDigest, and cmsAlgorithmProtect; by default no unsigned attribute is included. // If you want to add your own signed attributes or unsigned attributes, see methods DefaultSignerInfo.setSignedAttributeGenerator and DefaultSignerInfo.setUnsignedAttributeGenerator. DefaultSignerInfo signerInfo1 = new DefaultSignerInfo(); signerInfo1.setIncludeCertificates(true); // if set to true then the certificate chain of the private key will be added to the Signed Data object signerInfo1.setSignatureAlgorithm("SHA256withRSA"); // signature algorithm; attention, the signature algorithm must fit to the signer private key. signerInfo1.setPrivateKeyAlias("rsa"); // alias of the private key used for the signing signerInfo1.setPassword("private_key_pw".toCharArray()); // optional parameter, if not set then the password of the KeyStoreParameters will be used for accessing the private key signerInfo1.setKeyStoreParameters(keystore); simpleReg.put("keyStoreParameters", keystore); //register keystore in the registry simpleReg.put("signer1", signerInfo1); //register signer info in the registry from("direct:start") //with the option includeContent=false the SignedData object without the signed text will be written into the header "CamelCryptoCmsSignedData" .to("crypto-cms:sign://testsign?signer=#signer1&includeContent=false&toBase64=true") //the verifier reads the Signed Data object form the header CamelCryptoCmsSignedData and assumes that the signed content is in the message body .to("crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters&signedDataHeaderBase64=true") .to("mock:result");
Detached Signature Example in Spring XML
<keyStoreParameters xmlns="http://camel.apache.org/schema/spring" id="keyStoreParameters1" resource="./keystore/keystore.jceks" password="some_password" type="JCEKS" /> <bean id="signer1" class="org.apache.camel.component.crypto.cms.sig.DefaultSignerInfo"> <property name="keyStoreParameters" ref="keyStoreParameters1" /> <property name="privateKeyAlias" value="rsa" /> <property name="signatureAlgorithm" value="SHA256withRSA" /> <property name="includeCertificates" value="true" /> <!-- optional parameter 'password', if not set then the password of the KeyStoreParameters will be used for accessing the private key --> <property name="password" value="private_key_pw" /> </bean> ... <route> <from uri="direct:start" /> <!-- with the option includeContent=false the SignedData object without the signed text will be written into the header "CamelCryptoCmsSignedData" --> <to uri="crypto-cms:sign://testsign?signer=#signer1&includeContent=false&toBase64=true" /> <!-- the verifier reads the Signed Data object form the header CamelCryptoCmsSignedData and assumes that the signed content is in the message body --> <to uri="crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters1&signedDataHeaderBase64=true" /> <to uri="mock:result" /> </route>
Chapter 76. Crypto (Java Cryptographic Extension) DataFormat
Available as of Camel version 2.3
The Crypto Data Format integrates the Java Cryptographic Extension into Camel, allowing simple and flexible encryption and decryption of messages using Camel’s familiar marshall and unmarshal formatting mechanism. It assumes marshalling to mean encryption to cyphertext and unmarshalling to mean decryption back to the original plaintext. This data format implements only symmetric (shared-key) encryption and decyption.
76.1. CryptoDataFormat Options
The Crypto (Java Cryptographic Extension) dataformat supports 10 options, which are listed below.
Name | Default | Java Type | Description |
---|---|---|---|
algorithm |
|
| The JCE algorithm name indicating the cryptographic algorithm that will be used. Is by default DES/CBC/PKCS5Padding. |
cryptoProvider |
| The name of the JCE Security Provider that should be used. | |
keyRef |
| Refers to the secret key to lookup from the register to use. | |
initVectorRef |
| Refers to a byte array containing the Initialization Vector that will be used to initialize the Cipher. | |
algorithmParameterRef |
| A JCE AlgorithmParameterSpec used to initialize the Cipher. Will lookup the type using the given name as a java.security.spec.AlgorithmParameterSpec type. | |
buffersize |
| The size of the buffer used in the signature process. | |
macAlgorithm |
|
| The JCE algorithm name indicating the Message Authentication algorithm. |
shouldAppendHMAC |
|
| Flag indicating that a Message Authentication Code should be calculated and appended to the encrypted data. |
inline |
|
| Flag indicating that the configured IV should be inlined into the encrypted data stream. Is by default false. |
contentTypeHeader |
|
| Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. |
76.2. Spring Boot Auto-Configuration
The component supports 33 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.crypto.configuration.algorithm | Sets the JCE name of the Algorithm that should be used for the signer. | SHA1WithDSA | String |
camel.component.crypto.configuration.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.configuration.buffer-size | Set the size of the buffer used to read in the Exchange payload data. | 2048 | Integer |
camel.component.crypto.configuration.certificate | Set the Certificate that should be used to verify the signature in the exchange based on its payload. | Certificate | |
camel.component.crypto.configuration.certificate-name | Sets the reference name for a PrivateKey that can be fond in the registry. | String | |
camel.component.crypto.configuration.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.crypto-operation | Set the Crypto operation from that supplied after the crypto scheme in the endpoint uri e.g. crypto:sign sets sign as the operation. | CryptoOperation | |
camel.component.crypto.configuration.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. | KeyStoreParameters | |
camel.component.crypto.configuration.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. | KeyStore | |
camel.component.crypto.configuration.keystore-name | Sets the reference name for a Keystore that can be fond in the registry. | String | |
camel.component.crypto.configuration.name | The logical name of this operation. | String | |
camel.component.crypto.configuration.password | Sets the password used to access an aliased PrivateKey in the KeyStore. | Character[] | |
camel.component.crypto.configuration.private-key | Set the PrivateKey that should be used to sign the exchange | PrivateKey | |
camel.component.crypto.configuration.private-key-name | Sets the reference name for a PrivateKey that can be fond in the registry. | String | |
camel.component.crypto.configuration.provider | Set the id of the security provider that provides the configured Signature algorithm. | String | |
camel.component.crypto.configuration.public-key | Set the PublicKey that should be used to verify the signature in the exchange. | PublicKey | |
camel.component.crypto.configuration.public-key-name | references that should be resolved when the context changes | String | |
camel.component.crypto.configuration.secure-random | Set the SecureRandom used to initialize the Signature service | SecureRandom | |
camel.component.crypto.configuration.secure-random-name | Sets the reference name for a SecureRandom that can be fond in the registry. | String | |
camel.component.crypto.configuration.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.component.crypto.enabled | Enable crypto component | true | Boolean |
camel.component.crypto.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.dataformat.crypto.algorithm | The JCE algorithm name indicating the cryptographic algorithm that will be used. Is by default DES/CBC/PKCS5Padding. | DES/CBC/PKCS5Padding | 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.buffersize | The size of the buffer used in the signature process. | Integer | |
camel.dataformat.crypto.content-type-header | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. | false | Boolean |
camel.dataformat.crypto.crypto-provider | The name of the JCE Security Provider that should be used. | String | |
camel.dataformat.crypto.enabled | Enable crypto dataformat | true | 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. | false | Boolean |
ND
76.3. Basic Usage
At its most basic all that is required to encrypt/decrypt an exchange is a shared secret key. If one or more instances of the Crypto data format are configured with this key the format can be used to encrypt the payload in one route (or part of one) and decrypted in another. For example, using the Java DSL as follows:
KeyGenerator generator = KeyGenerator.getInstance("DES"); CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", generator.generateKey()); from("direct:basic-encryption") .marshal(cryptoFormat) .to("mock:encrypted") .unmarshal(cryptoFormat) .to("mock:unencrypted");
In Spring the dataformat is configured first and then used in routes
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <dataFormats> <crypto id="basic" algorithm="DES" keyRef="desKey" /> </dataFormats> ... <route> <from uri="direct:basic-encryption" /> <marshal ref="basic" /> <to uri="mock:encrypted" /> <unmarshal ref="basic" /> <to uri="mock:unencrypted" /> </route> </camelContext>
76.4. Specifying the Encryption Algorithm
Changing the algorithm is a matter of supplying the JCE algorithm name. If you change the algorithm you will need to use a compatible key.
KeyGenerator generator = KeyGenerator.getInstance("DES"); CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", generator.generateKey()); cryptoFormat.setShouldAppendHMAC(true); cryptoFormat.setMacAlgorithm("HmacMD5"); from("direct:hmac-algorithm") .marshal(cryptoFormat) .to("mock:encrypted") .unmarshal(cryptoFormat) .to("mock:unencrypted");
A list of the available algorithms in Java 7 is available via the Java Cryptography Architecture Standard Algorithm Name Documentation.
76.5. Specifying an Initialization Vector
Some crypto algorithms, particularly block algorithms, require configuration with an initial block of data known as an Initialization Vector. In the JCE this is passed as an AlgorithmParameterSpec when the Cipher is initialized. To use such a vector with the CryptoDataFormat you can configure it with a byte[] containing the required data e.g.
KeyGenerator generator = KeyGenerator.getInstance("DES"); byte[] initializationVector = new byte[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES/CBC/PKCS5Padding", generator.generateKey()); cryptoFormat.setInitializationVector(initializationVector); from("direct:init-vector") .marshal(cryptoFormat) .to("mock:encrypted") .unmarshal(cryptoFormat) .to("mock:unencrypted");
or with spring, suppling a reference to a byte[]
<crypto id="initvector" algorithm="DES/CBC/PKCS5Padding" keyRef="desKey" initVectorRef="initializationVector" />
The same vector is required in both the encryption and decryption phases. As it is not necessary to keep the IV a secret, the DataFormat allows for it to be inlined into the encrypted data and subsequently read out in the decryption phase to initialize the Cipher. To inline the IV set the /oinline flag.
KeyGenerator generator = KeyGenerator.getInstance("DES"); byte[] initializationVector = new byte[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; SecretKey key = generator.generateKey(); CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES/CBC/PKCS5Padding", key); cryptoFormat.setInitializationVector(initializationVector); cryptoFormat.setShouldInlineInitializationVector(true); CryptoDataFormat decryptFormat = new CryptoDataFormat("DES/CBC/PKCS5Padding", key); decryptFormat.setShouldInlineInitializationVector(true); from("direct:inline") .marshal(cryptoFormat) .to("mock:encrypted") .unmarshal(decryptFormat) .to("mock:unencrypted");
or with spring.
<crypto id="inline" algorithm="DES/CBC/PKCS5Padding" keyRef="desKey" initVectorRef="initializationVector" inline="true" /> <crypto id="inline-decrypt" algorithm="DES/CBC/PKCS5Padding" keyRef="desKey" inline="true" />
For more information of the use of Initialization Vectors, consult
76.6. Hashed Message Authentication Codes (HMAC)
To avoid attacks against the encrypted data while it is in transit the CryptoDataFormat can also calculate a Message Authentication Code for the encrypted exchange contents based on a configurable MAC algorithm. The calculated HMAC is appended to the stream after encryption. It is separated from the stream in the decryption phase. The MAC is recalculated and verified against the transmitted version to insure nothing was tampered with in transit.For more information on Message Authentication Codes see http://en.wikipedia.org/wiki/HMAC
KeyGenerator generator = KeyGenerator.getInstance("DES"); CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", generator.generateKey()); cryptoFormat.setShouldAppendHMAC(true); from("direct:hmac") .marshal(cryptoFormat) .to("mock:encrypted") .unmarshal(cryptoFormat) .to("mock:unencrypted");
or with spring.
<crypto id="hmac" algorithm="DES" keyRef="desKey" shouldAppendHMAC="true" />
By default the HMAC is calculated using the HmacSHA1 mac algorithm though this can be easily changed by supplying a different algorithm name. See here for how to check what algorithms are available through the configured security providers
KeyGenerator generator = KeyGenerator.getInstance("DES"); CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", generator.generateKey()); cryptoFormat.setShouldAppendHMAC(true); cryptoFormat.setMacAlgorithm("HmacMD5"); from("direct:hmac-algorithm") .marshal(cryptoFormat) .to("mock:encrypted") .unmarshal(cryptoFormat) .to("mock:unencrypted");
or with spring.
<crypto id="hmac-algorithm" algorithm="DES" keyRef="desKey" macAlgorithm="HmacMD5" shouldAppendHMAC="true" />
76.7. 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 neither be feasible or desirable. It would be useful to be able to specify keys dynamically on a per exchange basis. The exchange could then be dynamically enriched with the key of its target recipient before being processed by the data format. To facilitate this the DataFormat allow for keys to be supplied dynamically via the message headers below
- CryptoDataFormat.KEY "CamelCryptoKey"
CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", null); /** * Note: the header containing the key should be cleared after * marshalling to stop it from leaking by accident and * potentially being compromised. The processor version below is * arguably better as the key is left in the header when you use * the DSL leaks the fact that camel encryption was used. */ from("direct:key-in-header-encrypt") .marshal(cryptoFormat) .removeHeader(CryptoDataFormat.KEY) .to("mock:encrypted"); from("direct:key-in-header-decrypt").unmarshal(cryptoFormat).process(new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().getHeaders().remove(CryptoDataFormat.KEY); exchange.getOut().copyFrom(exchange.getIn()); } }).to("mock:unencrypted");
or with spring.
<crypto id="nokey" algorithm="DES" />
76.8. Dependencies
To use the Crypto dataformat in your camel routes you need to add the following dependency to your pom.
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-crypto</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
76.9. See Also
- Data Format
- Crypto (Digital Signatures)
- http://www.bouncycastle.org/java.html
Chapter 77. CSV DataFormat
Available as of Camel version 1.3
The CSV Data Format uses Apache Commons CSV to handle CSV payloads (Comma Separated Values) such as those exported/imported by Excel.
77.1. Options
The CSV dataformat supports 28 options, which are listed below.
Name | Default | Java Type | Description |
---|---|---|---|
formatRef |
| The reference format to use, it will be updated with the other format options, the default value is CSVFormat.DEFAULT | |
formatName |
| The name of the format to use, the default value is CSVFormat.DEFAULT | |
commentMarkerDisabled |
|
| Disables the comment marker of the reference format. |
commentMarker |
| Sets the comment marker of the reference format. | |
delimiter |
| Sets the delimiter to use. The default value is , (comma) | |
escapeDisabled |
|
| Use for disabling using escape character |
escape |
| Sets the escape character to use | |
headerDisabled |
|
| Use for disabling headers |
header |
| To configure the CSV headers | |
allowMissingColumnNames |
|
| Whether to allow missing column names. |
ignoreEmptyLines |
|
| Whether to ignore empty lines. |
ignoreSurroundingSpaces |
|
| Whether to ignore surrounding spaces |
nullStringDisabled |
|
| Used to disable null strings |
nullString |
| Sets the null string | |
quoteDisabled |
|
| Used to disable quotes |
quote |
| Sets the quote which by default is | |
recordSeparatorDisabled |
| Used for disabling record separator | |
recordSeparator |
| Sets the record separator (aka new line) which by default is new line characters (CRLF) | |
skipHeaderRecord |
|
| Whether to skip the header record in the output |
quoteMode |
| Sets the quote mode | |
ignoreHeaderCase |
|
| Sets whether or not to ignore case when accessing header names. |
trim |
|
| Sets whether or not to trim leading and trailing blanks. |
trailingDelimiter |
|
| Sets whether or not to add a trailing delimiter. |
lazyLoad |
|
| Whether the unmarshalling should produce an iterator that reads the lines on the fly or if all the lines must be read at one. |
useMaps |
|
| Whether the unmarshalling should produce maps (HashMap)for the lines values instead of lists. It requires to have header (either defined or collected). |
useOrderedMaps |
|
| Whether the unmarshalling should produce ordered maps (LinkedHashMap) for the lines values instead of lists. It requires to have header (either defined or collected). |
recordConverterRef |
| Refers to a custom CsvRecordConverter to lookup from the registry to use. | |
contentTypeHeader |
|
| Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. |
77.2. Spring Boot Auto-Configuration
The component supports 29 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.dataformat.csv.allow-missing-column-names | Whether to allow missing column names. | false | Boolean |
camel.dataformat.csv.comment-marker | Sets the comment marker of the reference format. | String | |
camel.dataformat.csv.comment-marker-disabled | Disables the comment marker of the reference format. | false | Boolean |
camel.dataformat.csv.content-type-header | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. | false | Boolean |
camel.dataformat.csv.delimiter | Sets the delimiter to use. The default value is , (comma) | String | |
camel.dataformat.csv.enabled | Enable csv dataformat | true | Boolean |
camel.dataformat.csv.escape | Sets the escape character to use | String | |
camel.dataformat.csv.escape-disabled | Use for disabling using escape character | false | Boolean |
camel.dataformat.csv.format-name | The name of the format to use, the default value is CSVFormat.DEFAULT | String | |
camel.dataformat.csv.format-ref | The reference format to use, it will be updated with the other format options, the default value is CSVFormat.DEFAULT | String | |
camel.dataformat.csv.header | To configure the CSV headers | List | |
camel.dataformat.csv.header-disabled | Use for disabling headers | false | Boolean |
camel.dataformat.csv.ignore-empty-lines | Whether to ignore empty lines. | false | Boolean |
camel.dataformat.csv.ignore-header-case | Sets whether or not to ignore case when accessing header names. | false | Boolean |
camel.dataformat.csv.ignore-surrounding-spaces | Whether to ignore surrounding spaces | false | Boolean |
camel.dataformat.csv.lazy-load | Whether the unmarshalling should produce an iterator that reads the lines on the fly or if all the lines must be read at one. | false | Boolean |
camel.dataformat.csv.null-string | Sets the null string | String | |
camel.dataformat.csv.null-string-disabled | Used to disable null strings | false | Boolean |
camel.dataformat.csv.quote | Sets the quote which by default is | String | |
camel.dataformat.csv.quote-disabled | Used to disable quotes | false | Boolean |
camel.dataformat.csv.quote-mode | Sets the quote mode | String | |
camel.dataformat.csv.record-converter-ref | Refers to a custom CsvRecordConverter to lookup from the registry to use. | String | |
camel.dataformat.csv.record-separator | Sets the record separator (aka new line) which by default is new line characters (CRLF) | String | |
camel.dataformat.csv.record-separator-disabled | Used for disabling record separator | String | |
camel.dataformat.csv.skip-header-record | Whether to skip the header record in the output | false | Boolean |
camel.dataformat.csv.trailing-delimiter | Sets whether or not to add a trailing delimiter. | false | Boolean |
camel.dataformat.csv.trim | Sets whether or not to trim leading and trailing blanks. | false | Boolean |
camel.dataformat.csv.use-maps | Whether the unmarshalling should produce maps (HashMap)for the lines values instead of lists. It requires to have header (either defined or collected). | false | Boolean |
camel.dataformat.csv.use-ordered-maps | Whether the unmarshalling should produce ordered maps (LinkedHashMap) for the lines values instead of lists. It requires to have header (either defined or collected). | false | Boolean |
ND
77.3. Marshalling a Map to CSV
The component allows you to marshal a Java Map (or any other message type that can be converted in a Map) into a CSV payload.
Considering the following body
Map<String, Object> body = new LinkedHashMap<>(); body.put("foo", "abc"); body.put("bar", 123);
and this Java route definition
from("direct:start") .marshal().csv() .to("mock:result");
or this XML route definition
<route> <from uri="direct:start" /> <marshal> <csv /> </marshal> <to uri="mock:result" /> </route>
then it will produce
abc,123
77.4. Unmarshalling a CSV message into a Java List
Unmarshalling will transform a CSV messsage into a Java List with CSV file lines (containing another List with all the field values).
An example: we have a CSV file with names of persons, their IQ and their current activity.
Jack Dalton, 115, mad at Averell Joe Dalton, 105, calming Joe William Dalton, 105, keeping Joe from killing Averell Averell Dalton, 80, playing with Rantanplan Lucky Luke, 120, capturing the Daltons
We can now use the CSV component to unmarshal this file:
from("file:src/test/resources/?fileName=daltons.csv&noop=true") .unmarshal().csv() .to("mock:daltons");
The resulting message will contain a List<List<String>>
like…
List<List<String>> data = (List<List<String>>) exchange.getIn().getBody(); for (List<String> line : data) { LOG.debug(String.format("%s has an IQ of %s and is currently %s", line.get(0), line.get(1), line.get(2))); }
77.5. Marshalling a List<Map> to CSV
Available as of Camel 2.1
If you have multiple rows of data you want to be marshalled into CSV format you can now store the message payload as a List<Map<String, Object>>
object where the list contains a Map for each row.
77.6. File Poller of CSV, then unmarshaling
Given a bean which can handle the incoming data…
MyCsvHandler.java
// Some comments here public void doHandleCsvData(List<List<String>> csvData) { // do magic here }
- your route then looks as follows
<route> <!-- poll every 10 seconds --> <from uri="file:///some/path/to/pickup/csvfiles?delete=true&consumer.delay=10000" /> <unmarshal><csv /></unmarshal> <to uri="bean:myCsvHandler?method=doHandleCsvData" /> </route>
77.7. Marshaling with a pipe as delimiter
Considering the following body
Map<String, Object> body = new LinkedHashMap<>(); body.put("foo", "abc"); body.put("bar", 123);
and this Java route definition
// Camel version < 2.15 CsvDataFormat oldCSV = new CsvDataFormat(); oldCSV.setDelimiter("|"); from("direct:start") .marshal(oldCSV) .to("mock:result") // Camel version >= 2.15 from("direct:start") .marshal(new CsvDataFormat().setDelimiter('|')) .to("mock:result")
or this XML route definition
<route> <from uri="direct:start" /> <marshal> <csv delimiter="|" /> </marshal> <to uri="mock:result" /> </route>
then it will produce
abc|123
Using autogenColumns, configRef and strategyRef attributes inside XML # DSL
Available as of Camel 2.9.2 / 2.10 and deleted for Camel 2.15
You can customize the CSV Data Format to make use of your own CSVConfig
and/or CSVStrategy
. Also note that the default value of the autogenColumns
option is true. The following example should illustrate this customization.
<route> <from uri="direct:start" /> <marshal> <!-- make use of a strategy other than the default one which is 'org.apache.commons.csv.CSVStrategy.DEFAULT_STRATEGY' --> <csv autogenColumns="false" delimiter="|" configRef="csvConfig" strategyRef="excelStrategy" /> </marshal> <convertBodyTo type="java.lang.String" /> <to uri="mock:result" /> </route> <bean id="csvConfig" class="org.apache.commons.csv.writer.CSVConfig"> <property name="fields"> <list> <bean class="org.apache.commons.csv.writer.CSVField"> <property name="name" value="orderId" /> </bean> <bean class="org.apache.commons.csv.writer.CSVField"> <property name="name" value="amount" /> </bean> </list> </property> </bean> <bean id="excelStrategy" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean"> <property name="staticField" value="org.apache.commons.csv.CSVStrategy.EXCEL_STRATEGY" /> </bean>
77.8. Using skipFirstLine option while unmarshaling
Available as of Camel 2.10 and deleted for Camel 2.15
You can instruct the CSV Data Format to skip the first line which contains the CSV headers. Using the Spring/XML DSL:
<route> <from uri="direct:start" /> <unmarshal> <csv skipFirstLine="true" /> </unmarshal> <to uri="bean:myCsvHandler?method=doHandleCsv" /> </route>
Or the Java DSL:
CsvDataFormat csv = new CsvDataFormat(); csv.setSkipFirstLine(true); from("direct:start") .unmarshal(csv) .to("bean:myCsvHandler?method=doHandleCsv");
77.9. Unmarshaling with a pipe as delimiter
Using the Spring/XML DSL:
<route> <from uri="direct:start" /> <unmarshal> <csv delimiter="|" /> </unmarshal> <to uri="bean:myCsvHandler?method=doHandleCsv" /> </route>
Or the Java DSL:
CsvDataFormat csv = new CsvDataFormat(); CSVStrategy strategy = CSVStrategy.DEFAULT_STRATEGY; strategy.setDelimiter('|'); csv.setStrategy(strategy); from("direct:start") .unmarshal(csv) .to("bean:myCsvHandler?method=doHandleCsv");
CsvDataFormat csv = new CsvDataFormat(); csv.setDelimiter("|"); from("direct:start") .unmarshal(csv) .to("bean:myCsvHandler?method=doHandleCsv");
CsvDataFormat csv = new CsvDataFormat(); CSVConfig csvConfig = new CSVConfig(); csvConfig.setDelimiter(";"); csv.setConfig(csvConfig); from("direct:start") .unmarshal(csv) .to("bean:myCsvHandler?method=doHandleCsv");
Issue in CSVConfig
It looks like that
CSVConfig csvConfig = new CSVConfig(); csvConfig.setDelimiter(';');
doesn’t work. You have to set the delimiter as a String!
77.10. Dependencies
To use CSV in your Camel routes you need to add a dependency on camel-csv, which implements this data format.
If you use Maven you can just add the following to your pom.xml, substituting the version number for the latest and greatest release (see the download page for the latest versions).
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-csv</artifactId> <version>x.x.x</version> </dependency>
Chapter 78. CXF
CXF Component
The cxf: component provides integration with Apache CXF for connecting to JAX-WS services hosted in CXF.
Maven users must add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-cxf</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
If you want to learn about CXF dependencies, see the WHICH-JARS
text file.
When using CXF in streaming modes (see DataFormat option), then also read about Stream caching.
Camel on EAP deployment
This component is supported by the Camel on EAP (Wildfly Camel) framework, which offers a simplified deployment model on the Red Hat JBoss Enterprise Application Platform (JBoss EAP) container.
The CXF component integrates with the JBoss EAP webservices
susbsystem that also uses Apache CXF. For more information, see JAX-WS.
At present, the Camel on EAP subsystem does not support CXF or Restlet consumers. However, it is possible to mimic CXF consumer behaviour, using the CamelProxy
.
URI format
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
Options
Name | Required | Description |
| No | The location of the WSDL. WSDL is obtained from endpoint address by default. For example:
|
| Yes | The name of the SEI (Service Endpoint Interface) class. This class can have, but does not require, JSR181 annotations. Since 2.0, this option is only required by POJO mode. If the wsdlURL option is provided, serviceClass is not required for PAYLOAD and MESSAGE mode. When wsdlURL option is used without serviceClass, the serviceName and portName (endpointName for Spring configuration) options MUST be provided.
Since 2.0, it is possible to use
Please be advised that the referenced object cannot be a Proxy (Spring AOP Proxy is OK) as it relies on Since 2.8, it is possible to omit both wsdlURL and serviceClass options for PAYLOAD and MESSAGE mode. When they are omitted, arbitrary XML elements can be put in CxfPayload’s body in PAYLOAD mode to facilitate CXF Dispatch Mode.
For example: |
|
Only if more than one |
The service name this service is implementing, it maps to the
|
|
Only if more than one |
The port name this service is implementing, it maps to the
|
| No |
Which message data format the CXF endpoint supports. Possible values are: |
| No |
Defines if a CXF endpoint relays headers along the route. See the section called “Description of relayHeaders option”. Currently only available when |
| No |
Which kind of operation the CXF endpoint producer invokes. Possible values are: |
| No |
Since 2.5.0 The WSDL style that describes how parameters are represented in the SOAP body. If the value is |
| No |
Deprecated: Specifies whether or not to use the default CXF bus for this endpoint. Possible values are: |
| No |
Deprecated: Specifies whether or not to use the default CXF bus for this endpoint. Possible values are: |
| No |
Use By default, uses the default bus created by CXF Bus Factory. |
| No |
Use |
| No |
Use |
| No |
New in 2.3, this option enables CXF Logging Feature which writes inbound and outbound SOAP messages to log. Possible values are: |
| No |
New in 2.4, this option sets the default
|
| No | New in 2.4, this option sets the default operationNamespace that is used by the CxfProducer which invokes the remote service. For example:
|
| No |
New in 2.5, this option lets CXF endpoint decide to use sync or async API to do the underlying work. The default value is |
| No |
New in 2.5, this option overrides the endpoint URL that appears in the published WSDL that is accessed using the service address URL plus
|
| No |
Camel 2.8: Allows you to set custom CXF properties in the endpoint URI. For example, setting |
| No |
New in 2.8.2. This option controls whether the CXF component, when running in PAYLOAD mode (see below), DOM parses the incoming messages into DOM Elements or keep the payload as a |
| No | New in 2.11. This option controls whether the PhaseInterceptorChain skips logging the Fault that it catches. |
| No |
New in Camel 2.11. This option could apply the implementation of |
| No | New in Camel 2.12.3 This option is used to set the basic authentication information of username for the CXF client. |
| No | New in Camel 2.12.3 This option is used to set the basic authentication information of password for the CXF client. |
| No | New in Camel 2.14.0 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. (Before Camel 2.14.0, CxfConsumer just set the continuation timeout to be 0, which means the continuation suspend operation never timeout.) Default: 30000 Example: continuation=80000 |
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.
The descriptions of the dataformats
DataFormat | Description |
| 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. |
|
|
|
|
|
New in Camel 2.8.2, |
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.CxfConstants.DATA_FORMAT_PROPERTY
.
Configuring the CXF Endpoints with Apache Aries Blueprint.
Since Camel 2.8, there is support for using Aries blueprint dependency injection for your CXF endpoints. The schema is very similar to the Spring schema, so the transition is fairly transparent.
For example:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0" xmlns:camel-cxf="http://camel.apache.org/schema/blueprint/cxf" xmlns:cxfcore="http://cxf.apache.org/blueprint/core" xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> <camel-cxf:cxfEndpoint id="routerEndpoint" address="http://localhost:9001/router" serviceClass="org.apache.servicemix.examples.cxf.HelloWorld"> <camel-cxf:properties> <entry key="dataFormat" value="MESSAGE"/> </camel-cxf:properties> </camel-cxf:cxfEndpoint> <camel-cxf:cxfEndpoint id="serviceEndpoint" address="http://localhost:9000/SoapContext/SoapPort" serviceClass="org.apache.servicemix.examples.cxf.HelloWorld"> </camel-cxf:cxfEndpoint> <camelContext xmlns="http://camel.apache.org/schema/blueprint"> <route> <from uri="routerEndpoint"/> <to uri="log:request"/> </route> </camelContext> </blueprint>
Currently the endpoint element is the first supported CXF namespacehandler.
You can also use the bean references just as in spring
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0" xmlns:jaxws="http://cxf.apache.org/blueprint/jaxws" xmlns:cxf="http://cxf.apache.org/blueprint/core" xmlns:camel="http://camel.apache.org/schema/blueprint" xmlns:camelcxf="http://camel.apache.org/schema/blueprint/cxf" xsi:schemaLocation=" http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd http://cxf.apache.org/blueprint/jaxws http://cxf.apache.org/schemas/blueprint/jaxws.xsd http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd "> <camelcxf:cxfEndpoint id="reportIncident" address="/camel-example-cxf-blueprint/webservices/incident" wsdlURL="META-INF/wsdl/report_incident.wsdl" serviceClass="org.apache.camel.example.reportincident.ReportIncidentEndpoint"> </camelcxf:cxfEndpoint> <bean id="reportIncidentRoutes" class="org.apache.camel.example.reportincident.ReportIncidentRoutes" /> <camelContext xmlns="http://camel.apache.org/schema/blueprint"> <routeBuilder ref="reportIncidentRoutes"/> </camelContext> </blueprint>
How to enable CXF’s LoggingOutInterceptor in MESSAGE 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 MESSAGE
mode), you have to configure LoggingOutInterceptor
to be run during the WRITE
phase. The following is an example.
<bean id="loggingOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor"> <!-- it really should have been user-prestream but CXF does have such phase! --> <constructor-arg value="target/write"/> </bean> <cxf:cxfEndpoint id="serviceEndpoint" address="http://localhost:9002/helloworld" serviceClass="org.apache.camel.component.cxf.HelloService"> <cxf:outInterceptors> <ref bean="loggingOutInterceptor"/> </cxf:outInterceptors> <cxf:properties> <entry key="dataFormat" value="MESSAGE"/> </cxf:properties> </cxf:cxfEndpoint>
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 set relayHeaders
to true
, which is the default value.
Available only in POJO mode
The relayHeaders=true
setting 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
is 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 namespaces. Currently only out-of-band headers are filtered, and in-band headers are always relayed when relayHeaders=true
. If there is a header on the wire, whose namespace is unknown to the runtime, then a fall back DefaultMessageHeadersRelay
is used, which simply allows all headers to be relayed.
The relayHeaders=false
setting asserts that all headers, in-band and out-of-band, is dropped.
You can plugin your own MessageHeadersRelay
implementations overriding or adding additional ones to the list of relays. To override a preloaded relay instance just make sure that your MessageHeadersRelay
implementation services the same namespaces as the one you looking to override. Also note, that the overriding relay has to service all of the namespaces as the one you looking to override, or else a runtime exception on route start up is thrown as this would introduce an ambiguity in namespaces 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:
Changes since Release 2.0
-
POJO
andPAYLOAD
modes are supported. InPOJO
mode, only out-of-band message headers are available for filtering as the in-band headers have been processed and removed from the header list by CXF. The in-band headers are incorporated into theMessageContentList
inPOJO
mode. Thecamel-cxf
component does make any attempt to remove the in-band headers from theMessageContentList
If filtering of in-band headers is required, please usePAYLOAD
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
. TherelayHeaders
option, its semantics, and default value remain the same, but it is a property ofCxfHeaderFilterStrategy
. Here is an example of configuring it.<bean id="dropAllMessageHeadersStrategy" class="org.apache.camel.component.cxf.common.header.CxfHeaderFilterStrategy"> <!-- Set relayHeaders to false to drop all SOAP headers --> <property name="relayHeaders" value="false"/> </bean>
Then, your endpoint can reference the
CxfHeaderFilterStrategy
.<route> <from uri="cxf:bean:routerNoRelayEndpoint?headerFilterStrategy=#dropAllMessageHeadersStrategy"/> <to uri="cxf:bean:serviceNoRelayEndpoint?headerFilterStrategy=#dropAllMessageHeadersStrategy"/> </route>
The
MessageHeadersRelay
interface has changed slightly and has been renamed toMessageHeaderFilter
. It is a property ofCxfHeaderFilterStrategy
. Here is an example of configuring user defined Message Header Filters:<bean id="customMessageFilterStrategy" class="org.apache.camel.component.cxf.common.header.CxfHeaderFilterStrategy"> <property name="messageHeaderFilters"> <list> <!-- SoapMessageHeaderFilter is the built in filter. It can be removed by omitting it. --> <bean class="org.apache.camel.component.cxf.common.header.SoapMessageHeaderFilter"/> <!-- Add custom filter here --> <bean class="org.apache.camel.component.cxf.soap.headers.CustomHeaderFilter"/> </list> </property> </bean>
-
Other than
relayHeaders
, there are new properties that can be configured inCxfHeaderFilterStrategy
.
Name | Description | type | Required? | Default value |
| All message headers is processed by Message Header Filters |
| No |
|
| All message headers is propagated (without processing by Message Header Filters) |
| No |
|
|
Handling of overlapping filters in activation namespace. If the value is |
| No |
|
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.
NOTE In Camel 2.x we change to use http://camel.apache.org/schema/cxf
as the CXF endpoint’s target namespace.
<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" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd "> ...
In Apache Camel 2.x, the http://activemq.apache.org/camel/schema/cxfEndpoint
namespace was changed to http://camel.apache.org/schema/cxf
.
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 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:
Name | Value |
|
The endpoint name this service is implementing, it maps to the |
|
The service name this service is implementing, it maps to the |
| The location of the WSDL. Can be on the classpath, file system, or be hosted remotely. |
|
The |
| The service publish address. |
| The bus name that is used in the JAX-WS endpoint. |
| The class name of the SEI (Service Endpoint Interface) class which could have JSR181 annotation or not. |
It also supports many child elements:
Name | Value |
|
The incoming interceptors for this endpoint. A list of |
|
The incoming fault interceptors for this endpoint. A list of |
|
The outgoing interceptors for this endpoint. A list of |
|
The outgoing fault interceptors for this endpoint. A list of |
| A properties map to supply to the JAX-WS endpoint. |
| A JAX-WS handler list which to provide to the JAX-WS endpoint. |
|
You can specify the which |
|
You can specify the |
|
The features that hold the interceptors for this endpoint. A list of |
|
The schema locations for endpoint to use. A list of |
|
The service factory for this endpoint to use. This can be supplied using the Spring |
You can find more advanced examples which show how to provide interceptors, properties and handlers here: http://cwiki.apache.org/CXF20DOC/jax-ws-configuration.html
You can use CXF:properties to set the CXF endpoint’s dataFormat
and setDefaultBus
properties from a Spring configuration file, as follows:
<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="MESSAGE"/> <entry key="setDefaultBus" value="true"/> </cxf:properties> </cxf:cxfEndpoint>
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 must contain the fully-qualified name of the class, org.apache.cxf.common.logging.Log4jLogger
, with no comments, on a single line.
How to let camel-cxf response message with xml start document
If you are using some SOAP client such as PHP, can cause this kind of error, because CXF doesn’t add the XML start document <?xml version="1.0" encoding="utf-8"?>
.
Error:sendSms: SoapFault exception: [Client] looks like we got no XML document in [...]
To resolved this issue, you just need to tell StaxOutInterceptor to write the XML start document for you.
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); } }
You can add a customer interceptor like this and configure it into you camel-cxf
endpont
<cxf:cxfEndpoint id="routerEndpoint" address="http://localhost:${CXFTestSupport.port2}/CXFGreeterRouterTest/CamelContext/RouterPort" serviceClass="org.apache.hello_world_soap_http.GreeterImpl" skipFaultLogging="true"> <cxf:outInterceptors> <!-- This interceptor forces the CXF server send the XML start document to client --> <bean class="org.apache.camel.component.cxf.WriteXmlDeclarationInterceptor"/> </cxf:outInterceptors> <cxf:properties> <!-- Set the publishedEndpointUrl which could override the service address from generated WSDL as you want --> <entry key="publishedEndpointUrl" value="http://www.simple.com/services/test" /> </cxf:properties> </cxf:cxfEndpoint>
Or adding a message header for it like this if you are using Camel 2.4.
// 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);
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.
public class PersonProcessor implements Processor { private static final transient Logger LOG = LoggerFactory.getLogger(PersonProcessor.class); @SuppressWarnings("unchecked") public void process(Exchange exchange) throws Exception { LOG.info("processing exchange in camel"); BindingOperationInfo boi = (BindingOperationInfo)exchange.getProperty(BindingOperationInfo.class.toString()); 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); // Since camel has its own exception handler framework, we can't throw the exception to trigger it // We just set the fault message in the exchange for camel-cxf component handling and return exchange.getOut().setFault(true); exchange.getOut().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.getOut().setBody(new Object[] {null, personId, ssn, name}); } }
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
tries to use the defaultOperationName
from CxfEndpoint
. If there is no defaultOperationName
set on CxfEndpoint
, it picks up the first operation name 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 follows:
Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut); final List<String> params = new ArrayList<String>(); // 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.getOut(); // 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 is filled in the reset of List. // The result is 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("The response context", "UTF-8", responseContext.get(org.apache.cxf.message.Message.ENCODING)); assertEquals("Reply body on Camel is wrong", "echo " + TEST_MESSAGE, result.get(0));
How to deal with the message for a camel-cxf endpoint in PAYLOAD data format
In Apache Camel 2.0: CxfMessage.getBody()
returns an org.apache.camel.component.cxf.CxfPayload
object, which has getters for SOAP message headers and Body elements. This change enables decoupling the native CXF message from the Apache Camel message.
protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { public void configure() { from(SIMPLE_ENDPOINT_URI + "&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<Source>(); // 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); outElements.add(new DOMSource(outDocument.getDocumentElement())); // set the payload header with null CxfPayload<SoapHeader> responsePayload = new CxfPayload<SoapHeader>(null, outElements, null); exchange.getOut().setBody(responsePayload); } }); } }; }
How to get and set SOAP headers in POJO mode
POJO
means that the data format is a list of Java objects when the CXF endpoint produces or consumes Camel exchanges. Even though Apache Camel exposes the message body as POJOs in this mode, the CXF component 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 in POJO mode.
The following example illustrates how to get/set SOAP headers. Suppose we have a route that forwards from one CXF endpoint to another. That is, SOAP Client → Apache Camel → CXF service. We can attach two processors to obtain/insert SOAP headers at (1) before request goes out to the CXF service and (2) before response comes back to the SOAP Client. Processor (1) and (2) in this example are InsertRequestOutHeaderProcessor and InsertResponseOutHeaderProcessor. Our route looks like this:
<route> <from uri="cxf:bean:routerRelayEndpointWithInsertion"/> <process ref="InsertRequestOutHeaderProcessor" /> <to uri="cxf:bean:serviceRelayEndpointWithInsertion"/> <process ref="InsertResponseOutHeaderProcessor" /> </route>
In 2.x SOAP headers are propagated to and from Apache Camel Message headers. The Apache 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 inserts 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.
public static class InsertResponseOutHeaderProcessor implements Processor { @SuppressWarnings("unchecked") public void process(Exchange exchange) throws Exception { // If exchange is routed from camel-cxf endpoint, this is the header List<SoapHeader> soapHeaders = CastUtils.cast((List<?>)exchange.getIn().getHeader(Header.HEADER_LIST)); if (soapHeaders == null) { // we just create a new soap headers in case the header is null soapHeaders = new ArrayList<SoapHeader>(); } // 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); } }
How to get and set SOAP headers in PAYLOAD mode
We have already shown how to access SOAP message (CxfPayload
object) in PAYLOAD
mode (see 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).
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 here", elements); assertEquals("Get the wrong elements size", 1, elements.size()); Element el = new XmlConverter().toDOMElement(elements.get(0)); elements.set(0, new DOMSource(el)); assertEquals("Get the wrong namespace URI", "http://camel.apache.org/pizza/types", el.getNamespaceURI()); List<SoapHeader> headers = payload.getHeaders(); assertNotNull("Headers here", headers); assertEquals("Get the wrong headers size", headers.size(), 1); assertEquals("Get the wrong namespace URI", ((Element)(headers.get(0).getObject())).getNamespaceURI(), "http://camel.apache.org/pizza/types"); } }) .to(getServiceEndpointURI());
Since Camel 2.16.0, you can use the same approach as described in the section called “How to get and set SOAP headers in POJO mode” to set or get the SOAP headers. You can now use the org.apache.cxf.headers.Header.list
header to get and set a list of SOAP headers. This means that if you have a route that forwards from one Camel CXF endpoint to another (SOAP Client → Camel → CXF service), the SOAP headers sent by the SOAP client are now also forwarded to the CXF service. If you do not want the headers to be forwarded, remove them from the org.apache.cxf.headers.Header.list
Camel header.
SOAP headers are not available in MESSAGE mode
SOAP headers are not available in MESSAGE
mode as SOAP processing is skipped.
How to throw a SOAP Fault from Apache Camel
If you are using a 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 like this:
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 the SOAP Fault message in the message body and set the response code in the message header.
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)); } });
The same is true for the POJO data format. You can set the SOAP Fault on the Out body and also indicate it’s a fault by calling Message.setFault(true)
, as follows:
from("direct:start").onException(SoapFault.class).maximumRedeliveries(0).handled(true) .process(new Processor() { public void process(Exchange exchange) throws Exception { SoapFault fault = exchange .getProperty(Exchange.EXCEPTION_CAUGHT, SoapFault.class); exchange.getOut().setFault(true); exchange.getOut().setBody(fault); } }).end().to(serviceURI);
How to propagate a 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 CXF endpoint producer to invoke the external Web service, you can set the request context and get the 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 opertion name", "{http://apache.org/hello_world_soap_http}greetMe", responseContext.get("javax.xml.ws.wsdl.operation").toString());
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 since 2.1.So, it is possible to retreive attachments by Camel Message API
DataHandler Message.getAttachment(String id)
.
Payload Mode: MTOM is supported since 2.1. Attachments can be retrieved by Camel Message APIs mentioned above. SOAP with Attachment is not supported as there is no SOAP processing in this mode.
To enable MTOM, set the CXF endpoint property "mtom_enabled" to true. (I believe you can only do it with Spring.)
<cxf:cxfEndpoint id="routerEndpoint" address="http://localhost:${CXFTestSupport.port1}/CxfMtomRouterPayloadModeTest/jaxws-mtom/hello" wsdlURL="mtom.wsdl" serviceName="ns:HelloService" endpointName="ns:HelloPort" xmlns:ns="http://apache.org/camel/cxf/mtom_feature"> <cxf:properties> <!-- enable mtom by setting this property to true --> <entry key="mtom-enabled" value="true"/> <!-- set the camel-cxf endpoint data fromat to PAYLOAD mode --> <entry key="dataFormat" value="PAYLOAD"/> </cxf:properties>
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.
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 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:" 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:" assertEquals(MtomTestHelper.REQ_IMAGE_CID, imageId); DataHandler dr = exchange.getIn().getAttachment(photoId); assertEquals("application/octet-stream", dr.getContentType()); MtomTestHelper.assertEquals(MtomTestHelper.REQ_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream())); dr = exchange.getIn().getAttachment(imageId); 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"))); } }
Message Mode: Attachments are not supported as it does not process the message at all.
CXF_MESSAGE Mode: MTOM is supported, and Attachments can be retrieved by Camel Message APIs mentioned above.
When receiving a multipart (that is, MTOM) message the default SOAPMessage
to String
converter provides the complete multi-part 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.
How to propagate stack trace information
It is possible to configure a CXF endpoint so that, when a Java exception is thrown on the server side, the stack trace for the exception is marshalled into a fault message and returned to the client. To enable this feaure, set the dataFormat
to PAYLOAD
and set the faultStackTraceEnabled
property to true
in the cxfEndpoint
element, as follows:
<cxf:cxfEndpoint id="router" address="http://localhost:9002/TestMessage"
wsdlURL="ship.wsdl"
endpointName="s:TestSoapEndpoint"
serviceName="s:TestService"
xmlns:s="http://test">
<cxf:properties>
<!-- enable sending the stack trace back to client; the default value is false-->
<entry key="faultStackTraceEnabled" value="true" /> <entry key="dataFormat" value="PAYLOAD" />
</cxf:properties>
</cxf:cxfEndpoint>
For security reasons, the stack trace does not include the causing exception (that is, the part of a stack trace that follows Caused by
). If you want to include the causing exception in the stack trace, set the exceptionMessageCauseEnabled
property to true
in the cxfEndpoint
element, as follows:
<cxf:cxfEndpoint id="router" address="http://localhost:9002/TestMessage"
wsdlURL="ship.wsdl"
endpointName="s:TestSoapEndpoint"
serviceName="s:TestService"
xmlns:s="http://test">
<cxf:properties>
<!-- enable to show the cause exception message and the default value is false -->
<entry key="exceptionMessageCauseEnabled" value="true" />
<!-- enable to send the stack trace back to client, the default value is false-->
<entry key="faultStackTraceEnabled" value="true" />
<entry key="dataFormat" value="PAYLOAD" />
</cxf:properties>
</cxf:cxfEndpoint>
Only enable the exceptionMessageCauseEnabled
flag for testing and diagnostic purposes. It is normal practice for servers to conceal the original cause of an exception to make it harder for hostile users to probe the server.
Streaming Support in PAYLOAD mode
In 2.8.2, 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. Starting in 2.8.2, 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
tofalse
to turn if off. That sets the global default, but setting the endpoint property above overrides this value for that endpoint.
Using the generic CXF Dispatch mode
From 2.8.0, 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).
78.1. CXF consumers on WildFly
The configuration of camel-cxf consumers on WildFly is different to that of standalone Camel. Producer endpoints work as per normal.
On WildFly, camel-cxf consumers leverage the default Undertow HTTP server provided by the container. The server is defined within the undertow subsystem configuration. Here’s an excerpt of the default configuration from standalone.xml:
<subsystem xmlns="urn:jboss:domain:undertow:4.0"> <buffer-cache name="default" /> <server name="default-server"> <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true" /> <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true" /> <host name="default-host" alias="localhost"> <location name="/" handler="welcome-content" /> <filter-ref name="server-header" /> <filter-ref name="x-powered-by-header" /> <http-invoker security-realm="ApplicationRealm" /> </host> </server> </subsystem>
In this instance, Undertow is configured to listen on interfaces / ports specified by the http and https socket-binding. By default this is port 8080 for http and 8443 for https.
For example, if you configure an endpoint consumer using different host or port combinations, a warning will appear within the server log file. For example the following host & port configurations would be ignored:
<cxf:rsServer id="cxfRsConsumer" address="http://somehost:1234/path/to/resource" serviceClass="org.example.ServiceClass" />
<cxf:cxfEndpoint id="cxfWsConsumer" address="http://somehost:1234/path/to/resource" serviceClass="org.example.ServiceClass" />
[org.wildfly.extension.camel] (pool-2-thread-1) Ignoring configured host: http://somehost:1234/path/to/resource
However, the consumer is still available on the default host & port localhost:8080 or localhost:8443.
Applications which use camel-cxf consumers must be packaged as a WAR. In previous WildFly-Camel releases, other types of archive such as JAR were permitted, but this is no longer supported.
78.1.1. Configuring alternative ports
If alternative ports are to be accepted, then these must be configured via the WildFly subsystem configuration. This is explained in the server documentation:
78.1.2. Configuring SSL
To configure SSL, refer to the WildFly SSL configuration guide:
78.1.3. Configuring security with Elytron
WildFly-Camel supports securing camel-cxf consumer endpoints with the Elytron security framework.
78.1.3.1. Configuring a security domain
To secure a WildFly-Camel application with Elytron, an application security domain needs to be referenced within WEB-INF/jboss-web.xml
of your WAR deployment:
<jboss-web> <security-domain>my-application-security-domain</security-domain> </jboss-web>
The <security-domain>
configuration references the name of an <application-security-domain>
defined by the Undertow subsystem. For example, the Undertow subsystem <application-security-domain>
is configured within the WildFly server standalone.xml
configuration file as follows:
<subsystem xmlns="urn:jboss:domain:undertow:6.0"> ... <application-security-domains> <application-security-domain name="my-application-security-domain" http-authentication-factory="application-http-authentication"/> </application-security-domains> </subsystem>
The <http-authentication-factory>
application-http-authentication
is defined within the Elytron subsystem. application-http-authentication
is available by default in both the standalone.xml
and standalone-full.xml
server configuration files. For example:
<subsystem xmlns="urn:wildfly:elytron:1.2"> ... <http> ... <http-authentication-factory name="application-http-authentication" http-server-mechanism-factory="global" security-domain="ApplicationDomain"> <mechanism-configuration> <mechanism mechanism-name="BASIC"> <mechanism-realm realm-name="Application Realm" /> </mechanism> <mechanism mechanism-name="FORM" /> </mechanism-configuration> </http-authentication-factory> <provider-http-server-mechanism-factory name="global" /> </http> ... </subsystem>
The <http-authentication-factory>
named application-http-authentication
, holds a reference to a Elytron security domain called ApplicationDomain
.
For more information on how to configure the Elytron subsystem, refer to the Elytron documentation.
78.1.3.2. Configuring security constraints, authentication methods and security roles
Security constraints, authentication methods and security roles for camel-cxf consumer endpoints can be configured within your WAR deployment WEB-INF/web.xml
. For example, to configure BASIC Authentication:
<web-app> <security-constraint> <web-resource-collection> <web-resource-name>secure</web-resource-name> <url-pattern>/webservices/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>my-role</role-name> </auth-constraint> </security-constraint> <security-role> <description>The role that is required to log in to /webservices/*</description> <role-name>my-role</role-name> </security-role> <login-config> <auth-method>BASIC</auth-method> <realm-name>my-realm</realm-name> </login-config> </web-app>
Note that the <url-pattern>
defined by the Servlet Specification is relative to the context path of the web application. If your application is packaged as my-app.war
, WildFly will make it accessible under the context path /my-app
and the <url-patternpattern>
/webservices/*
will be applied to paths relative to /my-app
.
For example, requests against http://my-server/my-app/webservices/my-endpoint
will match the /webservices/*
pattern, while http://my-server/webservices/my-endpoint
will not match.
This is important because WildFly-Camel allows the creation of camel-cxf endpoint consumers whose base path is outside of the host web application context path. For example, it is possible to create a camel-cxf consumer for http://my-server/webservices/my-endpoint
inside my-app.war
.
In order to define security constraints for such out-of-context endpoints, WildFly-Camel supports a custom, non-standard <url-pattern>
convention where prefixing the pattern with three forward slashes ///
will be interpreted as absolute to server host name. For example, to secure http://my-server/webservices/my-endpoint
inside my-app.war
, you would add the following configuration to web.xml
:
<web-app> <security-constraint> <web-resource-collection> <web-resource-name>secure</web-resource-name> <url-pattern>///webservices/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>my-role</role-name> </auth-constraint> </security-constraint> <security-role> <description>The role that is required to log in to /webservices/*</description> <role-name>my-role</role-name> </security-role> <login-config> <auth-method>BASIC</auth-method> <realm-name>my-realm</realm-name> </login-config> </web-app>
Chapter 79. CXF-RS Component
Available as of Camel version 2.0
The cxfrs: component provides integration with Apache CXF for connecting to JAX-RS 1.1 and 2.0 services hosted in CXF.
When using CXF as a consumer, the CXF Bean Component allows you to factor out how message payloads are received from their processing as a RESTful or SOAP web service. This has the potential of using a multitude of transports to consume web services. The bean component’s configuration is also simpler and provides the fastest method to implement web services using Camel and CXF.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-cxf</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
79.1. URI format
cxfrs://address?options
Where address represents the CXF endpoint’s address
cxfrs:bean:rsEndpoint
Where rsEndpoint represents the spring bean’s name which presents the CXFRS client or server
For either style above, you can append options to the URI as follows:
cxfrs:bean:cxfEndpoint?resourceClasses=org.apache.camel.rs.Example
79.2. Options
The CXF-RS component supports 3 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
useGlobalSslContext Parameters (security) | Enable usage of global SSL context parameters. | false | boolean |
headerFilterStrategy (filter) | To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message. | HeaderFilterStrategy | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The CXF-RS endpoint is configured using URI syntax:
cxfrs:beanId:address
with the following path and query parameters:
79.2.1. Path Parameters (2 parameters):
Name | Description | Default | Type |
---|---|---|---|
beanId | To lookup an existing configured CxfRsEndpoint. Must used bean: as prefix. | String | |
address | The service publish address. | String |
79.2.2. Query Parameters (30 parameters):
Name | Description | Default | Type |
---|---|---|---|
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. | Default | BindingStyle |
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 |
publishedEndpointUrl (consumer) | This option can override the endpointUrl that published from the WADL which can be accessed with resource address url plus _wadl | String | |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
serviceBeans (consumer) | The service beans which you want to export as REST service. Multiple beans can be separated by comma. | List | |
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) | 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 |
ignoreDeleteMethodMessage Body (producer) | This option is used to tell CxfRsProducer to ignore the message body of the DELETE method when using HTTP API. | false | boolean |
maxClientCacheSize (producer) | 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 |
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 |
cxfRsEndpointConfigurer (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 configureServer/Client method of CxfEndpointConfigurer. | CxfRsEndpoint Configurer | |
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 |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
79.3. Spring Boot Auto-Configuration
The component supports 4 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.cxfrs.enabled | Enable cxfrs component | true | 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. | String | |
camel.component.cxfrs.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.cxfrs.use-global-ssl-context-parameters | Enable usage of global SSL context parameters. | false | Boolean |
You can also configure the CXF REST endpoint through the spring configuration. Since there are lots of difference between the CXF REST client and CXF REST Server, we provide different configuration for them. Please check out the schema file and CXF JAX-RS documentation for more information.
79.4. How to configure the REST endpoint in Camel
In 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 here.
79.5. How to override the CXF producer address from message header
The camel-cxfrs
producer supports to override the services 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()));
79.6. Consuming a REST Request - Simple Binding Style
Available as of 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. Somewhat inelegant, difficult and error-prone.
In contrast, the SimpleConsumer
binding style performs the following mappings, in order 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 other 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, supportingDataHandler
,InputStream
,DataSource
and CXF’sAttachment
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 newResponse
is created and the message body is set as the entity (so long it’s not null). The response status code is taken from theExchange.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.
79.6.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");
79.6.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);
Request payload is placed in IN message body, replacing the original MessageContentsList.
public Response doAction(BusinessObject request, @HeaderParam("abcd") String abcd, @QueryParam("defg") String defg);
Request payload placed in IN message body, replacing the original MessageContentsList. Both request params mapped as IN message headers with names abcd and defg.
public Response doAction(@HeaderParam("abcd") String abcd, @QueryParam("defg") String defg);
Both request params mapped as IN message headers with names abcd and defg. The original MessageContentsList is preserved, even though it only contains the 2 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.
79.6.3. More 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>
For more examples on how to process requests and write responses can be found here.
79.7. Consuming a REST Request - Default Binding Style
The CXF JAXRS front end implements the JAX-RS (JSR-311) API, so we can export the resources classes as a REST service. And we leverage the CXF Invoker API to turn a REST request into a normal Java object method invocation. Unlike the Camel Restlet component, you don’t need to specify the URI template within your endpoint, 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 a right processor or endpoint.
Here is an example of a CXFRS route…
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 used to configure the endpoint…
INFO:*Note about resource classes*
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.
Note that starting from Camel 2.15 it is also sufficient to provide an interface only as opposed to a no-op service implementation class for the default mode.
Starting from Camel 2.15, 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); }
79.8. 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 just need to specify the operation name in the message header and prepare the parameter in the message body, the camel-cxfrs producer will generate right REST request for you.
Here is an 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"); // setup the accept 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.getOut().getBody(); assertNotNull("The response should not be null ", response); assertEquals("Get a wrong customer id ", 123, response.getId()); assertEquals("Get a wrong customer name", "John", response.getName()); assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE)); assertEquals("Get a wrong header value", "value", exchange.getOut().getHeader("key"));
The CXF JAXRS front end also provides a 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); } });
From Camel 2.1, we also support to 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);
79.9. What’s the Camel Transport for CXF
In CXF you offer or consume a webservice by defining its address. The first part of the address specifies the protocol to use. For example address="http://localhost:9000" in an endpoint configuration means your service will be offered using the http protocol on port 9000 of localhost. When you integrate Camel Tranport into CXF you get a new transport "camel". So you can specify address="camel://direct:MyEndpointName" to bind the CXF service address to a camel direct endpoint.
Technically speaking Camel transport for CXF is a component which implements the CXF transport API with the Camel core library. This allows you to easily use Camel’s routing engine and integration patterns support together with your CXF services.
79.10. Integrate Camel into CXF transport layer
To include the Camel Tranport into your CXF bus you use the CamelTransportFactory. You can do this in Java as well as in Spring.
79.10.1. Setting up the Camel Transport in Spring
You can use the following snippet in your applicationcontext if you want to configure anything special. If you only want to activate the camel transport you do not have to do anything in your application context. As soon as you include the camel-cxf-transport jar (or camel-cxf.jar if your camel version is less than 2.7.x) in your app, cxf will scan the jar and load a CamelTransportFactory for you.
<!-- you don't need to specify the CamelTransportFactory configuration as it is auto load by CXF bus --> <bean class="org.apache.camel.component.cxf.transport.CamelTransportFactory"> <property name="bus" ref="cxf" /> <property name="camelContext" ref="camelContext" /> <!-- checkException new added in Camel 2.1 and Camel 1.6.2 --> <!-- If checkException is true , CamelDestination will check the outMessage's exception and set it into camel exchange. You can also override this value in CamelDestination's configuration. The default value is false. This option should be set true when you want to leverage the camel's error handler to deal with fault message --> <property name="checkException" value="true" /> <property name="transportIds"> <list> <value>http://cxf.apache.org/transports/camel</value> </list> </property> </bean>
79.10.2. Integrating the Camel Transport in a programmatic way
Camel transport provides a setContext method that you could use to set the Camel context into the transport factory. If you want this factory take effect, you need to register the factory into the CXF bus. Here is a full example for you.
import org.apache.cxf.Bus; import org.apache.cxf.BusFactory; import org.apache.cxf.transport.ConduitInitiatorManager; import org.apache.cxf.transport.DestinationFactoryManager; ... BusFactory bf = BusFactory.newInstance(); Bus bus = bf.createBus(); CamelTransportFactory camelTransportFactory = new CamelTransportFactory(); // set up the CamelContext which will be use by the CamelTransportFactory camelTransportFactory.setCamelContext(context) // if you are using CXF higher then 2.4.x the camelTransportFactory.setBus(bus); // if you are lower CXF, you need to register the ConduitInitiatorManager and DestinationFactoryManager like below // register the conduit initiator ConduitInitiatorManager cim = bus.getExtension(ConduitInitiatorManager.class); cim.registerConduitInitiator(CamelTransportFactory.TRANSPORT_ID, camelTransportFactory); // register the destination factory DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class); dfm.registerDestinationFactory(CamelTransportFactory.TRANSPORT_ID, camelTransportFactory); // set or bus as the default bus for cxf BusFactory.setDefaultBus(bus);
79.11. Configure the destination and conduit with Spring
79.11.1. Namespace
The elements used to configure an Camel transport endpoint are defined in the namespace http://cxf.apache.org/transports/camel
. It is commonly referred to using the prefix camel
. In order to use the Camel transport configuration elements, you will need to add the lines shown below to the beans element of your endpoint’s configuration file. In addition, you will need to add the configuration elements' namespace to the xsi:schemaLocation
attribute.
Adding the Configuration Namespace
<beans ... xmlns:camel="http://cxf.apache.org/transports/camel ... xsi:schemaLocation="... http://cxf.apache.org/transports/camel http://cxf.apache.org/transports/camel.xsd ...>
79.11.2. The destination
element
You configure an Camel transport server endpoint using the camel:destination
element and its children. The camel:destination
element takes a single attribute, name
, that specifies the WSDL port element that corresponds to the endpoint. The value for the name
attribute takes the form portQName`.camel-destination`. The example below shows the camel:destination
element that would be used to add configuration for an endpoint that was specified by the WSDL fragment <port binding="widgetSOAPBinding" name="widgetSOAPPort">
if the endpoint’s target namespace was http://widgets.widgetvendor.net
.
camel:destination Element
... <camel:destination name="{http://widgets/widgetvendor.net}widgetSOAPPort.http-destination> <camelContext id="context" xmlns="http://activemq.apache.org/camel/schema/spring"> <route> <from uri="direct:EndpointC" /> <to uri="direct:EndpointD" /> </route> </camelContext> </camel:destination> <!-- new added feature since Camel 2.11.x <camel:destination name="{http://widgets/widgetvendor.net}widgetSOAPPort.camel-destination" camelContextId="context" /> ...
The camel:destination
element for Spring has a number of child elements that specify configuration information. They are described below.
Element
Description
camel-spring:camelContext
You can specify the camel context in the camel destination
camel:camelContextRef
The camel context id which you want inject into the camel destination
79.11.3. The conduit
element
You configure a Camel transport client using the camel:conduit
element and its children. The camel:conduit
element takes a single attribute, name
, that specifies the WSDL port element that corresponds to the endpoint. The value for the name
attribute takes the form portQName`.camel-conduit`. For example, the code below shows the camel:conduit
element that would be used to add configuration for an endpoint that was specified by the WSDL fragment <port binding="widgetSOAPBinding" name="widgetSOAPPort">
if the endpoint’s target namespace was http://widgets.widgetvendor.net
.
http-conf:conduit Element
... <camelContext id="conduit_context" xmlns="http://activemq.apache.org/camel/schema/spring"> <route> <from uri="direct:EndpointA" /> <to uri="direct:EndpointB" /> </route> </camelContext> <camel:conduit name="{http://widgets/widgetvendor.net}widgetSOAPPort.camel-conduit"> <camel:camelContextRef>conduit_context</camel:camelContextRef> </camel:conduit> <!-- new added feature since Camel 2.11.x <camel:conduit name="{http://widgets/widgetvendor.net}widgetSOAPPort.camel-conduit" camelContextId="conduit_context" /> <camel:conduit name="*.camel-conduit"> <!-- you can also using the wild card to specify the camel-conduit that you want to configure --> ... </camel:conduit> ...
The camel:conduit
element has a number of child elements that specify configuration information. They are described below.
Element
Description
camel-spring:camelContext
You can specify the camel context in the camel conduit
camel:camelContextRef
The camel context id which you want inject into the camel conduit
79.12. Configure the destination and conduit with Blueprint
From Camel 2.11.x, Camel Transport supports to be configured with Blueprint.
If you are using blueprint, you should use the namespace http://cxf.apache.org/transports/camel/blueprint
and import the schema like the blow.
Adding the Configuration Namespace for blueprint
<beans ... xmlns:camel="http://cxf.apache.org/transports/camel/blueprint" ... xsi:schemaLocation="... http://cxf.apache.org/transports/camel/blueprint http://cxf.apache.org/schmemas/blueprint/camel.xsd ...>
In blueprint camel:conduit
camel:destination
only has one camelContextId attribute, they doesn’t support to specify the camel context in the camel destination.
<camel:conduit id="*.camel-conduit" camelContextId="camel1" /> <camel:destination id="*.camel-destination" camelContextId="camel1" />
79.13. Example Using Camel as a load balancer for CXF
This example shows how to use the camel load balancing feature in CXF. You need to load the configuration file in CXF and publish the endpoints on the address "camel://direct:EndpointA" and "camel://direct:EndpointB"
79.14. Complete Howto and Example for attaching Camel to CXF
Chapter 80. Data Format Component
Available as of Camel version 2.12
The dataformat: component allows to use Data Format as a Camel Component.
80.1. 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.
80.2. DataFormat Options
The Data Format component has no options.
The Data Format endpoint is configured using URI syntax:
dataformat:name:operation
with the following path and query parameters:
80.2.1. Path Parameters (2 parameters):
Name | Description | Default | Type |
---|---|---|---|
name | Required Name of data format | String | |
operation | Required Operation to use either marshal or unmarshal | String |
80.2.2. Query Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
80.3. 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>
Chapter 81. Dataset Component
Available as of Camel version 1.3
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 dataset’s.
81.1. 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
.
81.2. Options
The Dataset component has no options.
The Dataset endpoint is configured using URI syntax:
dataset:name
with the following path and query parameters:
81.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
name | Required Name of DataSet to lookup in the registry | DataSet |
81.2.2. Query Parameters (19 parameters):
Name | Description | Default | Type |
---|---|---|---|
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 | 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/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) | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions, that will be logged at WARN/ERROR level and ignored. | ExceptionHandler | |
exchangePattern (consumer) | Sets the default exchange pattern when creating an exchange. | 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 setAssertPeriod(long) method for. By default this period is disabled. | 0 | 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 |
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 | 0 | long |
resultWaitTime (producer) | Sets the maximum amount of time (in millis) the assertIsSatisfied() will wait on a latch until it is satisfied | 0 | 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 | 0 | long |
copyOnExchange (producer) | Sets whether to make a deep copy of the incoming Exchange when received at this mock endpoint. Is by default true. | true | boolean |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
You can append query options to the URI in the following format, ?option=value&option=value&…
81.3. 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>
81.4. 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.
81.5. DataSetSupport (abstract class)
The DataSetSupport abstract class is a nice starting point for new DataSets, and provides some useful features to derived classes.
81.5.1. Properties on DataSetSupport
Property | Type | Default | Description |
---|---|---|---|
|
|
|
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 |
|
| null | |
|
|
| Specifies how many messages to send/consume. |
|
|
|
Specifies the number of messages to be received before reporting progress. Useful for showing progress of a large load test. If < 0, then |
81.6. SimpleDataSet
The SimpleDataSet
extends DataSetSupport
, and adds a default body.
81.6.1. Additional Properties on SimpleDataSet
Property | Type | Default | Description |
---|---|---|---|
|
|
|
Specifies the default message body. By default, the |
81.7. ListDataSet
Available since Camel 2.17
The List`DataSet` extends DataSetSupport
, and adds a list of default bodies.
81.7.1. Additional Properties on ListDataSet
Property | Type | Default | Description |
---|---|---|---|
|
|
|
Specifies the default message body. By default, the |
|
| the size of the defaultBodies list |
Specifies how many messages to send/consume. This value can be different from the size of the |
81.8. FileDataSet
Available since Camel 2.17
The FileDataSet
extends ListDataSet
, and adds support for loading the bodies from a file.
81.8.1. Additional Properties on FileDataSet
Property | Type | Default | Description |
---|---|---|---|
|
| null | Specifies the source file for payloads |
|
| \z |
Specifies the delimiter pattern used by a |
Chapter 82. DigitalOcean Component
Available as of Camel version 2.19
The DigitalOcean component allows you to manage Droplets and resources within the DigitalOcean cloud with Camel by encapsulating [digitalocean-api-java](https://www.digitalocean.com/community/projects/api-client-in-java). All of the functionality that you are familiar with in the DigitalOcean control panel is also available through this Camel component.
82.1. Prerequisites
You must have a valid DigitalOcean account and a valid OAuth token. You can generate an OAuth token by visiting the [Apps & API](https://cloud.digitalocean.com/settings/applications) section of the DigitalOcean control panel for your account.
82.2. URI format
The DigitalOcean Component uses the following URI format:
digitalocean://endpoint?[options]
where endpoint
is a DigitalOcean resource type.
Example : to list your droplets:
digitalocean://droplets?operation=list&oAuthToken=XXXXXX&page=1&perPage=10
The DigitalOcean component only supports producer endpoints so you cannot use this component at the beginning of a route to listen to messages in a channel.
82.3. Options
The DigitalOcean component has no options.
The DigitalOcean endpoint is configured using URI syntax:
digitalocean:operation
with the following path and query parameters:
82.3.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
operation | The operation to perform to the given resource. | DigitalOceanOperations |
82.3.2. Query Parameters (10 parameters):
Name | Description | Default | Type |
---|---|---|---|
page (producer) | Use for pagination. Force the page number. | 1 | Integer |
perPage (producer) | Use for pagination. Set the number of item per request. The maximum number of results per page is 200. | 25 | Integer |
resource (producer) | Required The DigitalOcean resource type on which perform the operation. | DigitalOceanResources | |
digitalOceanClient (advanced) | To use a existing configured DigitalOceanClient as client | DigitalOceanClient | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
httpProxyHost (proxy) | Set a proxy host if needed | String | |
httpProxyPassword (proxy) | Set a proxy password if needed | String | |
httpProxyPort (proxy) | Set a proxy port if needed | Integer | |
httpProxyUser (proxy) | Set a proxy host if needed | String | |
oAuthToken (security) | DigitalOcean OAuth Token | String |
82.4. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.digitalocean.enabled | Enable digitalocean component | true | Boolean |
camel.component.digitalocean.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
You have to provide an operation value for each endpoint, with the operation
URI option or the CamelDigitalOceanOperation
message header.
All operation values are defined in DigitalOceanOperations
enumeration.
All header names used by the component are defined in DigitalOceanHeaders
enumeration.
82.5. Message body result
All message bodies returned are using objects provided by the digitalocean-api-java library.
82.6. API Rate Limits
DigitalOcean REST API encapsulated by camel-digitalocean component is subjected to API Rate Limiting. You can find the per method limits in the [API Rate Limits documentation](https://developers.digitalocean.com/documentation/v2/#rate-limit).
82.7. Account endpoint
| operation | Description | Headers | Result | | ------ | ---- | ------- | ----------- | | get
| get account info | | com.myjeeva.digitalocean.pojo.Account
|
82.8. BlockStorages endpoint
| operation | Description | Headers | Result | | ------ | ---- | ------- | ----------- | | list
| list all of the Block Storage volumes available on your account | | List<com.myjeeva.digitalocean.pojo.Volume>
| | get
| show information about a Block Storage volume| CamelDigitalOceanId
Integer| com.myjeeva.digitalocean.pojo.Volume
| | get
| show information about a Block Storage volume by name| CamelDigitalOceanName
String <br>`CamelDigitalOceanRegion` String| com.myjeeva.digitalocean.pojo.Volume
| | listSnapshots
| retrieve the snapshots that have been created from a volume | CamelDigitalOceanId
Integer| List<com.myjeeva.digitalocean.pojo.Snapshot>
| | create
| create a new volume | CamelDigitalOceanVolumeSizeGigabytes
Integer<br>`CamelDigitalOceanName` String<br>`CamelDigitalOceanDescription`* String<br>`CamelDigitalOceanRegion`* String| com.myjeeva.digitalocean.pojo.Volume
| | delete
| delete a Block Storage volume, destroying all data and removing it from your account| CamelDigitalOceanId
Integer| com.myjeeva.digitalocean.pojo.Delete
| | delete
| delete a Block Storage volume by name| CamelDigitalOceanName
String<br>`CamelDigitalOceanRegion` String| com.myjeeva.digitalocean.pojo.Delete
| attach
| attach a Block Storage volume to a Droplet| CamelDigitalOceanId
Integer <br>`CamelDigitalOceanDropletId` Integer<br>`CamelDigitalOceanDropletRegion` String| com.myjeeva.digitalocean.pojo.Action
| attach
| attach a Block Storage volume to a Droplet by name| CamelDigitalOceanName
String<br>`CamelDigitalOceanDropletId` Integer<br>`CamelDigitalOceanDropletRegion` String| com.myjeeva.digitalocean.pojo.Action
| detach
| detach a Block Storage volume from a Droplet| CamelDigitalOceanId
Integer <br>`CamelDigitalOceanDropletId` Integer<br>`CamelDigitalOceanDropletRegion` String| com.myjeeva.digitalocean.pojo.Action
| attach
| detach a Block Storage volume from a Droplet by name| CamelDigitalOceanName
String<br>`CamelDigitalOceanDropletId` Integer<br>`CamelDigitalOceanDropletRegion` String| com.myjeeva.digitalocean.pojo.Action
| resize
| resize a Block Storage volume | CamelDigitalOceanVolumeSizeGigabytes
Integer<br>`CamelDigitalOceanRegion` String| com.myjeeva.digitalocean.pojo.Action
| | listActions
| retrieve all actions that have been executed on a volume | CamelDigitalOceanId
Integer| List<com.myjeeva.digitalocean.pojo.Action>
|
82.9. Droplets endpoint
| operation | Description | Headers | Result | | ------ | ---- | ------- | ----------- | | list
| list all Droplets in your account | | List<com.myjeeva.digitalocean.pojo.Droplet>
| | get
| show an individual droplet | CamelDigitalOceanId
Integer| com.myjeeva.digitalocean.pojo.Droplet
| | create
| create a new Droplet | CamelDigitalOceanName
String <br>`CamelDigitalOceanDropletImage` String <br>`CamelDigitalOceanRegion` String <br>`CamelDigitalOceanDropletSize` String <br>`CamelDigitalOceanDropletSSHKeys`* List\<String\> <br>`CamelDigitalOceanDropletEnableBackups`* Boolean <br>`CamelDigitalOceanDropletEnableIpv6`* Boolean <br>`CamelDigitalOceanDropletEnablePrivateNetworking`* Boolean <br>`CamelDigitalOceanDropletUserData`* String <br>`CamelDigitalOceanDropletVolumes`* List\<String\> <br>`CamelDigitalOceanDropletTags` List\<String\>| com.myjeeva.digitalocean.pojo.Droplet
| | create
| create multiple Droplets | CamelDigitalOceanNames
List\<String\> <br>`CamelDigitalOceanDropletImage` String <br>`CamelDigitalOceanRegion` String <br>`CamelDigitalOceanDropletSize` String <br>`CamelDigitalOceanDropletSSHKeys`* List\<String\> <br>`CamelDigitalOceanDropletEnableBackups`* Boolean <br>`CamelDigitalOceanDropletEnableIpv6`* Boolean <br>`CamelDigitalOceanDropletEnablePrivateNetworking`* Boolean <br>`CamelDigitalOceanDropletUserData`* String <br>`CamelDigitalOceanDropletVolumes`* List\<String\> <br>`CamelDigitalOceanDropletTags` List\<String\>| com.myjeeva.digitalocean.pojo.Droplet
| | delete
| delete a Droplet, | CamelDigitalOceanId
Integer| com.myjeeva.digitalocean.pojo.Delete
| | enableBackups
| enable backups on an existing Droplet | CamelDigitalOceanId
Integer| com.myjeeva.digitalocean.pojo.Action
| | disableBackups
| disable backups on an existing Droplet | CamelDigitalOceanId
Integer| com.myjeeva.digitalocean.pojo.Action
| | enableIpv6
| enable IPv6 networking on an existing Droplet | CamelDigitalOceanId
Integer| com.myjeeva.digitalocean.pojo.Action
| | enablePrivateNetworking
| enable private networking on an existing Droplet | CamelDigitalOceanId
Integer| com.myjeeva.digitalocean.pojo.Action
| | reboot
| reboot a Droplet | CamelDigitalOceanId
Integer| com.myjeeva.digitalocean.pojo.Action
| | powerCycle
| power cycle a Droplet | CamelDigitalOceanId
Integer| com.myjeeva.digitalocean.pojo.Action
| | shutdown
| shutdown a Droplet | CamelDigitalOceanId
Integer| com.myjeeva.digitalocean.pojo.Action
| | powerOff
| power off a Droplet | CamelDigitalOceanId
Integer| com.myjeeva.digitalocean.pojo.Action
| | powerOn
| power on a Droplet | CamelDigitalOceanId
Integer| com.myjeeva.digitalocean.pojo.Action
| | restore
| shutdown a Droplet | CamelDigitalOceanId
Integer <br>`CamelDigitalOceanImageId` Integer| com.myjeeva.digitalocean.pojo.Action
| | passwordReset
| reset the password for a Droplet | CamelDigitalOceanId
Integer| com.myjeeva.digitalocean.pojo.Action
| | resize
| resize a Droplet | CamelDigitalOceanId
Integer <br>`CamelDigitalOceanDropletSize` String| com.myjeeva.digitalocean.pojo.Action
| | rebuild
| rebuild a Droplet | CamelDigitalOceanId
Integer <br>`CamelDigitalOceanImageId` Integer| com.myjeeva.digitalocean.pojo.Action
| | rename
| rename a Droplet | CamelDigitalOceanId
Integer <br>`CamelDigitalOceanName` String| com.myjeeva.digitalocean.pojo.Action
| | changeKernel
| change the kernel of a Droplet | CamelDigitalOceanId
Integer <br>`CamelDigitalOceanKernelId` Integer| com.myjeeva.digitalocean.pojo.Action
| | takeSnapshot
| snapshot a Droplet | CamelDigitalOceanId
Integer <br>`CamelDigitalOceanName`* String| com.myjeeva.digitalocean.pojo.Action
| | tag
| tag a Droplet | CamelDigitalOceanId
Integer <br>`CamelDigitalOceanName` String| com.myjeeva.digitalocean.pojo.Response
| | untag
| untag a Droplet | CamelDigitalOceanId
Integer <br>`CamelDigitalOceanName` String| com.myjeeva.digitalocean.pojo.Response
| | listKernels
| retrieve a list of all kernels available to a Droplet | CamelDigitalOceanId
Integer | List<com.myjeeva.digitalocean.pojo.Kernel>
| | listSnapshots
| retrieve the snapshots that have been created from a Droplet | CamelDigitalOceanId
Integer | List<com.myjeeva.digitalocean.pojo.Snapshot>
| | listBackups
| retrieve any backups associated with a Droplet | CamelDigitalOceanId
Integer | List<com.myjeeva.digitalocean.pojo.Backup>
| | listActions
| retrieve all actions that have been executed on a Droplet | CamelDigitalOceanId
Integer | List<com.myjeeva.digitalocean.pojo.Action>
| | listNeighbors
| retrieve a list of droplets that are running on the same physical server | CamelDigitalOceanId
Integer | List<com.myjeeva.digitalocean.pojo.Droplet>
| | listAllNeighbors
| retrieve a list of any droplets that are running on the same physical hardware | | List<com.myjeeva.digitalocean.pojo.Droplet>
|
82.10. Images endpoint
| operation | Description | Headers | Result | | ------ | ---- | ------- | ----------- | | list
| list images available on your account | CamelDigitalOceanType
* DigitalOceanImageTypes | List<com.myjeeva.digitalocean.pojo.Image>
| | ownList
| retrieve only the private images of a user | | List<com.myjeeva.digitalocean.pojo.Image>
| | listActions
| retrieve all actions that have been executed on a Image | CamelDigitalOceanId
Integer | List<com.myjeeva.digitalocean.pojo.Action>
| | get
| retrieve information about an image (public or private) by id| CamelDigitalOceanId
Integer| com.myjeeva.digitalocean.pojo.Image
| | get
| retrieve information about an public image by slug| CamelDigitalOceanDropletImage
String| com.myjeeva.digitalocean.pojo.Image
| | update
| update an image| CamelDigitalOceanId
Integer <br>`CamelDigitalOceanName` String| com.myjeeva.digitalocean.pojo.Image
| | delete
| delete an image| CamelDigitalOceanId
Integer | com.myjeeva.digitalocean.pojo.Delete
| | transfer
| transfer an image to another region| CamelDigitalOceanId
Integer <br>`CamelDigitalOceanRegion` String| com.myjeeva.digitalocean.pojo.Action
| | convert
| convert an image, for example, a backup to a snapshot| CamelDigitalOceanId
Integer | com.myjeeva.digitalocean.pojo.Action
|
82.11. Snapshots endpoint
| operation | Description | Headers | Result | | ------ | ---- | ------- | ----------- | | list
| list all of the snapshots available on your account | CamelDigitalOceanType
* DigitalOceanSnapshotTypes | List<com.myjeeva.digitalocean.pojo.Snapshot>
| | get
| retrieve information about a snapshot| CamelDigitalOceanId
Integer| com.myjeeva.digitalocean.pojo.Snapshot
| | delete
| delete an snapshot| CamelDigitalOceanId
Integer | com.myjeeva.digitalocean.pojo.Delete
|
82.12. Keys endpoint
| operation | Description | Headers | Result | | ------ | ---- | ------- | ----------- | | list
| list all of the keys in your account | | List<com.myjeeva.digitalocean.pojo.Key>
| | get
| retrieve information about a key by id| CamelDigitalOceanId
Integer| com.myjeeva.digitalocean.pojo.Key
| | get
| retrieve information about a key by fingerprint| CamelDigitalOceanKeyFingerprint
String| com.myjeeva.digitalocean.pojo.Key
| | update
| update a key by id| CamelDigitalOceanId
Integer <br>`CamelDigitalOceanName` String| com.myjeeva.digitalocean.pojo.Key
| | update
| update a key by fingerprint| CamelDigitalOceanKeyFingerprint
String <br>`CamelDigitalOceanName` String| com.myjeeva.digitalocean.pojo.Key
| | delete
| delete a key by id| CamelDigitalOceanId
Integer | com.myjeeva.digitalocean.pojo.Delete
| | delete
| delete a key by fingerprint| CamelDigitalOceanKeyFingerprint
String | com.myjeeva.digitalocean.pojo.Delete
|
82.13. Regions endpoint
| operation | Description | Headers | Result | | ------ | ---- | ------- | ----------- | | list
| list all of the regions that are available | | List<com.myjeeva.digitalocean.pojo.Region>
|
82.14. Sizes endpoint
| operation | Description | Headers | Result | | ------ | ---- | ------- | ----------- | | list
| list all of the sizes that are available | | List<com.myjeeva.digitalocean.pojo.Size>
|
82.15. Floating IPs endpoint
| operation | Description | Headers | Result | | ------ | ---- | ------- | ----------- | | list
| list all of the Floating IPs available on your account | | List<com.myjeeva.digitalocean.pojo.FloatingIP>
| | create
| create a new Floating IP assigned to a Droplet | CamelDigitalOceanId
Integer | List<com.myjeeva.digitalocean.pojo.FloatingIP>
| | create
| create a new Floating IP assigned to a Region | CamelDigitalOceanRegion
String | List<com.myjeeva.digitalocean.pojo.FloatingIP>
| | get
| retrieve information about a Floating IP| CamelDigitalOceanFloatingIPAddress
String| com.myjeeva.digitalocean.pojo.Key
| | delete
| delete a Floating IP and remove it from your account| CamelDigitalOceanFloatingIPAddress
String| com.myjeeva.digitalocean.pojo.Delete
| | assign
| assign a Floating IP to a Droplet| CamelDigitalOceanFloatingIPAddress
String <br>`CamelDigitalOceanDropletId` Integer| com.myjeeva.digitalocean.pojo.Action
| | unassign
| unassign a Floating IP | CamelDigitalOceanFloatingIPAddress
String | com.myjeeva.digitalocean.pojo.Action
| | listActions
| retrieve all actions that have been executed on a Floating IP | CamelDigitalOceanFloatingIPAddress
String | List<com.myjeeva.digitalocean.pojo.Action>
|
82.16. Tags endpoint
| operation | Description | Headers | Result | | ------ | ---- | ------- | ----------- | | list
| list all of your tags | | List<com.myjeeva.digitalocean.pojo.Tag>
| | create
| create a Tag | CamelDigitalOceanName
String | com.myjeeva.digitalocean.pojo.Tag
| | get
| retrieve an individual tag | CamelDigitalOceanName
String | com.myjeeva.digitalocean.pojo.Tag
| | delete
| delete a tag | CamelDigitalOceanName
String | com.myjeeva.digitalocean.pojo.Delete
| | update
| update a tag | CamelDigitalOceanName
String <br>`CamelDigitalOceanNewName` String| com.myjeeva.digitalocean.pojo.Tag
|
82.17. Examples
Get your account info
from("direct:getAccountInfo") .setHeader(DigitalOceanConstants.OPERATION, constant(DigitalOceanOperations.get)) .to("digitalocean:account?oAuthToken=XXXXXX")
Create a droplet
from("direct:createDroplet") .setHeader(DigitalOceanConstants.OPERATION, constant("create")) .setHeader(DigitalOceanHeaders.NAME, constant("myDroplet")) .setHeader(DigitalOceanHeaders.REGION, constant("fra1")) .setHeader(DigitalOceanHeaders.DROPLET_IMAGE, constant("ubuntu-14-04-x64")) .setHeader(DigitalOceanHeaders.DROPLET_SIZE, constant("512mb")) .to("digitalocean:droplet?oAuthToken=XXXXXX")
List all your droplets
from("direct:getDroplets") .setHeader(DigitalOceanConstants.OPERATION, constant("list")) .to("digitalocean:droplets?oAuthToken=XXXXXX")
Retrieve information for the Droplet (dropletId = 34772987)
from("direct:getDroplet") .setHeader(DigitalOceanConstants.OPERATION, constant("get")) .setHeader(DigitalOceanConstants.ID, 34772987) .to("digitalocean:droplet?oAuthToken=XXXXXX")
Shutdown information for the Droplet (dropletId = 34772987)
from("direct:shutdown") .setHeader(DigitalOceanConstants.ID, 34772987) .to("digitalocean:droplet?operation=shutdown&oAuthToken=XXXXXX")
Chapter 83. Direct Component
Available as of Camel version 1.0
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.
Asynchronous The SEDA component provides asynchronous invocation of any consumers when a producer sends a message exchange.
Connection to other camel contexts The VM component provides connections between Camel contexts as long they run in the same JVM.
83.1. URI format
direct:someName[?options]
Where someName can be any string to uniquely identify the endpoint
83.2. Options
The Direct component supports 3 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
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 |
timeout (producer) | The timeout value to use if block is enabled. | 30000 | long |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Direct endpoint is configured using URI syntax:
direct:name
with the following path and query parameters:
83.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
name | Required Name of direct endpoint | String |
83.2.2. Query Parameters (7 parameters):
Name | Description | Default | Type |
---|---|---|---|
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/ERROR level and ignored. | false | boolean |
exceptionHandler (consumer) | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions, that will be logged at WARN/ERROR level and ignored. | ExceptionHandler | |
exchangePattern (consumer) | Sets the default exchange pattern when creating an exchange. | 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. | false | boolean |
timeout (producer) | The timeout value to use if block is enabled. | 30000 | long |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
83.3. 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.
83.4. See Also
Chapter 84. Direct VM Component
Available as of Camel version 2.10
The direct-vm: component provides direct, synchronous invocation of any consumers in the JVM when a producer sends a message exchange.
This endpoint can be used to connect existing routes in the same camel context, as well from other camel contexts in the same JVM.
This component differs from the Direct component in that Direct-VM supports communication across CamelContext instances - so you can use this mechanism to communicate across web applications (provided that camel-core.jar is on the system/boot classpath).
At runtime you can swap in new consumers, by stopping the existing consumer(s) and start new consumers.
But at any given time there can be at most only one active consumer for a given endpoint.
This component allows also to connect routes deployed in different OSGI Bundles as you can see here after. Even if they are running in different bundles, the camel routes will use
the same thread. That autorises to develop applications using Transactions - Tx.
84.1. URI format
direct-vm:someName
Where someName can be any string to uniquely identify the endpoint
84.2. Options
The Direct VM component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
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 |
timeout (producer) | The timeout value to use if block is enabled. | 30000 | long |
headerFilterStrategy (advanced) | Sets a HeaderFilterStrategy that will only be applied on producer endpoints (on both directions: request and response). Default value: none. | HeaderFilterStrategy | |
propagateProperties (advanced) | Whether to propagate or not properties from the producer side to the consumer side, and vice versa. Default value: true. | true | boolean |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Direct VM endpoint is configured using URI syntax:
direct-vm:name
with the following path and query parameters:
84.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
name | Required Name of direct-vm endpoint | String |
84.2.2. Query Parameters (9 parameters):
Name | Description | Default | Type |
---|---|---|---|
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/ERROR level and ignored. | false | boolean |
exceptionHandler (consumer) | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions, that will be logged at WARN/ERROR level and ignored. | ExceptionHandler | |
exchangePattern (consumer) | Sets the default exchange pattern when creating an exchange. | 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-VM endpoint with no active consumers. | false | boolean |
timeout (producer) | The timeout value to use if block is enabled. | 30000 | long |
headerFilterStrategy (producer) | Sets a HeaderFilterStrategy that will only be applied on producer endpoints (on both directions: request and response). Default value: none. | HeaderFilterStrategy | |
propagateProperties (advanced) | Whether to propagate or not properties from the producer side to the consumer side, and vice versa. Default value: true. | true | boolean |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
84.3. 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-vm:processOrder");
And now in another CamelContext, such as another OSGi bundle
from("direct-vm: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-vm:processOrder"/> </route> <route> <from uri="direct-vm:processOrder"/> <to uri="bean:orderService?method=process"/> <to uri="activemq:queue:order.out"/> </route>
84.4. See Also
Chapter 85. Disruptor Component
Available as of Camel version 2.12
The disruptor: component provides asynchronous SEDA behavior much as the standard SEDA Component, but utilizes a Disruptor instead of a BlockingQueue utilized by the standard SEDA. Alternatively, a
disruptor-vm: endpoint is supported by this component, providing an alternative to the standard VM. As with the SEDA component, buffers of the disruptor: endpoints are only visible within a single CamelContext and no support is provided for persistence or recovery. The buffers of the disruptor-vm: endpoints also provides support for communication across CamelContexts instances so you can use this mechanism to communicate across web applications (provided that camel-disruptor.jar is on the system/boot classpath).
The main advantage of choosing to use the Disruptor Component over the SEDA or the VM Component is performance in use cases where there is high contention between producer(s) and/or multicasted or concurrent Consumers. In those cases, significant increases of throughput and reduction of latency has been observed. Performance in scenarios without contention is comparable to the SEDA and VM Components.
The Disruptor is implemented with the intention of mimicing the behaviour and options of the SEDA and VM Components as much as possible. The main differences with the them are the following:
- The buffer used is always bounded in size (default 1024 exchanges).
- As a the buffer is always bouded, the default behaviour for the Disruptor is to block while the buffer is full instead of throwing an exception. This default behaviour may be configured on the component (see options).
- The Disruptor enpoints don’t implement the BrowsableEndpoint interface. As such, the exchanges currently in the Disruptor can’t be retrieved, only the amount of exchanges.
- The Disruptor requires its consumers (multicasted or otherwise) to be statically configured. Adding or removing consumers on the fly requires complete flushing of all pending exchanges in the Disruptor.
- As a result of the reconfiguration: Data sent over a Disruptor is directly processed and 'gone' if there is at least one consumer, late joiners only get new exchanges published after they’ve joined.
- The pollTimeout option is not supported by the Disruptor Component.
- When a producer blocks on a full Disruptor, it does not respond to thread interrupts.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-disruptor</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
85.1. URI format
disruptor:someName[?options]
or
disruptor-vm:someName[?options]
Where someName can be any string that uniquely identifies the endpoint within the current CamelContext (or across contexts in case of
disruptor-vm:).
You can append query options to the URI in the following format:
?option=value&option=value&…
85.2. Options
All the following options are valid for both the disruptor: and disruptor-vm: components.
The Disruptor component supports 8 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
defaultConcurrent Consumers (consumer) | To configure the default number of concurrent consumers | 1 | int |
defaultMultiple Consumers (consumer) | To configure the default value for multiple consumers | false | boolean |
defaultProducerType (producer) | To configure the default value for DisruptorProducerType The default value is Multi. | Multi | DisruptorProducerType |
defaultWaitStrategy (consumer) | To configure the default value for DisruptorWaitStrategy The default value is Blocking. | Blocking | DisruptorWaitStrategy |
defaultBlockWhenFull (producer) | To configure the default value for block when full The default value is true. | true | boolean |
queueSize (common) | Deprecated To configure the ring buffer size | int | |
bufferSize (common) | To configure the ring buffer size | 1024 | int |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Disruptor endpoint is configured using URI syntax:
disruptor:name
with the following path and query parameters:
85.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
name | Required Name of queue | String |
85.2.2. Query Parameters (12 parameters):
Name | Description | Default | Type |
---|---|---|---|
size (common) | The maximum capacity of the Disruptors ringbuffer Will be effectively increased to the nearest power of two. Notice: Mind if you use this option, then its the first endpoint being created with the queue name, that determines the size. To make sure all endpoints use same size, then configure the size option on all of them, or the first endpoint being created. | 1024 | int |
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) | Number of concurrent threads processing exchanges. | 1 | int |
multipleConsumers (consumer) | Specifies whether multiple consumers are allowed. If enabled, you can use Disruptor for Publish-Subscribe messaging. That is, you can send a message to the queue and have each consumer receive a copy of the message. When enabled, this option should be specified on every consumer endpoint. | false | boolean |
waitStrategy (consumer) | Defines the strategy used by consumer threads to wait on new exchanges to be published. The options allowed are:Blocking, Sleeping, BusySpin and Yielding. | Blocking | DisruptorWaitStrategy |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
blockWhenFull (producer) | Whether a thread that sends messages to a full Disruptor will block until the ringbuffer’s capacity is no longer exhausted. By default, the calling thread will block and wait until the message can be accepted. By disabling this option, an exception will be thrown stating that the queue is full. | false | boolean |
producerType (producer) | Defines the producers allowed on the Disruptor. The options allowed are: Multi to allow multiple producers and Single to enable certain optimizations only allowed when one concurrent producer (on one thread or otherwise synchronized) is active. | Multi | DisruptorProducerType |
timeout (producer) | Timeout (in milliseconds) before a producer will stop waiting for an asynchronous task to complete. You can disable timeout by using 0 or a negative value. | 30000 | long |
waitForTaskToComplete (producer) | Option to specify whether the caller should wait for the async task to complete or not before continuing. The following three options are supported: Always, Never or IfReplyExpected. The first two values are self-explanatory. The last value, IfReplyExpected, will only wait if the message is Request Reply based. | IfReplyExpected | WaitForTaskToComplete |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
85.3. Spring Boot Auto-Configuration
The component supports 18 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.disruptor-vm.buffer-size | To configure the ring buffer size | 1024 | Integer |
camel.component.disruptor-vm.default-block-when-full | To configure the default value for block when full The default value is true. | true | Boolean |
camel.component.disruptor-vm.default-concurrent-consumers | To configure the default number of concurrent consumers | 1 | Integer |
camel.component.disruptor-vm.default-multiple-consumers | To configure the default value for multiple consumers | false | Boolean |
camel.component.disruptor-vm.default-producer-type | To configure the default value for DisruptorProducerType The default value is Multi. | DisruptorProducerType | |
camel.component.disruptor-vm.default-wait-strategy | To configure the default value for DisruptorWaitStrategy The default value is Blocking. | DisruptorWaitStrategy | |
camel.component.disruptor-vm.enabled | Enable disruptor-vm component | true | Boolean |
camel.component.disruptor-vm.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.disruptor.buffer-size | To configure the ring buffer size | 1024 | Integer |
camel.component.disruptor.default-block-when-full | To configure the default value for block when full The default value is true. | true | Boolean |
camel.component.disruptor.default-concurrent-consumers | To configure the default number of concurrent consumers | 1 | Integer |
camel.component.disruptor.default-multiple-consumers | To configure the default value for multiple consumers | false | Boolean |
camel.component.disruptor.default-producer-type | To configure the default value for DisruptorProducerType The default value is Multi. | DisruptorProducerType | |
camel.component.disruptor.default-wait-strategy | To configure the default value for DisruptorWaitStrategy The default value is Blocking. | DisruptorWaitStrategy | |
camel.component.disruptor.enabled | Enable disruptor component | true | Boolean |
camel.component.disruptor.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.disruptor-vm.queue-size | To configure the ring buffer size | Integer | |
camel.component.disruptor.queue-size | To configure the ring buffer size | Integer |
85.4. Wait strategies
The wait strategy effects the type of waiting performed by the consumer threads that are currently waiting for the next exchange to be published. The following strategies can be chosen:
Name | Description | Advice |
---|---|---|
Blocking | Blocking strategy that uses a lock and condition variable for Consumers waiting on a barrier. | This strategy can be used when throughput and low-latency are not as important as CPU resource. |
Sleeping | Sleeping strategy that initially spins, then uses a Thread.yield(), and eventually for the minimum number of nanos the OS and JVM will allow while the Consumers are waiting on a barrier. | This strategy is a good compromise between performance and CPU resource. Latency spikes can occur after quiet periods. |
BusySpin | Busy Spin strategy that uses a busy spin loop for Consumers waiting on a barrier. | This strategy will use CPU resource to avoid syscalls which can introduce latency jitter. It is best used when threads can be bound to specific CPU cores. |
Yielding | Yielding strategy that uses a Thread.yield() for Consumers waiting on a barrier after an initially spinning. | This strategy is a good compromise between performance and CPU resource without incurring significant latency spikes. |
85.5. Use of Request Reply
The Disruptor component supports using Request Reply, where the caller will wait for the Async route to complete. For instance:
from("mina:tcp://0.0.0.0:9876?textline=true&sync=true").to("disruptor:input"); from("disruptor:input").to("bean:processInput").to("bean:createResponse");
In the route above, we have a TCP listener on port 9876 that accepts incoming requests. The request is routed to the disruptor:input buffer. As it is a Request Reply message, we wait for the response. When the consumer on the disruptor:input buffer is complete, it copies the response to the original message response.
85.6. Concurrent consumers
By default, the Disruptor endpoint uses a single consumer thread, but you can configure it to use concurrent consumer threads. So instead of thread pools you can use:
from("disruptor:stageName?concurrentConsumers=5").process(...)
As for the difference between the two, note a thread pool can increase/shrink dynamically at runtime depending on load, whereas the number of concurrent consumers is always fixed and supported by the Disruptor internally so performance will be higher.
85.7. Thread pools
Be aware that adding a thread pool to a Disruptor endpoint by doing something like:
from("disruptor:stageName").thread(5).process(...)
Can wind up with adding a normal BlockingQueue to be used in conjunction with the Disruptor, effectively negating part of the performance gains achieved by using the Disruptor. Instead, it is advices to directly configure number of threads that process messages on a Disruptor endpoint using the concurrentConsumers option.
85.8. Sample
In the route below we use the Disruptor to send the request to this async queue to be able to send a fire-and-forget message for further processing in another thread, and return a constant reply in this thread to the original caller.
public void configure() throws Exception { from("direct:start") // send it to the disruptor that is async .to("disruptor:next") // return a constant response .transform(constant("OK")); from("disruptor:next").to("mock:result"); }
Here we send a Hello World message and expects the reply to be OK.
Object out = template.requestBody("direct:start", "Hello World"); assertEquals("OK", out);
The "Hello World" message will be consumed from the Disruptor from another thread for further processing. Since this is from a unit test, it will be sent to a mock endpoint where we can do assertions in the unit test.
85.9. Using multipleConsumers
In this example we have defined two consumers and registered them as spring beans.
<!-- define the consumers as spring beans --> <bean id="consumer1" class="org.apache.camel.spring.example.FooEventConsumer"/> <bean id="consumer2" class="org.apache.camel.spring.example.AnotherFooEventConsumer"/> <camelContext xmlns="http://camel.apache.org/schema/spring"> <!-- define a shared endpoint which the consumers can refer to instead of using url --> <endpoint id="foo" uri="disruptor:foo?multipleConsumers=true"/> </camelContext>
Since we have specified multipleConsumers=true on the Disruptor foo endpoint we can have those two or more consumers receive their own copy of the message as a kind of pub-sub style messaging. As the beans are part of an unit test they simply send the message to a mock endpoint, but notice how we can use @Consume to consume from the Disruptor.
public class FooEventConsumer { @EndpointInject(uri = "mock:result") private ProducerTemplate destination; @Consume(ref = "foo") public void doSomething(String body) { destination.sendBody("foo" + body); } }
85.10. Extracting disruptor information
If needed, information such as buffer size, etc. can be obtained without using JMX in this fashion:
DisruptorEndpoint disruptor = context.getEndpoint("disruptor:xxxx"); int size = disruptor.getBufferSize();
Chapter 86. DNS Component
Available as of Camel version 2.7
This is an additional component for Camel to run DNS queries, using DNSJava. The component is a thin layer on top of DNSJava.
The component offers the following operations:
- ip, to resolve a domain by its ip
- lookup, to lookup information about the domain
- dig, to run DNS queries
INFO:*Requires SUN JVM* The DNSJava library requires running on the SUN JVM.
If you use Apache ServiceMix or Apache Karaf, you’ll need to adjust the etc/jre.properties
file, to add sun.net.spi.nameservice
to the list of Java platform packages exported. The server will need restarting before this change takes effect.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-dns</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
86.1. URI format
The URI scheme for a DNS component is as follows
dns://operation[?options]
This component only supports producers.
86.2. Options
The DNS component has no options.
The DNS endpoint is configured using URI syntax:
dns:dnsType
with the following path and query parameters:
86.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
dnsType | Required The type of the lookup. | DnsType |
86.2.2. Query Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
86.3. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.dns.enabled | Enable dns component | true | Boolean |
camel.component.dns.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
86.4. Headers
Header | Type | Operations | Description |
---|---|---|---|
dns.domain | String | ip | The domain name. Mandatory. |
dns.name | String | lookup | The name to lookup. Mandatory. |
dns.type | lookup, dig |
The type of the lookup. Should match the values of | |
dns.class | lookup, dig |
The DNS class of the lookup. Should match the values of | |
dns.query | String | dig | The query itself. Mandatory. |
dns.server | String | dig | The server in particular for the query. If none is given, the default one specified by the OS will be used. Optional. |
86.5. Examples
86.5.1. IP lookup
<route id="IPCheck"> <from uri="direct:start"/> <to uri="dns:ip"/> </route>
This looks up a domain’s IP. For example, www.example.com resolves to 192.0.32.10.
The IP address to lookup must be provided in the header with key "dns.domain"
.
86.5.2. DNS lookup
<route id="IPCheck"> <from uri="direct:start"/> <to uri="dns:lookup"/> </route>
This returns a set of DNS records associated with a domain.
The name to lookup must be provided in the header with key "dns.name"
.
86.5.3. DNS Dig
Dig is a Unix command-line utility to run DNS queries.
<route id="IPCheck"> <from uri="direct:start"/> <to uri="dns:dig"/> </route>
The query must be provided in the header with key "dns.query"
.
86.6. Dns Activation Policy
DnsActivationPolicy can be used to dynamically start and stop routes based on dns state.
If you have instances of the same component running in different regions you can configure a route in each region to activate only if dns is pointing to its region.
i.e. You may have an instance in NYC and an instance in SFO. You would configure a service CNAME service.example.com to point to nyc-service.example.com to bring NYC instance up and SFO instance down. When you change the CNAME service.example.com to point to sfo-service.example.com — nyc instance would stop its routes and sfo will bring its routes up. This allows you to switch regions without restarting actual components.
<bean id="dnsActivationPolicy" class="org.apache.camel.component.dns.policy.DnsActivationPolicy"> <property name="hostname" value="service.example.com" /> <property name="resolvesTo" value="nyc-service.example.com" /> <property name="ttl" value="60000" /> <property name="stopRoutesOnException" value="false" /> </bean> <route id="routeId" autoStartup="false" routePolicyRef="dnsActivationPolicy"> </route>
Chapter 87. Docker Component
Available as of Camel version 2.15
Camel component for communicating with Docker.
The Docker Camel component leverages the docker-java via the Docker Remote API.
87.1. URI format
docker://[operation]?[options]
Where operation is the specific action to perform on Docker.
87.2. General Options
The Docker component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | To use the shared docker configuration | DockerConfiguration | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Docker endpoint is configured using URI syntax:
docker:operation
with the following path and query parameters:
87.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
operation | Required Which operation to use | DockerOperation |
87.2.2. Query Parameters (20 parameters):
Name | Description | Default | Type |
---|---|---|---|
email (common) | Email address associated with the user | String | |
host (common) | Required Docker host | localhost | String |
port (common) | Required Docker port | 2375 | Integer |
requestTimeout (common) | Request timeout for response (in seconds) | Integer | |
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) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
cmdExecFactory (advanced) | The fully qualified class name of the DockerCmdExecFactory implementation to use | com.github.dockerjava.netty.NettyDockerCmdExecFactory | String |
followRedirectFilter (advanced) | Whether to follow redirect filter | false | boolean |
loggingFilter (advanced) | Whether to use logging filter | false | boolean |
maxPerRouteConnections (advanced) | Maximum route connections | 100 | Integer |
maxTotalConnections (advanced) | Maximum total connections | 100 | Integer |
serverAddress (advanced) | Server address for docker registry. | String | |
socket (advanced) | Socket connection mode | true | boolean |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
certPath (security) | Location containing the SSL certificate chain | String | |
password (security) | Password to authenticate with | String | |
secure (security) | Use HTTPS communication | false | boolean |
tlsVerify (security) | Check TLS | false | boolean |
username (security) | User name to authenticate with | String |
87.3. Spring Boot Auto-Configuration
The component supports 20 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.docker.configuration.cert-path | Location containing the SSL certificate chain | String | |
camel.component.docker.configuration.cmd-exec-factory | The fully qualified class name of the DockerCmdExecFactory implementation to use | com.github.dockerjava.netty.NettyDockerCmdExecFactory | String |
camel.component.docker.configuration.email | Email address associated with the user | String | |
camel.component.docker.configuration.follow-redirect-filter | Whether to follow redirect filter | false | Boolean |
camel.component.docker.configuration.host | Docker host | localhost | String |
camel.component.docker.configuration.logging-filter | Whether to use logging filter | false | Boolean |
camel.component.docker.configuration.max-per-route-connections | Maximum route connections | 100 | Integer |
camel.component.docker.configuration.max-total-connections | Maximum total connections | 100 | Integer |
camel.component.docker.configuration.operation | Which operation to use | DockerOperation | |
camel.component.docker.configuration.parameters | Additional configuration parameters as key/value pairs | Map | |
camel.component.docker.configuration.password | Password to authenticate with | String | |
camel.component.docker.configuration.port | Docker port | 2375 | Integer |
camel.component.docker.configuration.request-timeout | Request timeout for response (in seconds) | Integer | |
camel.component.docker.configuration.secure | Use HTTPS communication | false | Boolean |
camel.component.docker.configuration.server-address | Server address for docker registry. | String | |
camel.component.docker.configuration.socket | Socket connection mode | true | Boolean |
camel.component.docker.configuration.tls-verify | Check TLS | false | Boolean |
camel.component.docker.configuration.username | User name to authenticate with | String | |
camel.component.docker.enabled | Enable docker component | true | Boolean |
camel.component.docker.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
87.4. Header Strategy
All URI option can be passed as Header properties. Values found in a message header take precedence over URI parameters. A header property takes the form of a URI option prefixed with CamelDocker as shown below
URI Option | Header Property |
---|---|
containerId | CamelDockerContainerId |
87.5. Examples
The following example consumes events from Docker:
from("docker://events?host=192.168.59.103&port=2375").to("log:event");
The following example queries Docker for system wide information
from("docker://info?host=192.168.59.103&port=2375").to("log:info");
87.6. Dependencies
To use Docker in your Camel routes you need to add a dependency on camel-docker, which implements the component.
If you use Maven you can just add the following to your pom.xml, substituting the version number for the latest and greatest release (see the download page for the latest versions).
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-docker</artifactId> <version>x.x.x</version> </dependency>
Chapter 88. Dozer Component
Available as of Camel version 2.15
The dozer: component provides the ability to map between Java beans using the Dozer mapping framework since Camel 2.15.0. Camel also supports the ability to trigger Dozer mappings as a type converter. The primary differences between using a Dozer endpoint and a Dozer converter are:
- The ability to manage Dozer mapping configuration on a per-endpoint basis vs. global configuration via the converter registry.
- A Dozer endpoint can be configured to marshal/unmarshal input and output data using Camel data formats to support a single, any-to-any transformation endpoint
- The Dozer component allows for fine-grained integration and extension of Dozer to support additional functionality (e.g. mapping literal values, using expressions for mappings, etc.).
In order to use the Dozer component, Maven users will need to add the following dependency to their pom.xml
:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-dozer</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
88.1. URI format
The Dozer component only supports producer endpoints.
dozer:endpointId[?options]
Where endpointId is a name used to uniquely identify the Dozer endpoint configuration.
An example Dozer endpoint URI:
from("direct:orderInput"). to("dozer:transformOrder?mappingFile=orderMapping.xml&targetModel=example.XYZOrder"). to("direct:orderOutput");
88.2. Options
The Dozer component has no options.
The Dozer endpoint is configured using URI syntax:
dozer:name
with the following path and query parameters:
88.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
name | Required A human readable name of the mapping. | String |
88.2.2. Query Parameters (7 parameters):
Name | Description | Default | Type |
---|---|---|---|
mappingConfiguration (producer) | The name of a DozerBeanMapperConfiguration bean in the Camel registry which should be used for configuring the Dozer mapping. This is an alternative to the mappingFile option that can be used for fine-grained control over how Dozer is configured. Remember to use a # prefix in the value to indicate that the bean is in the Camel registry (e.g. #myDozerConfig). | DozerBeanMapper Configuration | |
mappingFile (producer) | The location of a Dozer configuration file. The file is loaded from the classpath by default, but you can use file:, classpath:, or http: to load the configuration from a specific location. | dozerBeanMapping.xml | String |
marshalId (producer) | The id of a dataFormat defined within the Camel Context to use for marshalling the mapping output to a non-Java type. | String | |
sourceModel (producer) | Fully-qualified class name for the source type used in the mapping. If specified, the input to the mapping is converted to the specified type before being mapped with Dozer. | String | |
targetModel (producer) | Required Fully-qualified class name for the target type used in the mapping. | String | |
unmarshalId (producer) | The id of a dataFormat defined within the Camel Context to use for unmarshalling the mapping input from a non-Java type. | String | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
88.3. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.dozer.enabled | Enable dozer component | true | Boolean |
camel.component.dozer.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
88.4. Using Data Formats with Dozer
Dozer does not support non-Java sources and targets for mappings, so it cannot, for example, map an XML document to a Java object on its own. Luckily, Camel has extensive support for marshalling between Java and a wide variety of formats using data formats. The Dozer component takes advantage of this support by allowing you to specify that input and output data should be passed through a data format prior to processing via Dozer. You can always do this on your own outside the call to Dozer, but supporting it directly in the Dozer component allows you to use a single endpoints to configure any-to-any transformation within Camel.
As an example, let’s say you wanted to map between an XML data structure and a JSON data structure using the Dozer component. If you had the following data formats defined in a Camel Context:
<dataFormats> <json library="Jackson" id="myjson"/> <jaxb contextPath="org.example" id="myjaxb"/> </dataFormats>
You could then configure a Dozer endpoint to unmarshal the input XML using a JAXB data format and marshal the mapping output using Jackson.
<endpoint uri="dozer:xml2json?marshalId=myjson&unmarshalId=myjaxb&targetModel=org.example.Order"/>
88.5. Configuring Dozer
All Dozer endpoints require a Dozer mapping configuration file which defines mappings between source and target objects. The component will default to a location of META-INF/dozerBeanMapping.xml if the mappingFile or mappingConfiguration options are not specified on an endpoint. If you need to supply multiple mapping configuration files for a single endpoint or specify additional configuration options (e.g. event listeners, custom converters, etc.), then you can use an instance of org.apache.camel.converter.dozer.DozerBeanMapperConfiguration
.
<bean id="mapper" class="org.apache.camel.converter.dozer.DozerBeanMapperConfiguration"> <property name="mappingFiles"> <list> <value>mapping1.xml</value> <value>mapping2.xml</value> </list> </property> </bean>
88.6. Mapping Extensions
The Dozer component implements a number of extensions to the Dozer mapping framework as custom converters. These converters implement mapping functions that are not supported directly by Dozer itself.
88.6.1. Variable Mappings
Variable mappings allow you to map the value of a variable definition within a Dozer configuration into a target field instead of using the value of a source field. This is equivalent to constant mapping in other mapping frameworks, where can you assign a literal value to a target field. To use a variable mapping, simply define a variable within your mapping configuration and then map from the VariableMapper class into your target field of choice:
<mappings xmlns="http://dozermapper.github.io/schema/bean-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://dozermapper.github.io/schema/bean-mapping http://dozermapper.github.io/schema/bean-mapping.xsd"> <configuration> <variables> <variable name="CUST_ID">ACME-SALES</variable> </variables> </configuration> <mapping> <class-a>org.apache.camel.component.dozer.VariableMapper</class-a> <class-b>org.example.Order</class-b> <field custom-converter-id="_variableMapping" custom-converter-param="${CUST_ID}"> <a>literal</a> <b>custId</b> </field> </mapping> </mappings>
88.6.2. Custom Mappings
Custom mappings allow you to define your own logic for how a source field is mapped to a target field. They are similar in function to Dozer customer converters, with two notable differences:
- You can have multiple converter methods in a single class with custom mappings.
- There is no requirement to implement a Dozer-specific interface with custom mappings.
A custom mapping is declared by using the built-in '_customMapping' converter in your mapping configuration. The parameter to this converter has the following syntax:
[class-name][,method-name]
Method name is optional - the Dozer component will search for a method that matches the input and output types required for a mapping. An example custom mapping and configuration are provided below.
public class CustomMapper { // All customer ids must be wrapped in "[ ]" public Object mapCustomer(String customerId) { return "[" + customerId + "]"; } }
<mappings xmlns="http://dozermapper.github.io/schema/bean-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://dozermapper.github.io/schema/bean-mapping http://dozermapper.github.io/schema/bean-mapping.xsd"> <mapping> <class-a>org.example.A</class-a> <class-b>org.example.B</class-b> <field custom-converter-id="_customMapping" custom-converter-param="org.example.CustomMapper,mapCustomer"> <a>header.customerNum</a> <b>custId</b> </field> </mapping> </mappings>
88.6.3. Expression Mappings
Expression mappings allow you to use the powerful language capabilities of Camel to evaluate an expression and assign the result to a target field in a mapping. Any language that Camel supports can be used in an expression mapping. Basic examples of expressions include the ability to map a Camel message header or exchange property to a target field or to concatenate multiple source fields into a target field. The syntax of a mapping expression is:
[language]:[expression]
An example of mapping a message header into a target field:
<mappings xmlns="http://dozermapper.github.io/schema/bean-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://dozermapper.github.io/schema/bean-mapping http://dozermapper.github.io/schema/bean-mapping.xsd"> <mapping> <class-a>org.apache.camel.component.dozer.ExpressionMapper</class-a> <class-b>org.example.B</class-b> <field custom-converter-id="_expressionMapping" custom-converter-param="simple:\${header.customerNumber}"> <a>expression</a> <b>custId</b> </field> </mapping> </mappings>
Note that any properties within your expression must be escaped with "\" to prevent an error when Dozer attempts to resolve variable values defined using the EL.
Chapter 89. Drill Component
Available as of Camel version 2.19
The drill: component gives you the ability to querying to Apache Drill Cluster
Drill is an Apache open-source SQL query engine for Big Data exploration. Drill is designed from the ground up to support high-performance analysis on the semi-structured and rapidly evolving data coming from modern Big Data applications, while still providing the familiarity and ecosystem of ANSI SQL, the industry-standard query language
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-drill</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
89.1. URI format
drill://host[?options]
You can append query options to the URI in the following format, ?option=value&option=value&…
89.2. Drill Producer
The producer execute query using CamelDrillQuery header and put results into body.
89.3. Options
The Drill component has no options.
The Drill endpoint is configured using URI syntax:
drill:host
with the following path and query parameters:
89.3.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
host | Required ZooKeeper host name or IP address. Use local instead of a host name or IP address to connect to the local Drillbit | String |
89.3.2. Query Parameters (5 parameters):
Name | Description | Default | Type |
---|---|---|---|
clusterId (producer) | Cluster ID https://drill.apache.org/docs/using-the-jdbc-driver/#determining-the-cluster-id | String | |
directory (producer) | Drill directory in ZooKeeper | String | |
mode (producer) | Connection mode: zk: Zookeeper drillbit: Drillbit direct connection https://drill.apache.org/docs/using-the-jdbc-driver/ | ZK | DrillConnectionMode |
port (producer) | ZooKeeper port number | Integer | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
89.4. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.drill.enabled | Enable drill component | true | Boolean |
camel.component.drill.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
89.5. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 90. Dropbox Component
Available as of Camel version 2.14
The dropbox: component allows you to treat Dropbox remote folders as a producer or consumer of messages. Using the Dropbox Java Core API (reference version for this component is 1.7.x), this camel component has the following features:
- As a consumer, download files and search files by queries
- As a producer, download files, move files between remote directories, delete files/dir, upload files and search files by queries
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-dropbox</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
90.1. URI format
dropbox://[operation]?[options]
Where operation is the specific action (typically is a CRUD action) to perform on Dropbox remote folder.
90.2. Operations
Operation | Description |
---|---|
| deletes files or directories on Dropbox |
| download files from Dropbox |
| move files from folders on Dropbox |
| upload files on Dropbox |
| search files on Dropbox based on string queries |
Operations require additional options to work, some are mandatory for the specific operation.
90.3. Options
In order to work with Dropbox API you need to obtain an accessToken and a clientIdentifier.
You can refer to the Dropbox documentation that explains how to get them.
The Dropbox component has no options.
The Dropbox endpoint is configured using URI syntax:
dropbox:operation
with the following path and query parameters:
90.3.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
operation | Required The specific action (typically is a CRUD action) to perform on Dropbox remote folder. | DropboxOperation |
90.3.2. Query Parameters (12 parameters):
Name | Description | Default | Type |
---|---|---|---|
accessToken (common) | Required The access token to make API requests for a specific Dropbox user | String | |
client (common) | To use an existing DbxClient instance as DropBox client. | DbxClientV2 | |
clientIdentifier (common) | Name of the app registered to make API requests | String | |
localPath (common) | Optional folder or file to upload on Dropbox from the local filesystem. If this option has not been configured then the message body is used as the content to upload. | String | |
newRemotePath (common) | Destination file or folder | String | |
query (common) | A space-separated list of sub-strings to search for. A file matches only if it contains all the sub-strings. If this option is not set, all files will be matched. | String | |
remotePath (common) | Original file or folder to move | String | |
uploadMode (common) | Which mode to upload. in case of add the new file will be renamed if a file with the same name already exists on dropbox. in case of force if a file with the same name already exists on dropbox, this will be overwritten. | DropboxUploadMode | |
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) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
90.4. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.dropbox.enabled | Enable dropbox component | true | Boolean |
camel.component.dropbox.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
90.5. Del operation
Delete files on Dropbox.
Works only as Camel producer.
Below are listed the options for this operation:
Property | Mandatory | Description |
---|---|---|
|
| Folder or file to delete on Dropbox |
90.5.1. Samples
from("direct:start") .to("dropbox://del?accessToken=XXX&clientIdentifier=XXX&remotePath=/root/folder1") .to("mock:result"); from("direct:start") .to("dropbox://del?accessToken=XXX&clientIdentifier=XXX&remotePath=/root/folder1/file1.tar.gz") .to("mock:result");
90.5.2. Result Message Headers
The following headers are set on message result:
Property | Value |
---|---|
| name of the path deleted on dropbox |
90.5.3. Result Message Body
The following objects are set on message body result:
Object type | Description |
---|---|
| name of the path deleted on dropbox |
90.6. Get (download) operation
Download files from Dropbox.
Works as Camel producer or Camel consumer.
Below are listed the options for this operation:
Property | Mandatory | Description |
---|---|---|
|
| Folder or file to download from Dropbox |
90.6.1. Samples
from("direct:start") .to("dropbox://get?accessToken=XXX&clientIdentifier=XXX&remotePath=/root/folder1/file1.tar.gz") .to("file:///home/kermit/?fileName=file1.tar.gz"); from("direct:start") .to("dropbox://get?accessToken=XXX&clientIdentifier=XXX&remotePath=/root/folder1") .to("mock:result"); from("dropbox://get?accessToken=XXX&clientIdentifier=XXX&remotePath=/root/folder1") .to("file:///home/kermit/");
90.6.2. Result Message Headers
The following headers are set on message result:
Property | Value |
---|---|
| in case of single file download, path of the remote file downloaded |
| in case of multiple files download, path of the remote files downloaded |
90.6.3. Result Message Body
The following objects are set on message body result:
Object type | Description |
---|---|
| in case of single file download, stream representing the file downloaded |
| in case of multiple files download, a map with as key the path of the remote file downloaded and as value the stream representing the file downloaded |
90.7. Move operation
Move files on Dropbox between one folder to another.
Works only as Camel producer.
Below are listed the options for this operation:
Property | Mandatory | Description |
---|---|---|
|
| Original file or folder to move |
|
| Destination file or folder |
90.7.1. Samples
from("direct:start") .to("dropbox://move?accessToken=XXX&clientIdentifier=XXX&remotePath=/root/folder1&newRemotePath=/root/folder2") .to("mock:result");
90.7.2. Result Message Headers
The following headers are set on message result:
Property | Value |
---|---|
| name of the path moved on dropbox |
90.7.3. Result Message Body
The following objects are set on message body result:
Object type | Description |
---|---|
| name of the path moved on dropbox |
90.8. Put (upload) operation
Upload files on Dropbox.
Works as Camel producer.
Below are listed the options for this operation:
Property | Mandatory | Description |
---|---|---|
|
| add or force this option specifies how a file should be saved on dropbox: in case of "add" the new file will be renamed if a file with the same name already exists on dropbox. In case of "force" if a file with the same name already exists on dropbox, this will be overwritten. |
|
| Folder or file to upload on Dropbox from the local filesystem. If this option has been configured then it takes precedence over uploading as a single file with content from the Camel message body (message body is converted into a byte array). |
|
| Folder destination on Dropbox. If the property is not set, the component will upload the file on a remote path equal to the local path. With Windows or without an absolute localPath you may run into an exception like the following:
Caused by: java.lang.IllegalArgumentException: 'path': bad path: must start with "/": "C:/My/File" |
90.8.1. Samples
from("direct:start").to("dropbox://put?accessToken=XXX&clientIdentifier=XXX&uploadMode=add&localPath=/root/folder1") .to("mock:result"); from("direct:start").to("dropbox://put?accessToken=XXX&clientIdentifier=XXX&uploadMode=add&localPath=/root/folder1&remotePath=/root/folder2") .to("mock:result");
And to upload a single file with content from the message body
from("direct:start") .setHeader(DropboxConstants.HEADER_PUT_FILE_NAME, constant("myfile.txt")) .to("dropbox://put?accessToken=XXX&clientIdentifier=XXX&uploadMode=add&remotePath=/root/folder2") .to("mock:result");
The name of the file can be provided in the header DropboxConstants.HEADER_PUT_FILE_NAME
or Exchange.FILE_NAME
in that order of precedence. If no header has been provided then the message id (uuid) is used as the file name.
90.8.2. Result Message Headers
The following headers are set on message result:
Property | Value |
---|---|
| in case of single file upload, path of the remote path uploaded |
| in case of multiple files upload, string with the remote paths uploaded |
90.8.3. Result Message Body
The following objects are set on message body result:
Object type | Description |
---|---|
| in case of single file upload, result of the upload operation, OK or KO |
| in case of multiple files upload, a map with as key the path of the remote file uploaded and as value the result of the upload operation, OK or KO |
90.9. Search operation
Search inside a remote Dropbox folder including its sub directories.
Works as Camel producer and as Camel consumer.
Below are listed the options for this operation:
Property | Mandatory | Description |
---|---|---|
|
| Folder on Dropbox where to search in. |
|
|
A space-separated list of sub-strings to search for. A file matches only if it contains all the sub-strings. If this option is not set, all files will be matched. The query is required to be provided in either the endpoint configuration or as a header |
90.9.1. Samples
from("dropbox://search?accessToken=XXX&clientIdentifier=XXX&remotePath=/XXX&query=XXX") .to("mock:result"); from("direct:start") .setHeader("CamelDropboxQuery", constant("XXX")) .to("dropbox://search?accessToken=XXX&clientIdentifier=XXX&remotePath=/XXX") .to("mock:result");
90.9.2. Result Message Headers
The following headers are set on message result:
Property | Value |
---|---|
| list of file path founded |
90.9.3. Result Message Body
The following objects are set on message body result:
Object type | Description |
---|---|
| list of file path founded. For more information on this object refer to Dropbox documentation, |
Chapter 91. Ehcache Component
Available as of Camel version 2.18
The ehcache component enables you to perform caching operations using Ehcache 3 as the Cache Implementation.
This component supports producer and event based consumer endpoints.
The Cache consumer is an event based consumer and can be used to listen and respond to specific cache activities.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-ehcache</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
91.1. URI format
ehcache://cacheName[?options]
You can append query options to the URI in the following format, ?option=value&option=#beanRef&…
91.2. Options
The Ehcache component supports 7 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | Sets the global component configuration | EhcacheConfiguration | |
cacheManager (common) | The cache manager | CacheManager | |
cacheManager Configuration (common) | The cache manager configuration | Configuration | |
cacheConfiguration (common) | The default cache configuration to be used to create caches. | CacheConfiguration | |
cachesConfigurations (common) | A map of caches configurations to be used to create caches. | Map | |
cacheConfigurationUri (common) | URI pointing to the Ehcache XML configuration file’s location | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Ehcache endpoint is configured using URI syntax:
ehcache:cacheName
with the following path and query parameters:
91.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
cacheName | Required the cache name | String |
91.2.2. Query Parameters (17 parameters):
Name | Description | Default | Type |
---|---|---|---|
cacheManager (common) | The cache manager | CacheManager | |
cacheManagerConfiguration (common) | The cache manager configuration | Configuration | |
configurationUri (common) | URI pointing to the Ehcache XML configuration file’s location | String | |
createCacheIfNotExist (common) | Configure if a cache need to be created if it does exist or can’t be pre-configured. | true | 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 |
eventFiring (consumer) | Set the delivery mode (synchronous, asynchronous) | ASYNCHRONOUS | EventFiring |
eventOrdering (consumer) | Set the delivery mode (ordered, unordered) | ORDERED | EventOrdering |
eventTypes (consumer) | Set the type of events to listen for | EVICTED,EXPIRED,REMOVED,CREATED,UPDATED | Set |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
action (producer) | To configure the default cache action. If an action is set in the message header, then the operation from the header takes precedence. | String | |
key (producer) | To configure the default action key. If a key is set in the message header, then the key from the header takes precedence. | Object | |
configuration (advanced) | The default cache configuration to be used to create caches. | CacheConfiguration | |
configurations (advanced) | A map of cache configuration to be used to create caches. | Map | |
keyType (advanced) | The cache key type, default java.lang.Object | java.lang.Object | String |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
valueType (advanced) | The cache value type, default java.lang.Object | java.lang.Object | String |
91.3. Spring Boot Auto-Configuration
The component supports 25 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.ehcache.cache-configuration | The default cache configuration to be used to create caches. The option is a org.ehcache.config.CacheConfiguration<?,?> type. | String | |
camel.component.ehcache.cache-configuration-uri | URI pointing to the Ehcache XML configuration file’s location | String | |
camel.component.ehcache.cache-manager | The cache manager. The option is a org.ehcache.CacheManager type. | String | |
camel.component.ehcache.cache-manager-configuration | The cache manager configuration. The option is a org.ehcache.config.Configuration type. | String | |
camel.component.ehcache.caches-configurations | A map of caches configurations to be used to create caches. | Map | |
camel.component.ehcache.configuration.action | To configure the default cache action. If an action is set in the message header, then the operation from the header takes precedence. | String | |
camel.component.ehcache.configuration.cache-manager | The cache manager | CacheManager | |
camel.component.ehcache.configuration.cache-manager-configuration | The cache manager configuration | Configuration | |
camel.component.ehcache.configuration.configuration | The default cache configuration to be used to create caches. | CacheConfiguration | |
camel.component.ehcache.configuration.configuration-uri | URI pointing to the Ehcache XML configuration file’s location | String | |
camel.component.ehcache.configuration.configurations | A map of cache configuration to be used to create caches. | Map | |
camel.component.ehcache.configuration.create-cache-if-not-exist | Configure if a cache need to be created if it does exist or can’t be pre-configured. | true | Boolean |
camel.component.ehcache.configuration.event-firing | Set the delivery mode (synchronous, asynchronous) | EventFiring | |
camel.component.ehcache.configuration.event-ordering | Set the delivery mode (ordered, unordered) | EventOrdering | |
camel.component.ehcache.configuration.event-types | Set the type of events to listen for | Set | |
camel.component.ehcache.configuration.key | To configure the default action key. If a key is set in the message header, then the key from the header takes precedence. | Object | |
camel.component.ehcache.configuration.key-type | The cache key type, default java.lang.Object | java.lang.Object | String |
camel.component.ehcache.configuration.value-type | The cache value type, default java.lang.Object | java.lang.Object | String |
camel.component.ehcache.customizer.cache-configuration.enabled | Enable or disable the cache-configuration customizer. | true | Boolean |
camel.component.ehcache.customizer.cache-configuration.mode | Configure if the cache configurations have be added or they have to replace those already configured on the component. | CacheConfiguration CustomizerConfiguration$ Mode | |
camel.component.ehcache.customizer.cache-manager.enabled | Enable or disable the cache-manager customizer. | true | Boolean |
camel.component.ehcache.customizer.cache-manager.override | Configure if the cache manager eventually set on the component should be overridden by the customizer. | false | Boolean |
camel.component.ehcache.enabled | Enable ehcache component | true | Boolean |
camel.component.ehcache.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.ehcache.configuration.config-uri (DEPRECATED - Use | URI pointing to the Ehcache XML configuration file’s location | String |
91.3.1. Message Headers Camel
Header | Type | Description |
---|---|---|
CamelEhcacheAction |
| The operation to be perfomed on the cache, valid options are: * CLEAR * PUT * PUT_ALL * PUT_IF_ABSENT * GET * GET_ALL * REMOVE * REMOVE_ALL * REPLACE |
CamelEhcacheActionHasResult | Boolean | Set to true if the action has a result |
CamelEhcacheActionSucceeded |
| Set to true if the actionsuccedded |
CamelEhcacheKey | Object | The cache key used for an action |
CamelEhcacheKeys | Set<Object> | A list of keys, used in * PUT_ALL * GET_ALL * REMOVE_ALL |
CamelEhcacheValue | Object | The value to put in the cache or the result of an operation |
CamelEhcacheOldValue | Object | The old value associated to a key for actions like PUT_IF_ABSENT or the Object used for comparison for actions like REPLACE |
CamelEhcacheEventType | EventType | The type of event received |
91.4. Ehcache based idempotent repository example:
CacheManager manager = CacheManagerBuilder.newCacheManager(new XmlConfiguration("ehcache.xml")); EhcacheIdempotentRepository repo = new EhcacheIdempotentRepository(manager, "idempotent-cache"); from("direct:in") .idempotentConsumer(header("messageId"), idempotentRepo) .to("mock:out");
91.5. Ehcache based aggregation repository example:
public class EhcacheAggregationRepositoryRoutesTest extends CamelTestSupport { private static final String ENDPOINT_MOCK = "mock:result"; private static final String ENDPOINT_DIRECT = "direct:one"; private static final int[] VALUES = generateRandomArrayOfInt(10, 0, 30); private static final int SUM = IntStream.of(VALUES).reduce(0, (a, b) -> a + b); private static final String CORRELATOR = "CORRELATOR"; @EndpointInject(uri = ENDPOINT_MOCK) private MockEndpoint mock; @Produce(uri = ENDPOINT_DIRECT) private ProducerTemplate producer; @Test public void checkAggregationFromOneRoute() throws Exception { mock.expectedMessageCount(VALUES.length); mock.expectedBodiesReceived(SUM); IntStream.of(VALUES).forEach( i -> producer.sendBodyAndHeader(i, CORRELATOR, CORRELATOR) ); mock.assertIsSatisfied(); } private Exchange aggregate(Exchange oldExchange, Exchange newExchange) { if (oldExchange == null) { return newExchange; } else { Integer n = newExchange.getIn().getBody(Integer.class); Integer o = oldExchange.getIn().getBody(Integer.class); Integer v = (o == null ? 0 : o) + (n == null ? 0 : n); oldExchange.getIn().setBody(v, Integer.class); return oldExchange; } } @Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { from(ENDPOINT_DIRECT) .routeId("AggregatingRouteOne") .aggregate(header(CORRELATOR)) .aggregationRepository(createAggregateRepository()) .aggregationStrategy(EhcacheAggregationRepositoryRoutesTest.this::aggregate) .completionSize(VALUES.length) .to("log:org.apache.camel.component.ehcache.processor.aggregate.level=INFO&showAll=true&mulltiline=true") .to(ENDPOINT_MOCK); } }; } protected EhcacheAggregationRepository createAggregateRepository() throws Exception { CacheManager cacheManager = CacheManagerBuilder.newCacheManager(new XmlConfiguration("ehcache.xml")); cacheManager.init(); EhcacheAggregationRepository repository = new EhcacheAggregationRepository(); repository.setCacheManager(cacheManager); repository.setCacheName("aggregate"); return repository; } }
Chapter 92. EJB Component
Available as of Camel version 2.4
The ejb: component binds EJBs to Camel message exchanges.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-ejb</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
92.1. URI format
ejb:ejbName[?options]
Where ejbName can be any string which is used to look up the EJB in the Application Server JNDI Registry
92.2. Options
The EJB component supports 4 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
context (producer) | The Context to use for looking up the EJBs | Context | |
properties (producer) | Properties for creating javax.naming.Context if a context has not been configured. | Properties | |
cache (advanced) | If enabled, Camel will cache the result of the first Registry look-up. Cache can be enabled if the bean in the Registry is defined as a singleton scope. | Boolean | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The EJB endpoint is configured using URI syntax:
ejb:beanName
with the following path and query parameters:
92.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
beanName | Required Sets the name of the bean to invoke | String |
92.2.2. Query Parameters (5 parameters):
Name | Description | Default | Type |
---|---|---|---|
method (producer) | Sets the name of the method to invoke on the bean | String | |
cache (advanced) | If enabled, Camel will cache the result of the first Registry look-up. Cache can be enabled if the bean in the Registry is defined as a singleton scope. | Boolean | |
multiParameterArray (advanced) | Deprecated How to treat the parameters which are passed from the message body.true means the message body should be an array of parameters.. Deprecation note: This option is used internally by Camel, and is not intended for end users to use. Deprecation note: This option is used internally by Camel, and is not intended for end users to use. | false | boolean |
parameters (advanced) | Used for configuring additional properties on the bean | Map | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
92.3. 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.
92.4. Examples
In the following examples we use the Greater EJB which is defined as follows:
GreaterLocal.java
public interface GreaterLocal { String hello(String name); String bye(String name); }
And the implementation
GreaterImpl.java
@Stateless public class GreaterImpl implements GreaterLocal { public String hello(String name) { return "Hello " + name; } public String bye(String name) { return "Bye " + name; } }
92.4.1. Using Java DSL
In this example we want to invoke the hello
method on the EJB. Since this example is based on an unit test using Apache OpenEJB we have to set a JndiContext
on the EJB component with the OpenEJB settings.
@Override protected CamelContext createCamelContext() throws Exception { CamelContext answer = new DefaultCamelContext(); // enlist EJB component using the JndiContext EjbComponent ejb = answer.getComponent("ejb", EjbComponent.class); ejb.setContext(createEjbContext()); return answer; } private static Context createEjbContext() throws NamingException { // here we need to define our context factory to use OpenEJB for our testing Properties properties = new Properties(); properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory"); return new InitialContext(properties); }
Then we are ready to use the EJB in the Camel route:
from("direct:start") // invoke the greeter EJB using the local interface and invoke the hello method .to("ejb:GreaterImplLocal?method=hello") .to("mock:result");
In a real application server
In a real application server you most likely do not have to setup a JndiContext
on the EJB component as it will create a default JndiContext
on the same JVM as the application server, which usually allows it to access the JNDI registry and lookup the EJBs. However if you need to access a application server on a remote JVM or the likes, you have to prepare the properties beforehand.
92.4.2. Using Spring XML
And this is the same example using Spring XML instead:
Again since this is based on an unit test we need to setup the EJB component:
<!-- setup Camel EJB component --> <bean id="ejb" class="org.apache.camel.component.ejb.EjbComponent"> <property name="properties" ref="jndiProperties"/> </bean> <!-- use OpenEJB context factory --> <p:properties id="jndiProperties"> <prop key="java.naming.factory.initial">org.apache.openejb.client.LocalInitialContextFactory</prop> </p:properties>
Before we are ready to use EJB in the Camel routes:
<camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="direct:start"/> <to uri="ejb:GreaterImplLocal?method=hello"/> <to uri="mock:result"/> </route> </camelContext>
92.5. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
- Bean
- Bean Binding
- Bean Integration
Chapter 93. Elasticsearch Component (deprecated)
Available as of Camel version 2.11
The ElasticSearch component allows you to interface with an ElasticSearch server.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-elasticsearch</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
93.1. URI format
elasticsearch://clusterName[?options]
93.2. Endpoint Options
The Elasticsearch component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
client (advanced) | To use an existing configured Elasticsearch client, instead of creating a client per endpoint. | Client | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Elasticsearch endpoint is configured using URI syntax:
elasticsearch:clusterName
with the following path and query parameters:
93.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
clusterName | Required Name of cluster or use local for local mode | String |
93.2.2. Query Parameters (11 parameters):
Name | Description | Default | Type |
---|---|---|---|
clientTransportSniff (producer) | Is the client allowed to sniff the rest of the cluster or not (default true). This setting map to the client.transport.sniff setting. | true | Boolean |
consistencyLevel (producer) | The write consistency level to use with INDEX and BULK operations (can be any of ONE, QUORUM, ALL or DEFAULT) | DEFAULT | WriteConsistencyLevel |
data (producer) | Is the node going to be allowed to allocate data (shards) to it or not. This setting map to the node.data setting. | Boolean | |
indexName (producer) | The name of the index to act against | String | |
indexType (producer) | The type of the index to act against | String | |
ip (producer) | The TransportClient remote host ip to use | String | |
operation (producer) | What operation to perform | String | |
pathHome (producer) | The path.home property of ElasticSearch configuration. You need to provide a valid path, otherwise the default, $user.home/.elasticsearch, will be used. | ${user.home}/.elasticsearch | String |
port (producer) | The TransportClient remote port to use (defaults to 9300) | 9300 | int |
transportAddresses (producer) | Comma separated list with ip:port formatted remote transport addresses to use. The ip and port options must be left blank for transportAddresses to be considered instead. | String | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
93.3. Spring Boot Auto-Configuration
The component supports 3 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.elasticsearch.client | To use an existing configured Elasticsearch client, instead of creating a client per endpoint. The option is a org.elasticsearch.client.Client type. | String | |
camel.component.elasticsearch.enabled | Enable elasticsearch component | true | Boolean |
camel.component.elasticsearch.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
93.4. Local testing
If you want to run against a local (in JVM/classloader) ElasticSearch server, just set the clusterName value in the URI to "local". See the client guide for more details.
93.5. 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.
operation | message body | description |
---|---|---|
INDEX | Map, String, byte[] or XContentBuilder content to index | adds content to an index and returns the content’s indexId in the body. Camel 2.15, you can set the indexId by setting the message header with the key "indexId". |
GET_BY_ID | index id of content to retrieve | retrieves the specified index and returns a GetResult object in the body |
DELETE | index id of content to delete | deletes the specified indexId and returns a DeleteResult object in the body |
BULK_INDEX | a List or Collection of any type that is already accepted (XContentBuilder, Map, byte[], String) | *Camel 2.14,*adds content to an index and return a List of the id of the successfully indexed documents in the body |
BULK | a List or Collection of any type that is already accepted (XContentBuilder, Map, byte[], String) | Camel 2.15: Adds content to an index and returns the BulkResponse object in the body |
SEARCH | Map or SearchRequest Object | Camel 2.15: search the content with the map of query string |
MULTIGET | List of MultigetRequest.Item object | Camel 2.17: retrieves the specified indexes, types etc. in MultigetRequest and returns a MultigetResponse object in the body |
MULTISEARCH | List of SearchRequest object | Camel 2.17: search for parameters specified in MultiSearchRequest and returns a MultiSearchResponse object in the body |
EXISTS | Index name as header | Camel 2.17: Returns a Boolean object in the body |
UPDATE | Map, String, byte[] or XContentBuilder content to update | Camel 2.17: Updates content to an index and returns the content’s indexId in the body. |
93.6. Index Example
Below is a simple INDEX example
from("direct:index") .to("elasticsearch://local?operation=INDEX&indexName=twitter&indexType=tweet");
<route> <from uri="direct:index" /> <to uri="elasticsearch://local?operation=INDEX&indexName=twitter&indexType=tweet"/> </route>
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);
93.7. For more information, see these resources
93.8. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 94. Elasticsearch5 Component (deprecated)
Available as of Camel version 2.19
The ElasticSearch component allows you to interface with an ElasticSearch 5.x API.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-elasticsearch5</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
94.1. URI format
elasticsearch5://clusterName[?options]
94.2. Endpoint Options
The Elasticsearch5 component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
client (advanced) | To use an existing configured Elasticsearch client, instead of creating a client per endpoint. This allow to customize the client with specific settings. | TransportClient | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Elasticsearch5 endpoint is configured using URI syntax:
elasticsearch5:clusterName
with the following path and query parameters:
94.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
clusterName | Required Name of the cluster | String |
94.2.2. Query Parameters (16 parameters):
Name | Description | Default | Type |
---|---|---|---|
clientTransportSniff (producer) | Is the client allowed to sniff the rest of the cluster or not. This setting map to the client.transport.sniff setting. | false | boolean |
indexName (producer) | The name of the index to act against | String | |
indexType (producer) | The type of the index to act against | String | |
ip (producer) | The TransportClient remote host ip to use | String | |
operation (producer) | What operation to perform | ElasticsearchOperation | |
pingSchedule (producer) | The time(in unit) the client ping the cluster. | 5s | String |
pingTimeout (producer) | The time(in unit) to wait for a ping response from a node too return. | 5s | String |
port (producer) | The TransportClient remote port to use (defaults to 9300) | 9300 | int |
tcpCompress (producer) | true if compression (LZF) enable between all nodes. | false | boolean |
tcpConnectTimeout (producer) | The time( in unit) to wait for connection timeout. | 30s | String |
transportAddresses (producer) | Comma separated list with ip:port formatted remote transport addresses to use. The ip and port options must be left blank for transportAddresses to be considered instead. | String | |
waitForActiveShards (producer) | Index creation waits for the write consistency number of shards to be available | 1 | int |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
enableSSL (security) | Enable SSL. Require XPack client jar on the classpath | false | boolean |
password (authentication) | Password for authenticate against the cluster. Require XPack client jar on the classpath | String | |
user (authentication) | User for authenticate against the cluster. Requires transport_client role for accessing the cluster. Require XPack client jar on the classpath | String |
94.3. Spring Boot Auto-Configuration
The component supports 3 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.elasticsearch5.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.transport.TransportClient type. | String | |
camel.component.elasticsearch5.enabled | Enable elasticsearch5 component | true | Boolean |
camel.component.elasticsearch5.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
94.4. 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.
operation | message body | description |
---|---|---|
INDEX | Map, String, byte[] or XContentBuilder content to index | Adds content to an index and returns the content’s indexId in the body. You can set the indexId by setting the message header with the key "indexId". |
GET_BY_ID | index id of content to retrieve | Retrieves the specified index and returns a GetResult object in the body |
DELETE | index name and type of content to delete | Deletes the specified indexName and indexType and returns a DeleteResponse object in the body |
DELETE_INDEX | index name of content to delete | Deletes the specified indexName and returns a DeleteIndexResponse object in the body |
BULK_INDEX | a List or Collection of any type that is already accepted (XContentBuilder, Map, byte[], String) | Adds content to an index and return a List of the id of the successfully indexed documents in the body |
BULK | a List or Collection of any type that is already accepted (XContentBuilder, Map, byte[], String) | Adds content to an index and returns the BulkResponse object in the body |
SEARCH | Map, String or SearchRequest Object | Search the content with the map of query string |
MULTIGET | List of MultigetRequest.Item object | Retrieves the specified indexes, types etc. in MultigetRequest and returns a MultigetResponse object in the body |
MULTISEARCH | List of SearchRequest object | Search for parameters specified in MultiSearchRequest and returns a MultiSearchResponse object in the body |
EXISTS | Index name as header | Checks the index exists or not and returns a Boolean flag in the body |
UPDATE | Map, String, byte[] or XContentBuilder content to update | Updates content to an index and returns the content’s indexId in the body. |
94.5. Index Example
Below is a simple INDEX example
from("direct:index") .to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet");
<route> <from uri="direct:index" /> <to uri="elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet"/> </route>
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);
94.6. For more information, see these resources
94.7. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 95. Elastichsearch Rest Component
Available as of Camel version 2.21
The ElasticSearch component allows you to interface with an ElasticSearch 6.x API using the REST Client library.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-elasticsearch-rest</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
95.1. URI format
elasticsearch-rest://clusterName[?options]
95.2. Endpoint Options
The Elastichsearch Rest component supports 12 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
client (advanced) | To use an existing configured Elasticsearch client, instead of creating a client per endpoint. This allow to customize the client with specific settings. | RestClient | |
hostAddresses (advanced) | 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 | |
socketTimeout (advanced) | The timeout in ms to wait before the socket will timeout. | 30000 | int |
connectionTimeout (advanced) | The time in ms to wait before connection will timeout. | 30000 | int |
user (security) | Basic authenticate user | String | |
password (security) | Password for authenticate | String | |
enableSSL (security) | Enable SSL | false | Boolean |
maxRetryTimeout (advanced) | The time in ms before retry | 30000 | int |
enableSniffer (advanced) | Enable automatically discover nodes from a running Elasticsearch cluster | false | Boolean |
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 |
sniffAfterFailureDelay (advanced) | The delay of a sniff execution scheduled after a failure (in milliseconds) | 60000 | int |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Elastichsearch Rest endpoint is configured using URI syntax:
elasticsearch-rest:clusterName
with the following path and query parameters:
95.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
clusterName | Required Name of the cluster | String |
95.2.2. Query Parameters (11 parameters):
Name | Description | Default | Type |
---|---|---|---|
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 |
enableSSL (producer) | Enable SSL | false | boolean |
hostAddresses (producer) | Required Comma separated list with ip:port formatted remote transport addresses to use. | String | |
indexName (producer) | The name of the index to act against | String | |
indexType (producer) | The type of the index to act against | String | |
maxRetryTimeout (producer) | The time in ms before retry | 30000 | int |
operation (producer) | What operation to perform | ElasticsearchOperation | |
socketTimeout (producer) | The timeout in ms to wait before the socket will timeout. | 30000 | int |
waitForActiveShards (producer) | Index creation waits for the write consistency number of shards to be available | 1 | int |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
95.3. Spring Boot Auto-Configuration
The component supports 13 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.elasticsearch-rest.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. | String | |
camel.component.elasticsearch-rest.connection-timeout | The time in ms to wait before connection will timeout. | 30000 | Integer |
camel.component.elasticsearch-rest.enable-s-s-l | Enable SSL | false | Boolean |
camel.component.elasticsearch-rest.enable-sniffer | Enable automatically discover nodes from a running Elasticsearch cluster | false | Boolean |
camel.component.elasticsearch-rest.enabled | Whether to enable auto configuration of the elasticsearch-rest component. This is enabled by default. | Boolean | |
camel.component.elasticsearch-rest.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-rest.max-retry-timeout | The time in ms before retry | 30000 | Integer |
camel.component.elasticsearch-rest.password | Password for authenticate | String | |
camel.component.elasticsearch-rest.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.elasticsearch-rest.sniff-after-failure-delay | The delay of a sniff execution scheduled after a failure (in milliseconds) | 60000 | Integer |
camel.component.elasticsearch-rest.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-rest.socket-timeout | The timeout in ms to wait before the socket will timeout. | 30000 | Integer |
camel.component.elasticsearch-rest.user | Basic authenticate user | String |
95.4. 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.
operation | message body | description |
---|---|---|
Index | Map, String, byte[], XContentBuilder or IndexRequest content to index | Adds content to an index and returns the content’s indexId in the body. You can set the indexId by setting the message header with the key "indexId". |
GetById | String or GetRequest index id of content to retrieve | Retrieves the specified index and returns a GetResult object in the body |
Delete | String or DeleteRequest index name and type of content to delete | Deletes the specified indexName and indexType and returns a DeleteResponse object in the body |
DeleteIndex | String or DeleteRequest index name of the index to delete | Deletes the specified indexName and returns a status code the body |
BulkIndex | a List, BulkRequest, or Collection of any type that is already accepted (XContentBuilder, Map, byte[], String) | Adds content to an index and return a List of the id of the successfully indexed documents in the body |
Bulk | a List, BulkRequest, or Collection of any type that is already accepted (XContentBuilder, Map, byte[], String) | Adds content to an index and returns the BulkItemResponse[] object in the body |
Search | Map, String or SearchRequest | Search the content with the map of query string |
MultiSearch | MultiSearchRequest | Multiple search in one |
Exists | Index name(indexName) as header | Checks the index exists or not and returns a Boolean flag in the body |
Update | Map, UpdateRequest, String, byte[] or XContentBuilder content to update | Updates content to an index and returns the content’s indexId in the body. |
Ping | None | Pings the remote Elasticsearch cluster and returns true if the ping succeeded, false otherwise |
Info | None | Get the info of the Elasticsearch cluster and returns them as MainResponse class instance |
95.5. Configure the component and enable basic authentication
To use the Elasticsearch component is has to be configured with a minimum configuration.
ElasticsearchComponent elasticsearchComponent = new ElasticsearchComponent(); elasticsearchComponent.setHostAddresses("myelkhost:9200"); camelContext.addComponent("elasticsearch-rest", 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); camelContext.addComponent("elasticsearch-rest", elasticsearchComponent);
95.6. Index Example
Below is a simple INDEX example
from("direct:index") .to("elasticsearch-rest://elasticsearch?operation=Index&indexName=twitter&indexType=tweet");
<route> <from uri="direct:index" /> <to uri="elasticsearch-rest://elasticsearch?operation=Index&indexName=twitter&indexType=tweet"/> </route>
For this operation you’ll 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);
95.7. 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-rest://elasticsearch?operation=Search&indexName=twitter&indexType=tweet");
<route> <from uri="direct:search" /> <to uri="elasticsearch-rest://elasticsearch?operation=Search&indexName=twitter&indexType=tweet"/> </route>
String query = "{\"query\":{\"match\":{\"content\":\"new release of ApacheCamel\"}}}"; SearchHits response = template.requestBody("direct:search", query, SearchHits.class);
Search on specific field(s) using Map.
Map<String, Object> actualQuery = new HashMap<>(); actualQuery.put("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); SearchHits response = template.requestBody("direct:search", query, SearchHits.class);
95.8. MultiSearch Example
MultiSearching on specific field(s) and value use the Operation ´MultiSearch´. Pass in the MultiSearchRequest instance
from("direct:multiSearch") .to("elasticsearch-rest://elasticsearch?operation=MultiSearch");
<route> <from uri="direct:multiSearch" /> <to uri="elasticsearch-rest://elasticsearch?operation=MultiSearch"/> </route>
MultiSearch on specific field(s)
SearchRequest req = new SearchRequest(); req.indices("twitter"); req.types("tweet"); SearchRequest req1 = new SearchRequest(); req.indices("twitter"); req.types("tweets"); MultiSearchRequest request = new MultiSearchRequest().add(req1).add(req); Item[] response = template.requestBody("direct:search", request, Item[].class);
Chapter 96. ElSQL Component
Available as of Camel version 2.16
The elsql: component is an extension to the existing SQL Component that uses ElSql to define the SQL queries.
This component uses spring-jdbc
behind the scenes for the actual SQL handling.
This component can be used as a Transactional Client.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-elsql</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
The SQL component uses the following endpoint URI notation:
sql:elSqlName:resourceUri[?options]
You can append query options to the URI in the following format, ?option=value&option=value&…
The parameters to the SQL queries are named parameters in the elsql mapping files, and maps to corresponding keys from the Camel message, in the given precedence:
- Camel 2.16.1: from message body if Simple expression.
- from message body if its a `java.util.Map`3. from message headers
If a named parameter cannot be resolved, then an exception is thrown.
96.1. Options
The ElSQL component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
databaseVendor (common) | To use a vendor specific com.opengamma.elsql.ElSqlConfig | ElSqlDatabaseVendor | |
dataSource (common) | Sets the DataSource to use to communicate with the database. | DataSource | |
elSqlConfig (advanced) | To use a specific configured ElSqlConfig. It may be better to use the databaseVendor option instead. | ElSqlConfig | |
resourceUri (common) | The resource file which contains the elsql SQL statements to use. You can specify multiple resources separated by comma. The resources are loaded on the classpath by default, you can prefix with file: to load from file system. Notice you can set this option on the component and then you do not have to configure this on the endpoint. | String | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The ElSQL endpoint is configured using URI syntax:
elsql:elsqlName:resourceUri
with the following path and query parameters:
96.1.1. Path Parameters (2 parameters):
Name | Description | Default | Type |
---|---|---|---|
elsqlName | Required The name of the elsql to use (is NAMED in the elsql file) | String | |
resourceUri | The resource file which contains the elsql SQL statements to use. You can specify multiple resources separated by comma. The resources are loaded on the classpath by default, you can prefix with file: to load from file system. Notice you can set this option on the component and then you do not have to configure this on the endpoint. | String |
96.1.2. Query Parameters (47 parameters):
Name | Description | Default | Type |
---|---|---|---|
allowNamedParameters (common) | Whether to allow using named parameters in the queries. | true | boolean |
databaseVendor (common) | To use a vendor specific com.opengamma.elsql.ElSqlConfig | ElSqlDatabaseVendor | |
dataSource (common) | Sets the DataSource to use to communicate with the database. | DataSource | |
dataSourceRef (common) | Deprecated Sets the reference to a DataSource to lookup from the registry, to use for communicating with the database. | String | |
outputClass (common) | Specify the full package and class name to use as conversion when outputType=SelectOne. | String | |
outputHeader (common) | Store the query result in a header instead of the message body. By default, outputHeader == null and the query result is stored in the message body, any existing content in the message body is discarded. If outputHeader is set, the value is used as the name of the header to store the query result and the original message body is preserved. | String | |
outputType (common) | Make the output of consumer or producer to SelectList as List of Map, or SelectOne as single Java object in the following way:a) If the query has only single column, then that JDBC Column object is returned. (such as SELECT COUNT( ) FROM PROJECT will return a Long object.b) If the query has more than one column, then it will return a Map of that result.c) If the outputClass is set, then it will convert the query result into an Java bean object by calling all the setters that match the column names.It will assume your class has a default constructor to create instance with.d) If the query resulted in more than one rows, it throws an non-unique result exception.StreamList streams the result of the query using an Iterator. This can be used with the Splitter EIP in streaming mode to process the ResultSet in streaming fashion. | SelectList | SqlOutputType |
separator (common) | The separator to use when parameter values is taken from message body (if the body is a String type), to be inserted at # placeholders.Notice if you use named parameters, then a Map type is used instead. The default value is comma | , | char |
breakBatchOnConsumeFail (consumer) | Sets whether to break batch if onConsume failed. | 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 |
expectedUpdateCount (consumer) | Sets an expected update count to validate when using onConsume. | -1 | int |
maxMessagesPerPoll (consumer) | Sets the maximum number of messages to poll | int | |
onConsume (consumer) | After processing each row then this query can be executed, if the Exchange was processed successfully, for example to mark the row as processed. The query can have parameter. | String | |
onConsumeBatchComplete (consumer) | After processing the entire batch, this query can be executed to bulk update rows etc. The query cannot have parameters. | String | |
onConsumeFailed (consumer) | After processing each row then this query can be executed, if the Exchange failed, for example to mark the row as failed. The query can have parameter. | String | |
routeEmptyResultSet (consumer) | Sets whether empty resultset should be allowed to be sent to the next hop. Defaults to false. So the empty resultset will be filtered out. | 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 |
transacted (consumer) | Enables or disables transaction. If enabled then if processing an exchange failed then the consumerbreak out processing any further exchanges to cause a rollback eager. | false | boolean |
useIterator (consumer) | Sets how resultset should be delivered to route. Indicates delivery as either a list or individual object. defaults to true. | true | boolean |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
pollStrategy (consumer) | 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. | PollingConsumerPoll Strategy | |
processingStrategy (consumer) | Allows to plugin to use a custom org.apache.camel.component.sql.SqlProcessingStrategy to execute queries when the consumer has processed the rows/batch. | SqlProcessingStrategy | |
batch (producer) | Enables or disables batch mode | false | boolean |
noop (producer) | If set, will ignore the results of the SQL query and use the existing IN message as the OUT message for the continuation of processing | false | boolean |
useMessageBodyForSql (producer) | Whether to use the message body as the SQL and then headers for parameters. If this option is enabled then the SQL in the uri is not used. | false | boolean |
alwaysPopulateStatement (advanced) | If enabled then the populateStatement method from org.apache.camel.component.sql.SqlPrepareStatementStrategy is always invoked, also if there is no expected parameters to be prepared. When this is false then the populateStatement is only invoked if there is 1 or more expected parameters to be set; for example this avoids reading the message body/headers for SQL queries with no parameters. | false | boolean |
elSqlConfig (advanced) | To use a specific configured ElSqlConfig. It may be better to use the databaseVendor option instead. | ElSqlConfig | |
parametersCount (advanced) | If set greater than zero, then Camel will use this count value of parameters to replace instead of querying via JDBC metadata API. This is useful if the JDBC vendor could not return correct parameters count, then user may override instead. | int | |
placeholder (advanced) | Specifies a character that will be replaced to in SQL query. Notice, that it is simple String.replaceAll() operation and no SQL parsing is involved (quoted strings will also change). | # | String |
prepareStatementStrategy (advanced) | Allows to plugin to use a custom org.apache.camel.component.sql.SqlPrepareStatementStrategy to control preparation of the query and prepared statement. | SqlPrepareStatement Strategy | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
templateOptions (advanced) | Configures the Spring JdbcTemplate with the key/values from the Map | Map | |
usePlaceholder (advanced) | Sets whether to use placeholder and replace all placeholder characters with sign in the SQL queries. | true | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 1000 | 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. | 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. | ScheduledExecutor Service | |
scheduler (scheduler) | To use a cron scheduler from either camel-spring or camel-quartz2 component | none | ScheduledPollConsumer Scheduler |
schedulerProperties (scheduler) | To configure additional properties when using a custom scheduler or any of the Quartz2, Spring based scheduler. | Map | |
startScheduler (scheduler) | Whether the scheduler should be auto started. | true | boolean |
timeUnit (scheduler) | Time unit for initialDelay and delay options. | MILLISECONDS | TimeUnit |
useFixedDelay (scheduler) | Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean |
96.2. Spring Boot Auto-Configuration
The component supports 6 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.elsql.data-source | Sets the DataSource to use to communicate with the database. The option is a javax.sql.DataSource type. | String | |
camel.component.elsql.database-vendor | To use a vendor specific com.opengamma.elsql.ElSqlConfig | ElSqlDatabaseVendor | |
camel.component.elsql.el-sql-config | To use a specific configured ElSqlConfig. It may be better to use the databaseVendor option instead. The option is a com.opengamma.elsql.ElSqlConfig type. | String | |
camel.component.elsql.enabled | Enable elsql component | true | Boolean |
camel.component.elsql.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.elsql.resource-uri | The resource file which contains the elsql SQL statements to use. You can specify multiple resources separated by comma. The resources are loaded on the classpath by default, you can prefix with file: to load from file system. Notice you can set this option on the component and then you do not have to configure this on the endpoint. | String |
96.3. Result of the query
For select
operations, the result is an instance of List<Map<String, Object>>
type, as returned by the JdbcTemplate.queryForList() method. For update
operations, the result is the number of updated rows, returned as an Integer
.
By default, the result is placed in the message body. If the outputHeader parameter is set, the result is placed in the header. This is an alternative to using a full message enrichment pattern to add headers, it provides a concise syntax for querying a sequence or some other small value into a header. It is convenient to use outputHeader and outputType together:
96.4. Header values
When performing update
operations, the SQL Component stores the update count in the following message headers:
Header | Description |
---|---|
|
The number of rows updated for |
|
The number of rows returned for |
96.4.1. Sample
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 for these parameters from the message body or 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)) .to("elsql:projects:com/foo/orders.elsql")
And the elsql mapping file
@NAME(projects) SELECT * FROM projects WHERE license = :lic AND id > :min ORDER BY id
Though if the message body is a java.util.Map
then the named parameters will be taken from the body.
from("direct:projects") .to("elsql:projects:com/foo/orders.elsql")
96.5. Using expression parameters in producers
In from Camel 2.16.1 onwards you can use Simple expressions as well, which allows to use an OGNL like notation on the message body, where it assumes to have getLicense
and getMinimum
methods:
@NAME(projects) SELECT * FROM projects WHERE license = :${body.license} AND id > :${body.minimum} ORDER BY id
96.5.1. Using expression parameters in consumers
Available as of Camel 2.23
When using the ElSql component as consumer, you can now also use expression parameters (simple language) to build dynamic query parameters, such as calling a method on a bean to retrieve an id, date or something.
For example in the sample below we call the nextId method on the bean myIdGenerator:
@NAME(projectsByIdBean) SELECT * FROM projects WHERE id = :${bean#myIdGenerator.nextId}
Notice in the bean syntax above, we must use #
instead of :
in the simple expression. This is because Spring query parameter parser is in-use which will separate parameters on colon. Also pay attention that Spring query parser will invoke the bean twice for each query.
And the bean has the following method:
public static class MyIdGenerator { private int id = 1; public int nextId() { // spring will call this twice, one for initializing query and 2nd for actual value id++; return id / 2; }
Notice that there is no existing Exchange
with message body and headers, so the simple expression you can use in the consumer are most useable for calling bean methods as in this example.
Chapter 97. etcd Component
Available as of Camel version 2.18
The camel etcd component allows you to work with Etcd, a distributed reliable key-value store.
97.1. URI Format
etcd:namespace/path[?options]
97.2. URI Options
The etcd component supports 7 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
uris (common) | To set the URIs the client connects. | String | |
sslContextParameters (common) | To configure security using SSLContextParameters. | SSLContextParameters | |
userName (common) | The user name to use for basic authentication. | String | |
password (common) | The password to use for basic authentication. | String | |
configuration (advanced) | Sets the common configuration shared among endpoints | EtcdConfiguration | |
useGlobalSslContext Parameters (security) | Enable usage of global SSL context parameters. | false | boolean |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The etcd endpoint is configured using URI syntax:
etcd:namespace/path
with the following path and query parameters:
97.2.1. Path Parameters (2 parameters):
Name | Description | Default | Type |
---|---|---|---|
namespace | Required The API namespace to use | EtcdNamespace | |
path | The path the endpoint refers to | String |
97.2.2. Query Parameters (29 parameters):
Name | Description | Default | Type |
---|---|---|---|
recursive (common) | To apply an action recursively. | false | boolean |
servicePath (common) | The path to look for for service discovery | /services/ | String |
timeout (common) | To set the maximum time an action could take to complete. | Long | |
uris (common) | To set the URIs the client connects. | 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 |
sendEmptyExchangeOnTimeout (consumer) | To send an empty message in case of timeout watching for a key. | 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) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
fromIndex (consumer) | The index to watch from | 0 | Long |
pollStrategy (consumer) | 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. | PollingConsumerPoll Strategy | |
timeToLive (producer) | To set the lifespan of a key in milliseconds. | Integer | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 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. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 1000 | 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. | 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. | ScheduledExecutor Service | |
scheduler (scheduler) | To use a cron scheduler from either camel-spring or camel-quartz2 component | none | ScheduledPollConsumer Scheduler |
schedulerProperties (scheduler) | To configure additional properties when using a custom scheduler or any of the Quartz2, Spring based scheduler. | Map | |
startScheduler (scheduler) | Whether the scheduler should be auto started. | true | boolean |
timeUnit (scheduler) | Time unit for initialDelay and delay options. | MILLISECONDS | TimeUnit |
useFixedDelay (scheduler) | Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean |
password (security) | The password to use for basic authentication. | String | |
sslContextParameters (security) | To configure security using SSLContextParameters. | SSLContextParameters | |
userName (security) | The user name to use for basic authentication. | String |
97.3. Spring Boot Auto-Configuration
The component supports 17 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.etcd.configuration.from-index | The index to watch from | 0 | Long |
camel.component.etcd.configuration.password | The password to use for basic authentication. | String | |
camel.component.etcd.configuration.recursive | To apply an action recursively. | false | Boolean |
camel.component.etcd.configuration.send-empty-exchange-on-timeout | To send an empty message in case of timeout watching for a key. | false | Boolean |
camel.component.etcd.configuration.service-path | The path to look for for service discovery | /services/ | String |
camel.component.etcd.configuration.ssl-context-parameters | To configure security using SSLContextParameters. | SSLContextParameters | |
camel.component.etcd.configuration.time-to-live | To set the lifespan of a key in milliseconds. | Integer | |
camel.component.etcd.configuration.timeout | To set the maximum time an action could take to complete. | Long | |
camel.component.etcd.configuration.uris | To set the URIs the client connects. | String | |
camel.component.etcd.configuration.user-name | The user name to use for basic authentication. | String | |
camel.component.etcd.enabled | Enable etcd component | true | Boolean |
camel.component.etcd.password | The password to use for basic authentication. | String | |
camel.component.etcd.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
camel.component.etcd.ssl-context-parameters | To configure security using SSLContextParameters. The option is a org.apache.camel.util.jsse.SSLContextParameters type. | String | |
camel.component.etcd.uris | To set the URIs the client connects. | String | |
camel.component.etcd.use-global-ssl-context-parameters | Enable usage of global SSL context parameters. | false | Boolean |
camel.component.etcd.user-name | The user name to use for basic authentication. | String |
Chapter 98. OSGi EventAdmin Component
Available as of Camel version 2.6
The eventadmin
component can be used in an OSGi environment to receive OSGi EventAdmin events and process them.
98.1. Dependencies
Maven users need to add the following dependency to their pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-eventadmin</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.6.0 or higher).
98.2. URI format
eventadmin:topic[?options]
where topic
is the name of the topic to listen too.
98.3. URI options
The OSGi EventAdmin component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
bundleContext (common) | The OSGi BundleContext is automatic injected by Camel | BundleContext | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The OSGi EventAdmin endpoint is configured using URI syntax:
eventadmin:topic
with the following path and query parameters:
98.3.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
topic | Name of topic to listen or send to | String |
98.3.2. Query Parameters (5 parameters):
Name | Description | Default | Type |
---|---|---|---|
send (common) | Whether to use 'send' or 'synchronous' deliver. Default false (async delivery) | 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 |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
98.4. Message headers
Name | Type | Message |
---|---|---|
Description |
98.5. Message body
The in
message body will be set to the received Event.
98.6. Example usage
<route> <from uri="eventadmin:*"/> <to uri="stream:out"/> </route>
Chapter 99. Exec Component
Available as of Camel version 2.3
The exec
component can be used to execute system commands.
99.1. Dependencies
Maven users need to add the following dependency to their pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-exec</artifactId> <version>${camel-version}</version> </dependency>
where ${camel-version
} must be replaced by the actual version of Camel (2.3.0 or higher).
99.2. URI format
exec://executable[?options]
where executable
is the name, or file path, of the system command that will be executed. If executable name is used (e.g. exec:java
), the executable must in the system path.
99.3. URI options
The Exec component has no options.
The Exec endpoint is configured using URI syntax:
exec:executable
with the following path and query parameters:
99.3.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
executable | Required Sets the executable to be executed. The executable must not be empty or null. | String |
99.3.2. Query Parameters (8 parameters):
Name | Description | Default | Type |
---|---|---|---|
args (producer) | The arguments may be one or many whitespace-separated tokens. | String | |
binding (producer) | A reference to a org.apache.commons.exec.ExecBinding in the Registry. | ExecBinding | |
commandExecutor (producer) | A reference to a org.apache.commons.exec.ExecCommandExecutor in the Registry that customizes the command execution. The default command executor utilizes the commons-exec library, which adds a shutdown hook for every executed command. | ExecCommandExecutor | |
outFile (producer) | The name of a file, created by the executable, that should be considered as its output. If no outFile is set, the standard output (stdout) of the executable will be used instead. | String | |
timeout (producer) | The timeout, in milliseconds, after which the executable should be terminated. If execution has not completed within the timeout, the component will send a termination request. | long | |
useStderrOnEmptyStdout (producer) | A boolean indicating that when stdout is empty, this component will populate the Camel Message Body with stderr. This behavior is disabled (false) by default. | false | boolean |
workingDir (producer) | The directory in which the command should be executed. If null, the working directory of the current process will be used. | String | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
99.4. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.exec.enabled | Enable exec component | true | Boolean |
camel.component.exec.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
99.5. Message headers
The supported headers are defined in org.apache.camel.component.exec.ExecBinding
.
Name | Type | Message | Description |
---|---|---|---|
|
|
|
The name of the system command that will be executed. Overrides |
|
|
|
Command-line arguments to pass to the executed process. The arguments are used literally - no quoting is applied. Overrides any existing |
|
|
|
Camel 2.5: The arguments of the executable as a Single string where each argument is whitespace separated (see |
|
|
|
The name of a file, created by the executable, that should be considered as its output. Overrides any existing |
|
|
|
The timeout, in milliseconds, after which the executable should be terminated. Overrides any existing |
|
|
|
The directory in which the command should be executed. Overrides any existing |
|
|
| The value of this header is the exit value of the executable. Non-zero exit values typically indicate abnormal termination. Note that the exit value is OS-dependent. |
|
|
|
The value of this header points to the standard error stream (stderr) of the executable. If no stderr is written, the value is |
|
|
|
Indicates that when |
99.6. Message body
If the Exec
component receives an in
message body that is convertible to java.io.InputStream
, it is used to feed input to the executable via its stdin. After execution, the message body is the result of the execution,- that is, an org.apache.camel.components.exec.ExecResult
instance containing the stdout, stderr, exit value, and out file. This component supports the following ExecResult
type converters for convenience:
From | To |
---|---|
|
|
|
|
|
|
|
|
If an out file is specified (in the endpoint via outFile
or the message headers via ExecBinding.EXEC_COMMAND_OUT_FILE
), converters will return the content of the out file. If no out file is used, then this component will convert the stdout of the process to the target type. For more details, please refer to the usage examples below.
99.7. Usage examples
99.7.1. Executing word count (Linux)
The example below executes wc
(word count, Linux) to count the words in file /usr/share/dict/words
. The word count (output) is written to the standard output stream of wc
.
from("direct:exec") .to("exec:wc?args=--words /usr/share/dict/words") .process(new Processor() { public void process(Exchange exchange) throws Exception { // By default, the body is ExecResult instance assertIsInstanceOf(ExecResult.class, exchange.getIn().getBody()); // Use the Camel Exec String type converter to convert the ExecResult to String // In this case, the stdout is considered as output String wordCountOutput = exchange.getIn().getBody(String.class); // do something with the word count } });
99.7.2. Executing java
The example below executes java
with 2 arguments: -server
and -version
, provided that java
is in the system path.
from("direct:exec") .to("exec:java?args=-server -version")
The example below executes java
in c:\temp
with 3 arguments: -server
, -version
and the sytem property user.name
.
from("direct:exec") .to("exec:c:/program files/jdk/bin/java?args=-server -version -Duser.name=Camel&workingDir=c:/temp")
99.7.3. Executing Ant scripts
The following example executes Apache Ant (Windows only) with the build file CamelExecBuildFile.xml
, provided that ant.bat
is in the system path, and that CamelExecBuildFile.xml
is in the current directory.
from("direct:exec") .to("exec:ant.bat?args=-f CamelExecBuildFile.xml")
In the next example, the ant.bat
command redirects its output to CamelExecOutFile.txt
with -l
. The file CamelExecOutFile.txt
is used as the out file with outFile=CamelExecOutFile.txt
. The example assumes that ant.bat
is in the system path, and that CamelExecBuildFile.xml
is in the current directory.
from("direct:exec") .to("exec:ant.bat?args=-f CamelExecBuildFile.xml -l CamelExecOutFile.txt&outFile=CamelExecOutFile.txt") .process(new Processor() { public void process(Exchange exchange) throws Exception { InputStream outFile = exchange.getIn().getBody(InputStream.class); assertIsInstanceOf(InputStream.class, outFile); // do something with the out file here } });
99.7.4. Executing echo
(Windows)
Commands such as echo
and dir
can be executed only with the command interpreter of the operating system. This example shows how to execute such a command - echo
- in Windows.
from("direct:exec").to("exec:cmd?args=/C echo echoString")
99.8. See Also
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 100. Facebook Component
Available as of Camel version 2.14
The Facebook component provides access to all of the Facebook APIs accessible using Facebook4J. It allows producing messages to retrieve, add, and delete posts, likes, comments, photos, albums, videos, photos, checkins, locations, links, etc. It also supports APIs that allow polling for posts, users, checkins, groups, locations, etc.
Facebook requires the use of OAuth for all client application authentication. In order to use camel-facebook with your account, you’ll need to create a new application within Facebook at https://developers.facebook.com/apps and grant the application access to your account. The Facebook application’s id and secret will allow access to Facebook APIs which do not require a current user. A user access token is required for APIs that require a logged in user. More information on obtaining a user access token can be found at https://developers.facebook.com/docs/facebook-login/access-tokens/.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-facebook</artifactId> <version>${camel-version}</version> </dependency>
100.1. URI format
facebook://[endpoint]?[options]
100.2. FacebookComponent
The facebook component can be configured with the Facebook account settings below, which are mandatory. The values can be provided to the component using the bean property configuration of type org.apache.camel.component.facebook.config.FacebookConfiguration. The oAuthAccessToken option may be ommited but that will only allow access to application APIs.
The Facebook component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (advanced) | To use the shared configuration | FacebookConfiguration | |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Facebook endpoint is configured using URI syntax:
facebook:methodName
with the following path and query parameters:
100.2.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
methodName | Required What operation to perform | String |
100.2.2. Query Parameters (102 parameters):
Name | Description | Default | Type |
---|---|---|---|
achievementURL (common) | The unique URL of the achievement | URL | |
albumId (common) | The album ID | String | |
albumUpdate (common) | The facebook Album to be created or updated | AlbumUpdate | |
appId (common) | The ID of the Facebook Application | String | |
center (common) | Location latitude and longitude | GeoLocation | |
checkinId (common) | The checkin ID | String | |
checkinUpdate (common) | Deprecated The checkin to be created. Deprecated, instead create a Post with an attached location | CheckinUpdate | |
clientURL (common) | Facebook4J API client URL | String | |
clientVersion (common) | Facebook4J client API version | String | |
commentId (common) | The comment ID | String | |
commentUpdate (common) | The facebook Comment to be created or updated | CommentUpdate | |
debugEnabled (common) | Enables deubg output. Effective only with the embedded logger | false | Boolean |
description (common) | The description text | String | |
distance (common) | Distance in meters | Integer | |
domainId (common) | The domain ID | String | |
domainName (common) | The domain name | String | |
domainNames (common) | The domain names | List | |
eventId (common) | The event ID | String | |
eventUpdate (common) | The event to be created or updated | EventUpdate | |
friendId (common) | The friend ID | String | |
friendlistId (common) | The friend list ID | String | |
friendlistName (common) | The friend list Name | String | |
friendUserId (common) | The friend user ID | String | |
groupId (common) | The group ID | String | |
gzipEnabled (common) | Use Facebook GZIP encoding | true | Boolean |
httpConnectionTimeout (common) | Http connection timeout in milliseconds | 20000 | Integer |
httpDefaultMaxPerRoute (common) | HTTP maximum connections per route | 2 | Integer |
httpMaxTotalConnections (common) | HTTP maximum total connections | 20 | Integer |
httpReadTimeout (common) | Http read timeout in milliseconds | 120000 | Integer |
httpRetryCount (common) | Number of HTTP retries | 0 | Integer |
httpRetryIntervalSeconds (common) | HTTP retry interval in seconds | 5 | Integer |
httpStreamingReadTimeout (common) | HTTP streaming read timeout in milliseconds | 40000 | Integer |
ids (common) | The ids of users | List | |
inBody (common) | Sets the name of a parameter to be passed in the exchange In Body | String | |
includeRead (common) | Enables notifications that the user has already read in addition to unread ones | Boolean | |
isHidden (common) | Whether hidden | Boolean | |
jsonStoreEnabled (common) | If set to true, raw JSON forms will be stored in DataObjectFactory | false | Boolean |
link (common) | Link URL | URL | |
linkId (common) | Link ID | String | |
locale (common) | Desired FQL locale | Locale | |
mbeanEnabled (common) | If set to true, Facebook4J mbean will be registerd | false | Boolean |
message (common) | The message text | String | |
messageId (common) | The message ID | String | |
metric (common) | The metric name | String | |
milestoneId (common) | The milestone id | String | |
name (common) | Test user name, must be of the form 'first last' | String | |
noteId (common) | The note ID | String | |
notificationId (common) | The notification ID | String | |
objectId (common) | The insight object ID | String | |
offerId (common) | The offer id | String | |
optionDescription (common) | The question’s answer option description | String | |
pageId (common) | The page id | String | |
permissionName (common) | The permission name | String | |
permissions (common) | Test user permissions in the format perm1,perm2,… | String | |
photoId (common) | The photo ID | String | |
pictureId (common) | The picture id | Integer | |
pictureId2 (common) | The picture2 id | Integer | |
pictureSize (common) | The picture size | PictureSize | |
placeId (common) | The place ID | String | |
postId (common) | The post ID | String | |
postUpdate (common) | The post to create or update | PostUpdate | |
prettyDebugEnabled (common) | Prettify JSON debug output if set to true | false | Boolean |
queries (common) | FQL queries | Map | |
query (common) | FQL query or search terms for search endpoints | String | |
questionId (common) | The question id | String | |
reading (common) | Optional reading parameters. See Reading Options(#reading) | Reading | |
readingOptions (common) | To configure Reading using key/value pairs from the Map. | Map | |
restBaseURL (common) | API base URL | String | |
scoreValue (common) | The numeric score with value | Integer | |
size (common) | The picture size, one of large, normal, small or square | PictureSize | |
source (common) | The media content from either a java.io.File or java.io.Inputstream | Media | |
subject (common) | The note of the subject | String | |
tabId (common) | The tab id | String | |
tagUpdate (common) | Photo tag information | TagUpdate | |
testUser1 (common) | Test user 1 | TestUser | |
testUser2 (common) | Test user 2 | TestUser | |
testUserId (common) | The ID of the test user | String | |
title (common) | The title text | String | |
toUserId (common) | The ID of the user to tag | String | |
toUserIds (common) | The IDs of the users to tag | List | |
userId (common) | The Facebook user ID | String | |
userId1 (common) | The ID of a user 1 | String | |
userId2 (common) | The ID of a user 2 | String | |
userIds (common) | The IDs of users to invite to event | List | |
userLocale (common) | The test user locale | String | |
useSSL (common) | Use SSL | true | Boolean |
videoBaseURL (common) | Video API base URL | String | |
videoId (common) | The video ID | 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 |
exceptionHandler (consumer) | 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) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
httpProxyHost (proxy) | HTTP proxy server host name | String | |
httpProxyPassword (proxy) | HTTP proxy server password | String | |
httpProxyPort (proxy) | HTTP proxy server port | Integer | |
httpProxyUser (proxy) | HTTP proxy server user name | String | |
oAuthAccessToken (security) | The user access token | String | |
oAuthAccessTokenURL (security) | OAuth access token URL | String | |
oAuthAppId (security) | The application Id | String | |
oAuthAppSecret (security) | The application Secret | String | |
oAuthAuthorizationURL (security) | OAuth authorization URL | String | |
oAuthPermissions (security) | Default OAuth permissions. Comma separated permission names. See https://developers.facebook.com/docs/reference/login/#permissions for the detail | String |
100.3. Spring Boot Auto-Configuration
The component supports 29 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.facebook.configuration.client-u-r-l | Facebook4J API client URL | String | |
camel.component.facebook.configuration.client-version | Facebook4J client API version | String | |
camel.component.facebook.configuration.debug-enabled | Enables deubg output. Effective only with the embedded logger | false | Boolean |
camel.component.facebook.configuration.gzip-enabled | Use Facebook GZIP encoding | true | Boolean |
camel.component.facebook.configuration.http-connection-timeout | Http connection timeout in milliseconds | 20000 | Integer |
camel.component.facebook.configuration.http-default-max-per-route | HTTP maximum connections per route | 2 | Integer |
camel.component.facebook.configuration.http-max-total-connections | HTTP maximum total connections | 20 | Integer |
camel.component.facebook.configuration.http-proxy-host | HTTP proxy server host name | String | |
camel.component.facebook.configuration.http-proxy-password | HTTP proxy server password | String | |
camel.component.facebook.configuration.http-proxy-port | HTTP proxy server port | Integer | |
camel.component.facebook.configuration.http-proxy-user | HTTP proxy server user name | String | |
camel.component.facebook.configuration.http-read-timeout | Http read timeout in milliseconds | 120000 | Integer |
camel.component.facebook.configuration.http-retry-count | Number of HTTP retries | 0 | Integer |
camel.component.facebook.configuration.http-retry-interval-seconds | HTTP retry interval in seconds | 5 | Integer |
camel.component.facebook.configuration.http-streaming-read-timeout | HTTP streaming read timeout in milliseconds | 40000 | Integer |
camel.component.facebook.configuration.json-store-enabled | If set to true, raw JSON forms will be stored in DataObjectFactory | false | Boolean |
camel.component.facebook.configuration.mbean-enabled | If set to true, Facebook4J mbean will be registerd | false | Boolean |
camel.component.facebook.configuration.o-auth-access-token | The user access token | String | |
camel.component.facebook.configuration.o-auth-access-token-u-r-l | OAuth access token URL |