Customising

Customising

Adding the custom code to the gateway

Rhiot.io gateway comes with the set of predefined components and features that can be used out of the box. It is however very likely that your gateway will execute some custom logic related to your business domain. This section of the documentation covers how can you add the custom code to the gateway.

We highly recommend to deploy the gateway as a fat jar. This approach reduces the devOps cycles needed to deliver the working solution. If you would like to add the custom logic to the gateway, we recommend to create the fat jar Maven project including the gateway core dependency:

io.rhiotrhiot-gateway${rhiot.version}

Avaliable for rhiot.version >= 0.1.1

Now all your custom code can just be added to the project. The resulting fat jar will contain both gateway core logic and your custom code.

Adding custom Groovy Camel verticle to the gateway

As the Rhiot gateway uses Vert.x event bus as its internal messaging core, the recommended option to add new Camel routes to the gateway is to deploy those as the Vert.x verticle. The Vert.x helper classes for the gateway are available in the following jar:

io.rhiotrhiot-vertx${rhiot.version}

Avaliable for rhiot.version >= 0.1.1

In order to create Vert.x verticle that can access single CamelContex instance shared between all the verticles within the given JVM, extend the io.rhiot.vertx.camel.GroovyCamelVerticle class:

@GatewayVerticle
class HeartbeatConsumerVerticle extends GroovyCamelVerticle {

    @Override
    void start() {
        fromEventBus('heartbeat') { it.to('mock:camelHeartbeatConsumer') }
    }

}

Rhiot gateway scans the classpath for the verticle classes marked with the io.rhiot.gateway.GatewayVerticle annotation. All those verticles are automatically loaded into the Vert.x backbone.

As you can see in the example above you can read the messages from the event bus and forward these to your Camel route using the fromEventBus(channel, closure(route)) method. You can also access the Camel context directly:

import static io.rhiot.steroids.camel.CamelBootInitializer.camelContext

@GatewayVerticle
class HeartbeatConsumerVerticle extends GroovyCamelVerticle {

    @Override
    void start() {
        camelContext().addRoutes(new RouteBuilder(){
            @Override
            void configure() {
                from('timer:test').to('seda:test')
            }
        })
    }

}

Last updated