I have a issue is like, a process is triggered with two identical requests, both instance are in progress hence there is no process-instance id, how can i identify that there is already a request is in progress and cancel any one of instance
if you start every process by message and use a unique business key for correlation, you can implement your requirements with this pattern:
Both message event have to use the same message definition. The event subprocess will cancel all following requests when a process instance is running.
Is there any other way, assume my workflow has a start event , service task and end event.
In this scenario how can I avoid duplicate calls , with the same request.
We have a service which will invoke workflow with rest API… due to some error scenario that service is invoking workflow multiple times within a fraction of second, and due to this request is getting processed twice as from workflow point of view it is two independent calls, two process instance will be there.
Is there any other way… even though there is duplicate only once it should process with the same request
Configure a ExecutionListener in StartEvent of the process and query by the businessKey in runtime tables and if process already exists throw the exception if already same entity is in process.
long processCount = execution.getProcessEngineServices().getRuntimeService()
.createExecutionQuery().processDefinitionKey("aProcessDefinitionKey")
.tenantIdIn("aTenantId").processInstanceBusinessKey("aBusinessKey")
.active().count();
if (processCount > 0) {
throw new RuntimeException("Process already exists for businessKey: "
+ execution.getBusinessKey());
}
@aravindhrs thanks,
i tried above thing, when process in active state i mean still is in progress(as per example i mentioned it is still in service delegate) the above queries returns null.
i am verify with two instances locally with diff port and with the same request , with a debugger: in both the instance it returns process instance as null. so duplicate process happens
Process instance will get created in start event itself. There’s no use of checking process duplication in service task. Handling in service task won’t prevent process duplication. Handle it in createvent in the Start event activity. You can reuse the delegates as listeners in start event execution listener. Start the process instance asynchronously by marking async:before=“true” for the StartEvent in your bpmn.
@aravindhrs let me try that, i have question here, when process instance is created and if i try to check with above queries with run time process instance id , it should return a single result right
@aravindhrs ya right., in my case still process is not active , it is still in execution phase right, i see above query returns null .
i have seen query returns true, i process is active and pending at manual test or time event like that.
In this scenario, a query beforehand will always return null, as I assume that the first process instance is not committed in the database when the second process instance is started. Both transactions will overlap and commit sucessfully.
To avoid duplication here, you have to make the business key a unique index the database. Then the second (and all other subsequence processs instances) can not get commited in the database and will throw an exception.
yes it will. But you can add a new table using a unique index in the camunda database and use this for synchronizing, if the unique business key is to restrictive.
The new table needs more effort to setup and fill with data, but should be possible.