Skip to content

Camel

Purpose

Apache Camel is a powerful open source integration framework based on known Enterprise Integration Patterns with powerful Bean Integration.

Methods

Binding name: camel

Method Usage
CamelContext getCtx() Gets the Camel context currently started within Platform 6.
Endpoint getEndpoint(String endpoint) Direct access to an endpoint within the context given it’s name.
Map endpointCallWaitInput(String endpoint) Synchronous call to given endpoint. Exchange In message returned as Map
Map endpointExchangeWaitInput(String endpoint, Map exchangeMap) Synchronous exchange with given endpoint. Exchange In message given as Map, Exchange In message returned as Map
Map endpointExchangeWaitOutput(String endpoint, Map exchangeMap) Synchronous exchange with given endpoint. Exchange In message given as Map, Exchange Out message returned as Map
Map endpointExchangeWaitBoth(String endpoint, Map exchangeMap) Synchronous exchange with given endpoint. Exchange In message given as Map, Exchange In and Out message returned as Map
void registerBean(String beanId, Class beanClass) Registers a named bean in the Spring application context.
void unregisterBean(String beanId) Removes a named bean from the Spring application context.
void destroyRoute(String routeId) Removes the route from the current camel context.
void destroyAllRoutes() Removes all route from the current camel context.

An Exchange represents an abstraction for an exchange of messages which involves a request message and its corresponding response or an exception message. This can be expressed as a map for use with this DSL:

// Example exchange map
def exchange = [
  body: "<xml>hello</xml>",
  headers: [hello : "world" ],
  attachments: [ myfile: "file:///Users/simont/Documents/temp/b2box-5.2.6-SNAPSHOT/b2run.sh"],
  properties: [ one : "one", two : "two" ]
]

Details

When Platform 6 starts, a camel context is started via Spring using the file: $B2BOX_HOME/conf/b2boxcontext.xml. It is possible to extend the context bean definition using this file; adding routes for example.

Because Spring starts the camel context, the bean registry used by this context will be Springs. Therefore adding additional beans via the Spring context is also a possibility. To do this the b2boxcontext.xml file should be moved from $B2BOX_HOME/conf to $B2BOX_DATA/conf.

Alternatively, creating routes and registering beans can be performed in the scripts and routes services using this DSL.

JAR dependencies

The following Camel JAR files ship with Platform 6:

  • camel-core
  • camel-jms
  • camel-spring
  • camel-file2
  • camel-quartz2

Camel/Spring Versions

The version of Camel shipped with Platform 6 is 2.18.1 which is compatible with the version of Spring used by the product: 4.3.4.RELEASE. Please do not attempt to update or use services and/or components that are not version compatible.

Camel has many other components and services that are distributed in other JAR files. If a developer wishes to use other components and services the JARs (and dependencies) should be downloaded and placed in $B2BOX_DATA/lib.

Using @Grab

We have encountered issues when using @Grab to download JAR dependencies at runtime. These issues can arise when multiple users run multiple scripts concurrently. Use of @Grab on production system is therefore not recommended however its use during development and prototyping is possible.

JMS integration

Platform 6 has an embedded JMS provider called HornetQ. Camel will therefore use this provider by default. In order to create named queues for use with Camel the file $B2BOX_HOME/conf/hornetq-jms.xml should be moved to $B2BOX_DATA/conf/hornetq-jms.xml and edited to add the required queues:

<configuration xmlns="urn:hornetq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">

    <connection-factory name="ConnectionFactory">
        <connectors>
            <connector-ref connector-name="in-vm"/>
        </connectors>
        <entries>
            <entry name="ConnectionFactory"/>
        </entries>
        <use-global-pools>false</use-global-pools>
        <scheduled-thread-pool-max-size>10</scheduled-thread-pool-max-size>
        <thread-pool-max-size>-1</thread-pool-max-size>

        <client-failure-check-period>2147483646</client-failure-check-period>
        <connection-ttl>-1</connection-ttl>
        <reconnect-attempts>-1</reconnect-attempts>

    </connection-factory>

    <queue name="myQueue">
        <entry name="/queue/cameltest"/>
    </queue>

</configuration>

Please see http://docs.jboss.org/hornetq/2.4.0.Final/docs/user-manual/html/index.html for more information.

JMX activation

JMX is activated within Platform 6 Camel by default allowing you to monitor and control the Camel managed objects with a JMX client.

JMX client

Please see: http://camel.apache.org/camel-jmx.html for more information

Examples

Camel weather

This is an example of using one of the many components available to Camel. For a full list see: https://github.com/apache/camel/tree/master/components#components The following JARs were downloaded and copied to $B2BOX_DATA/lib:

  • camel-weather-2.18.1.jar
  • jackson-core-asl-1.9.12.jar
  • jackson-mapper-asl-1.9.12.jar

I then created a free account with: http://openweathermap.org/ to obtain an appid.

See: http://camel.apache.org/weather.html

println "WEATHER INFO> " + camel.endpointCallWaitInput("weather:foo?appid=3cacd3cba74f4288ec0d8c1396513824")