Skip to content

Commit

Permalink
feat(generator): support inbound deduplication; boolean props; enhanc…
Browse files Browse the repository at this point in the history
…ed conditions (#2310)

* feat(generator): support inbound deduplication; boolean props; enhanced conditions

* adjustments after testing

* add regex validation for dedup id
  • Loading branch information
chillleader committed Apr 16, 2024
1 parent a81816f commit 585116f
Show file tree
Hide file tree
Showing 37 changed files with 831 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** Inbound connector definition implementation that also contains connector properties */
public record InboundConnectorElement(
@JsonIgnore Map<String, String> rawProperties,
ProcessCorrelationPoint correlationPoint,
ProcessElement element) {

private static final Logger LOG = LoggerFactory.getLogger(InboundConnectorElement.class);

public String type() {
return Optional.ofNullable(rawProperties.get(Keywords.INBOUND_TYPE_KEYWORD))
.orElseThrow(
Expand All @@ -60,16 +64,19 @@ public String activationCondition() {
}

public String deduplicationId(List<String> deduplicationProperties) {

LOG.debug("Computing deduplicationId for element {}", element.elementId());
var deduplicationMode = rawProperties.get(Keywords.DEDUPLICATION_MODE_KEYWORD);
if (deduplicationMode == null) {
// legacy deployment, return a deterministic unique id
LOG.debug("Missing deduplicationMode property, using legacy deduplicationId computation");
return element.tenantId() + "-" + element.processDefinitionKey() + "-" + element.elementId();
} else if (DeduplicationMode.AUTO.name().equals(deduplicationMode)) {
// auto mode, compute deduplicationId from properties
LOG.debug("Using deduplicationMode=AUTO, computing deduplicationId from properties");
return computeDeduplicationId(deduplicationProperties);
} else if (DeduplicationMode.MANUAL.name().equals(deduplicationMode)) {
// manual mode, expect deduplicationId property
LOG.debug("Using deduplicationMode=MANUAL, expecting deduplicationId property");
return Optional.ofNullable(rawProperties.get(Keywords.DEDUPLICATION_ID_KEYWORD))
.orElseThrow(
() ->
Expand Down Expand Up @@ -97,7 +104,7 @@ private String computeDeduplicationId(List<String> deduplicationProperties) {
throw new InvalidInboundConnectorDefinitionException(
"Missing deduplication properties, expected at least one property to compute deduplicationId");
}
return String.valueOf(Objects.hash(propsToHash));
return tenantId() + "-" + element.bpmnProcessId() + "-" + Objects.hash(propsToHash);
}

public Map<String, String> rawPropertiesWithoutKeywords() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected CorrelationResult triggerStartEvent(
.send()
.join();

LOG.info("Created a process instance with key" + result.getProcessInstanceKey());
LOG.info("Created a process instance with key {}", result.getProcessInstanceKey());
return new CorrelationResult.Success.ProcessInstanceCreated(
getElementContext(activatedElement),
result.getProcessInstanceKey(),
Expand Down Expand Up @@ -205,7 +205,7 @@ private CorrelationResult publishMessage(
.send()
.join();

LOG.info("Published message with key: " + response.getMessageKey());
LOG.info("Published message with key: {}", response.getMessageKey());
result =
new CorrelationResult.Success.MessagePublished(
getElementContext(activatedElement),
Expand Down Expand Up @@ -233,8 +233,10 @@ protected boolean isActivationConditionMet(InboundConnectorElement definition, O
LOG.debug("No activation condition specified for connector");
return true;
}
LOG.debug("Evaluating activation condition: {}", maybeCondition);
try {
Object shouldActivate = feelEngine.evaluate(maybeCondition, context);
LOG.debug("Activation condition evaluated to: {}", shouldActivate);
return Boolean.TRUE.equals(shouldActivate);
} catch (FeelEngineWrapperException e) {
throw new ConnectorInputException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id" : "io.camunda.connectors.inbound.RabbitMQ.Boundary.v1",
"description" : "Receive a message from RabbitMQ",
"documentationRef" : "https://docs.camunda.io/docs/components/connectors/out-of-the-box-connectors/rabbitmq/?rabbitmq=inbound",
"version" : 6,
"version" : 7,
"category" : {
"id" : "connectors",
"name" : "Connectors"
Expand All @@ -29,6 +29,10 @@
}, {
"id" : "correlation",
"label" : "Correlation"
}, {
"id" : "deduplication",
"label" : "Deduplication",
"tooltip" : "Deduplication allows you to configure multiple inbound connector elements to reuse the same backend (consumer/thread/endpoint) by sharing the same deduplication ID."
}, {
"id" : "output",
"label" : "Output mapping"
Expand Down Expand Up @@ -291,6 +295,66 @@
"type" : "bpmn:Message#property"
},
"type" : "Hidden"
}, {
"id" : "deduplicationModeManualFlag",
"label" : "Manual mode",
"description" : "By default, similar connectors receive the same deduplication ID. Customize by activating manual mode",
"value" : false,
"group" : "deduplication",
"binding" : {
"name" : "deduplicationModeManualFlag",
"type" : "zeebe:property"
},
"type" : "Boolean"
}, {
"id" : "deduplicationId",
"label" : "Deduplication ID",
"constraints" : {
"notEmpty" : true,
"pattern" : {
"value" : "^[a-zA-Z0-9_-]+$",
"message" : "Only alphanumeric characters, dashes, and underscores are allowed"
}
},
"group" : "deduplication",
"binding" : {
"name" : "deduplicationId",
"type" : "zeebe:property"
},
"condition" : {
"property" : "deduplicationModeManualFlag",
"equals" : true,
"type" : "simple"
},
"type" : "String"
}, {
"id" : "deduplicationModeManual",
"value" : "MANUAL",
"group" : "deduplication",
"binding" : {
"name" : "deduplicationMode",
"type" : "zeebe:property"
},
"condition" : {
"property" : "deduplicationId",
"isActive" : true,
"type" : "simple"
},
"type" : "Hidden"
}, {
"id" : "deduplicationModeAuto",
"value" : "AUTO",
"group" : "deduplication",
"binding" : {
"name" : "deduplicationMode",
"type" : "zeebe:property"
},
"condition" : {
"property" : "deduplicationId",
"isActive" : false,
"type" : "simple"
},
"type" : "Hidden"
}, {
"id" : "resultVariable",
"label" : "Result variable",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id" : "io.camunda.connectors.inbound.RabbitMQ.Intermediate.v1",
"description" : "Receive a message from RabbitMQ",
"documentationRef" : "https://docs.camunda.io/docs/components/connectors/out-of-the-box-connectors/rabbitmq/?rabbitmq=inbound",
"version" : 6,
"version" : 7,
"category" : {
"id" : "connectors",
"name" : "Connectors"
Expand All @@ -29,6 +29,10 @@
}, {
"id" : "correlation",
"label" : "Correlation"
}, {
"id" : "deduplication",
"label" : "Deduplication",
"tooltip" : "Deduplication allows you to configure multiple inbound connector elements to reuse the same backend (consumer/thread/endpoint) by sharing the same deduplication ID."
}, {
"id" : "output",
"label" : "Output mapping"
Expand Down Expand Up @@ -291,6 +295,66 @@
"type" : "bpmn:Message#property"
},
"type" : "Hidden"
}, {
"id" : "deduplicationModeManualFlag",
"label" : "Manual mode",
"description" : "By default, similar connectors receive the same deduplication ID. Customize by activating manual mode",
"value" : false,
"group" : "deduplication",
"binding" : {
"name" : "deduplicationModeManualFlag",
"type" : "zeebe:property"
},
"type" : "Boolean"
}, {
"id" : "deduplicationId",
"label" : "Deduplication ID",
"constraints" : {
"notEmpty" : true,
"pattern" : {
"value" : "^[a-zA-Z0-9_-]+$",
"message" : "Only alphanumeric characters, dashes, and underscores are allowed"
}
},
"group" : "deduplication",
"binding" : {
"name" : "deduplicationId",
"type" : "zeebe:property"
},
"condition" : {
"property" : "deduplicationModeManualFlag",
"equals" : true,
"type" : "simple"
},
"type" : "String"
}, {
"id" : "deduplicationModeManual",
"value" : "MANUAL",
"group" : "deduplication",
"binding" : {
"name" : "deduplicationMode",
"type" : "zeebe:property"
},
"condition" : {
"property" : "deduplicationId",
"isActive" : true,
"type" : "simple"
},
"type" : "Hidden"
}, {
"id" : "deduplicationModeAuto",
"value" : "AUTO",
"group" : "deduplication",
"binding" : {
"name" : "deduplicationMode",
"type" : "zeebe:property"
},
"condition" : {
"property" : "deduplicationId",
"isActive" : false,
"type" : "simple"
},
"type" : "Hidden"
}, {
"id" : "resultVariable",
"label" : "Result variable",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id" : "io.camunda.connectors.inbound.RabbitMQ.MessageStart.v1",
"description" : "Receive a message from RabbitMQ",
"documentationRef" : "https://docs.camunda.io/docs/components/connectors/out-of-the-box-connectors/rabbitmq/?rabbitmq=inbound",
"version" : 6,
"version" : 7,
"category" : {
"id" : "connectors",
"name" : "Connectors"
Expand All @@ -29,6 +29,10 @@
}, {
"id" : "correlation",
"label" : "Correlation"
}, {
"id" : "deduplication",
"label" : "Deduplication",
"tooltip" : "Deduplication allows you to configure multiple inbound connector elements to reuse the same backend (consumer/thread/endpoint) by sharing the same deduplication ID."
}, {
"id" : "output",
"label" : "Output mapping"
Expand Down Expand Up @@ -319,6 +323,66 @@
"type" : "bpmn:Message#property"
},
"type" : "Hidden"
}, {
"id" : "deduplicationModeManualFlag",
"label" : "Manual mode",
"description" : "By default, similar connectors receive the same deduplication ID. Customize by activating manual mode",
"value" : false,
"group" : "deduplication",
"binding" : {
"name" : "deduplicationModeManualFlag",
"type" : "zeebe:property"
},
"type" : "Boolean"
}, {
"id" : "deduplicationId",
"label" : "Deduplication ID",
"constraints" : {
"notEmpty" : true,
"pattern" : {
"value" : "^[a-zA-Z0-9_-]+$",
"message" : "Only alphanumeric characters, dashes, and underscores are allowed"
}
},
"group" : "deduplication",
"binding" : {
"name" : "deduplicationId",
"type" : "zeebe:property"
},
"condition" : {
"property" : "deduplicationModeManualFlag",
"equals" : true,
"type" : "simple"
},
"type" : "String"
}, {
"id" : "deduplicationModeManual",
"value" : "MANUAL",
"group" : "deduplication",
"binding" : {
"name" : "deduplicationMode",
"type" : "zeebe:property"
},
"condition" : {
"property" : "deduplicationId",
"isActive" : true,
"type" : "simple"
},
"type" : "Hidden"
}, {
"id" : "deduplicationModeAuto",
"value" : "AUTO",
"group" : "deduplication",
"binding" : {
"name" : "deduplicationMode",
"type" : "zeebe:property"
},
"condition" : {
"property" : "deduplicationId",
"isActive" : false,
"type" : "simple"
},
"type" : "Hidden"
}, {
"id" : "resultVariable",
"label" : "Result variable",
Expand Down
Loading

0 comments on commit 585116f

Please sign in to comment.