Anuar
July 19, 2021, 9:20am
1
Hello.
I work with Camunda based on SpringBoot. I use RabbitMQ to communicate with services.
Task “service_a” sends message via RabbitMQ:
@Autowired
private RabbitTemplate rabbitTemplate;
…
rabbitTemplate.convertAndSend(direct.getName(), process_binding, mbMessage.toString());
Message Event waits message.
I have RabbitMQ listener:
@RabbitListener(queues = "#{autoDeleteQueue1.name}")
public void receive1(String str) throws InterruptedException {
ObjectMapper mapper = new ObjectMapper();
try {
MBMessage mbMessage = mapper.readValue(str, MBMessage.class);
System.out.println(new java.util.Date() + " alfa_camunda received message: " + mbMessage);
camunda.getRuntimeService().createMessageCorrelation(mbMessage.getActivityId())
.processInstanceVariableEquals("process_id", mbMessage.getProcess_id())
.setVariable(mbMessage.getActivityId() + "_output", mbMessage.getInput())
.correlateWithResult();
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
How to handle correlation error in listener? When i get exception and add try-catch block:
try {
camunda.getRuntimeService().createMessageCorrelation(mbMessage.getActivityId())
.processInstanceVariableEquals("process_id", mbMessage.getProcess_id())
.setVariable(mbMessage.getActivityId() + "_output", mbMessage.getInput())
.correlateWithResult();
} catch (Exception e) {
e.printStackTrace();
}
I get the error over and over again infinitely as if I read the message every time.
How properly propagate BpmnError and catch it on BPMN Diagram in case when it appears in Listener?
process_correlation.bpmn (15.1 KB)
Anuar
July 22, 2021, 8:58am
2
Realized that it is possible to pre-check for a pending “message event”.
long correlatingInstances = camunda.getRuntimeService().createExecutionQuery()
.processInstanceId(mbMessage.getProcess_id())
.activityId(mbMessage.getActivityId() + "_receive")
//.messageEventSubscriptionName(mbMessage.getActivityId() + "_receive")
//.variableValueEquals("process_id", mbMessage.getProcess_id())
.count();
if (correlatingInstances == 1) {
camunda.getRuntimeService().createMessageCorrelation(mbMessage.getActivityId())
.processInstanceId(mbMessage.getProcess_id())
.setVariable(mbMessage.getActivityId() + "_output", mbMessage.getInput())
.correlateWithResult();
} else {
System.out.println("message event not found");
}
but I can not search correlationInstances by method “messageEventSubscriptionName”, its always null. Where should I set this name in “intermediateCatchEvent” or “receiveTask” on diagram. I filled all fields Id, name, global message name.
Anuar
July 22, 2021, 11:16am
3
Worked when autowired not
@Autowired
private ProcessEngine camunda;
but
@Autowired
private RuntimeService runtimeService;
then I used code:
long correlatingInstances = runtimeService.createExecutionQuery()
.processInstanceId(mbMessage.getProcess_id())
.messageEventSubscriptionName(mbMessage.getActivityId())
.count();
messageEventSubscriptionName looks at “Global Message Name” in “intermediateCatchEvent” or “receiveTask” of BPMN diagram.
Hello @Anuar ,
welcome to our forum. As possible answer, I would like to refer to this thread:
Hi there,
I am facing one of the issue in process engine for no corelation id found is receive task and my task get stuck there in receive task even though after receiving Event from the another system, the process is as follows
Process Engine
Start
Send task( Send JMS message )
Receive Task( Spring Streams) Receive JMS Event through Messages( But here it sometimes fails for corelation id)
End Task
Is there any solution to avoid this, like transactional or run camunda process parallel or so…
Here, a very similar question came up. Maybe this helps
Jonathan