Routes
The platform6.routes
service allows you 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.
Read the user guide of the Routes service to discover its operating mode.
Add a route¶
This resource creates a new route if there is no route with the same identifier, otherwise, it does nothing.
Parameters¶
Headers of the request
Header’s key | Description | Value |
---|---|---|
platform6.request.user |
The email address of the user sending the message (required) | |
platform6.request.action |
The action to perform (required) | add |
id |
The identifier of the route (required) | |
description |
The description of the route (required) | |
enabled |
Is the item enabled or not (default to false ) |
|
autoStart |
Shall the route start when the instance is launched (default to false ) |
|
type |
The type of the route (required) | scheduler , file_listener , web3j , xml_routing , rest , mixed |
templateText |
The content of the template of the route (required) | |
scriptSegments |
The main file of the script |
The new route will be verified before upsert.
The last author of the modification will be the user who sent the common message.
The content mode will automatically be set to NONE
.
Warning
The identifier and the description must validate the service’s item rules.
Headers of the response
Header’s key | Description |
---|---|
platform6.response.status |
true if the item was created, false if it already exists |
Example¶
import groovy.json.JsonOutput def cm = [ headers: [ 'platform6.request.user': 'admin@amalto.com', 'platform6.request.action': 'add', 'id': 'my_new_route', 'description': JsonOutput.toJson([EN: 'A new route', FR: 'Une nouvelle route']), 'enabled': 'true', 'autostart': 'false', 'type': 'rest', 'templateText': 'camel.getCtx().addRoutes(new RouteBuilder() { void configure() { rest( "/public/say" ) } })' ] ] print service.request('platform6.routes', cm).headers['platform6.response.status']
true
if the route is validated and created.
If a route with the same id already exists, it will return false
.
If a field of the input is incorrect, it will throw an exception.
{ "message" : "Unexpected exception adding a new route deployment script 'my_new_route': the parameter 'type' is missing.", "stackTrace" : [ "com.amalto.b2box.core.api.B2boxException: Unexpected exception adding a new route deployment script 'my_new_route': the parameter 'type' is missing.", " at com.amalto.service.routes.RoutesService.notifyRequestMessage(RoutesService.java:144)", " at com.amalto.b2box.core.impl.servicecomponent.AbstractServiceComponent.onCommonMessage(AbstractServiceComponent.java:688)", " at com.amalto.b2box.core.impl.platform.messagebus.BusQueueController$ServiceQueueRunner.run(BusQueueController.java:183)", " at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)", " at java.util.concurrent.FutureTask.run(FutureTask.java:266)", " at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)", " at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)", " at java.lang.Thread.run(Thread.java:748)" ] }
Execute a route deployment script¶
This resource executes a specific route deployment script if it is enabled.
Parameters¶
Headers of the request
Header’s key | Description | Value |
---|---|---|
platform6.request.user |
The email address of the user sending the message (required) | |
platform6.request.action |
The action to perform (required) | execute |
id |
The identifier of the route (required) |
The author of the route’s execution will be the user who sent the common message.
Headers of the response
Header’s key | Description |
---|---|
platform6.response.value |
The identifier of the job launched for the execution of the route |
Example¶
The route’s content of this example is in the example above.
def cm = [ headers: [ 'platform6.request.user': 'admin@amalto.com', 'platform6.request.action': 'execute', 'id': 'my_new_route' ] ] print service.request('platform6.routes', cm).headers['platform6.response.value']
The output will be the launched job’s id:
1165532117
If the route is disabled, it will throw an error:
{ "message" : "The route deployment script'my_new_route' is disabled! You need to enable it to start it.", "stackTrace" : [ "com.amalto.b2box.core.api.B2boxException: The route deployment script'my_new_route' is disabled! You need to enable it to start it.", " at com.amalto.service.routes.RouteManager.startRouteDeployer(RouteManager.java:36)", " at com.amalto.service.routes.RoutesService.startRouteDeployer(RoutesService.java:84)", " at com.amalto.service.routes.RoutesService.notifyRequestMessage(RoutesService.java:179)", " at com.amalto.b2box.core.impl.servicecomponent.AbstractServiceComponent.onCommonMessage(AbstractServiceComponent.java:688)", " at com.amalto.b2box.core.impl.platform.messagebus.BusQueueController$ServiceQueueRunner.run(BusQueueController.java:183)", " at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)", " at java.util.concurrent.FutureTask.run(FutureTask.java:266)", " at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)", " at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)", " at java.lang.Thread.run(Thread.java:748)" ] }
If the route is already running, it will thrown an error:
{ "message" : "The route deployment script 'my_new_route' is already running! It cannot be started.", "stackTrace" : [ "com.amalto.b2box.core.api.B2boxException: The route deployment script 'my_new_route' is already running! It cannot be started.", " at com.amalto.service.routes.RouteManager.startRouteDeployer(RouteManager.java:32)", " at com.amalto.service.routes.RoutesService.startRouteDeployer(RoutesService.java:84)", " at com.amalto.service.routes.RoutesService.notifyRequestMessage(RoutesService.java:179)", " at com.amalto.b2box.core.impl.servicecomponent.AbstractServiceComponent.onCommonMessage(AbstractServiceComponent.java:688)", " at com.amalto.b2box.core.impl.platform.messagebus.BusQueueController$ServiceQueueRunner.run(BusQueueController.java:183)", " at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)", " at java.util.concurrent.FutureTask.run(FutureTask.java:266)", " at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)", " at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)", " at java.lang.Thread.run(Thread.java:748)" ] }