Skip to content
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

By doing the validation whether the kafka message was successfully se… #455

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.axonframework.lifecycle.Phase;
import org.axonframework.messaging.EventPublicationFailedException;
import org.axonframework.messaging.unitofwork.CurrentUnitOfWork;
import org.axonframework.messaging.unitofwork.UnitOfWork;
import org.axonframework.monitoring.MessageMonitor;
import org.axonframework.monitoring.MessageMonitor.MonitorCallback;
import org.axonframework.monitoring.NoOpMessageMonitor;
Expand Down Expand Up @@ -137,7 +136,6 @@ public <T extends EventMessage<?>> void send(T event) {
logger.debug("Skip publishing event for [{}] since topicFunction returned empty.", event.getPayloadType());
return;
}
UnitOfWork<?> uow = CurrentUnitOfWork.get();

MonitorCallback monitorCallback = messageMonitor.onMessageIngested(event);
Producer<K, V> producer = producerFactory.createProducer();
Expand All @@ -150,21 +148,20 @@ public <T extends EventMessage<?>> void send(T event) {
// Sends event messages to Kafka and receive a future indicating the status.
Future<RecordMetadata> publishStatus = producer.send(messageConverter.createKafkaMessage(event, topic.get()));

uow.onPrepareCommit(u -> {
if (confirmationMode.isTransactional()) {
tryCommit(producer, monitorCallback);
} else if (confirmationMode.isWaitForAck()) {
waitForPublishAck(publishStatus, monitorCallback);
}
tryClose(producer);
});

uow.onRollback(u -> {
CurrentUnitOfWork.get().onRollback(u -> {
//provides a way to prevent duplicate messages on Kafka, in case there is a problem with the token store
if (confirmationMode.isTransactional()) {
tryRollback(producer);
}
tryClose(producer);
});

if (confirmationMode.isTransactional()) {
tryCommit(producer, monitorCallback);
} else if (confirmationMode.isWaitForAck()) {
waitForPublishAck(publishStatus, monitorCallback);
}
tryClose(producer);
}

private void tryBeginTxn(Producer<?, ?> producer) {
Expand Down