Same process instance consuming Multiple messages

Hi there,

I am trying to implement a business process flow which is shown below:

  1. Process instance starts with an AMQP message. We’ll get an Id here in the message.
  2. Next service task makes a get call to fetch data corresponding to Id which is a list.
  3. I do another rest call to another component (Lets say CompT) in order to make changes to all those data.
  4. The CompT then publishes an event for each of the modified data.
  5. I have to consume these messages in the same process instance and log.

I have completed till 4th step. I am not able to achieve from 5th step. Can anyone guide me at an example Process diagram and related Java code if available?

Thanks in advance.
Below is the attachment.

releaseOrder.bpmn (6.7 KB)

Hi @abhishekBharadwaj

maybe you could model what you have so far and attach here as a BPMN file?
Then it’s easier for people to help you based on what you got :slight_smile:

Best
Felix

Hi @felix-mueller,

Thanks for the reply. I have attached the BPMN file. Its not complete. Please take a look.

Regards,
Abhishek

It sounds like a situation for a multi-instance. Not sure if the call to CompT is done once for all of the changes or one at a time. In the first case, what you have is ok but you could add a multi instance to your receive task to collect the event emitted for each of the changes (based on the collection you already retrieved before). If it’s one request-reply pattern for each change, create a subprocess for service task, then receive task and apply a multi-instance on the whole subprocess, so it gets executed for each element in the list. More information on using mulit-instances can be found here: https://docs.camunda.org/manual/7.9/reference/bpmn20/tasks/task-markers/#multiple-instance

Hi @tiesebarrell,

That was a great guide. I implemented multi-instance activity. But the problem I am facing now is that how to give different messages to different instances of that activity. I have a amqp receiver and I have attached the code snippet trying give message to the multi-instance activity.

ProcessInstance processInstance =
    camunda
        .getRuntimeService()
        .createProcessInstanceQuery()
        .processInstanceBusinessKey(orderHeaderId)
        .singleResult();
List<Execution> executionList =
    camunda
        .getRuntimeService()
        .createExecutionQuery()
        .processInstanceId(processInstance.getId())
        .activityId(ProcessConstants.TASK_EVENT_RECEIVE_TASK_ID)
        .orderByProcessInstanceId()
        .asc()
        .list();
camunda.getRuntimeService().signal(executionList.get(0).getId(), variableMap);

I couldn’t figure out how to distribute the message to different instances. It would be great if you could throw some light on this issue.

One way you could do that is to create a local variable in the receive task’s execution (for instance, by using a listener that does this on creation) and query for an execution that has that value in the variable. That way you could match them exactly to the right one. I don’t think that’s available using messages only.

1 Like

That’s the right approach. Correlation supports matching local variables, see Message Events | docs.camunda.org.