Skip to content

Commit

Permalink
[Fix_#3337] Avoid creating duplicate consumer (apache#3357)
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado authored and rgdoliveira committed Jan 25, 2024
1 parent 43e4d0d commit e8dfa15
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.kie.kogito.codegen.core.AbstractGenerator;
import org.kie.kogito.codegen.core.DashboardGeneratedFileUtils;
import org.kie.kogito.codegen.process.config.ProcessConfigGenerator;
import org.kie.kogito.codegen.process.events.ProcessCloudEventMeta;
import org.kie.kogito.codegen.process.events.ProcessCloudEventMetaFactoryGenerator;
import org.kie.kogito.internal.SupportedExtensions;
import org.kie.kogito.internal.process.runtime.KogitoWorkflowProcess;
Expand Down Expand Up @@ -279,7 +280,7 @@ protected Collection<GeneratedFile> internalGenerate() {
List<ProcessInstanceGenerator> pis = new ArrayList<>();
List<ProcessExecutableModelGenerator> processExecutableModelGenerators = new ArrayList<>();
List<ProcessResourceGenerator> rgs = new ArrayList<>(); // REST resources
List<MessageConsumerGenerator> megs = new ArrayList<>(); // message endpoints/consumers
Map<ProcessCloudEventMeta, MessageConsumerGenerator> megs = new HashMap<>(); // message endpoints/consumers
List<MessageProducerGenerator> mpgs = new ArrayList<>(); // message producers

Map<String, ModelClassGenerator> processIdToModelGenerator = new HashMap<>();
Expand Down Expand Up @@ -372,14 +373,14 @@ protected Collection<GeneratedFile> internalGenerate() {

// generate message consumers for processes with message start events
if (trigger.getType().equals(TriggerMetaData.TriggerType.ConsumeMessage)) {
MessageConsumerGenerator messageConsumerGenerator = new MessageConsumerGenerator(
context(),
workFlowProcess,
modelClassGenerator.className(),
execModelGen.className(),
applicationCanonicalName(),
trigger);
megs.add(messageConsumerGenerator);
MessageConsumerGenerator messageConsumerGenerator =
megs.computeIfAbsent(new ProcessCloudEventMeta(workFlowProcess.getId(), trigger), k -> new MessageConsumerGenerator(
context(),
workFlowProcess,
modelClassGenerator.className(),
execModelGen.className(),
applicationCanonicalName(),
trigger));
metaData.addConsumer(trigger.getName(), messageConsumerGenerator.compilationUnit());
} else if (trigger.getType().equals(TriggerMetaData.TriggerType.ProduceMessage)) {
MessageProducerGenerator messageProducerGenerator = new MessageProducerGenerator(
Expand Down Expand Up @@ -441,7 +442,7 @@ protected Collection<GeneratedFile> internalGenerate() {
}
}

for (MessageConsumerGenerator messageConsumerGenerator : megs) {
for (MessageConsumerGenerator messageConsumerGenerator : megs.values()) {
storeFile(MESSAGE_CONSUMER_TYPE, messageConsumerGenerator.generatedFilePath(),
messageConsumerGenerator.generate());
}
Expand Down

0 comments on commit e8dfa15

Please sign in to comment.