Error Boundary Event not working from Java Code

I have a BPMN process with an “Error Boundary Event” Code= 1 and Message=“MAIN_FLOW_BUSINESS_ERROR” linked to a sub process; when throwing the exception from the java Code the sub process is not starting:

throw new BpmnError(“1”, “MAIN_FLOW_BUSINESS_ERROR”);

PS: I’m using org.camunda.bpm.springboot:camunda-bpm-spring-boot-starter-webapp:7.21.0

Hello my friend!

Is there anything described in your log?

Didn’t receive a Mismatching Correlation Exception?

Was your instance inside this subprocess where is the error boundary event?

William Robert Alves

Nothing in the log attached the method where I’m throwing the BpmnError:

@Service
public class MessageListener
{
private ProcessEngine camunda;

public MessageListener(ProcessEngine camunda)
{
	this.camunda = camunda;
}

@Bean
Consumer<Message<Object>> onMessageReceived()
{
return message -> {
	if(message.getErrorDetails().getErrorCode() != null)
	{
		throw new BpmnError("1", "MAIN_FLOW_BUSINESS_ERROR");
	}
	else
	{
		objectMapper = new ObjectMapper();
		long correlatingInstances = camunda.getRuntimeService().createExecutionQuery() //
			.messageEventSubscriptionName(message.getMetadata().getType()) //
			.processInstanceBusinessKey(message.getMetadata().getId()) //
			.count();

		if(correlatingInstances == 1)
		{
		try
		{
			camunda.getRuntimeService()//
				.createMessageCorrelation(message.getMetadata().getType())
				.processInstanceBusinessKey(message.getMetadata().getId())//
				.correlateWithResult();
		}
		catch(JsonProcessingException e)
		{
			LOGGER.error("JsonProcessingException :", e.toString());
			return;
		}
		}

	}
};
}

}

I suggest adding some more logs for us to check, or debugging your code to check for possible problems.

Maybe in your bpmnError block, you could add a log there to inform that you are calling your bpmnError.

William Robert Alves

The class should implement any of the Camunda classes in order to be able to Throw org.camunda.bpm.engine.delegate.BpmnError? since when throwing the BpmnError it’s throwing “error occurred in message handler” related to spring framework, however throwing the org.camunda.bpm.engine.delegate.BpmnError in a class that implements JavaDelegate, the process will work successfully.

Can you show the rest of your model?
Is it possible that there’s no wait sate within the sub process that throws the error?

the issue is how Throwing BPMN errors from a Message listeners? is there any code template? to do so.

Can yous share more about the code you’re using to throw the error and the process?

@Service
public class MessageListener
{
private ProcessEngine camunda;

public MessageListener(ProcessEngine camunda)
{
	this.camunda = camunda;
}

@Bean
Consumer<Message<Object>> onMessageReceived()
{
return message -> {
	if(message.getErrorDetails().getErrorCode() != null)
	{
		throw new BpmnError("1", "MAIN_FLOW_BUSINESS_ERROR");
	}
	else
	{
		objectMapper = new ObjectMapper();
		long correlatingInstances = camunda.getRuntimeService().createExecutionQuery() //
			.messageEventSubscriptionName(message.getMetadata().getType()) //
			.processInstanceBusinessKey(message.getMetadata().getId()) //
			.count();

		if(correlatingInstances == 1)
		{
		try
		{
			camunda.getRuntimeService()//
				.createMessageCorrelation(message.getMetadata().getType())
				.processInstanceBusinessKey(message.getMetadata().getId())//
				.correlateWithResult();
		}
		catch(JsonProcessingException e)
		{
			LOGGER.error("JsonProcessingException :", e.toString());
			return;
		}
		}

	}
};
}

}

I’m not using wait state in the Sub process. is it mandatory and what is the purpose link to the issue resolution?

If there’s no wait state the listening error event may not be committed to the database to be picked up. when the error throw is activated.
I’d suggest adding a wait state at the beginning of the sub process and seeing how that affects the error

Please can you share an example of adding a wait state at the beginning of a sub-proces?

And can you confirm for me that I can throw new org.camunda.bpm.engine.delegate.BpmnError inside a class that don’t implements Java Delegate?

the below is correct?

image

Try ticking the async before ticket box on the start event in the sub process. This will create a transaction boundary. More details can be found here.

1 Like

you mean to configure the below? is it correct?

still same issue? any other solutions?

Hello my friend!

The ascyn before must be placed within the SUBPROCESS start event. Exactly where I marked with the red arrows.

William Robert Alves

Hello @Niall and @WilliamR.Alves

Still the same I’m getting the below exception:

org.springframework.messaging.MessageHandlingException: error occurred in message handler …

In the Camunda 7 documentation; it’s mentioned that throwing BPMN error in listeners invoked outside of the normal flow (in my case message listener) will not be caught.

Please advice if this is the case and if yes can you provide a workaround?

Ref: Delegation Code | docs.camunda.org

Thanks for your support.

Best Regards

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.