Skip to content

Commit

Permalink
Replaced TransactionTemplate by EventuateTransactionTemplate in Trans…
Browse files Browse the repository at this point in the history
…actionalNoopDuplicateMessageDetector. See eventuate-tram/eventuate-tram-core-quarkus#7
  • Loading branch information
dartartem committed Feb 24, 2021
1 parent a6df659 commit bddf3e4
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package io.eventuate.tram.consumer.jdbc;

import io.eventuate.common.jdbc.EventuateTransactionTemplate;
import io.eventuate.tram.consumer.common.DuplicateMessageDetector;
import io.eventuate.tram.consumer.common.SubscriberIdAndMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.support.TransactionTemplate;

public class TransactionalNoopDuplicateMessageDetector implements DuplicateMessageDetector {

private Logger logger = LoggerFactory.getLogger(getClass());

private TransactionTemplate transactionTemplate;
private EventuateTransactionTemplate transactionTemplate;

public TransactionalNoopDuplicateMessageDetector(TransactionTemplate transactionTemplate) {
public TransactionalNoopDuplicateMessageDetector(EventuateTransactionTemplate transactionTemplate) {
this.transactionTemplate = transactionTemplate;
}

Expand All @@ -23,16 +23,14 @@ public boolean isDuplicate(String consumerId, String messageId) {

@Override
public void doWithMessage(SubscriberIdAndMessage subscriberIdAndMessage, Runnable callback) {
transactionTemplate.execute(ts -> {
transactionTemplate.executeInTransaction(() -> {
try {
callback.run();
return null;
} catch (Throwable e) {
logger.error("Got exception - marking for rollback only", e);
ts.setRollbackOnly();
throw e;
}
});

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.eventuate.tram.micronaut.consumer.jdbc;

import io.eventuate.common.jdbc.EventuateTransactionTemplate;
import io.eventuate.tram.consumer.common.DuplicateMessageDetector;
import io.eventuate.tram.consumer.jdbc.TransactionalNoopDuplicateMessageDetector;
import io.micronaut.context.annotation.Factory;
Expand All @@ -13,7 +14,7 @@ public class TransactionalNoopDuplicateMessageDetectorFactory {

@Singleton
@Requires(property = "transactional.noop.duplicate.message.detector.factory.enabled")
public DuplicateMessageDetector duplicateMessageDetector(TransactionTemplate transactionTemplate) {
return new TransactionalNoopDuplicateMessageDetector(transactionTemplate);
public DuplicateMessageDetector duplicateMessageDetector(EventuateTransactionTemplate eventuateTransactionTemplate) {
return new TransactionalNoopDuplicateMessageDetector(eventuateTransactionTemplate);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.eventuate.tram.spring.cloudsleuthintegration.test;

import io.eventuate.common.common.spring.jdbc.EventuateSpringTransactionTemplate;
import io.eventuate.common.jdbc.EventuateTransactionTemplate;
import io.eventuate.tram.spring.inmemory.TramInMemoryConfiguration;
import io.eventuate.util.test.async.Eventually;
import org.junit.Test;
Expand All @@ -17,6 +19,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.web.client.RestTemplate;

import java.util.List;
Expand All @@ -41,6 +44,11 @@ public RestTemplate restTemplate() {
return new RestTemplate();
}

@Bean
public EventuateTransactionTemplate eventuateTransactionTemplate(TransactionTemplate transactionTemplate) {
return new EventuateSpringTransactionTemplate(transactionTemplate);
}

}

@Value("${spring.zipkin.baseUrl}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package io.eventuate.tram.spring.consumer.jdbc;

import io.eventuate.common.jdbc.EventuateTransactionTemplate;
import io.eventuate.common.spring.jdbc.EventuateCommonJdbcOperationsConfiguration;
import io.eventuate.tram.consumer.common.DuplicateMessageDetector;
import io.eventuate.tram.consumer.jdbc.TransactionalNoopDuplicateMessageDetector;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.transaction.support.TransactionTemplate;

@Configuration
public class TransactionalNoopDuplicateMessageDetectorConfiguration {

@Bean
public DuplicateMessageDetector duplicateMessageDetector(TransactionTemplate transactionTemplate) {
return new TransactionalNoopDuplicateMessageDetector(transactionTemplate);
public DuplicateMessageDetector duplicateMessageDetector(EventuateTransactionTemplate eventuateTransactionTemplate) {
return new TransactionalNoopDuplicateMessageDetector(eventuateTransactionTemplate);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.eventuate.tram.spring.inmemory;

import io.eventuate.common.common.spring.jdbc.EventuateSpringTransactionTemplate;
import io.eventuate.common.jdbc.EventuateTransactionTemplate;
import io.eventuate.tram.messaging.consumer.MessageConsumer;
import io.eventuate.tram.messaging.producer.MessageProducer;
import io.eventuate.tram.inmemory.test.AbstractInMemoryMessageProducerTest;
Expand All @@ -9,6 +11,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringRunner;
Expand All @@ -23,6 +26,10 @@ public class InMemoryMessageProducerTest extends AbstractInMemoryMessageProducer
@EnableAutoConfiguration
@Import({TramInMemoryConfiguration.class})
public static class InMemoryMessagingTestConfiguration {
@Bean
public EventuateTransactionTemplate eventuateTransactionTemplate(TransactionTemplate transactionTemplate) {
return new EventuateSpringTransactionTemplate(transactionTemplate);
}
}

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.eventuate.tram.testing;

import io.eventuate.common.common.spring.jdbc.EventuateSpringTransactionTemplate;
import io.eventuate.common.jdbc.EventuateTransactionTemplate;
import io.eventuate.tram.commands.common.Command;
import io.eventuate.tram.commands.producer.CommandProducer;
import io.eventuate.tram.spring.commands.producer.TramCommandProducerConfiguration;
Expand All @@ -17,6 +19,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.support.TransactionTemplate;

import java.util.Collections;
import java.util.Set;
Expand All @@ -39,6 +42,11 @@ public static class MessageTrackerTestConfiguration {
public MessageTracker messageTracker(MessageConsumer messageConsumer) {
return new MessageTracker(channels, messageConsumer);
}

@Bean
public EventuateTransactionTemplate eventuateTransactionTemplate(TransactionTemplate transactionTemplate) {
return new EventuateSpringTransactionTemplate(transactionTemplate);
}
}

@Autowired
Expand Down

0 comments on commit bddf3e4

Please sign in to comment.