Apache Camel Component Reference
Configuration reference for Camel components
Abstract
Chapter 1. Components Overview Copy linkLink copied to clipboard!
This chapter provides a summary of all the components available for Apache Camel.
1.1. Container types Copy linkLink copied to clipboard!
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 spcifically for Java EE (that is, JBoss EAP), and cannot be supported in the other container types.
1.2. Supported components Copy linkLink copied to clipboard!
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 | Type | Containerless | Spring Boot 1.x | Spring Boot 2.x | Karaf | JBoss EAP |
|---|---|---|---|---|---|---|
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ❌ | ❌ | ✔ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | Deprecated | Deprecated | Deprecated | ❌ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Language | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ❌ |
|
| Endpoint | Deprecated | Deprecated | Deprecated | Deprecated | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ❌ | ❌ | ✔ | ❌ |
|
| Endpoint | ✔ | ❌ | ❌ | ❌ | ❌ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | Deprecated | Deprecated | Deprecated | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | Deprecated | Deprecated | Deprecated | Deprecated | ✔ |
|
| Endpoint | ✔ | ❌ | ❌ | Deprecated | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Language | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | ❌ | ❌ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Deprecated | ❌ | ❌ | ❌ | ❌ | |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ❌ | ❌ | ❌ | ✔ |
|
| Language | Deprecated | ❌ | ❌ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ❌ | ❌ | ✔ | ❌ |
|
| Language | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ❌ | ❌ | ✔ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Language | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ❌ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | ❌ | ❌ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ❌ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ❌ | ❌ | ✔ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ❌ |
|
| Language | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Deprecated | ❌ | ❌ | ❌ | ❌ | |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | Deprecated | Deprecated | ❌ | ❌ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | Deprecated | Deprecated | Deprecated | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ❌ | ❌ |
|
| Endpoint | Deprecated | ❌ | ❌ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Language | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| ✔ | ✔ | ✔ | ✔ | ✔ | |
|
| Data Format | Deprecated | Deprecated | Deprecated | Deprecated | Deprecated |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | Deprecated | Deprecated | ✔ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | ❌ | ❌ | ❌ | ❌ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ❌ | ❌ | ❌ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ❌ | ❌ | ✔ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ❌ | ❌ | ❌ | ❌ | ❌ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | ❌ | ❌ | ❌ | ❌ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ❌ | ❌ | ❌ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ❌ | ❌ | ✔ | ❌ |
|
| Endpoint | ✔ | ❌ | ❌ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | Deprecated | Deprecated | Deprecated | ❌ |
|
| Endpoint | ❌ | ❌ | ❌ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | Deprecated | Deprecated | Deprecated | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ❌ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Language | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | Deprecated | Deprecated | Deprecated | ❌ |
|
| Language | Deprecated | ❌ | ❌ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | Deprecated | Deprecated | Deprecated | ❌ |
|
| Endpoint | Deprecated | Deprecated | Deprecated | Deprecated | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| ✔ | ❌ | ❌ | ✔ | ❌ | |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ❌ | ❌ | ❌ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| ❌ | ❌ | ❌ | ❌ | ✔ | |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| ✔ | ✔ | ✔ | ✔ | ❌ | |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ❌ | ❌ | ✔ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | ❌ | ❌ | ✔ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | Deprecated | Deprecated | Deprecated | Deprecated |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Language | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | Deprecated | Deprecated | ✔ | ❌ |
|
| Endpoint | Deprecated | Deprecated | Deprecated | ✔ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ❌ |
|
| Endpoint | ❌ | ❌ | ✔ | ❌ | ❌ |
|
| Language | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | ❌ | ❌ | ✔ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| ✔ | ✔ | ✔ | ✔ | ✔ | |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ❌ | ❌ | ✔ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Language | Deprecated | Deprecated | Deprecated | ❌ | Deprecated |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Language | Deprecated | Deprecated | Deprecated | ❌ | Deprecated |
|
| Endpoint | Deprecated | ❌ | ❌ | ✔ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| ✔ | ✔ | ✔ | ✔ | ✔ | |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Language | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ❌ |
|
| ✔ | ✔ | ✔ | ❌ | ✔ | |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | ❌ | ❌ | ✔ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Language | Deprecated | Deprecated | Deprecated | ❌ | Deprecated |
|
| Endpoint | Deprecated | Deprecated | Deprecated | Deprecated | ❌ |
|
| Endpoint | ❌ | ❌ | ✔ | ❌ | ❌ |
|
| Endpoint | ❌ | ❌ | ❌ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | Deprecated | Deprecated | Deprecated | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | ✔ | ✔ | Deprecated | ❌ |
|
| Endpoint | Deprecated | Deprecated | Deprecated | Deprecated | Deprecated |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ❌ | ❌ | ✔ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | Deprecated | Deprecated | Deprecated | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Language | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ❌ | ❌ |
|
| Language | ✔ | ✔ | ✔ | ❌ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ❌ | ❌ |
|
| ✔ | ✔ | ✔ | ❌ | ❌ | |
|
| Endpoint | ❌ | ❌ | ✔ | ❌ | ❌ |
|
| ✔ | ✔ | ✔ | ❌ | ❌ | |
|
| Endpoint | ❌ | ❌ | ✔ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ❌ | ✔ |
|
| Endpoint | ✔ | ❌ | ❌ | ❌ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ❌ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ❌ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | ❌ | ❌ | Deprecated | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Language | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | Deprecated | Deprecated | Deprecated | Deprecated | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ❌ | ❌ | ✔ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ❌ |
|
| Data Format | Deprecated | Deprecated | Deprecated | Deprecated | ✔ |
|
| Data Format | Deprecated | Deprecated | Deprecated | Deprecated | Deprecated |
|
| Endpoint | ❌ | ❌ | ❌ | ❌ | ❌ |
|
| Data Format | ❌ | ❌ | ❌ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Language | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Language | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Language | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ❌ | ❌ | ❌ | ❌ | ❌ |
|
| Endpoint | ✔ | ✔ | ✔ | ❌ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Data Format | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
|
| Endpoint | ✔ | ✔ | ✔ | ✔ | ✔ |
Chapter 2. ActiveMQ Copy linkLink copied to clipboard!
ActiveMQ Component Copy linkLink copied to clipboard!
The ActiveMQ component allows messages to be sent to a JMS Queue or Topic; or messages to be consumed from a JMS Queue or Topic using Apache ActiveMQ.
This component is based on the Chapter 178, JMS Component and uses Spring’s JMS support for declarative transactions, using Spring’s JmsTemplate for sending and a MessageListenerContainer for consuming. All the options from the Chapter 178, JMS Component component also apply for this 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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
See Options on the Chapter 178, JMS Component component as all these options also apply for this component.
Camel on EAP deployment Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
When sending to an ActiveMQ broker using Camel it’s recommended to use a pooled connection factory to handle efficient pooling of JMS connections, sessions and producers. This is documented in the page ActiveMQ Spring Support.
You can grab Jencks AMQ pool with Maven:
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
<version>5.3.2</version>
</dependency>
And then setup 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. This is important to ensure the connection pool is properly started and shutdown.
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 better reflect its purpose, being named as maxActiveSessionPerConnection. Notice the concurrentConsumers is set to a higher value than maxConnections is. This is okay, as each consumer is using a session, and as a session can share the same connection, we are in the safe. In this example we can have 8 * 500 = 4000 active sessions at the same time.
Invoking MessageListener POJOs in a route Copy linkLink copied to clipboard!
The ActiveMQ component also provides a helper Type Converter from a JMS MessageListener to a Processor. This means that the Chapter 43, Bean Component component is capable of invoking any JMS MessageListener bean directly inside any route.
So for example you can create a MessageListener in JMS as follows:
public class MyListener implements MessageListener {
public void onMessage(Message jmsMessage) {
// ...
}
}
Then use it in your route as follows
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 Copy linkLink copied to clipboard!
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:
<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 Copy linkLink copied to clipboard!
ActiveMQ can generate Advisory messages which are put in topics that 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.
<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 data/activemq folder :
advisoryConnection-20100312.txt advisoryProducer-20100312.txt
and containing string:
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 Copy linkLink copied to clipboard!
You need this dependency:
-
activemq-camel
ActiveMQ is an extension of the Chapter 178, JMS Component component released with the ActiveMQ project.
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<version>5.6.0</version>
</dependency>
Chapter 3. AHC Component Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
The AHC endpoint is configured using URI syntax:
ahc:httpUri
with the following path and query parameters:
3.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| httpUri | Required The URI to use such as http://hostname:port/path | URI |
3.2.2. Query Parameters (13 parameters): Copy linkLink copied to clipboard!
| 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. AhcComponent Options Copy linkLink copied to clipboard!
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.4. Message Headers Copy linkLink copied to clipboard!
| 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.5. Message Body Copy linkLink copied to clipboard!
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.6. Response code Copy linkLink copied to clipboard!
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
AhcOperationFailedExceptionwith the information. Response code is 400+, Camel regards it as an external server failure and will throw a
AhcOperationFailedExceptionwith the information.throwExceptionOnFailure
The option,
throwExceptionOnFailure, can be set tofalseto prevent theAhcOperationFailedExceptionfrom being thrown for failed response codes. This allows you to get any response from the remote server.
3.7. AhcOperationFailedException Copy linkLink copied to clipboard!
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.8. Calling using GET or POST Copy linkLink copied to clipboard!
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.9. Configuring URI to call Copy linkLink copied to clipboard!
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.10. Configuring URI Parameters Copy linkLink copied to clipboard!
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.11. How to set the http method to the HTTP producer Copy linkLink copied to clipboard!
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.12. Configuring charset Copy linkLink copied to clipboard!
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.12.1. URI Parameters from the endpoint URI Copy linkLink copied to clipboard!
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.12.2. URI Parameters from the Message Copy linkLink copied to clipboard!
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.12.3. Getting the Response Code Copy linkLink copied to clipboard!
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.13. Configuring AsyncHttpClient Copy linkLink copied to clipboard!
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.14. SSL Support (HTTPS) Copy linkLink copied to clipboard!
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.15. See Also Copy linkLink copied to clipboard!
Chapter 4. AHC Websocket Component Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| httpUri | Required The URI to use such as http://hostname:port/path | URI |
4.2.2. Query Parameters (18 parameters): Copy linkLink copied to clipboard!
| 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 options 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. Writing and Reading Data over Websocket Copy linkLink copied to clipboard!
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.4. Configuring URI to Write or Read Data Copy linkLink copied to clipboard!
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.5. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AHC
- Atmosphere-Websocket
Chapter 5. AMQP Component Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
amqp:[queue:|topic:]destinationName[?options]
5.2. AMQP Options Copy linkLink copied to clipboard!
You can specify all of the various configuration options of the JMS component after the destination name.
The AMQP component supports 80 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 JmsConfigurationisAcceptMessagesWhileStopping 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 | |
| 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 MessageisFault() will be send back in the response as a JMS header with the key org.apache.camel.component.jms.JmsConstantsJMS_TRANSFER_FAULTJMS_TRANSFER_FAULT. If the client is Camel, the returned fault flag will be set on the link org.apache.camel.MessagesetFault(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): Copy linkLink copied to clipboard!
| 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 (91 parameters): Copy linkLink copied to clipboard!
| 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 JmsConfigurationisAcceptMessagesWhileStopping 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 options 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 | |
| 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 MessageisFault() will be send back in the response as a JMS header with the key org.apache.camel.component.jms.JmsConstantsJMS_TRANSFER_FAULTJMS_TRANSFER_FAULT. If the client is Camel, the returned fault flag will be set on the link org.apache.camel.MessagesetFault(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. Usage Copy linkLink copied to clipboard!
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.4. Configuring AMQP component Copy linkLink copied to clipboard!
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://lcoalhost: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.5. Using topics Copy linkLink copied to clipboard!
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.6. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 6. APNS Component Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
To send notifications:
apns:notify[?options]
To consume feedback:
apns:consumer[?options]
6.2. Options Copy linkLink copied to clipboard!
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): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| name | Name of the endpoint | String |
6.2.2. Query Parameters (20 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
You can append query options to the URI in the following format, ?option=value&option=value&…
6.2.3. Component Copy linkLink copied to clipboard!
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.2.3.1. SSL Setting Copy linkLink copied to clipboard!
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.3. Exchange data format Copy linkLink copied to clipboard!
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.4. Message Headers Copy linkLink copied to clipboard!
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.5. ApnsServiceFactory builder callback Copy linkLink copied to clipboard!
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.6. Samples Copy linkLink copied to clipboard!
6.6.1. Camel Xml route Copy linkLink copied to clipboard!
<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.6.2. Camel Java route Copy linkLink copied to clipboard!
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.7. See Also Copy linkLink copied to clipboard!
Chapter 7. ASN.1 File DataFormat Copy linkLink copied to clipboard!
Available as of Camel version 2.20
The ASN.1 Data Format Data Format [Intoduction 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-jdk15on 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 Copy linkLink copied to clipboard!
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. Unmarshal Copy linkLink copied to clipboard!
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-jdk15on 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.3. Dependencies Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
as2://apiName/methodName
apiName can be one of:
- client
- server
8.2. AS2 Options Copy linkLink copied to clipboard!
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): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| apiName | Required What kind of operation to perform | AS2ApiName |
8.2.2. Query Parameters (30 parameters): Copy linkLink copied to clipboard!
| 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 Copy linkLink copied to clipboard!
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: Copy linkLink copied to clipboard!
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: Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
asterisk:name[?options]
9.2. Options Copy linkLink copied to clipboard!
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): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| name | Required Logical name | String |
9.2.2. Query Parameters (8 parameters): Copy linkLink copied to clipboard!
| 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 options 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. Action Copy linkLink copied to clipboard!
Supported actions are:
- QUEUE_STATUS, Queue Status
- SIP_PEERS, List SIP Peers
- EXTENSION_STATE, Check Extension Status
Chapter 10. Atmos Component Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| name | Atmos name | String | |
| operation | Required Operation to perform | AtmosOperation |
10.1.2. Query Parameters (12 parameters): Copy linkLink copied to clipboard!
| 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 options 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. Dependencies Copy linkLink copied to clipboard!
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.3. Integrations Copy linkLink copied to clipboard!
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.4. Examples Copy linkLink copied to clipboard!
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.5. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 11. Atmosphere Websocket Component Copy linkLink copied to clipboard!
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>
11.1. Atmosphere-Websocket Options Copy linkLink copied to clipboard!
The Atmosphere Websocket component supports 8 options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
| servletName (common) | Default name of servlet to use. The default name is CamelServlet. | String | |
| httpRegistry (common) | To use a custom org.apache.camel.component.servlet.HttpRegistry. | HttpRegistry | |
| attachmentMultipart Binding (common) | 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 |
| 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:
11.1.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| servicePath | Required Name of websocket endpoint | String |
11.1.2. Query Parameters (37 parameters): Copy linkLink copied to clipboard!
| 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 options 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 | |
| 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 |
11.2. URI Format Copy linkLink copied to clipboard!
atmosphere-websocket:///relative path[?options]
11.3. Reading and Writing Data over Websocket Copy linkLink copied to clipboard!
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.
11.4. Configuring URI to Read or Write Data Copy linkLink copied to clipboard!
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>
11.5. See Also Copy linkLink copied to clipboard!
Chapter 12. Atom Component Copy linkLink copied to clipboard!
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>
12.1. URI format Copy linkLink copied to clipboard!
atom://atomUri[?options]
Where atomUri is the URI to the Atom feed to poll.
12.2. Options Copy linkLink copied to clipboard!
The Atom component has no options.
The Atom endpoint is configured using URI syntax:
atom:feedUri
with the following path and query parameters:
12.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| feedUri | Required The URI to the feed to poll. | String |
12.2.2. Query Parameters (27 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
You can append query options to the URI in the following format, ?option=value&option=value&…
12.3. Exchange data format Copy linkLink copied to clipboard!
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):
12.4. Message Headers Copy linkLink copied to clipboard!
Camel atom uses these headers.
| Header | Description |
|---|---|
|
|
When consuming the |
12.5. Samples Copy linkLink copied to clipboard!
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.
12.6. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- RSS
Chapter 13. Atomix Map Component Copy linkLink copied to clipboard!
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>
13.1. URI format Copy linkLink copied to clipboard!
atomix-map:mapName
13.2. Options Copy linkLink copied to clipboard!
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:
13.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| resourceName | Required The distributed resource name | String |
13.2.2. Query Parameters (18 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
13.3. Headers Copy linkLink copied to clipboard!
| 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 |
13.4. Configuring the component to connect to an Atomix cluster Copy linkLink copied to clipboard!
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>
13.5. Usage examples: Copy linkLink copied to clipboard!
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 14. Atomix Messaging Component Copy linkLink copied to clipboard!
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>
14.1. URI format Copy linkLink copied to clipboard!
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:
14.1.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| resourceName | Required The distributed resource name | String |
14.1.2. Query Parameters (19 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
Chapter 15. Atomix MultiMap Component Copy linkLink copied to clipboard!
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>
15.1. URI format Copy linkLink copied to clipboard!
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:
15.1.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| resourceName | Required The distributed resource name | String |
15.1.2. Query Parameters (18 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
Chapter 16. Atomix Queue Component Copy linkLink copied to clipboard!
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>
16.1. URI format Copy linkLink copied to clipboard!
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:
16.1.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| resourceName | Required The distributed resource name | String |
16.1.2. Query Parameters (16 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
Chapter 17. Atomix Set Component Copy linkLink copied to clipboard!
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>
17.1. URI format Copy linkLink copied to clipboard!
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:
17.1.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| resourceName | Required The distributed resource name | String |
17.1.2. Query Parameters (17 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
Chapter 18. Atomix Value Component Copy linkLink copied to clipboard!
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>
18.1. URI format Copy linkLink copied to clipboard!
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:
18.1.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| resourceName | Required The distributed resource name | String |
18.1.2. Query Parameters (17 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
Chapter 19. Avro Component Copy linkLink copied to clipboard!
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>
19.1. Apache Avro Overview Copy linkLink copied to clipboard!
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.
19.2. Using the Avro data format Copy linkLink copied to clipboard!
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.
19.3. Using Avro RPC in Camel Copy linkLink copied to clipboard!
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.
19.4. Avro RPC URI Options Copy linkLink copied to clipboard!
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:
19.4.1. Path Parameters (4 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| transport | Required Transport to use | AvroTransport | |
| port | Required Port number to use | int | |
| host | Required Hostname to use | String | |
| messageName | The name of the message to send. | String |
19.4.2. Query Parameters (10 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
19.5. Avro RPC Headers Copy linkLink copied to clipboard!
| Name | Description |
|---|---|
|
| The name of the message to send. In consumer overrides message name from URI (if any) |
19.6. Examples Copy linkLink copied to clipboard!
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 20. Avro DataFormat Copy linkLink copied to clipboard!
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>
20.1. Apache Avro Overview Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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. Avro Dataformat Options Copy linkLink copied to clipboard!
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. |
Chapter 21. AWS CloudWatch Component Copy linkLink copied to clipboard!
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.
21.1. URI Format Copy linkLink copied to clipboard!
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&…
21.2. URI Options Copy linkLink copied to clipboard!
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:
21.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| namespace | Required The metric namespace | String |
21.2.2. Query Parameters (11 parameters): Copy linkLink copied to clipboard!
| 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 |
Required CW component options
You have to provide the amazonCwClient in the Registry or your accessKey and secretKey to access the Amazon’s CloudWatch.
21.3. Usage Copy linkLink copied to clipboard!
21.3.1. Message headers evaluated by the CW producer Copy linkLink copied to clipboard!
| 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. |
21.3.2. Advanced AmazonCloudWatch configuration Copy linkLink copied to clipboard!
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);
21.4. Dependencies Copy linkLink copied to clipboard!
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).
21.5. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 22. AWS DynamoDB Component Copy linkLink copied to clipboard!
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.
22.1. URI Format Copy linkLink copied to clipboard!
aws-ddb://domainName[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
22.2. URI Options Copy linkLink copied to clipboard!
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:
22.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| tableName | Required The name of the table currently worked with. | String |
22.2.2. Query Parameters (13 parameters): Copy linkLink copied to clipboard!
| 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 |
Required DDB component options
You have to provide the amazonDDBClient in the Registry or your accessKey and secretKey to access the Amazon’s DynamoDB.
22.3. Usage Copy linkLink copied to clipboard!
22.3.1. Message headers evaluated by the DDB producer Copy linkLink copied to clipboard!
| 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. |
22.3.2. Message headers set during BatchGetItems operation Copy linkLink copied to clipboard!
| 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. |
22.3.3. Message headers set during DeleteItem operation Copy linkLink copied to clipboard!
| Header | Type | Description |
|---|---|---|
|
|
| The list of attributes returned by the operation. |
22.3.4. Message headers set during DeleteTable operation Copy linkLink copied to clipboard!
| 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 |
22.3.5. Message headers set during DescribeTable operation Copy linkLink copied to clipboard!
| 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. |
22.3.6. Message headers set during GetItem operation Copy linkLink copied to clipboard!
| Header | Type | Description |
|---|---|---|
|
|
| The list of attributes returned by the operation. |
22.3.7. Message headers set during PutItem operation Copy linkLink copied to clipboard!
| Header | Type | Description |
|---|---|---|
|
|
| The list of attributes returned by the operation. |
22.3.8. Message headers set during Query operation Copy linkLink copied to clipboard!
| 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. |
22.3.9. Message headers set during Scan operation Copy linkLink copied to clipboard!
| 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. |
22.3.10. Message headers set during UpdateItem operation Copy linkLink copied to clipboard!
| Header | Type | Description |
|---|---|---|
|
|
| The list of attributes returned by the operation. |
22.3.11. Advanced AmazonDynamoDB configuration Copy linkLink copied to clipboard!
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);
22.4. Dependencies Copy linkLink copied to clipboard!
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.5. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 23. AWS DynamoDB Streams Component Copy linkLink copied to clipboard!
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
23.1. URI Format Copy linkLink copied to clipboard!
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&…
23.2. URI Options Copy linkLink copied to clipboard!
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:
23.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| tableName | Required Name of the dynamodb table | String |
23.2.2. Query Parameters (28 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
Required DynampDBStream component options
You have to provide the amazonDynamoDbStreamsClient in the Registry with proxies and relevant credentials configured.
23.3. Sequence Numbers Copy linkLink copied to clipboard!
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.
23.4. Batch Consumer Copy linkLink copied to clipboard!
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.
23.5. Usage Copy linkLink copied to clipboard!
23.5.1. AmazonDynamoDBStreamsClient configuration Copy linkLink copied to clipboard!
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);
23.5.2. Providing AWS Credentials Copy linkLink copied to clipboard!
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(…).
23.6. Coping with Downtime Copy linkLink copied to clipboard!
23.6.1. AWS DynamoDB Streams outage of less than 24 hours Copy linkLink copied to clipboard!
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.
23.6.2. AWS DynamoDB Streams outage of more than 24 hours Copy linkLink copied to clipboard!
Given that AWS only retain 24 hours worth of changes, you will have missed change events no matter what mitigations are in place.
23.7. Dependencies Copy linkLink copied to clipboard!
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).
23.8. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
-
AWS Component
+
Chapter 24. AWS EC2 Component Copy linkLink copied to clipboard!
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.
24.1. URI Format Copy linkLink copied to clipboard!
aws-ec2://label[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
24.2. URI Options Copy linkLink copied to clipboard!
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:
24.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| label | Required Logical name | String |
24.2.2. Query Parameters (8 parameters): Copy linkLink copied to clipboard!
| 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 |
Required EC2 component options
You have to provide the amazonEc2Client in the Registry or your accessKey and secretKey to access the Amazon EC2 service.
24.3. Usage Copy linkLink copied to clipboard!
24.3.1. Message headers evaluated by the EC2 producer Copy linkLink copied to clipboard!
| 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).
24.4. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 25. AWS IAM Component Copy linkLink copied to clipboard!
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.
25.1. URI Format Copy linkLink copied to clipboard!
aws-kms://label[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
25.2. URI Options Copy linkLink copied to clipboard!
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:
25.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| label | Required Logical name | String |
25.2.2. Query Parameters (8 parameters): Copy linkLink copied to clipboard!
| 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 |
25.3. Spring Boot Auto-Configuration Copy linkLink copied to clipboard!
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.
25.4. Usage Copy linkLink copied to clipboard!
25.4.1. Message headers evaluated by the IAM producer Copy linkLink copied to clipboard!
| 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 |
25.4.2. IAM Producer operations Copy linkLink copied to clipboard!
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).
25.5. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 26. AWS Kinesis Component Copy linkLink copied to clipboard!
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
26.1. URI Format Copy linkLink copied to clipboard!
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&…
26.2. URI Options Copy linkLink copied to clipboard!
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:
26.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| streamName | Required Name of the stream | String |
26.2.2. Query Parameters (30 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
Required Kinesis component options
You have to provide the amazonKinesisClient in the Registry with proxies and relevant credentials configured.
26.3. Batch Consumer Copy linkLink copied to clipboard!
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.
26.4. Usage Copy linkLink copied to clipboard!
26.4.1. Message headers set by the Kinesis consumer Copy linkLink copied to clipboard!
| 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. |
26.4.2. AmazonKinesis configuration Copy linkLink copied to clipboard!
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");
26.4.3. Providing AWS Credentials Copy linkLink copied to clipboard!
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(…).
26.4.4. Message headers used by the Kinesis producer to write to Kinesis. The producer expects that the message body is a ByteBuffer. Copy linkLink copied to clipboard!
| Header | Type | Description |
|---|---|---|
|
|
| The PartitionKey to pass to Kinesis to store this record. |
|
|
| Optional paramter to indicate the sequence number of this record. |
26.4.5. Message headers set by the Kinesis producer on successful storage of a Record Copy linkLink copied to clipboard!
| Header | Type | Description |
|---|---|---|
|
|
| The sequence number of the record, as defined in Response Syntax |
|
|
| The shard ID of where the Record was stored |
26.5. Dependencies Copy linkLink copied to clipboard!
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).
26.6. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 27. AWS Kinesis Firehose Component Copy linkLink copied to clipboard!
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
27.1. URI Format Copy linkLink copied to clipboard!
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&…
27.2. URI Options Copy linkLink copied to clipboard!
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:
27.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| streamName | Required Name of the stream | String |
27.2.2. Query Parameters (7 parameters): Copy linkLink copied to clipboard!
| 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 |
Required Kinesis Firehose component options
You have to provide the amazonKinesisClient in the Registry with proxies and relevant credentials configured.
27.3. Usage Copy linkLink copied to clipboard!
27.3.1. Amazon Kinesis Firehose configuration Copy linkLink copied to clipboard!
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");
27.3.2. Providing AWS Credentials Copy linkLink copied to clipboard!
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.3.3. Message headers set by the Kinesis producer on successful storage of a Record Copy linkLink copied to clipboard!
| Header | Type | Description |
|---|---|---|
|
|
| The record ID, as defined in Response Syntax |
27.4. Dependencies Copy linkLink copied to clipboard!
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).
27.5. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 28. AWS KMS Component Copy linkLink copied to clipboard!
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.
28.1. URI Format Copy linkLink copied to clipboard!
aws-kms://label[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
28.2. URI Options Copy linkLink copied to clipboard!
The AWS KMS component supports 5 options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
| configuration (advanced) | The AWS MQ default configuration | KMSConfiguration | |
| 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 KMS endpoint is configured using URI syntax:
aws-kms:label
with the following path and query parameters:
28.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| label | Required Logical name | String |
28.2.2. Query Parameters (8 parameters): Copy linkLink copied to clipboard!
| 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 |
Required KMS component options
You have to provide the amazonKmsClient in the Registry or your accessKey and secretKey to access the Amazon KMS service.
28.3. Usage Copy linkLink copied to clipboard!
28.3.1. Message headers evaluated by the MQ producer Copy linkLink copied to clipboard!
| 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 |
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).
28.4. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 29. AWS Lambda Component Copy linkLink copied to clipboard!
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.
29.1. URI Format Copy linkLink copied to clipboard!
aws-lambda://functionName[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
29.2. URI Options Copy linkLink copied to clipboard!
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:
29.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| function | Required Name of the Lambda function. | String |
29.2.2. Query Parameters (8 parameters): Copy linkLink copied to clipboard!
| 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 |
Required Lambda component options
You have to provide the awsLambdaClient in the Registry or your accessKey and secretKey to access the Amazon Lambda service.
29.3. Usage Copy linkLink copied to clipboard!
29.3.1. Message headers evaluated by the Lambda producer Copy linkLink copied to clipboard!
| 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 |
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.4. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 30. AWS MQ Component Copy linkLink copied to clipboard!
Available as of Camel version 2.21
The MQ 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.
30.1. URI Format Copy linkLink copied to clipboard!
aws-mq://label[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
30.2. URI Options Copy linkLink copied to clipboard!
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:
30.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| label | Required Logical name | String |
30.2.2. Query Parameters (8 parameters): Copy linkLink copied to clipboard!
| 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 |
Required EC2 component options
You have to provide the amazonEc2Client in the Registry or your accessKey and secretKey to access the Amazon EC2 service.
30.3. Usage Copy linkLink copied to clipboard!
30.3.1. Message headers evaluated by the MQ producer Copy linkLink copied to clipboard!
| 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 |
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.4. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 31. AWS S3 Storage Service Component Copy linkLink copied to clipboard!
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.
31.1. URI Format Copy linkLink copied to clipboard!
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");
31.2. URI Options Copy linkLink copied to clipboard!
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:
31.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| bucketNameOrArn | Required Bucket name or ARN | String |
31.2.2. Query Parameters (50 parameters): Copy linkLink copied to clipboard!
| 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.AmazonS3setBucketPolicy() 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 link S3ConstantsBUCKET_NAME and link S3ConstantsKEY headers, or only the link S3ConstantsKEY 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 options 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 |
Required S3 component options
You have to provide the amazonS3Client in the Registry or your accessKey and secretKey to access the Amazon’s S3.
31.3. Batch Consumer Copy linkLink copied to clipboard!
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.
31.4. Usage Copy linkLink copied to clipboard!
31.4.1. Message headers evaluated by the S3 producer Copy linkLink copied to clipboard!
| 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, listBuckets, deleteBucket, downloadLink |
|
|
| 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 |
31.4.2. Message headers set by the S3 producer Copy linkLink copied to clipboard!
| 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. |
31.4.3. Message headers set by the S3 consumer Copy linkLink copied to clipboard!
| 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. |
31.4.4. Advanced AmazonS3 configuration Copy linkLink copied to clipboard!
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");
31.4.5. Use KMS with the S3 component Copy linkLink copied to clipboard!
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.
31.4.6. Use "useIAMCredentials" with the s3 component Copy linkLink copied to clipboard!
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.
31.5. Dependencies Copy linkLink copied to clipboard!
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).
31.6. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 32. AWS SimpleDB Component Copy linkLink copied to clipboard!
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.
32.1. URI Format Copy linkLink copied to clipboard!
aws-sdb://domainName[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
32.2. URI Options Copy linkLink copied to clipboard!
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:
32.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| domainName | Required The name of the domain currently worked with. | String |
32.2.2. Query Parameters (10 parameters): Copy linkLink copied to clipboard!
| 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 |
Required SDB component options
You have to provide the amazonSDBClient in the Registry or your accessKey and secretKey to access the Amazon’s SDB.
32.3. Usage Copy linkLink copied to clipboard!
32.3.1. Message headers evaluated by the SDB producer Copy linkLink copied to clipboard!
| 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. |
32.3.2. Message headers set during DomainMetadata operation Copy linkLink copied to clipboard!
| 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. |
32.3.3. Message headers set during GetAttributes operation Copy linkLink copied to clipboard!
| Header | Type | Description |
|---|---|---|
|
|
| The list of attributes returned by the operation. |
32.3.4. Message headers set during ListDomains operation Copy linkLink copied to clipboard!
| 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. |
32.3.5. Message headers set during Select operation Copy linkLink copied to clipboard!
| 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. |
32.3.6. Advanced AmazonSimpleDB configuration Copy linkLink copied to clipboard!
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);
32.4. Dependencies Copy linkLink copied to clipboard!
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).
32.5. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 33. AWS Simple Email Service Component Copy linkLink copied to clipboard!
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.
33.1. URI Format Copy linkLink copied to clipboard!
aws-ses://from[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
33.2. URI Options Copy linkLink copied to clipboard!
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:
33.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| from | Required The sender’s email address. | String |
33.2.2. Query Parameters (11 parameters): Copy linkLink copied to clipboard!
| 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 |
Required SES component options
You have to provide the amazonSESClient in the Registry or your accessKey and secretKey to access the Amazon’s SES.
33.3. Usage Copy linkLink copied to clipboard!
33.3.1. Message headers evaluated by the SES producer Copy linkLink copied to clipboard!
| 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. |
33.3.2. Message headers set by the SES producer Copy linkLink copied to clipboard!
| Header | Type | Description |
|---|---|---|
|
|
| The Amazon SES message ID. |
33.3.3. Advanced AmazonSimpleEmailService configuration Copy linkLink copied to clipboard!
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);
33.4. Dependencies Copy linkLink copied to clipboard!
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.5. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 34. AWS Simple Notification System Component Copy linkLink copied to clipboard!
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.
34.1. URI Format Copy linkLink copied to clipboard!
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&…
34.2. URI Options Copy linkLink copied to clipboard!
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:
34.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| topicNameOrArn | Required Topic name or ARN | String |
34.2.2. Query Parameters (11 parameters): Copy linkLink copied to clipboard!
| 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 |
Required SNS component options
You have to provide the amazonSNSClient in the Registry or your accessKey and secretKey to access the Amazon’s SNS.
34.3. Usage Copy linkLink copied to clipboard!
34.3.1. Message headers evaluated by the SNS producer Copy linkLink copied to clipboard!
| Header | Type | Description |
|---|---|---|
|
|
|
The Amazon SNS message subject. If not set, the subject from the |
34.3.2. Message headers set by the SNS producer Copy linkLink copied to clipboard!
| Header | Type | Description |
|---|---|---|
|
|
| The Amazon SNS message ID. |
34.3.3. Advanced AmazonSNS configuration Copy linkLink copied to clipboard!
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);
34.4. Dependencies Copy linkLink copied to clipboard!
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).
34.5. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 35. AWS Simple Queue Service Component Copy linkLink copied to clipboard!
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.
35.1. URI Format Copy linkLink copied to clipboard!
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&…
35.2. URI Options Copy linkLink copied to clipboard!
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:
35.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| queueNameOrArn | Required Queue name or ARN | String |
35.2.2. Query Parameters (46 parameters): Copy linkLink copied to clipboard!
| 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 | |
| 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 options 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 | |
| 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 |
Required SQS component options
You have to provide the amazonSQSClient in the Registry or your accessKey and secretKey to access the Amazon’s SQS.
35.3. Batch Consumer Copy linkLink copied to clipboard!
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.
35.4. Usage Copy linkLink copied to clipboard!
35.4.1. Message headers set by the SQS producer Copy linkLink copied to clipboard!
| 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. |
35.4.2. Message headers set by the SQS consumer Copy linkLink copied to clipboard!
| 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. |
35.4.3. Advanced AmazonSQS configuration Copy linkLink copied to clipboard!
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");
35.5. Dependencies Copy linkLink copied to clipboard!
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).
35.6. JMS-style Selectors Copy linkLink copied to clipboard!
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.
35.7. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- AWS Component
Chapter 36. AWS Simple Workflow Component Copy linkLink copied to clipboard!
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.
36.1. URI Format Copy linkLink copied to clipboard!
aws-swf://<workflow|activity>[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
36.2. URI Options Copy linkLink copied to clipboard!
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:
36.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| type | Required Activity or workflow | String |
36.2.2. Query Parameters (30 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
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.
36.3. Usage Copy linkLink copied to clipboard!
36.3.1. Message headers evaluated by the SWF Workflow Producer Copy linkLink copied to clipboard!
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. |
36.3.2. Message headers set by the SWF Workflow Producer Copy linkLink copied to clipboard!
| Header | Type | Description |
|---|---|---|
|
|
| The worfklow ID used or newly generated. |
|
|
| The worfklow run ID used or generated. |
36.3.3. Message headers set by the SWF Workflow Consumer Copy linkLink copied to clipboard!
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. |
36.3.4. Message headers set by the SWF Activity Producer Copy linkLink copied to clipboard!
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. |
36.3.5. Message headers set by the SWF Activity Consumer Copy linkLink copied to clipboard!
| Header | Type | Description |
|---|---|---|
|
|
| The task token that is required to report task completion for manually completed tasks. |
36.3.6. Advanced amazonSWClient configuration Copy linkLink copied to clipboard!
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);
36.4. Dependencies Copy linkLink copied to clipboard!
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).
36.5. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
AWS Component
Chapter 37. AWS XRay Component Copy linkLink copied to clipboard!
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.
37.1. Dependency Copy linkLink copied to clipboard!
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>
37.2. Configuration Copy linkLink copied to clipboard!
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:
37.2.1. Explicit Copy linkLink copied to clipboard!
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.
37.2.2. Tracking of comprehensive route execution Copy linkLink copied to clipboard!
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.
37.3. Example Copy linkLink copied to clipboard!
You can find an example demonstrating the way to configure AWS XRay tracing within the tests accompanying this project.
Chapter 38. Camel Components for Windows Azure Services Copy linkLink copied to clipboard!
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 39. Azure Storage Blob Service Component Copy linkLink copied to clipboard!
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.
39.1. URI Format Copy linkLink copied to clipboard!
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, 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");
39.2. URI Options Copy linkLink copied to clipboard!
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:
39.2.1. Path Parameters (1 parameter) Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| containerOrBlobUri | Required: Container or Blob compact URI. | String |
39.2.2. Query Parameters (19 parameters) Copy linkLink copied to clipboard!
| 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 | 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. | String | |
| publicForRead (common) | Storage resources can be public for reading their content. If this property is enabled, 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. This means any exceptions that occurred (for example, while the consumer was trying to pick up incoming messages), will now be processed as a message and handled by the routing Error Handler. By default, the consumer will use the | false | boolean |
| exceptionHandler (consumer) |
To let the consumer use a custom | ExceptionHandler | |
| exchangePattern (consumer) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
| blobMetadata (producer) | Set the blob metadata. | Map | |
| blobPrefix (producer) | Set a prefix that 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 |
Required Azure Storage Blob Service component options
You must provide the containerOrBlob name and the credentials if the private blob needs to be accessed.
39.3. Usage Copy linkLink copied to clipboard!
39.3.1. Message headers set by the Azure Storage Blob Service producer Copy linkLink copied to clipboard!
| Header | Type | Description |
|---|---|---|
|
|
| The file name for the downloaded blob content. |
39.3.2. Message headers set by the Azure Storage Blob Service producer consumer Copy linkLink copied to clipboard!
| Header | Type | Description |
|---|---|---|
|
|
| The file name for the downloaded blob content. |
39.3.3. Azure Blob Service operations Copy linkLink copied to clipboard!
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. |
39.3.4. Azure Blob Client configuration Copy linkLink copied to clipboard!
If your Camel application is running behind a firewall or if you need more control over the Azure Blob Client configuration, you can create your own instance:
StorageCredentials credentials = new StorageCredentialsAccountAndKey(accountName, accessKey);
CloudBlob client = new CloudBlockBlob(URI.create("https://"
+ accountName + ".blob.core.windows.net/" + containerName
+ "/" + fileName), credentials);
registry.bind("azureBlobClient", client);
Refer to this instance in your Camel azure-blob component configuration:
from("azure-blob://" + accountName + "/" + containerName + "/" + fileName + "?azureBlobClient=#client")
.to("mock:result");
39.4. Dependencies Copy linkLink copied to clipboard!
Maven users must 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).
39.5. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- Azure Component
Chapter 40. Azure Storage Queue Service Component Copy linkLink copied to clipboard!
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 Windows Azure Storage account. More information is available at Azure Documentation Portal.
40.1. URI Format Copy linkLink copied to clipboard!
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, to get a message content from the queue messageQueue in the camelazure storage account, use the following snippet:
from("azure-queue:camelazure/messageQueue").
to("file://queuedirectory");
40.2. URI Options Copy linkLink copied to clipboard!
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:
40.2.1. Path Parameters (1 parameter) Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| containerAndQueueUri | Required: Container Queue compact URI. | String |
40.2.2. Query Parameters (10 parameters) Copy linkLink copied to clipboard!
| 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. This means any exceptions that occurred (for example, while the consumer was trying to pick up incoming messages) will now be processed as a message and handled by the routing Error Handler. By default, the consumer will use the | false | boolean |
| exceptionHandler (consumer) |
To let the consumer use a custom | 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) | Queue service operation hint to the producer. | 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 |
Required Azure Storage Queue Service component options
You must provide the containerAndQueue URI and the credentials.
40.3. Usage Copy linkLink copied to clipboard!
40.3.1. Azure Queue Service operations Copy linkLink copied to clipboard!
| 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. |
40.3.2. Azure Queue Client configuration Copy linkLink copied to clipboard!
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");
40.4. Dependencies Copy linkLink copied to clipboard!
Maven users must 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.5. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- Azure Component
Chapter 41. Barcode DataFormat Copy linkLink copied to clipboard!
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.
41.1. Dependencies Copy linkLink copied to clipboard!
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>
41.2. Barcode Options Copy linkLink copied to clipboard!
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. |
41.3. Using the Java DSL Copy linkLink copied to clipboard!
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.
41.3.1. Marshalling Copy linkLink copied to clipboard!
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:
41.3.2. Unmarshalling Copy linkLink copied to clipboard!
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 42. Base64 DataFormat Copy linkLink copied to clipboard!
Available as of Camel version 2.11
The Base64 data format is used for base64 encoding and decoding.
42.1. Options Copy linkLink copied to clipboard!
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. |
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.
42.2. Marshal Copy linkLink copied to clipboard!
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"/>
42.3. Unmarshal Copy linkLink copied to clipboard!
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">
<marshal>
<base64/>
</marshal>
<to uri="bean:newOrder"/>
42.4. Dependencies Copy linkLink copied to clipboard!
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 43. Bean Component Copy linkLink copied to clipboard!
Available as of Camel version 1.0
The bean: component binds beans to Camel message exchanges.
43.1. URI format Copy linkLink copied to clipboard!
bean:beanName[?options]
Where beanID can be any string which is used to look up the bean in the Registry
43.2. Options Copy linkLink copied to clipboard!
The Bean component has no options.
The Bean endpoint is configured using URI syntax:
bean:beanName
with the following path and query parameters:
43.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| beanName | Required Sets the name of the bean to invoke | String |
43.2.2. Query Parameters (5 parameters): Copy linkLink copied to clipboard!
| 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. | false | 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&…
43.3. Using Copy linkLink copied to clipboard!
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>
43.4. Bean as endpoint Copy linkLink copied to clipboard!
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.
43.5. Java DSL bean syntax Copy linkLink copied to clipboard!
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);
43.6. Bean Binding Copy linkLink copied to clipboard!
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.
43.7. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- Class component
- Bean Binding
- Bean Integration
Chapter 44. BeanIO DataFormat Copy linkLink copied to clipboard!
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.
44.1. Options Copy linkLink copied to clipboard!
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. |
44.2. Usage Copy linkLink copied to clipboard!
An example of a mapping file is here.
44.2.1. Using Java DSL Copy linkLink copied to clipboard!
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:
44.2.2. Using XML DSL Copy linkLink copied to clipboard!
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.
44.3. Dependencies Copy linkLink copied to clipboard!
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 45. Beanstalk Component Copy linkLink copied to clipboard!
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.
45.1. Dependencies Copy linkLink copied to clipboard!
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).
45.2. URI format Copy linkLink copied to clipboard!
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.
45.3. Beanstalk options Copy linkLink copied to clipboard!
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:
45.3.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| connectionSettings | Connection settings host:port/tube | String |
45.3.2. Query Parameters (26 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
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.
45.4. Consumer Headers Copy linkLink copied to clipboard!
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 |
45.5. Examples Copy linkLink copied to clipboard!
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.
45.6. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 46. Bean Validator Component Copy linkLink copied to clipboard!
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>
46.1. URI format Copy linkLink copied to clipboard!
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&…
46.2. URI Options Copy linkLink copied to clipboard!
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:
46.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| label | Required Where label is an arbitrary text value describing the endpoint | String |
46.2.2. Query Parameters (6 parameters): Copy linkLink copied to clipboard!
| 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 |
46.3. OSGi deployment Copy linkLink copied to clipboard!
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.
46.4. Example Copy linkLink copied to clipboard!
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>
46.5. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 47. Binding Component (deprecated) Copy linkLink copied to clipboard!
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.
47.1. Options Copy linkLink copied to clipboard!
The Binding component has no options.
The Binding endpoint is configured using URI syntax:
binding:bindingName:delegateUri
with the following path and query parameters:
47.1.1. Path Parameters (2 parameters): Copy linkLink copied to clipboard!
| 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 |
47.1.2. Query Parameters (4 parameters): Copy linkLink copied to clipboard!
| 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 |
47.2. Using Bindings Copy linkLink copied to clipboard!
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).
47.3. Using the binding URI Copy linkLink copied to clipboard!
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.
47.4. Using a BindingComponent Copy linkLink copied to clipboard!
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.
47.5. When to use Bindings Copy linkLink copied to clipboard!
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 48. Bindy DataFormat Copy linkLink copied to clipboard!
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.
48.1. Options Copy linkLink copied to clipboard!
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. |
48.2. Annotations Copy linkLink copied to clipboard!
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 :
48.3. 1. CsvRecord Copy linkLink copied to clipboard!
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'. 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
48.4. 2. Link Copy linkLink copied to clipboard!
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 {
}
48.5. 3. DataField Copy linkLink copied to clipboard!
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.
48.6. 4. FixedLengthRecord Copy linkLink copied to clipboard!
The FixedLengthRecord annotation is used to identified the root class of the model. It represents a record = a line of a file/message containing data fixed length formatted and can be linked to several children model classes. This format is a bit particular beause 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 'padd' characters.
| Annotation name | Record type | Level |
|---|---|---|
| FixedLengthRecord | fixed | Class |
| Parameter name | type | Info |
|---|---|---|
| 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). This option is used only during marshalling, whereas unmarshalling uses system default JDK provided line delimiter unless eol is customized |
| eol | string | optional - default="" which is empty 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 |
| paddingChar | char | mandatory - default value = ' ' |
| length | int | mandatory = size of the fixed length record |
| hasHeader | boolean | Camel 2.11 - optional - Indicates that the record(s) of this type may be preceded by a single header record at the beginning of the file / stream |
| hasFooter | boolean | Camel 2.11 - optional - Indicates that the record(s) of this type may be followed by a single footer record at the end of the file / stream |
| skipHeader | boolean | Camel 2.11 - optional - 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). |
| skipFooter | boolean | Camel 2.11 - optional - 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).. |
| isHeader | boolean | Camel 2.11 - optional - Identifies this FixedLengthRecord as a header record |
| isFooter | boolean | Camel 2.11 - optional - Identifies this FixedLengthRecords as a footer record |
| ignoreTrailingChars | boolean | Camel 2.11.1 - optional - 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. |
The hasHeader/hasFooter parameters are mutually exclusive with isHeader/isFooter. A record may not be both a header/footer and a primary fixed-length record.
case 1 : Simple fixed length record
This simple example shows how to design the model to parse/format a fixed message
10A9PaulineMISINXD12345678BUYShare2500.45USD01-08-2009
Fixed-simple
@FixedLengthRecord(length=54, paddingChar=' ')
public static class Order {
@DataField(pos = 1, length=2)
private int orderNr;
@DataField(pos = 3, length=2)
private String clientNr;
@DataField(pos = 5, length=7)
private String firstName;
@DataField(pos = 12, length=1, align="L")
private String lastName;
@DataField(pos = 13, length=4)
private String instrumentCode;
@DataField(pos = 17, length=10)
private String instrumentNumber;
@DataField(pos = 27, length=3)
private String orderType;
@DataField(pos = 30, length=5)
private String instrumentType;
@DataField(pos = 35, precision = 2, length=7)
private BigDecimal amount;
@DataField(pos = 42, length=3)
private String currency;
@DataField(pos = 45, length=10, pattern = "dd-MM-yyyy")
private Date orderDate;
}
case 2 : Fixed length record with alignment and padding
This more elaborated example show how to define the alignment for a field and how to assign a padding character which is ' ' here''
10A9 PaulineM ISINXD12345678BUYShare2500.45USD01-08-2009
Fixed-padding-align
@FixedLengthRecord(length=60, paddingChar=' ')
public static class Order {
@DataField(pos = 1, length=2)
private int orderNr;
@DataField(pos = 3, length=2)
private String clientNr;
@DataField(pos = 5, length=9)
private String firstName;
@DataField(pos = 14, length=5, align="L") // align text to the LEFT zone of the block
private String lastName;
@DataField(pos = 19, length=4)
private String instrumentCode;
@DataField(pos = 23, length=10)
private String instrumentNumber;
@DataField(pos = 33, length=3)
private String orderType;
@DataField(pos = 36, length=5)
private String instrumentType;
@DataField(pos = 41, precision = 2, length=7)
private BigDecimal amount;
@DataField(pos = 48, length=3)
private String currency;
@DataField(pos = 51, length=10, pattern = "dd-MM-yyyy")
private Date orderDate;
}
case 3 : Field padding
Sometimes, the default padding defined for record cannnot be applied to the field as we have a number format where we would like to padd with '0' instead of ' '. In this case, you can use in the model the attribute paddingField to set this value.
10A9 PaulineM ISINXD12345678BUYShare000002500.45USD01-08-2009
Fixed-padding-field
@FixedLengthRecord(length = 65, paddingChar = ' ')
public static class Order {
@DataField(pos = 1, length = 2)
private int orderNr;
@DataField(pos = 3, length = 2)
private String clientNr;
@DataField(pos = 5, length = 9)
private String firstName;
@DataField(pos = 14, length = 5, align = "L")
private String lastName;
@DataField(pos = 19, length = 4)
private String instrumentCode;
@DataField(pos = 23, length = 10)
private String instrumentNumber;
@DataField(pos = 33, length = 3)
private String orderType;
@DataField(pos = 36, length = 5)
private String instrumentType;
@DataField(pos = 41, precision = 2, length = 12, paddingChar = '0')
private BigDecimal amount;
@DataField(pos = 53, length = 3)
private String currency;
@DataField(pos = 56, length = 10, pattern = "dd-MM-yyyy")
private Date orderDate;
}
case 4: Fixed length record with delimiter
Fixed-length records sometimes have delimited content within the record. The firstName and lastName fields are delimited with the '^' character in the following example:
10A9Pauline^M^ISINXD12345678BUYShare000002500.45USD01-08-2009
Fixed-delimited
@FixedLengthRecord()
public static class Order {
@DataField(pos = 1, length = 2)
private int orderNr;
@DataField(pos = 2, length = 2)
private String clientNr;
@DataField(pos = 3, delimiter = "^")
private String firstName;
@DataField(pos = 4, delimiter = "^")
private String lastName;
@DataField(pos = 5, length = 4)
private String instrumentCode;
@DataField(pos = 6, length = 10)
private String instrumentNumber;
@DataField(pos = 7, length = 3)
private String orderType;
@DataField(pos = 8, length = 5)
private String instrumentType;
@DataField(pos = 9, precision = 2, length = 12, paddingChar = '0')
private BigDecimal amount;
@DataField(pos = 10, length = 3)
private String currency;
@DataField(pos = 11, length = 10, pattern = "dd-MM-yyyy")
private Date orderDate;
}
As of Camel 2.11 the 'pos' value(s) in a fixed-length record may optionally be defined using ordinal, sequential values instead of precise column numbers.
case 5 : Fixed length record with record-defined field length
Occasionally a fixed-length record may contain a field that define the expected length of another field within the same record. In the following example the length of the instrumentNumber field value is defined by the value of instrumentNumberLen field in the record.
10A9Pauline^M^ISIN10XD12345678BUYShare000002500.45USD01-08-2009
Fixed-delimited
@FixedLengthRecord()
public static class Order {
@DataField(pos = 1, length = 2)
private int orderNr;
@DataField(pos = 2, length = 2)
private String clientNr;
@DataField(pos = 3, delimiter = "^")
private String firstName;
@DataField(pos = 4, delimiter = "^")
private String lastName;
@DataField(pos = 5, length = 4)
private String instrumentCode;
@DataField(pos = 6, length = 2, align = "R", paddingChar = '0')
private int instrumentNumberLen;
@DataField(pos = 7, lengthPos=6)
private String instrumentNumber;
@DataField(pos = 8, length = 3)
private String orderType;
@DataField(pos = 9, length = 5)
private String instrumentType;
@DataField(pos = 10, precision = 2, length = 12, paddingChar = '0')
private BigDecimal amount;
@DataField(pos = 11, length = 3)
private String currency;
@DataField(pos = 12, length = 10, pattern = "dd-MM-yyyy")
private Date orderDate;
}
case 6 : Fixed length record with header and footer
Bindy will discover fixed-length header and footer records that are configured as part of the model – provided that the annotated classes exist either in the same package as the primary @FixedLengthRecord class, or within one of the configured scan packages. The following text illustrates two fixed-length records that are bracketed by a header record and footer record.
101-08-2009
10A9 PaulineM ISINXD12345678BUYShare000002500.45USD01-08-2009
10A9 RichN ISINXD12345678BUYShare000002700.45USD01-08-2009
9000000002
Fixed-header-and-footer-main-class
@FixedLengthRecord(hasHeader = true, hasFooter = true)
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(isHeader = true)
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(isFooter = true)
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. (Camel 2.11.1)
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
}
48.7. 5. Message Copy linkLink copied to clipboard!
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)
48.8. 6. KeyValuePairField Copy linkLink copied to clipboard!
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;
}
48.9. 7. Section Copy linkLink copied to clipboard!
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;
}
48.10. 8. OneToMany Copy linkLink copied to clipboard!
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;
}
48.11. 9. BindyConverter Copy linkLink copied to clipboard!
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();
}
}
48.12. 10. FormatFactories Copy linkLink copied to clipboard!
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);
}
};
}
}
48.13. Supported Datatypes Copy linkLink copied to clipboard!
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).
48.14. Using the Java DSL Copy linkLink copied to clipboard!
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);
48.14.1. Setting locale Copy linkLink copied to clipboard!
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());
48.14.2. Unmarshaling Copy linkLink copied to clipboard!
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");
48.14.3. Marshaling Copy linkLink copied to clipboard!
To generate CSV records from a collection of model objects, you create the following route :
from("direct:handleOrders")
.marshal(bindy)
.to("file://outbox")
48.15. Using Spring XML Copy linkLink copied to clipboard!
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
48.16. Dependencies Copy linkLink copied to clipboard!
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 49. Using OSGi blueprint with Camel Copy linkLink copied to clipboard!
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.
49.1. Overview Copy linkLink copied to clipboard!
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
49.2. Using camel-blueprint Copy linkLink copied to clipboard!
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 50. Bonita Component Copy linkLink copied to clipboard!
Available as of Camel version 2.19
Used for communicating with a remote Bonita BPM process engine.
50.1. URI format Copy linkLink copied to clipboard!
bonita://[operation]?[options]
Where operation is the specific action to perform on Bonita.
50.2. General Options Copy linkLink copied to clipboard!
The Bonita component has no options.
The Bonita endpoint is configured using URI syntax:
bonita:operation
with the following path and query parameters:
50.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| operation | Required Operation to use | BonitaOperation |
50.2.2. Query Parameters (9 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
50.3. Body content Copy linkLink copied to clipboard!
For the startCase operation, the input variables are retrieved from the body message. This one has to contains a Map<String,Serializable>.
50.4. Examples Copy linkLink copied to clipboard!
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")
50.5. Dependencies Copy linkLink copied to clipboard!
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 51. Boon DataFormat Copy linkLink copied to clipboard!
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.
51.1. Options Copy linkLink copied to clipboard!
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. |
51.2. Using the Java DSL Copy linkLink copied to clipboard!
DataFormat boonDataFormat = new BoonDataFormat("com.acme.model.Person");
from("activemq:My.Queue")
.unmarshal(boonDataFormat)
.to("mqseries:Another.Queue");
51.3. Using Blueprint XML Copy linkLink copied to clipboard!
<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>
51.4. Dependencies Copy linkLink copied to clipboard!
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-boon</artifactId>
<version>x.x.x</version>
</dependency>
Chapter 52. Box Component Copy linkLink copied to clipboard!
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>
52.1. Connection Authentication Types Copy linkLink copied to clipboard!
The Box component supports three different types of authenticated connections.
52.1.1. Standard Authentication Copy linkLink copied to clipboard!
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.
52.1.2. App Enterprise Authentication Copy linkLink copied to clipboard!
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.
52.1.3. App User Authentication Copy linkLink copied to clipboard!
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.
52.2. Box Options Copy linkLink copied to clipboard!
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:
52.2.1. Path Parameters (2 parameters): Copy linkLink copied to clipboard!
| 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 |
52.2.2. Query Parameters (20 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
52.3. URI format Copy linkLink copied to clipboard!
box:apiName/methodName
apiName can be one of:
- collaborations
- comments
- event-logs
- files
- folders
- groups
- events
- search
- tasks
- users
52.4. Producer Endpoints: Copy linkLink copied to clipboard!
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.
52.4.1. Endpoint Prefix collaborations Copy linkLink copied to clipboard!
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 |
52.4.2. Endpoint Prefix comments Copy linkLink copied to clipboard!
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 |
52.4.3. Endpoint Prefix events-logs Copy linkLink copied to clipboard!
For more information on Box event logs see https://developer.box.com/reference#events. The following endpoints can be invoked with the prefix events 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[] |
52.4.4. Endpoint Prefix files Copy linkLink copied to clipboard!
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 |
52.4.5. Endpoint Prefix folders Copy linkLink copied to clipboard!
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 | com.box.sdk.BoxFolder |
| 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 |
52.4.6. Endpoint Prefix groups Copy linkLink copied to clipboard!
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 |
52.4.7. Endpoint Prefix search Copy linkLink copied to clipboard!
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 |
52.4.8. Endpoint Prefix tasks Copy linkLink copied to clipboard!
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 |
52.4.9. Endpoint Prefix users Copy linkLink copied to clipboard!
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 |
52.5. Consumer Endpoints: Copy linkLink copied to clipboard!
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 |
52.6. Message header Copy linkLink copied to clipboard!
Any of the options can be provided in a message header for producer endpoints with CamelBox. prefix.
52.7. Message body Copy linkLink copied to clipboard!
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.
52.8. Samples Copy linkLink copied to clipboard!
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 53. Braintree Component Copy linkLink copied to clipboard!
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>
53.1. Braintree Options Copy linkLink copied to clipboard!
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:
53.1.1. Path Parameters (2 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| apiName | Required What kind of operation to perform | BraintreeApiName | |
| methodName | What sub operation to use for the selected operation | String |
53.1.2. Query Parameters (14 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
53.2. URI format Copy linkLink copied to clipboard!
braintree://endpoint-prefix/endpoint?[options]
Endpoint prefix can be one of:
- addOn
- address
- clientToken
- creditCardverification
- customer
- discount
- merchantAccount
- paymentmethod
- paymentmethodNonce
- plan
- settlementBatchSummary
- subscription
- transaction
- webhookNotification
53.3. BraintreeComponent Copy linkLink copied to clipboard!
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
53.4. Producer Endpoints: Copy linkLink copied to clipboard!
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
53.4.1. Endpoint prefix addOn Copy linkLink copied to clipboard!
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> |
53.4.2. Endpoint prefix address Copy linkLink copied to clipboard!
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 |
53.4.3. Endpoint prefix clientToken Copy linkLink copied to clipboard!
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 |
53.4.4. Endpoint prefix creditCardVerification Copy linkLink copied to clipboard!
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 |
53.4.5. Endpoint prefix customer Copy linkLink copied to clipboard!
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 |
53.4.6. Endpoint prefix discount Copy linkLink copied to clipboard!
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> |
+
+
53.4.7. Endpoint prefix merchantAccount Copy linkLink copied to clipboard!
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 |
53.4.8. Endpoint prefix paymentMethod Copy linkLink copied to clipboard!
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 |
53.4.9. Endpoint prefix paymentMethodNonce Copy linkLink copied to clipboard!
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 |
53.4.10. Endpoint prefix plan Copy linkLink copied to clipboard!
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> |
53.4.11. Endpoint prefix settlementBatchSummary Copy linkLink copied to clipboard!
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 |
53.4.12. Endpoint prefix subscription Copy linkLink copied to clipboard!
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. |
53.4.13. Endpoint prefix transaction Copy linkLink copied to clipboard!
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 |
53.4.14. Endpoint prefix webhookNotification Copy linkLink copied to clipboard!
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 |
53.5. Consumer Endpoints Copy linkLink copied to clipboard!
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.
53.6. Message Headers Copy linkLink copied to clipboard!
Any URI option can be provided in a message header for producer endpoints with a CamelBraintree. prefix.
53.7. Message body Copy linkLink copied to clipboard!
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.
53.8. Examples Copy linkLink copied to clipboard!
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>
53.9. See Also Copy linkLink copied to clipboard!
* Configuring Camel * Component * Endpoint * Getting Started
Chapter 54. Browse Component Copy linkLink copied to clipboard!
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.
54.1. URI format Copy linkLink copied to clipboard!
browse:someName[?options]
Where someName can be any string to uniquely identify the endpoint.
54.2. Options Copy linkLink copied to clipboard!
The Browse component has no options.
The Browse endpoint is configured using URI syntax:
browse:name
with the following path and query parameters:
54.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| name | Required A name which can be any string to uniquely identify the endpoint | String |
54.2.2. Query Parameters (4 parameters): Copy linkLink copied to clipboard!
| 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 |
54.3. Sample Copy linkLink copied to clipboard!
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
}
}
54.4. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 55. EHCache Component (deprecated) Copy linkLink copied to clipboard!
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>
55.1. URI format Copy linkLink copied to clipboard!
cache://cacheName[?options]
You can append query options to the URI in the following format, ?option=value&option=#beanRef&…
55.2. Options Copy linkLink copied to clipboard!
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:
55.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| cacheName | Required Name of the cache | String |
55.2.2. Query Parameters (19 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
55.3. Sending/Receiving Messages to/from the cache Copy linkLink copied to clipboard!
55.3.1. Message Headers up to Camel 2.7 Copy linkLink copied to clipboard!
| 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 |
55.3.2. Message Headers Camel 2.8+ Copy linkLink copied to clipboard!
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. |
55.3.3. Cache Producer Copy linkLink copied to clipboard!
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
55.3.4. Cache Consumer Copy linkLink copied to clipboard!
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.
55.3.5. Cache Processors Copy linkLink copied to clipboard!
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
55.4. Cache Usage Samples Copy linkLink copied to clipboard!
55.4.1. Example 1: Configuring the cache Copy linkLink copied to clipboard!
from("cache://MyApplicationCache" +
"?maxElementsInMemory=1000" +
"&memoryStoreEvictionPolicy=" +
"MemoryStoreEvictionPolicy.LFU" +
"&overflowToDisk=true" +
"&eternal=true" +
"&timeToLiveSeconds=300" +
"&timeToIdleSeconds=true" +
"&diskPersistent=true" +
"&diskExpiryThreadIntervalSeconds=300")
55.4.2. Example 2: Adding keys to the cache Copy linkLink copied to clipboard!
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")
}
};
55.4.3. Example 2: Updating existing keys in a cache Copy linkLink copied to clipboard!
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")
}
};
55.4.4. Example 3: Deleting existing keys in a cache Copy linkLink copied to clipboard!
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")
}
};
55.4.5. Example 4: Deleting all existing keys in a cache Copy linkLink copied to clipboard!
RouteBuilder builder = new RouteBuilder() {
public void configure() {
from("direct:start")
.setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_DELETEALL))
.to("cache://TestCache1");
}
};
55.4.6. Example 5: Notifying any changes registering in a Cache to Processors and other Producers Copy linkLink copied to clipboard!
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
}
})
}
};
55.4.7. Example 6: Using Processors to selectively replace payload with cache values Copy linkLink copied to clipboard!
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");
}
};
55.4.8. Example 7: Getting an entry from the Cache Copy linkLink copied to clipboard!
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");
55.4.9. Example 8: Checking for an entry in the Cache Copy linkLink copied to clipboard!
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();
55.5. Management of EHCache Copy linkLink copied to clipboard!
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.
55.6. Cache replication Camel 2.8 Copy linkLink copied to clipboard!
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.
55.6.1. Example: JMS cache replication Copy linkLink copied to clipboard!
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 56. Caffeine Cache Component Copy linkLink copied to clipboard!
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>
56.1. URI format Copy linkLink copied to clipboard!
caffeine-cache://cacheName[?options]
You can append query options to the URI in the following format, ?option=value&option=#beanRef&…
56.2. Options Copy linkLink copied to clipboard!
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:
56.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| cacheName | Required the cache name | String |
56.2.2. Query Parameters (19 parameters): Copy linkLink copied to clipboard!
| 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 options 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 the default an already instantianted 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 |
Chapter 57. Caffeine LoadCache Component Copy linkLink copied to clipboard!
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>
57.1. URI format Copy linkLink copied to clipboard!
caffeine-loadcache://cacheName[?options]
You can append query options to the URI in the following format, ?option=value&option=#beanRef&…
57.2. Options Copy linkLink copied to clipboard!
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:
57.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| cacheName | Required the cache name | String |
57.2.2. Query Parameters (19 parameters): Copy linkLink copied to clipboard!
| 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 options 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 the default an already instantianted 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 |
Chapter 58. Castor DataFormat (deprecated) Copy linkLink copied to clipboard!
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.
58.1. Using the Java DSL Copy linkLink copied to clipboard!
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();
58.2. Using Spring XML Copy linkLink copied to clipboard!
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>
58.3. Options Copy linkLink copied to clipboard!
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.EndpointHelpermatchPattern(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.EndpointHelpermatchPattern(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. |
58.4. Dependencies Copy linkLink copied to clipboard!
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 59. Camel CDI Copy linkLink copied to clipboard!
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.
59.1. Auto-configured Camel context Copy linkLink copied to clipboard!
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.
59.2. Auto-detecting Camel routes Copy linkLink copied to clipboard!
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);
}
59.3. Auto-configured Camel primitives Copy linkLink copied to clipboard!
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;
59.4. Camel context configuration Copy linkLink copied to clipboard!
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);
}
}
59.5. Multiple Camel contexts Copy linkLink copied to clipboard!
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;
59.6. Configuration properties Copy linkLink copied to clipboard!
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.
59.7. Auto-configured type converters Copy linkLink copied to clipboard!
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.
59.8. Camel bean integration Copy linkLink copied to clipboard!
59.8.1. Camel annotations Copy linkLink copied to clipboard!
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 |
| If using DeltaSpike configuration mechanism:
See configuration properties for more details. |
| Producer template injection (default Camel context) |
|
|
| Endpoint injection (default Camel context) |
|
|
| Endpoint injection (Camel context by name) |
|
|
| Bean injection (by type) |
|
|
| Bean injection (by name) |
|
|
| POJO consuming |
|
|
59.8.2. Bean component Copy linkLink copied to clipboard!
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");
59.8.3. Referring beans from Endpoint URIs Copy linkLink copied to clipboard!
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;
}
59.9. Camel events to CDI events Copy linkLink copied to clipboard!
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 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.
59.10. CDI events endpoint Copy linkLink copied to clipboard!
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.
59.11. Camel XML configuration import Copy linkLink copied to clipboard!
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/>
59.12. Transaction support Copy linkLink copied to clipboard!
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.
59.12.1. Transaction policies Copy linkLink copied to clipboard!
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.
59.12.2. Transactional error handler Copy linkLink copied to clipboard!
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));
}
}
59.13. Auto-configured OSGi integration Copy linkLink copied to clipboard!
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.
59.14. Lazy Injection / Programmatic Lookup Copy linkLink copied to clipboard!
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);
59.15. Maven Archetype Copy linkLink copied to clipboard!
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
59.16. Supported containers Copy linkLink copied to clipboard!
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 |
59.17. Examples Copy linkLink copied to clipboard!
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 Swagger Java with CDI |
|
| The Widget and Gadget use-case from the EIP book implemented in Java with CDI dependency Injection |
59.18. See Also Copy linkLink copied to clipboard!
- 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)
59.19. Camel CDI for EAR deployments on {wildfly-camel} Copy linkLink copied to clipboard!
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 60. Chronicle Engine Component Copy linkLink copied to clipboard!
Available as of Camel version 2.18
The camel chronicle-engine component let you leverage the power of OpenHFT’s Chronicle-Engine
60.1. URI Format Copy linkLink copied to clipboard!
chronicle-engine:addresses/path[?options]
60.2. URI Options Copy linkLink copied to clipboard!
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:
60.2.1. Path Parameters (2 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| addresses | Required Engine addresses. Multiple addresses can be separated by comma. | String | |
| path | Required Engine path | String |
60.2.2. Query Parameters (12 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
Chapter 61. Chunk Component Copy linkLink copied to clipboard!
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>
61.1. URI format Copy linkLink copied to clipboard!
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&…
61.2. Options Copy linkLink copied to clipboard!
The Chunk component has no options.
The Chunk endpoint is configured using URI syntax:
chunk:resourceUri
with the following path and query parameters:
61.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| 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 |
61.2.2. Query Parameters (7 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| 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 |
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.
61.3. Chunk Context Copy linkLink copied to clipboard!
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). |
61.4. Dynamic templates Copy linkLink copied to clipboard!
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. |
61.5. Samples Copy linkLink copied to clipboard!
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");
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.
61.6. The Email Sample Copy linkLink copied to clipboard!
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}
61.7. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 62. Class Component Copy linkLink copied to clipboard!
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.
62.1. URI format Copy linkLink copied to clipboard!
class:className[?options]
Where className is the fully qualified class name to create and use as bean.
62.2. Options Copy linkLink copied to clipboard!
The Class component has no options.
The Class endpoint is configured using URI syntax:
class:beanName
with the following path and query parameters:
62.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| beanName | Required Sets the name of the bean to invoke | String |
62.2.2. Query Parameters (5 parameters): Copy linkLink copied to clipboard!
| 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. | false | 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 |
62.3. Using Copy linkLink copied to clipboard!
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");
62.4. Setting properties on the created instance Copy linkLink copied to clipboard!
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.
62.5. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- Bean
- Bean Binding
- Bean Integration
Chapter 63. CMIS Component Copy linkLink copied to clipboard!
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.
63.1. URI Format Copy linkLink copied to clipboard!
cmis://cmisServerUrl[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
63.2. CMIS Options Copy linkLink copied to clipboard!
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:
63.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| cmsUrl | Required URL to the cmis repository | String |
63.2.2. Query Parameters (13 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
63.3. Usage Copy linkLink copied to clipboard!
63.3.1. Message headers evaluated by the producer Copy linkLink copied to clipboard!
| 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 |
63.3.2. Message headers set during querying Producer operation Copy linkLink copied to clipboard!
| 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.
63.4. Dependencies Copy linkLink copied to clipboard!
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).
63.5. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 64. CM SMS Gateway Component Copy linkLink copied to clipboard!
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>
64.1. Options Copy linkLink copied to clipboard!
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:
64.1.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| host | Required SMS Provider HOST with scheme | String |
64.1.2. Query Parameters (5 parameters): Copy linkLink copied to clipboard!
| 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 | 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 |
64.2. Sample Copy linkLink copied to clipboard!
You can try this project to see how camel-cm-sms can be integrated in a camel route.
Chapter 65. CoAP Component Copy linkLink copied to clipboard!
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>
65.1. Options Copy linkLink copied to clipboard!
The CoAP component has no options.
The CoAP endpoint is configured using URI syntax:
coap:uri
with the following path and query parameters:
65.1.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| uri | The URI for the CoAP endpoint | URI |
65.1.2. Query Parameters (5 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
65.2. Message Headers Copy linkLink copied to clipboard!
| 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. |
65.2.1. Configuring the CoAP producer request method Copy linkLink copied to clipboard!
The following rules determine which request method the CoAP producer will use to invoke the target URI:
-
The value of the
CamelCoapMethodheader - 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 66. Constant Language Copy linkLink copied to clipboard!
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.
66.1. Constant Options Copy linkLink copied to clipboard!
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 |
66.2. Example usage Copy linkLink copied to clipboard!
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");
66.3. Dependencies Copy linkLink copied to clipboard!
The Constant language is part of camel-core.
Chapter 67. CometD Component Copy linkLink copied to clipboard!
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>
67.1. URI format Copy linkLink copied to clipboard!
cometd://host:port/channelName[?options]
The channelName represents a topic that can be subscribed to by the Camel endpoints.
67.2. Examples Copy linkLink copied to clipboard!
cometd://localhost:8080/service/mychannel
cometds://localhost:8443/service/mychannel
where cometds: represents an SSL configured endpoint.
67.3. Options Copy linkLink copied to clipboard!
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:
67.3.1. Path Parameters (3 parameters): Copy linkLink copied to clipboard!
| 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 |
67.3.2. Query Parameters (16 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
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
67.4. Authentication Copy linkLink copied to clipboard!
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
67.5. Setting up SSL for Cometd Component Copy linkLink copied to clipboard!
67.5.1. Using the JSSE Configuration Utility Copy linkLink copied to clipboard!
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"/>...
67.6. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 68. Consul Component Copy linkLink copied to clipboard!
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>
68.1. URI format Copy linkLink copied to clipboard!
consul://domain?[options]
You can append query options to the URI in the following format:
?option=value&option=value&...
68.2. Options Copy linkLink copied to clipboard!
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:
68.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| apiEndpoint | Required The API endpoint | String |
68.2.2. Query Parameters (4 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
68.3. Headers Copy linkLink copied to clipboard!
| 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 69. Control Bus Component Copy linkLink copied to clipboard!
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.
69.1. ControlBus Component Copy linkLink copied to clipboard!
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.
69.2. Commands Copy linkLink copied to clipboard!
| 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. |
69.3. Options Copy linkLink copied to clipboard!
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:
69.3.1. Path Parameters (2 parameters): Copy linkLink copied to clipboard!
| 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 |
69.3.2. Query Parameters (6 parameters): Copy linkLink copied to clipboard!
| 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&…
69.4. Using route command Copy linkLink copied to clipboard!
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);
69.5. Getting performance statistics Copy linkLink copied to clipboard!
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);
69.6. Using Simple language Copy linkLink copied to clipboard!
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 70. Couchbase Component Copy linkLink copied to clipboard!
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>
70.1. URI format Copy linkLink copied to clipboard!
couchbase:url
70.2. Options Copy linkLink copied to clipboard!
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:
70.2.1. Path Parameters (3 parameters): Copy linkLink copied to clipboard!
| 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 |
70.2.2. Query Parameters (47 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
Chapter 71. CouchDB Component Copy linkLink copied to clipboard!
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 and from Camel 2.18 delete (by using CouchDbMethod with DELETE value) documents 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>
71.1. URI format Copy linkLink copied to clipboard!
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.
71.2. Options Copy linkLink copied to clipboard!
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:
71.2.1. Path Parameters (4 parameters): Copy linkLink copied to clipboard!
| 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 |
71.2.2. Query Parameters (12 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
71.3. Headers Copy linkLink copied to clipboard!
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.
71.4. Message Body Copy linkLink copied to clipboard!
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.
71.5. Samples Copy linkLink copied to clipboard!
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 72. Cassandra CQL Component Copy linkLink copied to clipboard!
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>
72.1. URI format Copy linkLink copied to clipboard!
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.
72.2. Cassandra Options Copy linkLink copied to clipboard!
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:
72.2.1. Path Parameters (4 parameters): Copy linkLink copied to clipboard!
| 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 |
72.2.2. Query Parameters (29 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
72.3. Messages Copy linkLink copied to clipboard!
72.3.1. Incoming Message Copy linkLink copied to clipboard!
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,StringorRegularStatement): CQL query either as a plain String or built using theQueryBuilder.
72.3.2. Outgoing Message Copy linkLink copied to clipboard!
The Camel Cassandra endpoint produces one or many a Cassandra Row objects depending on the resultSetConversionStrategy:
-
List<Row>ifresultSetConversionStrategyisALLorLIMIT_[0-9]+ -
Single` Row` if
resultSetConversionStrategyisONE -
Anything else, if
resultSetConversionStrategyis a custom implementation of theResultSetConversionStrategy
72.4. Repositories Copy linkLink copied to clipboard!
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.
72.5. Idempotent repository Copy linkLink copied to clipboard!
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: |
72.6. Aggregation repository Copy linkLink copied to clipboard!
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: |
Chapter 73. Crypto (JCE) Component Copy linkLink copied to clipboard!
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>
73.1. Introduction Copy linkLink copied to clipboard!
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 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
73.2. URI format Copy linkLink copied to clipboard!
As mentioned Camel provides a pair of crypto endpoints to create and verify signatures
crypto:sign:name[?options]
crypto:verify:name[?options]
-
crypto:signcreates the signature and stores it in the Header keyed by the constantorg.apache.camel.component.crypto.DigitalSignatureConstants.SIGNATURE, i.e."CamelDigitalSignature". -
crypto:verifywill 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.
73.3. Options Copy linkLink copied to clipboard!
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:
73.3.1. Path Parameters (2 parameters): Copy linkLink copied to clipboard!
| 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 |
73.3.2. Query Parameters (19 parameters): Copy linkLink copied to clipboard!
| 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 link org.apache.camel.component.crypto.DigitalSignatureConstantsKEYSTORE_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 |
73.4. Using Copy linkLink copied to clipboard!
73.4.1. Raw keys Copy linkLink copied to clipboard!
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
73.4.2. KeyStores and Aliases. Copy linkLink copied to clipboard!
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.
73.4.3. Changing JCE Provider and Algorithm Copy linkLink copied to clipboard!
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
73.4.4. Changing the Signature Message Header Copy linkLink copied to clipboard!
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
73.4.5. Changing the buffersize Copy linkLink copied to clipboard!
In case you need to update the size of the buffer…
or
73.4.6. Supplying Keys dynamically. Copy linkLink copied to clipboard!
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);
73.5. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 74. Crypto CMS Component Copy linkLink copied to clipboard!
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-jdk15on and bcpkix-jdk15on.
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.
74.1. Options Copy linkLink copied to clipboard!
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:
74.1.1. Path Parameters (2 parameters): Copy linkLink copied to clipboard!
| 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 |
74.1.2. Query Parameters (15 parameters): Copy linkLink copied to clipboard!
| 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/rfc5652section-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/rfc5652section-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 |
74.2. Enveloped Data Copy linkLink copied to clipboard!
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>
74.3. Signed Data Copy linkLink copied to clipboard!
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 75. Crypto (Java Cryptographic Extension) DataFormat Copy linkLink copied to clipboard!
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.
75.1. CryptoDataFormat Options Copy linkLink copied to clipboard!
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. |
75.2. Basic Usage Copy linkLink copied to clipboard!
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>
75.3. Specifying the Encryption Algorithm Copy linkLink copied to clipboard!
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.
75.4. Specifying an Initialization Vector Copy linkLink copied to clipboard!
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
75.5. Hashed Message Authentication Codes (HMAC) Copy linkLink copied to clipboard!
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" />
75.6. Supplying Keys Dynamically Copy linkLink copied to clipboard!
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" />
75.7. Dependencies Copy linkLink copied to clipboard!
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>
75.8. See Also Copy linkLink copied to clipboard!
- Data Format
- Crypto (Digital Signatures)
- http://www.bouncycastle.org/java.html
Chapter 76. CSV DataFormat Copy linkLink copied to clipboard!
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.
76.1. Options Copy linkLink copied to clipboard!
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. |
76.2. Marshalling a Map to CSV Copy linkLink copied to clipboard!
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
76.3. Unmarshalling a CSV message into a Java List Copy linkLink copied to clipboard!
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)));
}
76.4. Marshalling a List Copy linkLink copied to clipboard!
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.
76.5. File Poller of CSV, then unmarshaling Copy linkLink copied to clipboard!
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>
76.6. Marshaling with a pipe as delimiter Copy linkLink copied to clipboard!
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>
76.7. Using skipFirstLine option while unmarshaling Copy linkLink copied to clipboard!
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");
76.8. Unmarshaling with a pipe as delimiter Copy linkLink copied to clipboard!
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!
76.9. Dependencies Copy linkLink copied to clipboard!
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 77. CXF Copy linkLink copied to clipboard!
CXF Component Copy linkLink copied to clipboard!
The cxf: component provides integration with Apache CXF for connecting to JAX-WS services hosted in 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>
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
| 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 |
Please see the Description of |
|
| No |
Which kind of operation the CXF endpoint producer will invoke. 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 will set the default
|
|
| No | New in 2.4, this option will set the default operationNamespace that will be used by the CxfProducer which invokes the remote service. For example:
|
|
| No |
New in 2.5, this option will let 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), will DOM parse the incoming messages into DOM Elements or keep the payload as a javax.xml.transform.Source object that would allow streaming in some cases. |
|
| 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 Copy linkLink copied to clipboard!
| 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. Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
There are in-band and out-of-band on-the-wire headers from the perspective of a JAXWS WSDL-first developer.
The in-band headers are headers that are explicitly defined as part of the WSDL binding contract for an endpoint such as SOAP headers.
The out-of-band headers are headers that are serialized over the wire, but are not explicitly part of the WSDL binding contract.
Headers relaying/filtering is bi-directional.
When a route has a CXF endpoint and the developer needs to have on-the-wire headers, such as SOAP headers, be relayed along the route to be consumed say by another JAXWS endpoint, then relayHeaders should be set to true, which is the default value.
Available only in POJO mode Copy linkLink copied to clipboard!
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 will be consulted to decide if a header needs to be relayed or not. There is already an implementation of SoapMessageHeadersRelay which binds itself to well-known SOAP name spaces. Currently only out-of-band headers are filtered, and in-band headers will always be relayed when relayHeaders=true. If there is a header on the wire, whose name space is unknown to the runtime, then a fall back DefaultMessageHeadersRelay will be used, which simply allows all headers to be relayed.
The relayHeaders=false setting asserts that all headers, in-band and out-of-band, will be dropped.
You can plugin your own MessageHeadersRelay implementations overriding or adding additional ones to the list of relays. In order to override a preloaded relay instance just make sure that your MessageHeadersRelay implementation services the same name spaces as the one you looking to override. Also note, that the overriding relay has to service all of the name spaces as the one you looking to override, or else a runtime exception on route start up will be thrown as this would introduce an ambiguity in name spaces to relay instance mappings.
<cxf:cxfEndpoint ...>
<cxf:properties>
<entry key="org.apache.camel.cxf.message.headers.relays">
<list>
<ref bean="customHeadersRelay"/>
</list>
</entry>
</cxf:properties>
</cxf:cxfEndpoint>
<bean id="customHeadersRelay" class="org.apache.camel.component.cxf.soap.headers.CustomHeadersRelay"/>
Take a look at the tests that show how you’d be able to relay/drop headers here:
Changes since Release 2.0 Copy linkLink copied to clipboard!
-
POJOandPAYLOADmodes are supported. InPOJOmode, 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 theMessageContentListinPOJOmode. Thecamel-cxfcomponent does make any attempt to remove the in-band headers from theMessageContentListIf filtering of in-band headers is required, please usePAYLOADmode or plug in a (pretty straightforward) CXF interceptor/JAXWS Handler to the CXF endpoint. The Message Header Relay mechanism has been merged into
CxfHeaderFilterStrategy. TherelayHeadersoption, 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
MessageHeadersRelayinterface 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 will be processed by Message Header Filters |
| No |
|
|
| All message headers will be propagated (without processing by Message Header Filters) |
| No |
|
|
|
If two filters overlap in activation namespace, the property control how it should be handled. If the value is |
| No |
|
Configure the CXF endpoints with Spring Copy linkLink copied to clipboard!
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 will be 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 which should be supplied to the JAX-WS endpoint. See below. |
|
| A JAX-WS handler list which should be supplied to the JAX-WS endpoint. See below. |
|
|
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 Copy linkLink copied to clipboard!
CXF’s default logger is java.util.logging. If you want to change it to log4j, proceed as follows. Create a file, in the classpath, named META-INF/cxf/org.apache.cxf.logger. This file should contain the fully-qualified name of the class, org.apache.cxf.common.logging.Log4jLogger, with no comments, on a single line.
How to let camel-cxf response message with xml start document Copy linkLink copied to clipboard!
If you are using some SOAP client such as PHP, you will get 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 will force 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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
The camel-cxf endpoint producer is based on the cxf client API. First you need to specify the operation name in the message header, then add the method parameters to a list, and initialize the message with this parameter list. The response message’s body is a messageContentsList, you can get the result from that list.
If you don’t specify the operation name in the message header, CxfProducer will try to use the defaultOperationName from CxfEndpoint. If there is no defaultOperationName set on CxfEndpoint, it will pick up the first 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 will be filled in the reset of List.
// The result will be extract from the MessageContentsList with the String class type
MessageContentsList result = (MessageContentsList)out.getBody();
LOG.info("Received output text: " + result.get(0));
Map<String, Object> responseContext = CastUtils.cast((Map<?, ?>)out.getHeader(Client.RESPONSE_CONTEXT));
assertNotNull(responseContext);
assertEquals("We should get the response context here", "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 Copy linkLink copied to clipboard!
In Apache Camel 2.0: CxfMessage.getBody() will return 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 Copy linkLink copied to clipboard!
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 {
// You should be able to get the header if exchange is routed from camel-cxf endpoint
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 Copy linkLink copied to clipboard!
We have already shown how to access SOAP message (CxfPayload object) in PAYLOAD mode (see the section called “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("We should get the 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("We should get the 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 Copy linkLink copied to clipboard!
SOAP headers are not available in MESSAGE mode as SOAP processing is skipped.
How to throw a SOAP Fault from Apache Camel Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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. Note that when receiving a multipart (that is, MTOM) message the default SOAPMessage to String converter will provide 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 Copy linkLink copied to clipboard!
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>
You should 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 Copy linkLink copied to clipboard!
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" to "false" to turn if off. That sets the global default, but setting the endpoint property above will override this value for that endpoint.
Using the generic CXF Dispatch mode Copy linkLink copied to clipboard!
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).
77.1. CXF consumers on {wildfly} Copy linkLink copied to clipboard!
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.
77.1.1. Configuring alternative ports Copy linkLink copied to clipboard!
If alternative ports are to be accepted, then these must be configured via the {wildfly} subsystem configuration. This is explained in the server documentation:
77.1.2. Configuring SSL Copy linkLink copied to clipboard!
To configure SSL, refer to the {wildfly} SSL configuration guide:
77.1.3. Configuring security with Elytron Copy linkLink copied to clipboard!
{wildfly-camel} supports securing camel-cxf consumer endpoints with the Elytron security framework.
77.1.3.1. Configuring a security domain Copy linkLink copied to clipboard!
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.
77.1.3.2. Configuring security constraints, authentication methods and security roles Copy linkLink copied to clipboard!
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 78. CXF-RS Component Copy linkLink copied to clipboard!
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>
78.1. URI format Copy linkLink copied to clipboard!
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
78.2. Options Copy linkLink copied to clipboard!
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:
78.2.1. Path Parameters (2 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| beanId | To lookup an existing configured CxfRsEndpoint. Must used bean: as prefix. | String | |
| address | The service publish address. | String |
78.2.2. Query Parameters (29 parameters): Copy linkLink copied to clipboard!
| 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 options 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 | |
| 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 |
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.
78.3. How to configure the REST endpoint in Camel Copy linkLink copied to clipboard!
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.
78.4. How to override the CXF producer address from message header Copy linkLink copied to clipboard!
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()));
78.5. Consuming a REST Request - Simple Binding Style Copy linkLink copied to clipboard!
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
@Multipartbody parts become IN message attachments, supportingDataHandler,InputStream,DataSourceand CXF’sAttachmentclass. -
Non-binary
@Multipartbody 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 newResponseis 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_CODEheader, 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
HeaderFilterStrategyare added to the HTTP response.
78.5.1. Enabling the Simple Binding Style Copy linkLink copied to clipboard!
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");
78.5.2. Examples of request binding with different method signatures Copy linkLink copied to clipboard!
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.
78.5.3. More examples of the Simple Binding Style Copy linkLink copied to clipboard!
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.
78.6. Consuming a REST Request - Default Binding Style Copy linkLink copied to clipboard!
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.
78.7. How to invoke the REST service through camel-cxfrs producer Copy linkLink copied to clipboard!
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.
From Camel 2.1, we also support to specify the query parameters from cxfrs URI for the CXFRS http centric client.
Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20
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.
78.8. What’s the Camel Transport for CXF Copy linkLink copied to clipboard!
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.
78.9. Integrate Camel into CXF transport layer Copy linkLink copied to clipboard!
To include the Camel Tranport into your CXF bus you use the CamelTransportFactory. You can do this in Java as well as in Spring.
78.9.1. Setting up the Camel Transport in Spring Copy linkLink copied to clipboard!
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>
78.9.2. Integrating the Camel Transport in a programmatic way Copy linkLink copied to clipboard!
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);
78.10. Configure the destination and conduit with Spring Copy linkLink copied to clipboard!
78.10.1. Namespace Copy linkLink copied to clipboard!
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
...>
78.10.2. The destination element Copy linkLink copied to clipboard!
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
78.10.3. The conduit element Copy linkLink copied to clipboard!
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
78.11. Configure the destination and conduit with Blueprint Copy linkLink copied to clipboard!
From Camel 2.11.x, Camel Transport supports to be configured with Blueprint.
If you are using blueprint, you should use the 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" />
78.12. Example Using Camel as a load balancer for CXF Copy linkLink copied to clipboard!
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"
78.13. Complete Howto and Example for attaching Camel to CXF Copy linkLink copied to clipboard!
Chapter 79. Data Format Component Copy linkLink copied to clipboard!
Available as of Camel version 2.12
The dataformat: component allows to use Data Format as a Camel Component.
79.1. URI format Copy linkLink copied to clipboard!
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.
79.2. DataFormat Options Copy linkLink copied to clipboard!
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:
79.2.1. Path Parameters (2 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| name | Required Name of data format | String | |
| operation | Required Operation to use either marshal or unmarshal | String |
79.2.2. Query Parameters (1 parameters): Copy linkLink copied to clipboard!
| 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 |
79.3. Samples Copy linkLink copied to clipboard!
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 80. Dataset Component Copy linkLink copied to clipboard!
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.
80.1. URI format Copy linkLink copied to clipboard!
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.
80.2. Options Copy linkLink copied to clipboard!
The Dataset component has no options.
The Dataset endpoint is configured using URI syntax:
dataset:name
with the following path and query parameters:
80.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| name | Required Name of DataSet to lookup in the registry | DataSet |
80.2.2. Query Parameters (19 parameters): Copy linkLink copied to clipboard!
| 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 link 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 link 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 link 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 link 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 link 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 link assertIsSatisfied() will wait on a latch until it is satisfied | 0 | long |
| resultWaitTime (producer) | Sets the maximum amount of time (in millis) the link 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 link 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 link getReceivedCounter() will still return 5000 but there is only the first 10 Exchanges in the link getExchanges() and link getReceivedExchanges() methods. When using this method, then some of the other expectation methods is not supported, for example the link expectedBodiesReceived(Object…) sets a expectation on the first number of bodies received. You can configure both link setRetainFirst(int) and link 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 link 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 link getReceivedCounter() will still return 5000 but there is only the last 20 Exchanges in the link getExchanges() and link getReceivedExchanges() methods. When using this method, then some of the other expectation methods is not supported, for example the link expectedBodiesReceived(Object…) sets a expectation on the first number of bodies received. You can configure both link setRetainFirst(int) and link 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 link 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&…
80.3. Configuring DataSet Copy linkLink copied to clipboard!
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>
80.4. Example Copy linkLink copied to clipboard!
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.
80.5. DataSetSupport (abstract class) Copy linkLink copied to clipboard!
The DataSetSupport abstract class is a nice starting point for new DataSets, and provides some useful features to derived classes.
80.5.1. Properties on DataSetSupport Copy linkLink copied to clipboard!
| 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 |
80.6. SimpleDataSet Copy linkLink copied to clipboard!
The SimpleDataSet extends DataSetSupport, and adds a default body.
80.6.1. Additional Properties on SimpleDataSet Copy linkLink copied to clipboard!
| Property | Type | Default | Description |
|---|---|---|---|
|
|
|
|
Specifies the default message body. By default, the |
80.7. ListDataSet Copy linkLink copied to clipboard!
Available since Camel 2.17
The List`DataSet` extends DataSetSupport, and adds a list of default bodies.
80.7.1. Additional Properties on ListDataSet Copy linkLink copied to clipboard!
| 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 |
80.8. FileDataSet Copy linkLink copied to clipboard!
Available since Camel 2.17
The FileDataSet extends ListDataSet, and adds support for loading the bodies from a file.
80.8.1. Additional Properties on FileDataSet Copy linkLink copied to clipboard!
| Property | Type | Default | Description |
|---|---|---|---|
|
|
| null | Specifies the source file for payloads |
|
|
| \z |
Specifies the delimiter pattern used by a |
Chapter 81. DigitalOcean Component Copy linkLink copied to clipboard!
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.
81.1. Prerequisites Copy linkLink copied to clipboard!
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.
81.2. URI format Copy linkLink copied to clipboard!
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.
81.3. Options Copy linkLink copied to clipboard!
The DigitalOcean component has no options.
The DigitalOcean endpoint is configured using URI syntax:
digitalocean:operation
with the following path and query parameters:
81.3.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| operation | The operation to perform to the given resource. | DigitalOceanOperations |
81.3.2. Query Parameters (10 parameters): Copy linkLink copied to clipboard!
| 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 |
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.
81.4. Message body result Copy linkLink copied to clipboard!
All message bodies returned are using objects provided by the digitalocean-api-java library.
81.5. API Rate Limits Copy linkLink copied to clipboard!
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).
81.6. Account endpoint Copy linkLink copied to clipboard!
| operation | Description | Headers | Result | | ------ | ---- | ------- | ----------- | | get | get account info | | com.myjeeva.digitalocean.pojo.Account |
81.7. BlockStorages endpoint Copy linkLink copied to clipboard!
| 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> |
81.8. Droplets endpoint Copy linkLink copied to clipboard!
| 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> |
81.9. Images endpoint Copy linkLink copied to clipboard!
| 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 |
81.10. Snapshots endpoint Copy linkLink copied to clipboard!
| 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 |
81.11. Keys endpoint Copy linkLink copied to clipboard!
| 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 |
81.12. Regions endpoint Copy linkLink copied to clipboard!
| operation | Description | Headers | Result | | ------ | ---- | ------- | ----------- | | list | list all of the regions that are available | | List<com.myjeeva.digitalocean.pojo.Region> |
81.13. Sizes endpoint Copy linkLink copied to clipboard!
| operation | Description | Headers | Result | | ------ | ---- | ------- | ----------- | | list | list all of the sizes that are available | | List<com.myjeeva.digitalocean.pojo.Size> |
81.14. Floating IPs endpoint Copy linkLink copied to clipboard!
| 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> |
81.15. Tags endpoint Copy linkLink copied to clipboard!
| 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 |
81.16. Examples Copy linkLink copied to clipboard!
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 82. Direct Component Copy linkLink copied to clipboard!
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.
82.1. URI format Copy linkLink copied to clipboard!
direct:someName[?options]
Where someName can be any string to uniquely identify the endpoint
82.2. Options Copy linkLink copied to clipboard!
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:
82.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| name | Required Name of direct endpoint | String |
82.2.2. Query Parameters (7 parameters): Copy linkLink copied to clipboard!
| 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 |
82.3. Samples Copy linkLink copied to clipboard!
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.
82.4. See Also Copy linkLink copied to clipboard!
Chapter 83. Direct VM Component Copy linkLink copied to clipboard!
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.
83.1. URI format Copy linkLink copied to clipboard!
direct-vm:someName
Where someName can be any string to uniquely identify the endpoint
83.2. Options Copy linkLink copied to clipboard!
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:
83.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| name | Required Name of direct-vm endpoint | String |
83.2.2. Query Parameters (9 parameters): Copy linkLink copied to clipboard!
| 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 |
83.3. Samples Copy linkLink copied to clipboard!
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>
83.4. See Also Copy linkLink copied to clipboard!
Chapter 84. Disruptor Component Copy linkLink copied to clipboard!
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>
84.1. URI format Copy linkLink copied to clipboard!
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&…
84.2. Options Copy linkLink copied to clipboard!
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:
84.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| name | Required Name of queue | String |
84.2.2. Query Parameters (12 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
84.3. Wait strategies Copy linkLink copied to clipboard!
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. |
84.4. Use of Request Reply Copy linkLink copied to clipboard!
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.
84.5. Concurrent consumers Copy linkLink copied to clipboard!
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.
84.6. Thread pools Copy linkLink copied to clipboard!
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.
84.7. Sample Copy linkLink copied to clipboard!
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.
84.8. Using multipleConsumers Copy linkLink copied to clipboard!
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);
}
}
84.9. Extracting disruptor information Copy linkLink copied to clipboard!
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 85. DNS Component Copy linkLink copied to clipboard!
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>
85.1. URI format Copy linkLink copied to clipboard!
The URI scheme for a DNS component is as follows
dns://operation[?options]
This component only supports producers.
85.2. Options Copy linkLink copied to clipboard!
The DNS component has no options.
The DNS endpoint is configured using URI syntax:
dns:dnsType
with the following path and query parameters:
85.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| dnsType | Required The type of the lookup. | DnsType |
85.2.2. Query Parameters (1 parameters): Copy linkLink copied to clipboard!
| 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 |
85.3. Headers Copy linkLink copied to clipboard!
| 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. |
85.4. Examples Copy linkLink copied to clipboard!
85.4.1. IP lookup Copy linkLink copied to clipboard!
<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".
85.4.2. DNS lookup Copy linkLink copied to clipboard!
<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".
85.4.3. DNS Dig Copy linkLink copied to clipboard!
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".
85.5. Dns Activation Policy Copy linkLink copied to clipboard!
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" />
</bean>
<route id="routeId" autoStartup="false" routePolicyRef="dnsActivationPolicy">
</route>
Chapter 86. Docker Component Copy linkLink copied to clipboard!
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.
86.1. URI format Copy linkLink copied to clipboard!
docker://[operation]?[options]
Where operation is the specific action to perform on Docker.
86.2. General Options Copy linkLink copied to clipboard!
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:
86.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| operation | Required Which operation to use | DockerOperation |
86.2.2. Query Parameters (20 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
86.3. Header Strategy Copy linkLink copied to clipboard!
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 |
86.4. Examples Copy linkLink copied to clipboard!
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");
86.5. Dependencies Copy linkLink copied to clipboard!
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 87. Dozer Component Copy linkLink copied to clipboard!
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>
87.1. URI format Copy linkLink copied to clipboard!
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");
87.2. Options Copy linkLink copied to clipboard!
The Dozer component has no options.
The Dozer endpoint is configured using URI syntax:
dozer:name
with the following path and query parameters:
87.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| name | Required A human readable name of the mapping. | String |
87.2.2. Query Parameters (7 parameters): Copy linkLink copied to clipboard!
| 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 |
87.3. Using Data Formats with Dozer Copy linkLink copied to clipboard!
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"/>
87.4. Configuring Dozer Copy linkLink copied to clipboard!
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>
87.5. Mapping Extensions Copy linkLink copied to clipboard!
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.
87.5.1. Variable Mappings Copy linkLink copied to clipboard!
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>
87.5.2. Custom Mappings Copy linkLink copied to clipboard!
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>
87.5.3. Expression Mappings Copy linkLink copied to clipboard!
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 88. Drill Component Copy linkLink copied to clipboard!
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>
88.1. URI format Copy linkLink copied to clipboard!
drill://host[?options]
You can append query options to the URI in the following format, ?option=value&option=value&…
88.2. Drill Producer Copy linkLink copied to clipboard!
The producer execute query using CamelDrillQuery header and put results into body.
88.3. Options Copy linkLink copied to clipboard!
The Drill component has no options.
The Drill endpoint is configured using URI syntax:
drill:host
with the following path and query parameters:
88.3.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| 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 |
88.3.2. Query Parameters (5 parameters): Copy linkLink copied to clipboard!
| 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 |
88.4. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 89. Dropbox Component Copy linkLink copied to clipboard!
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>
89.1. URI format Copy linkLink copied to clipboard!
dropbox://[operation]?[options]
Where operation is the specific action (typically is a CRUD action) to perform on Dropbox remote folder.
89.2. Operations Copy linkLink copied to clipboard!
| 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.
89.3. Options Copy linkLink copied to clipboard!
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:
89.3.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| operation | Required The specific action (typically is a CRUD action) to perform on Dropbox remote folder. | DropboxOperation |
89.3.2. Query Parameters (12 parameters): Copy linkLink copied to clipboard!
| 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 options 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 |
89.4. Del operation Copy linkLink copied to clipboard!
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 |
89.4.1. Samples Copy linkLink copied to clipboard!
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");
89.4.2. Result Message Headers Copy linkLink copied to clipboard!
The following headers are set on message result:
| Property | Value |
|---|---|
|
| name of the path deleted on dropbox |
89.4.3. Result Message Body Copy linkLink copied to clipboard!
The following objects are set on message body result:
| Object type | Description |
|---|---|
|
| name of the path deleted on dropbox |
89.5. Get (download) operation Copy linkLink copied to clipboard!
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 |
89.5.1. Samples Copy linkLink copied to clipboard!
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/");
89.5.2. Result Message Headers Copy linkLink copied to clipboard!
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 |
89.5.3. Result Message Body Copy linkLink copied to clipboard!
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 |
89.6. Move operation Copy linkLink copied to clipboard!
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 |
89.6.1. Samples Copy linkLink copied to clipboard!
from("direct:start")
.to("dropbox://move?accessToken=XXX&clientIdentifier=XXX&remotePath=/root/folder1&newRemotePath=/root/folder2")
.to("mock:result");
89.6.2. Result Message Headers Copy linkLink copied to clipboard!
The following headers are set on message result:
| Property | Value |
|---|---|
|
| name of the path moved on dropbox |
89.6.3. Result Message Body Copy linkLink copied to clipboard!
The following objects are set on message body result:
| Object type | Description |
|---|---|
|
| name of the path moved on dropbox |
89.7. Put (upload) operation Copy linkLink copied to clipboard!
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" |
89.7.1. Samples Copy linkLink copied to clipboard!
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.
89.7.2. Result Message Headers Copy linkLink copied to clipboard!
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 |
89.7.3. Result Message Body Copy linkLink copied to clipboard!
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 |
89.8. Search operation Copy linkLink copied to clipboard!
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 |
89.8.1. Samples Copy linkLink copied to clipboard!
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");
89.8.2. Result Message Headers Copy linkLink copied to clipboard!
The following headers are set on message result:
| Property | Value |
|---|---|
|
| list of file path founded |
89.8.3. Result Message Body Copy linkLink copied to clipboard!
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 90. Ehcache Component Copy linkLink copied to clipboard!
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>
90.1. URI format Copy linkLink copied to clipboard!
ehcache://cacheName[?options]
You can append query options to the URI in the following format, ?option=value&option=#beanRef&…
90.2. Options Copy linkLink copied to clipboard!
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:
90.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| cacheName | Required the cache name | String |
90.2.2. Query Parameters (17 parameters): Copy linkLink copied to clipboard!
| 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 the delivery mode (synchronous, asynchronous) | ASYNCHRONOUS | EventFiring |
| eventOrdering (consumer) | Set the 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 options 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 |
90.2.3. Message Headers Camel Copy linkLink copied to clipboard!
| 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 |
90.3. Ehcache based idempotent repository example: Copy linkLink copied to clipboard!
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");
90.4. Ehcache based aggregation repository example: Copy linkLink copied to clipboard!
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 91. EJB Component Copy linkLink copied to clipboard!
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>
91.1. URI format Copy linkLink copied to clipboard!
ejb:ejbName[?options]
Where ejbName can be any string which is used to look up the EJB in the Application Server JNDI Registry
91.2. Options Copy linkLink copied to clipboard!
The EJB component supports 3 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 | |
| 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:
91.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| beanName | Required Sets the name of the bean to invoke | String |
91.2.2. Query Parameters (5 parameters): Copy linkLink copied to clipboard!
| 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. | false | 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 |
91.3. Bean Binding Copy linkLink copied to clipboard!
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.
91.4. Examples Copy linkLink copied to clipboard!
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;
}
}
91.4.1. Using Java DSL Copy linkLink copied to clipboard!
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.
91.4.2. Using Spring XML Copy linkLink copied to clipboard!
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>
91.5. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
- Bean
- Bean Binding
- Bean Integration
Chapter 92. Elasticsearch Component (deprecated) Copy linkLink copied to clipboard!
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>
92.1. URI format Copy linkLink copied to clipboard!
elasticsearch://clusterName[?options]
92.2. Endpoint Options Copy linkLink copied to clipboard!
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:
92.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| clusterName | Required Name of cluster or use local for local mode | String |
92.2.2. Query Parameters (11 parameters): Copy linkLink copied to clipboard!
| 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 |
92.3. Local testing Copy linkLink copied to clipboard!
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.
92.4. Message Operations Copy linkLink copied to clipboard!
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. |
92.5. Index Example Copy linkLink copied to clipboard!
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);
92.6. For more information, see these resources Copy linkLink copied to clipboard!
92.7. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 93. Elasticsearch5 Component (deprecated) Copy linkLink copied to clipboard!
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>
93.1. URI format Copy linkLink copied to clipboard!
elasticsearch5://clusterName[?options]
93.2. Endpoint Options Copy linkLink copied to clipboard!
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:
93.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| clusterName | Required Name of the cluster | String |
93.2.2. Query Parameters (16 parameters): Copy linkLink copied to clipboard!
| 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 |
93.3. Message Operations Copy linkLink copied to clipboard!
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. |
93.4. Index Example Copy linkLink copied to clipboard!
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);
93.5. For more information, see these resources Copy linkLink copied to clipboard!
93.6. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started
Chapter 94. Elastichsearch Rest Component Copy linkLink copied to clipboard!
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>
94.1. URI format Copy linkLink copied to clipboard!
elasticsearch-rest://clusterName[?options]
94.2. Endpoint Options Copy linkLink copied to clipboard!
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 (advance) | Basic authenticate user | String | |
| password (producer) | Password for authenticate | String | |
| enableSSL (advanced) | 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:
94.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
| Name | Description | Default | Type |
|---|---|---|---|
| clusterName | Required Name of the cluster | String |
94.2.2. Query Parameters (11 parameters): Copy linkLink copied to clipboard!
| 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. The ip and port options must be left blank for hostAddresses to be considered instead. | 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 |
94.3. Message Operations Copy linkLink copied to clipboard!
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 |
| 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 |
94.4. Configure the component and enable basic authentication Copy linkLink copied to clipboard!
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);
94.5. Index Example Copy linkLink copied to clipboard!
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>
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. Search Example Copy linkLink copied to clipboard!
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="eelasticsearch-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);
Chapter 95. ElSQL Component Copy linkLink copied to clipboard!
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.
95.1. Options Copy linkLink copied to clipboard!
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:
95.1.1. Path Parameters (2 parameters): Copy linkLink copied to clipboard!
| 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 |
95.1.2. Query Parameters (47 parameters): Copy linkLink copied to clipboard!
| 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 options 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 (producer) | 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 |
| parametersCount (producer) | 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 | |
| elSqlConfig (advanced) | To use a specific configured ElSqlConfig. It may be better to use the databaseVendor option instead. | ElSqlConfig | |
| 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 |