-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[incubator-kie-issues#1457] Allow grouping of events #3654
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f90bc99
[Fix apache/incubator-kie-issues#1457] Allow grouping of events
fjtirado c818ec0
Add test for coverage
gmunozfe c7a64ff
[Fix apache/incubator-kie-issues#1457] Grouping of event serialization
fjtirado bb37d76
[Fix apache/incubator-kie-issues#1457] Adding default constructor
fjtirado b8be950
[Fix apache/incubator-kie-issues#1457] Adding TYPE constant
fjtirado File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...nts-core/src/main/java/org/kie/kogito/event/process/MultipleProcessInstanceDataEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.kie.kogito.event.process; | ||
|
||
import java.net.URI; | ||
import java.util.Collection; | ||
|
||
public class MultipleProcessInstanceDataEvent extends ProcessInstanceDataEvent<Collection<ProcessInstanceDataEvent<?>>> { | ||
|
||
public static final String TYPE = "MultipleProcessInstanceDataEvent"; | ||
|
||
public MultipleProcessInstanceDataEvent() { | ||
} | ||
|
||
public MultipleProcessInstanceDataEvent(URI source, Collection<ProcessInstanceDataEvent<?>> body) { | ||
super(TYPE, source, body); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...s-core/src/main/java/org/kie/kogito/event/usertask/MultipleUserTaskInstanceDataEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.kie.kogito.event.usertask; | ||
|
||
import java.net.URI; | ||
import java.util.Collection; | ||
|
||
public class MultipleUserTaskInstanceDataEvent extends UserTaskInstanceDataEvent<Collection<UserTaskInstanceDataEvent<?>>> { | ||
|
||
public static final String TYPE = "MultipleUserTaskInstanceDataEvent"; | ||
|
||
public MultipleUserTaskInstanceDataEvent() { | ||
} | ||
|
||
public MultipleUserTaskInstanceDataEvent(URI source, Collection<UserTaskInstanceDataEvent<?>> body) { | ||
super(TYPE, source, body); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 188 additions & 0 deletions
188
.../runtime/src/main/java/org/kie/kogito/events/process/AbstractMessagingEventPublisher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.kie.kogito.events.process; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CompletionStage; | ||
import java.util.function.Consumer; | ||
|
||
import org.eclipse.microprofile.reactive.messaging.Channel; | ||
import org.eclipse.microprofile.reactive.messaging.Message; | ||
import org.eclipse.microprofile.reactive.messaging.OnOverflow; | ||
import org.eclipse.microprofile.reactive.messaging.OnOverflow.Strategy; | ||
import org.kie.kogito.addon.quarkus.common.reactive.messaging.MessageDecoratorProvider; | ||
import org.kie.kogito.event.DataEvent; | ||
import org.kie.kogito.event.EventPublisher; | ||
import org.kie.kogito.events.config.EventsRuntimeConfig; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import io.smallrye.reactive.messaging.MutinyEmitter; | ||
import io.smallrye.reactive.messaging.providers.locals.ContextAwareMessage; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import jakarta.enterprise.inject.Instance; | ||
import jakarta.inject.Inject; | ||
|
||
public abstract class AbstractMessagingEventPublisher implements EventPublisher { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(AbstractMessagingEventPublisher.class); | ||
|
||
@Inject | ||
ObjectMapper json; | ||
|
||
@Inject | ||
@Channel(PROCESS_INSTANCES_TOPIC_NAME) | ||
@OnOverflow(Strategy.UNBOUNDED_BUFFER) | ||
MutinyEmitter<String> processInstancesEventsEmitter; | ||
private AbstractMessageEmitter processInstanceConsumer; | ||
|
||
@Inject | ||
@Channel(PROCESS_DEFINITIONS_TOPIC_NAME) | ||
MutinyEmitter<String> processDefinitionEventsEmitter; | ||
private AbstractMessageEmitter processDefinitionConsumer; | ||
|
||
@Inject | ||
@Channel(USER_TASK_INSTANCES_TOPIC_NAME) | ||
MutinyEmitter<String> userTasksEventsEmitter; | ||
private AbstractMessageEmitter userTaskConsumer; | ||
@Inject | ||
EventsRuntimeConfig eventsRuntimeConfig; | ||
|
||
@Inject | ||
Instance<MessageDecoratorProvider> decoratorProviderInstance; | ||
|
||
private MessageDecoratorProvider decoratorProvider; | ||
|
||
@PostConstruct | ||
public void init() { | ||
decoratorProvider = decoratorProviderInstance.isResolvable() ? decoratorProviderInstance.get() : null; | ||
processDefinitionConsumer = eventsRuntimeConfig.isProcessInstancesPropagateError() ? new BlockingMessageEmitter(processDefinitionEventsEmitter, PROCESS_DEFINITIONS_TOPIC_NAME) | ||
: new ReactiveMessageEmitter(processDefinitionEventsEmitter, PROCESS_DEFINITIONS_TOPIC_NAME); | ||
processInstanceConsumer = eventsRuntimeConfig.isProcessDefinitionPropagateError() ? new BlockingMessageEmitter(processInstancesEventsEmitter, PROCESS_INSTANCES_TOPIC_NAME) | ||
: new ReactiveMessageEmitter(processInstancesEventsEmitter, PROCESS_INSTANCES_TOPIC_NAME); | ||
userTaskConsumer = eventsRuntimeConfig.isUserTasksPropagateError() ? new BlockingMessageEmitter(userTasksEventsEmitter, USER_TASK_INSTANCES_TOPIC_NAME) | ||
: new ReactiveMessageEmitter(userTasksEventsEmitter, USER_TASK_INSTANCES_TOPIC_NAME); | ||
} | ||
|
||
protected Optional<AbstractMessageEmitter> getConsumer(DataEvent<?> event) { | ||
if (event == null) { | ||
return Optional.empty(); | ||
} | ||
switch (event.getType()) { | ||
case "ProcessDefinitionEvent": | ||
return eventsRuntimeConfig.isProcessDefinitionEventsEnabled() ? Optional.of(processDefinitionConsumer) : Optional.empty(); | ||
|
||
case "ProcessInstanceErrorDataEvent": | ||
case "ProcessInstanceNodeDataEvent": | ||
case "ProcessInstanceSLADataEvent": | ||
case "ProcessInstanceStateDataEvent": | ||
case "ProcessInstanceVariableDataEvent": | ||
return eventsRuntimeConfig.isProcessInstancesEventsEnabled() ? Optional.of(processInstanceConsumer) : Optional.empty(); | ||
|
||
case "UserTaskInstanceAssignmentDataEvent": | ||
case "UserTaskInstanceAttachmentDataEvent": | ||
case "UserTaskInstanceCommentDataEvent": | ||
case "UserTaskInstanceDeadlineDataEvent": | ||
case "UserTaskInstanceStateDataEvent": | ||
case "UserTaskInstanceVariableDataEvent": | ||
return eventsRuntimeConfig.isUserTasksEventsEnabled() ? Optional.of(userTaskConsumer) : Optional.empty(); | ||
|
||
default: | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
@Override | ||
public void publish(Collection<DataEvent<?>> events) { | ||
for (DataEvent<?> event : events) { | ||
publish(event); | ||
} | ||
} | ||
|
||
protected void publishToTopic(AbstractMessageEmitter emitter, Object event) { | ||
logger.debug("About to publish event {} to topic {}", event, emitter.topic); | ||
Message<String> message = null; | ||
try { | ||
String eventString = json.writeValueAsString(event); | ||
logger.debug("Event payload '{}'", eventString); | ||
message = decorateMessage(ContextAwareMessage.of(eventString)); | ||
} catch (Exception e) { | ||
logger.error("Error while creating event to topic {} for event {}", emitter.topic, event); | ||
} | ||
if (message != null) { | ||
emitter.accept(message); | ||
} | ||
} | ||
|
||
protected Message<String> decorateMessage(Message<String> message) { | ||
return decoratorProvider != null ? decoratorProvider.decorate(message) : message; | ||
} | ||
|
||
protected static abstract class AbstractMessageEmitter implements Consumer<Message<String>> { | ||
|
||
protected final String topic; | ||
protected final MutinyEmitter<String> emitter; | ||
|
||
protected AbstractMessageEmitter(MutinyEmitter<String> emitter, String topic) { | ||
this.emitter = emitter; | ||
this.topic = topic; | ||
} | ||
} | ||
|
||
private static class BlockingMessageEmitter extends AbstractMessageEmitter { | ||
protected BlockingMessageEmitter(MutinyEmitter<String> emitter, String topic) { | ||
super(emitter, topic); | ||
} | ||
|
||
@Override | ||
public void accept(Message<String> message) { | ||
emitter.sendMessageAndAwait(message); | ||
logger.debug("Successfully published message {}", message.getPayload()); | ||
} | ||
} | ||
|
||
private static class ReactiveMessageEmitter extends AbstractMessageEmitter { | ||
protected ReactiveMessageEmitter(MutinyEmitter<String> emitter, String topic) { | ||
super(emitter, topic); | ||
} | ||
|
||
@Override | ||
public void accept(Message<String> message) { | ||
emitter.sendMessageAndForget(message | ||
.withAck(() -> onAck(message)) | ||
.withNack(reason -> onNack(reason, message))); | ||
} | ||
|
||
private CompletionStage<Void> onAck(Message<String> message) { | ||
logger.debug("Successfully published message {}", message.getPayload()); | ||
return CompletableFuture.completedFuture(null); | ||
} | ||
|
||
private CompletionStage<Void> onNack(Throwable reason, Message<String> message) { | ||
logger.error("Error while publishing message {}", message, reason); | ||
return CompletableFuture.completedFuture(null); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed to include a fix on connector deserialization