Routes
Service Id: platform6.routes
1. Upsert a Route Service Items¶
Header key | Description | Value |
---|---|---|
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 | |
platform6.request.user |
The email address of the user sending the message (optional) |
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.
A valid response will be:
Header key | Description |
---|---|
platform6.response.status |
true |
Example¶
import groovy.json.JsonOutput
def cm = [
headers: [
'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': 'p6.camel.getCtx().addRoutes(new RouteBuilder() { void configure() { rest( "/public/say" ) } })'
]
]
print p6.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" : [
"io.platform6.common.util.P6Exception: Unexpected exception adding a new route deployment script 'my_new_route': the parameter 'type' is missing.",
" at io.platform6.core.service.routes.RoutesService.notifyRequestMessage(RoutesService.java:144)",
" at io.platform6.core.impl.servicecomponent.AbstractServiceComponent.onCommonMessage(AbstractServiceComponent.java:688)",
" at io.platform6.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)"
]
}
2. Execute a Route Service Items Route Deployment Script (if it’s enabled)¶
Header key | Description | Value |
---|---|---|
platform6.request.action |
The action to perform (required) | execute |
id |
The identifier of the route (required) | |
platform6.request.user |
The email address of the user sending the message |
The author of the route’s execution will be the user who sent the common message.
_A valid response will be:
Header key | Description |
---|---|
platform6.response.status |
OK |
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.action': 'execute',
'id': 'my_new_route'
]
]
print p6.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" : [
"io.platform6.common.util.P6Exception: The route deployment script'my_new_route' is disabled! You need to enable it to start it.",
" at io.platform6.core.service.routes.RouteManager.startRouteDeployer(RouteManager.java:36)",
" at io.platform6.core.service.routes.RoutesService.startRouteDeployer(RoutesService.java:84)",
" at io.platform6.core.service.routes.RoutesService.notifyRequestMessage(RoutesService.java:179)",
" at io.platform6.core.impl.servicecomponent.AbstractServiceComponent.onCommonMessage(AbstractServiceComponent.java:688)",
" at io.platform6.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 throw an error:
{
"message" : "The route deployment script 'my_new_route' is already running! It cannot be started.",
"stackTrace" : [
"io.platform6.common.util.P6Exception: The route deployment script 'my_new_route' is already running! It cannot be started.",
" at io.platform6.core.service.routes.RouteManager.startRouteDeployer(RouteManager.java:32)",
" at io.platform6.core.service.routes.RoutesService.startRouteDeployer(RoutesService.java:84)",
" at io.platform6.core.service.routes.RoutesService.notifyRequestMessage(RoutesService.java:179)",
" at io.platform6.core.impl.servicecomponent.AbstractServiceComponent.onCommonMessage(AbstractServiceComponent.java:688)",
" at io.platform6.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)"
]
}