subprocess business key

1,322 views
Skip to first unread message

Claudia Carpineti

unread,
Dec 29, 2014, 12:21:51 PM12/29/14
to camunda-...@googlegroups.com
Hi All,

I try to model a simple scenario where there are 4 instance of subprocess talk to another pool and wait for the response. I have problem when the other pool try to reply to the message.

I have this error:
Cannot correlate message MsgRevisioneArticolo with process instance business key null and correlation keys null: 4 executions match the correlation keys. Should be one or zero.

I don't know how can set the business key of the subprocess instance. Doesn't matter if I pass the business key or not from the main process to the subprocess.
Is possible to set business key, one differente for each instance, or get the business key after the start event (now it seems to be empty)?

Thank you in advance   
Claudia





Christian Lipphardt

unread,
Dec 29, 2014, 2:25:07 PM12/29/14
to camunda-...@googlegroups.com
Hi Claudia,

Could you please describe in detail what you mean with subprocess? Do you mean a (embedded / event) Subprocess[1] as in BPMN or a Call Activity [2]? Or is the subprocess just an instance of the process definition?

You are able to set a business key when you start your process instance through the RuntimeService.startProcessInstanceByXXX methods. To propagate the business key to a process started by a call activity, see [3].
It is currently not possible to set a business key when the process instance is already started.

Maybe you can correlate on some variable values which identifies your instances uniquely?

Cheers,
Christian


--
You received this message because you are subscribed to the Google Groups "camunda BPM users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camunda-bpm-us...@googlegroups.com.
To post to this group, send email to camunda-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/camunda-bpm-users/6b152867-d857-43bc-8af3-10b564eee602%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Claudia Carpineti

unread,
Dec 29, 2014, 6:20:16 PM12/29/14
to camunda-...@googlegroups.com
Hi Christian,
tnks for the reply and sorry for the inaccuracy.
I try to be more specify:

This is the piece of BPMN that generates problems. Above I have the Process1, below he Process2


This is the definition of my embedded subprocess:

<bpmn2:subProcess id="OttieniRevisione" name="Ottieni revisione">
    <bpmn2:incoming>SequenceFlow_3</bpmn2:incoming>
    <bpmn2:outgoing>SequenceFlow_17</bpmn2:outgoing>
    <bpmn2:multiInstanceLoopCharacteristics>
         <bpmn2:loopCardinality xsi:type="bpmn2:tFormalExpression">
               <![CDATA[${execution.getVariable("nrRevisioniDaOttenere")}]]
         </bpmn2:loopCardinality>
    </bpmn2:multiInstanceLoopCharacteristics>

    <bpmn2:startEvent id="StartEvent_2">
            <bpmn2:outgoing>SequenceFlow_5</bpmn2:outgoing>
    </bpmn2:startEvent>
    <bpmn2:sequenceFlow id="SequenceFlow_5" name="" sourceRef="StartEvent_2" targetRef="InformaRevisore"/>
    <bpmn2:sendTask id="InformaRevisore" camunda:class="org.camunda.bpm.pubb.InformaRevisore" name="Informa revisore">
      <bpmn2:incoming>SequenceFlow_5</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_1</bpmn2:outgoing>
    </bpmn2:sendTask>
    <bpmn2:sequenceFlow id="SequenceFlow_1" name="" sourceRef="InformaRevisore" targetRef="EventBasedGateway_1"/>      

     
<
bpmn2:intermediateCatchEvent id="DeadLineOttieniRevisione_nonOttenuta">
      <bpmn2:incoming>SequenceFlow_13</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_14</bpmn2:outgoing>
      <bpmn2:timerEventDefinition id="_TimerEventDefinition_29">
           <bpmn2:timeDate xsi:type="bpmn2:tFormalExpression">
                <![CDATA[
${execution.getVariable("deadlineRevisioni")}]]>
           
</
bpmn2:timeDate>
      </bpmn2:timerEventDefinition>
      </bpmn2:intermediateCatchEvent>
       <bpmn2:sequenceFlow id="SequenceFlow_14" name="" sourceRef="DeadLineOttieniRevisione_nonOttenuta" targetRef="End_ArticoloNonRevisionato"/>
       <bpmn2:endEvent id="End_ArticoloNonRevisionato" name="Articolo non revisionato">        
             <bpmn2:incoming>SequenceFlow_14</bpmn2:incoming>
       </bpmn2:endEvent>
       <bpmn2:eventBasedGateway id="EventBasedGateway_1">
              <bpmn2:incoming>SequenceFlow_1</bpmn2:incoming>
              <bpmn2:outgoing>SequenceFlow_12</bpmn2:outgoing>
              <bpmn2:outgoing>SequenceFlow_13</bpmn2:outgoing>
       </bpmn2:eventBasedGateway>
       <bpmn2:sequenceFlow id="SequenceFlow_12" name="" sourceRef="EventBasedGateway_1" targetRef="revisioneOttenuta"/>
       <bpmn2:sequenceFlow id="SequenceFlow_13" name="" sourceRef="EventBasedGateway_1" targetRef="DeadLineOttieniRevisione_nonOttenuta"/>
       <bpmn2:intermediateCatchEvent id="revisioneOttenuta" name="Revisione ottenuta">
              <bpmn2:extensionElements>
                      <camunda:executionListener class="org.camunda.bpm.pubb.RevisioneOttenutaListener" event="start"/>
             </bpmn2:extensionElements>
             <bpmn2:incoming>SequenceFlow_12</bpmn2:incoming>
             <bpmn2:outgoing>SequenceFlow_15</bpmn2:outgoing>
             <bpmn2:messageEventDefinition id="_MessageEventDefinition_68" messageRef="Message_5"/>
       </bpmn2:intermediateCatchEvent>
       <bpmn2:sequenceFlow id="SequenceFlow_15" name="" sourceRef="revisioneOttenuta" targetRef="DeadLineOttieniRevisione_ottenuta"/>
              <bpmn2:intermediateCatchEvent id="DeadLineOttieniRevisione_ottenuta">
                   <bpmn2:incoming>SequenceFlow_15</bpmn2:incoming>
                   <bpmn2:outgoing>SequenceFlow_16</bpmn2:outgoing>
                   <bpmn2:timerEventDefinition id="_TimerEventDefinition_30">
                             <bpmn2:timeDate xsi:type="bpmn2:tFormalExpression">
                                      <![CDATA[
${execution.getVariable("deadlineRevisioni")}]]>
                           
</
bpmn2:timeDate>
                  </bpmn2:timerEventDefinition>
               </bpmn2:intermediateCatchEvent>
         <bpmn2:sequenceFlow id="SequenceFlow_16" name="" sourceRef="DeadLineOttieniRevisione_ottenuta" targetRef="End_ArticoloRevisionato"/>
<bpmn2:endEvent id="End_ArticoloRevisionato" name="Articolo revisionato"><bpmn2:incoming>SequenceFlow_16</bpmn2:incoming>

</bpmn2:endEvent>
</bpmn2:subProcess>


This is the class associated to the send task in the Process1

public class InformaRevisore implements JavaDelegate {
   
@Override
    pubblic
void execute (DelegateExecution execution) throws Exception{
         
//build payload of messagge for Process2
         
TreeMap <String, Object> variable4Process2 = new TreeMap<String, Object>();
         variable4Process2
.put("autore",execution.getVariable("autore"));
         variable4Process2
.put("bkPorocess1",((String)execution.getVariable("bkProcess1"));
         
//build business key for Process2
          java.util.Date date = new java.util.Date();
         
TimeStamp currentTimestamp = new TimeStamp(date.getTime());
         
String bkProcess2= "Process2" + currentTimeStamp;
         
//send message to Process2
         
ProcessEngine processEngine =  ProcessEngines.getDefaultProcessEngine();
         processEngine
.getRuntimeService().startProcessInstanceByMessage("MsgRichiestaRevisione",bkProcess2,variable4Process2);
}
}


This is the class associated to the send task in the Process2

public class InviaRevisione implements JavaDelegate {
@Override
   public void execute(delegateExecution execution) throws Excecption {
   // build the payload for the reply message
   TreeMap<string,Object> variable4Process1= new TreeMap<String,Object>();
    ...
   //send message to Process1
   ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  processEngine.getRuntimeService().correlateMessage("MsgRevisioneArticolo"),(String)execution.getVariable("bkProcess1"), variabl4Process1);

}
}

The above line fail:

 processEngine.getRuntimeService().correlateMessage("MsgRevisioneArticolo"),(String)execution.getVariable("bkProcess1"), variabl4Process1);

with this error
Cannot correlate message MsgRevisioneArticolo with process instance business key null and correlation keys null: 4 executions match the correlation keys. Should be one or zero.

I hope I have been clearer,
if not I apologize now
Thank you in advance
Claudia


webcyberrob

unread,
Dec 29, 2014, 9:28:04 PM12/29/14
to camunda-...@googlegroups.com
Hi Claudia,

My guess is you have some handler code which is either using the Java API and calling RuntimeService.correlateMessage(String messageName) or the equivalent using the REST API. Hence the engine is saying there are potentially four matching process instances and thus it can't resolve to a given instance and throws the exception.

If this is the case, you will probably have to use a version of correlateMessage wich uses additional parameters to resolve down to a single process instance - for example if you were using the java API, you cold use something like the correlateMessage(String messageName, String businessKey) or similar. CHeck out the REST API or Java Doc references in Camunda Docs for more info on the APIs avaialable.

regards

Rob
...

Claudia Carpineti

unread,
Dec 30, 2014, 2:55:07 AM12/30/14
to camunda-...@googlegroups.com
Hi Rob,

many tnks for the reply. 
I use correlate message as I report below, specifying the business key of Process1, but all the instance of the subprocess have the same business key.

processEngine.getRuntimeService().correlateMessage("MsgRevisioneArticolo"),(String)execution.getVariable("bkProcess1"), variabl4Process1);



Do you have some suggestion?
Thank you in advance
Claudia

webcyberrob

unread,
Dec 30, 2014, 4:32:15 AM12/30/14
to camunda-...@googlegroups.com
Hi Claudia,

Looking a little more closely at your process diagram, it looks like you have an inline multi-instance sub-process and an event driven subprocess. It looks like you want the event driven sub-process to correlate messages back to the inline multi-instance sub-processes.

There's potentially a lot going on here and hard to pinpoint without all the code. Are you wanting to understand message correlation and event driven sub-processes, or could we simplify a little. For example, you could put the user task associated with the event driven process (Reviciona articolo) inline with the multi-instance inline-subprocess. In other words rather than use a send message task (Informa revisione), just put the user task here...

regards

Rob

Claudia Carpineti

unread,
Jan 3, 2015, 6:10:15 AM1/3/15
to camunda-...@googlegroups.com

Hi Rob,

I try in different way and now seems work, but I'm not very satisfied of my solution.
I removed the multi-instance and I made sure that the send task invoke a specific number of startProcessInstanceByMessage.
So the code handling the send task "informa revisori" change in this way:

public void execute(DelegateExecution execution) throws Exception {

/* build pay load of message */


                TreeMap<String, Object> variable4revisore = new TreeMap<String, Object>();

                String businessKeySubProcess = ((String)execution.getVariable("bkRivista"));

                variable4revisore.put("bkRivista", bkSubProcessBkRivista);


                ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();


                 for(int i=0; i<(int)execution.getVariable("nrRevisioniDaOttenere"); i++){

                                              processEngine.getRuntimeService().startProcessInstanceByMessage("MsgRichiestaRevisione", variable4revisore);


                 }



So my BPMN change in this way:


And now the process can use the same business key for reply to the message.
Do you think this solution can be good?

Thank you for your time
Claudia
Reply all
Reply to author
Forward
0 new messages