Routes DSL
The custom Platform 6 components built to integrate with the Apache Camel router architecture provide a powerful and feature-rich service.
https://camel.apache.org/routes.html
Route deployment scripts and templates¶
The Routes are defined using a Groovy-based DSL. The user interface allows the selection of named event templates to reduce the quantity of boiler plate code required to define a route.
Templates are stored in:
${P6_DATA}/resources/templates
${P6_HOME}/resources/templates
and have the .groovy
file extension.
The FreeMarker template engine is used for simple token markup allowing the development of custom templates.
The bindings available for routes scripts are:
Note
Although routes are defined using Groovy, the full Platform 6 DSL bindings are not available during route definition.
It is recommended that the P6Cmb component or service
DSL is used to call a script to gain full access to the Platform 6 DSL methods.
Components¶
Camel has a library of hundreds of useful components: https://github.com/apache/camel/tree/master/components
The following components are Platform 6 specific or recommended replacements for older Amalto integration components.
Pre-installed components:
Platform 6 specific components:
Other components used less frequently by Platform 6 projects can be found here: https://github.com/amalto/platform6-library/tree/master/route-components.
Components are referred to using a URL syntax within a route definition:
<componentid>://<component specifc args>
Camel Route Structure¶
A camel route typically starts with a from()
or rest()
statement to define the origin for a trigger event.
A to()
statement is used to denote the route destination.
A routId()
(or id()
when using route()
) is used to name your route in memory.
It must be unique.
Any attempt to create a route that already exists will generate an error.
If you fail to name your routes, camel will name them for you as routeN, where N is a unique number.
A description()
statement allows you to add a more verbose description about the intention of the route.
This will be displayed in the active routes list of the UI.
from(/*...*/)
.to(/*...*/)
.routeId("MyRoute")
.description("My Route description in here")
Examples¶
Groovy bean execution¶
Using template: BaseRouteWithBean.groovy
This demonstrates how additional groovy bean(s) code can be executed.
${addBeanAndRegister}
:=
class ServiceBean {
def void run() {
println("Hello World!")
}
}
p6.camel.registerBean("myBean", ServiceBean )
${addRoutes} :=
from("timer://mTimer?period=3000")
.to("log://logger?level=INFO")
.to("bean://myBean?method=run")
.routeId("myBeanRoute")
${destroyRoutes}
:=
p6.camel.destroyRoute("myBeanRoute")
p6.camel.unregister("myBean")
Rename files to process with bean¶
Using template: BaseRouteWithBean.groovy
Combines the File2 and the bean components to show how filenames can be manipulated during a route.
${addBeanAndRegister}
:=
class UpperCaseTextService {
def String transform(String text) {
return text.toUpperCase()
}
}
p6.camel.registerBean("upperCaseTextService", UpperCaseTextService )
def dataDir = "${P6_DATA}/test/demo"
${addRoutes}
:=
from("file://${dataDir}/in")
.to("log://logger")
.to("bean://upperCaseTextService?method=transform")
.to("file://${dataDir}/out")
.routeId("myRoute")
${destroyRoutes}
:=
p6.camel.destroyRoute("myRoute")
p6.camel.unregister("upperCaseTextService")
Perform WEB3_SHA request using Web3j¶
Web3j is a Producer as well as a Consumer component and as such, you can use it to call any number of Web3 RPC methods:
def exchange = [ body: "0x68656c6c6f20776f726c64" ]
def exMap = p6.camel.endpointExchangeWaitInput("web3j://http://127.0.0.1:8545?operation=WEB3_SHA3", exchange)
assert(exMap["body"].equals("0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"))
Note
It may be better for the user the web3ethereum
DSL binding in Platform 6 scripts for more complex web3 RPC interactions.