Rhiot Documentation
  • Introduction
  • Gateway
    • Camel Kura router
    • Monitoring
    • Customising
    • Camel components
      • Camel Bluetooth component
      • Camel GPS BU353 component
      • Camel GPSD component
      • Camel TinkerForge component
      • Camel Pi4j component
      • Camel Framebuffer component
      • Camel Webcam component
    • Eclipse Kura support
      • Camel components for Eclipse Kura
        • Camel Kura Wifi component
        • Camel Kura Cloud component
    • Mini gateway
      • Installing
      • GPS
  • Backend
    • Camel Components
      • Camel OpenIMAJ component
      • Camel PubNub component
  • Tooling
  • Performances
  • Steroids
  • Quickstarts
    • Kura Camel quickstart
    • AMQP Cloudlet quickstarts
    • MQTT Cloudlet quickstart
  • Articles, presentations & videos
  • Building
    • Manage Kura Maven dependencies
  • Releases notes
Powered by GitBook
On this page
  • Customising
  • Adding the custom code to the gateway
  • Adding custom Groovy Camel verticle to the gateway

Was this helpful?

  1. Gateway

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')
            }
        })
    }

}
PreviousMonitoringNextCamel components

Last updated 3 years ago

Was this helpful?