Handle Errors on Message Correlation

Hello.
I work with Camunda based on SpringBoot. I use RabbitMQ to communicate with services.

  1. Task “service_a” sends message via RabbitMQ:

@Autowired
private RabbitTemplate rabbitTemplate;

rabbitTemplate.convertAndSend(direct.getName(), process_binding, mbMessage.toString());

  1. Message Event waits message.

  2. 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)

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.

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:

Here, a very similar question came up. Maybe this helps

Jonathan