I am trying to implement a business process flow which is shown below:
Process instance starts with an AMQP message. We’ll get an Id here in the message.
Next service task makes a get call to fetch data corresponding to Id which is a list.
I do another rest call to another component (Lets say CompT) in order to make changes to all those data.
The CompT then publishes an event for each of the modified data.
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?
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
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.
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.