From 34a82ec84f18b63bad0704a6e318eded6f6c40c2 Mon Sep 17 00:00:00 2001 From: Igor Petrov <108870003+igpetrov@users.noreply.github.com> Date: Fri, 6 Oct 2023 18:01:55 +0300 Subject: [PATCH] chore(correlation): fixed correct message ID fetching (#1233) --- .../InboundCorrelationHandler.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/connector-runtime/connector-runtime-core/src/main/java/io/camunda/connector/runtime/core/inbound/correlation/InboundCorrelationHandler.java b/connector-runtime/connector-runtime-core/src/main/java/io/camunda/connector/runtime/core/inbound/correlation/InboundCorrelationHandler.java index e6a7cd53bd..d0b67cb54c 100644 --- a/connector-runtime/connector-runtime-core/src/main/java/io/camunda/connector/runtime/core/inbound/correlation/InboundCorrelationHandler.java +++ b/connector-runtime/connector-runtime-core/src/main/java/io/camunda/connector/runtime/core/inbound/correlation/InboundCorrelationHandler.java @@ -52,7 +52,7 @@ public InboundCorrelationHandler(ZeebeClient zeebeClient, FeelEngineWrapper feel public CorrelationResult correlate( InboundConnectorDefinitionImpl definition, Object variables) { - return correlate(definition, variables, UUID.randomUUID().toString()); + return correlate(definition, variables, null); } public CorrelationResult correlate( @@ -69,7 +69,7 @@ public CorrelationResult correlate( msgCorPoint.messageName(), msgCorPoint.correlationKeyExpression(), variables, - messageId); + resolveMessageId(msgCorPoint.messageIdExpression(), messageId, variables)); } if (correlationPoint instanceof MessageStartEventCorrelationPoint msgStartCorPoint) { return triggerMessageStartEvent(definition, msgStartCorPoint, variables); @@ -80,7 +80,8 @@ public CorrelationResult correlate( boundaryEventCorrelationPoint.messageName(), boundaryEventCorrelationPoint.correlationKeyExpression(), variables, - boundaryEventCorrelationPoint.messageIdExpression()); + resolveMessageId( + boundaryEventCorrelationPoint.messageIdExpression(), messageId, variables)); } throw new ConnectorException( "Process correlation point " @@ -137,7 +138,7 @@ protected CorrelationResult triggerMessageStartEvent( new CorrelationErrorData(CorrelationErrorReason.ACTIVATION_CONDITION_NOT_MET)); } - String messageId = extractMessageKey(correlationPoint, variables); + String messageId = extractMessageId(correlationPoint.messageIdExpression(), variables); if (correlationPoint.messageIdExpression() != null && !correlationPoint.messageIdExpression().isBlank() && messageId == null) { @@ -258,8 +259,7 @@ protected String extractCorrelationKey(String correlationKeyExpression, Object c } } - protected String extractMessageKey(MessageStartEventCorrelationPoint point, Object context) { - final String messageIdExpression = point.messageIdExpression(); + protected String extractMessageId(String messageIdExpression, Object context) { if (messageIdExpression == null || messageIdExpression.isBlank()) { return ""; } @@ -275,4 +275,15 @@ protected Object extractVariables( return ConnectorHelper.createOutputVariables( rawVariables, definition.resultVariable(), definition.resultExpression()); } + + private String resolveMessageId(String messageId, String messageIdExpression, Object context) { + if (messageId == null) { + if (messageIdExpression != null) { + return extractMessageId(messageIdExpression, context); + } else { + return UUID.randomUUID().toString(); + } + } + return messageId; + } }