A quickstart project shows use of timer based activities within the process to allow a flexible delays before continuing process execution. There are two types of timers used in this quick start
This example shows
working with timers (both intermediate and boundary)
optionally use Job Service that allows to externalize time tracking to separate service and by that offload the runtime service
Intermediate timer event (timers.bpmn)
Timer expression is expected to be given in ISO-8601 format e.g. PT30S - wait 30 seconds before expiring. This needs to be given when starting process instance as delay attribute of type string.
You will need:
mvn clean compile spring-boot:run
mvn clean package
To run the generated native executable, generated in target/
, execute
java -jar target/process-timer-springboot.jar
You can take a look at the OpenAPI definition - automatically generated and included in this service - to determine all available operations exposed by this service. For easy readability you can visualize the OpenAPI definition file using a UI tool like for example available Swagger UI.
In addition, various clients to interact with this service can be easily generated using this OpenAPI definition.
To make use of this application it is as simple as putting a sending request to http://localhost:8080/timers
with following content
{ "delay" : "PT30S" }
Complete curl command can be found below:
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"delay" : "PT30S"}' http://localhost:8080/timers
curl -H 'Content-Type:application/json' -H 'Accept:application/json' http://localhost:8080/timers
curl -X DELETE 'http://localhost:8080/timers/{uuid}'
where {uuid}
is the id of the given timer instance
To make use of this application it is as simple as putting a sending request to http://localhost:8080/timerscycle
with following content
{ "delay" : "R2/PT1S" }
Complete curl command can be found below:
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"delay" : "R2/PT1S"}' http://localhost:8080/timerscycle
curl -H 'Content-Type:application/json' -H 'Accept:application/json' http://localhost:8080/timerscycle
curl -X DELETE 'http://localhost:8080/timerscycle/{uuid}'
where {uuid}
is the id of the given timer cycle instance
To make use of this application it is as simple as putting a sending request to http://localhost:8080/timersOnTask
with following content
{ "delay" : "PT30S" }
Complete curl command can be found below:
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"delay" : "PT30S"}' http://localhost:8080/timersOnTask
curl -H 'Content-Type:application/json' -H 'Accept:application/json' http://localhost:8080/timersOnTask
curl -X DELETE 'http://localhost:8080/timersOnTask/{uuid}'
where {uuid}
is the id of the given timer instance
After executing the above commands you should see a log similar to
Before timer... waiting for PT30S After Timer Before timer, waiting for task to be complete or expires in PT30S After Timer Before timer... waiting for R2/PT1S After Timer After Timer
There is additional configuration needed in the application.properties
file.
To allow to use Job Service as timer service there is a need to specify additional properties
kogito.jobs-service.url=http://localhost:8085 kogito.service.url=http://localhost:8080
First one is used to direct the Kogito runtime to let it know where is the Kogito Job Service - it needs to match the location of the Kogito Job Service when starting it - see below. Second one is used by Kogito Job Service to callback when the timer expires and needs to be pointing to the service host and port
java -Dquarkus.http.port=8085 -jar jobs-service-infinispan/target/jobs-service-infinispan-{version}-runner.jar
If you'd like to use PostgresSQL or MongoDB as persistence, start the PostgreSQL or MongoDB server, then start job service with following command
For PostgreSQL:
java -Dquarkus.http.port=8085 -Dquarkus.datasource.username={username} -Dquarkus.datasource.password={password} -Dquarkus.datasource.reactive.url=postgresql://{host}:{port}/{db} -Dquarkus.datasource.jdbc.url=jdbc:postgresql://{host}:{port}/{db} -jar jobs-service-postgresql/target/jobs-service-postgresql-{version}-runner.jar
For MongoDB:
java -Dquarkus.http.port=8085 -Dquarkus.mongodb.connection-string=mongodb://{username}:{password}@{host}:{port} -Dquarkus.mongodb.database={db} -jar jobs-service-mongodb/target/jobs-service-mongodb-{version}-runner.jar
In all cases replace {version}
with actual Kogito version to be used (Job Service is available from 0.6.0)
After that you can redo the timer queries described above.
Generated application comes with sample test process that allows you to verify if the application is working as expected. Simply execute following command to try it out
curl -X POST -H 'Content-Type: application/json' -i 'http://example-route-on-openshift/timer'
Once successfully invoked you should see “Before timer” and “After timer” in the console of the running application.