Download Service_activator.bpmn file
Service_activator_C8.zip file
⤳ case study requires Spring Boot Java
Download Service_activator_C8_V2.zip file
⤳ case study requires Spring Boot Java
Service activator design pattern offers a single entry point for a business service while hiding the way “concrete” services may be requested to provide the expected business data. Indeed, possible failures resulting from requests must lead to appropriate tactics to serve the required data
As an illustration, case study is the search for the up-to-date currency exchange rate (timestamp of rate capture as well) between the Moroccan Dirham against the US Dollar and/or the Euro. This occurs through the call of two professional RESTful APIs with free subscription
* openexchangerates_org_defect as
value of Code field for BPMN error event
creates the mapping (see prior slide)
Service_activator.bpmn file within Camunda Modeler
Service_activator_C8.zip file
and
run Service_activator_C8 Java project
in your favorite IDEService_activator.bpmn and next create process instance within Camunda Modeler
⤳ check result in http://localhost:8080/operate console678cd96edd4b4f3eb637bf74ef8e0815 to
678cd96edd4b4f3eb637bf74ef8e0816
within openexchangerates.org task
Service_activator.bpmn and next re-create process instance within Camunda Modeler
⤳ check result in http://localhost:8080/operate console
*Doc. ☛
package com.BarbierDarnal.service_activator;
@org.springframework.stereotype.Component
public class Openexchangerates_org_success_execution_listener {
// 'type' attribute operates the mapping with the BPMN model:
@io.camunda.client.annotation.JobWorker(type = "Openexchangerates_org_success")
public void my_execution_listener(final io.camunda.client.api.response.ActivatedJob job) {
Object when = job.getVariable("when"); // 'when' process variable...
System.out.println("'when' within 'Openexchangerates_org_success': " + when.toString());
}
}
@org.springframework.stereotype.Component
public class Service_activator_job_worker_example {
private final static org.slf4j.Logger _Log = org.slf4j.LoggerFactory.getLogger(Service_activator_job_worker_example.class);
@io.camunda.client.annotation.JobWorker(type = "Service_activator_job_worker_example")
public void my_service_task(final io.camunda.client.api.worker.JobClient client, final io.camunda.client.api.response.ActivatedJob job, @io.camunda.client.annotation.Variable(name = "Comment_ca_va_") @jakarta.annotation.Nullable String plutot_bien) {
_Log.info("Processing 'Service_activator_job_worker_example': {}", job.getKey());
System.out.println("Comment ça va ? " + plutot_bien);
Object one_US_dollar_to_Moroccan_dirham = job.getVariable("one_US_dollar_to_Moroccan_dirham");
System.out.println("'one_US_dollar_to_Moroccan_dirham': " + one_US_dollar_to_Moroccan_dirham.toString());
try {
var timestamp = new java.sql.Timestamp(1000 * ((Number) job.getVariable("timestamp")).longValue());
String when = timestamp.toLocalDateTime().format(java.time.format.DateTimeFormatter.ISO_DATE_TIME);
System.out.println("'when' within 'Service_activator_job_worker_example': " + when);
client.newCompleteCommand(job).variable("when", when).send().join(); // Creation of 'when' as process var.
} catch (ClassCastException cce) {System.err.println("Push system error to BPMN? No...");}
_Log.info("'Service_activator_job_worker_example' completed: {}", job.getKey());
}
}
.env file of
Camunda 8 Run
Service_activator_C8_V2.zip)
@org.springframework.stereotype.Component
public class Log_error implements io.camunda.client.api.worker.JobHandler {
@io.camunda.client.annotation.JobWorker(type = "Log_error", autoComplete = false)
@Override
public void handle(final io.camunda.client.api.worker.JobClient client, final io.camunda.client.api.response.ActivatedJob job) {
// All parent process variables have been passed:
// job.getVariablesAsMap().forEach((variable_name, variable_value) -> System.out.println(variable_name + ": " + variable_value.toString()));
Object error_message = job.getVariable("error_message"); // 'error_message' parent process variable...
System.err.println(error_message.toString());
client.newCompleteCommand(job).send();
}
}
Log_error.bpmn and Service_activator_V2.bpmn
found within Service_activator_C8_V2.zipService_activator_V2.bpmn process instanceLog_error.bpmn process instance
will be viewable
in http://localhost:8080/operate console
Change 678cd96edd4b4f3eb637bf74ef8e0815 to
678cd96edd4b4f3eb637bf74ef8e0816
within openexchangerates.org task
Create Service_activator_V2.bpmn process instance
Log_error.bpmn process instances
will be viewable
in http://localhost:8080/operate console
Change f9ae18a1a70ceef1bbf421ecf494ecb4 to
f9ae18a1a70ceef1bbf421ecf494ecb5
within .env file (Camunda 8 Run restart required)
Create Service_activator_V2.bpmn process instance