Skip to content

Routes

Overview

Apache Camel is the technology framework used by Platform 6 to allow users to define and implement routing and mediation rules using a Groovy DSL (Domain Specific Language).

A single Camel Context is created when Platform 6 starts. This context can be loaded with various routing rules automatically when the Platform 6 Routes service starts. Alternatively, routing rules can be added and removed in an ad-hoc manner as the development of a Platform 6 application takes place.

The Routes service is a tool to manage the lifecycle of camel routing rules via startup when deployed in production, or under the control of a developer working on a new solution.

Both Routes service and the Scripts service execute Groovy scripts and have DSL bindings. However, the Routes service has been designed to help the Platform 6 developer organize and assist with routing rule lifecycle:

  • Route deployment scripts can run automatically when Platform 6 starts.
  • Route deployment scripts can be templated to hide complexity and repetition, enforcing routing rule creation standards.
  • Route deployment scripts can be typed for easy search and categorisation.
  • Route deployment scripts can be started and stopped under user control.

Structure of a route deployment script

The route deployment script is just a regular Groovy script with a limited number of bindings that may optionally be executed when the Routes service is started.

Note

In fact, a route deployment script does not have to interact with Camel to define routes at all! Instead, it may just be used as a mechanism to execute some custom code when Platform 6 starts.

Please refer to the section Routes DSL to understand what you can do with the script and how to do it.

For more information about the other route deployment script’s fields and the management of these items, read the guide Routes user interface.

Typical format

Development

  1. Add routes.
  2. Pause indefinitely.
  3. Remove routes.

This format is ideal for development as it can be started and stopped via the UI under the control of the developer.

Here is a typical route deployment script’s template that defines this:

 try {

  p6.camel.getCtx().addRoutes(new RouteBuilder() {

    void configure() {

      ${addRoutes}

    }
  })

  p6.utils.pause()

} finally {

  ${destroyRoutes}

}

The script executes and pauses until Platform 6 is stopped or the user manually stops the script via the UI. Stopping a route deployment script simply interrupts the running script (blocked in a pause) causing it to remove and destroy the installed Camel routing rules before exiting.

Warning

Each route deployment script formatted in this way will cause the creation of a blocking script job. This may not be the best approach in instances that require a large number of route deployment scripts.

Production

Add routes and exit.

p6.camel.getCtx().addRoutes(new RouteBuilder() {

  void configure() {

    ${addRoutes}

  }
})

Auto executing this script when Platform 6 starts simply adds the routing rules to the Camel context and exits.

Camel Context Configuration

Note

The following context attributes can be set at runtime using the Hawtio admin console See: Monitoring

Tracing

Tracing is disabled by default ensuring optimal runtime performance.

However, tracing can be useful during development and is enabled using the following configuration property:

  • p6.camel.context.tracing.enable: true

Once enabled trace output will be sent as DEBUG level logging using the logger io.platform6.camel

Message History

The message history is disabled by default (to optimize for lower footprint out of the box). You should only enable message history if needed, such as during development, where Camel can report route stack-traces when a message failed with an exception

Message history is enabled using the following configuration property:

  • p6.camel.context.message.history.enable: true

A breadcrumb is a unique id added to each camel exchange and used for tracking messages across transports. It is usually of little value to platform 6 developers and is therefore disabled by default.

Breadcrumbs can be enabled using the following property:

  • p6.camel.context.breadcrumbs.enable: true

Further reading

For more information about Camel, please read the book Camel In Action by Claus Ibsen and Jonathan Anstey (PDF Download).