Skip to content

Routes DSL

The Routes service can be used as a replacement for the following b2box5 legacy features:

  • Routing rules
  • Scheduler adapter
  • File system monitor
  • Custom receive servlets

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:

  • ${B2BOX_DATA}/resources/templates
  • ${B2BOX_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 binding 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!")
    }
}

camel.registerBean("myBean", ServiceBean )

${addRoutes} :=

from("timer://mTimer?period=3000")
    .to("log://logger?level=INFO")
    .to("bean://myBean?method=run")
    .routeId("myBeanRoute")

${destroyRoutes} :=

camel.destroyRoute("myBeanRoute")
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()
    }
}

camel.registerBean("upperCaseTextService", UpperCaseTextService )

def dataDir = "${B2BOX_DATA}/test/demo"

${addRoutes} :=

from("file://${dataDir}/in")
    .to("log://logger")
    .to("bean://upperCaseTextService?method=transform")
    .to("file://${dataDir}/out")
    .routeId("myRoute")

${destroyRoutes} :=

camel.destroyRoute("myRoute")
camel.unregister("upperCaseTextService")

Perform WEB3_SHA request using P6Web3j

P6web3j 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 = camel.endpointExchangeWaitInput("p6web3j://http://127.0.0.1:8545?operation=WEB3_SHA3", exchange)

assert(exMap["body"].equals("0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"))

Note

It may be better for the user the ethereumrpc DSL binding in Platform 6 scripts for more complex web3 RPC interactions.