Skip to content

Commit

Permalink
eventuate-tram#188 fix auto-configuration loading in Spring Boot 3
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonglau committed Jan 16, 2023
1 parent 12edfbe commit 4e86f96
Show file tree
Hide file tree
Showing 33 changed files with 54 additions and 37 deletions.
1 change: 1 addition & 0 deletions .java-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.8.0.342
3 changes: 1 addition & 2 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ test.enabled=false

repositories {
mavenCentral()
jcenter()
}

dependencies {
compile "com.jayway.restassured:rest-assured:2.9.0"
implementation "io.rest-assured:rest-assured:3.0.0"
}

5 changes: 2 additions & 3 deletions buildSrc/src/main/groovy/WaitForCdc.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import io.restassured.RestAssured;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction;

import java.util.Optional;
import java.util.concurrent.TimeUnit;

import com.jayway.restassured.RestAssured;

public class WaitForCdc extends DefaultTask {

private String getenv(String name, String defaultValue) {
Expand Down Expand Up @@ -54,4 +53,4 @@ public void waitForCdc() {
throw new RuntimeException("CDC failed to start");

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import io.eventuate.tram.messaging.consumer.MessageConsumer;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

Expand All @@ -26,7 +25,6 @@ public MyReplyConsumer(MessageConsumer messageConsumer, String replyChannel) {
this.replyChannel = replyChannel;
}

@PostConstruct
public void subscribe() {
messageConsumer.subscribe(getClass().getName(), singleton(channelMapping.transform(replyChannel)), this::handler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@
TramCommandConsumerConfiguration.class
})
public class TramCommandsDBBrokerIntegrationTestConfiguration {



@Bean
public TramCommandsDBBrokerIntegrationData tramCommandsAndEventsIntegrationData() {
return new TramCommandsDBBrokerIntegrationData();
}

}

@Bean
public ChannelMapping channelMapping(TramCommandsDBBrokerIntegrationData data) {
Expand All @@ -51,14 +49,12 @@ public CommandDispatcher consumerCommandDispatcher(MyTestCommandHandler target,
return commandDispatcherFactory.make("customerCommandDispatcher", target.defineCommandHandlers());
}


@Bean
public MyTestCommandHandler myTestCommandHandler() {
return Mockito.spy(new MyTestCommandHandler());
}


@Bean
@Bean(initMethod = "subscribe")
public MyReplyConsumer myReplyConsumer(MessageConsumer messageConsumer) {
return new MyReplyConsumer(messageConsumer, "ReplyTo");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -43,7 +42,6 @@ public CommandDispatcher(String commandDispatcherId,
this.commandNameMapping = commandNameMapping;
}

@PostConstruct
public void initialize() {
messageConsumer.subscribe(commandDispatcherId,
commandHandlers.getChannels(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public CommandDispatcherFactory(MessageConsumer messageConsumer,

public CommandDispatcher make(String commandDispatcherId,
CommandHandlers commandHandlers) {
return new CommandDispatcher(commandDispatcherId, commandHandlers, messageConsumer, commandNameMapping, commandReplyProducer);
CommandDispatcher commandDispatcher = new CommandDispatcher(commandDispatcherId, commandHandlers, messageConsumer, commandNameMapping, commandReplyProducer);
commandDispatcher.initialize();
return commandDispatcher;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public static InMemoryCommands make(CommandHandlers commandHandlers, InMemoryMes
CommandReplyProducer commandReplyProducer = new CommandReplyProducer(inMemoryMessaging.messageProducer);
CommandDispatcherFactory commandDispatcherFactory = new CommandDispatcherFactory(inMemoryMessaging.messageConsumer, commandNameMapping, commandReplyProducer);
CommandDispatcher commandDispatcher = commandDispatcherFactory.make("subscriberId", commandHandlers);
commandDispatcher.initialize();
return new InMemoryCommands(commandProducer, commandReplyProducer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.PostConstruct;
import java.util.Optional;

public class DomainEventDispatcher {
Expand All @@ -29,7 +28,6 @@ public DomainEventDispatcher(String eventDispatcherId, DomainEventHandlers domai
this.domainEventNameMapping = domainEventNameMapping;
}

@PostConstruct
public void initialize() {
logger.info("Initializing domain event dispatcher");
messageConsumer.subscribe(eventDispatcherId, domainEventHandlers.getAggregateTypesAndEvents(), this::messageHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public DomainEventDispatcherFactory(MessageConsumer messageConsumer, DomainEvent
}

public DomainEventDispatcher make(String eventDispatcherId, DomainEventHandlers domainEventHandlers) {
return new DomainEventDispatcher(eventDispatcherId, domainEventHandlers, messageConsumer, domainEventNameMapping);
DomainEventDispatcher domainEventDispatcher = new DomainEventDispatcher(eventDispatcherId, domainEventHandlers, messageConsumer, domainEventNameMapping);
domainEventDispatcher.initialize();
return domainEventDispatcher;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;

import javax.annotation.PostConstruct;
import java.util.Optional;

import static java.util.Collections.singletonList;
Expand All @@ -38,7 +37,6 @@ public ReactiveCommandDispatcher(String commandDispatcherId,
this.commandReplyProducer = commandReplyProducer;
}

@PostConstruct
public void initialize() {
messageConsumer.subscribe(commandDispatcherId, commandHandlers.getChannels(), this::messageHandler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public ReactiveCommandDispatcherFactory(ReactiveMessageConsumer messageConsumer,

public ReactiveCommandDispatcher make(String commandDispatcherId,
ReactiveCommandHandlers commandHandlers) {
return new ReactiveCommandDispatcher(commandDispatcherId, commandHandlers, messageConsumer, commandReplyProducer);
ReactiveCommandDispatcher reactiveCommandDispatcher = new ReactiveCommandDispatcher(commandDispatcherId, commandHandlers, messageConsumer, commandReplyProducer);
reactiveCommandDispatcher.initialize();
return reactiveCommandDispatcher;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public void init() {
@Test
public void testHandlerInvocation() {
reactiveCommandDispatcher = new ReactiveCommandDispatcher("", commandHandlers, messageConsumer, commandReplyProducer);
reactiveCommandDispatcher.initialize();

when(commandHandler.invokeMethod(any())).thenReturn(Mono.just(replyMessage));

Expand All @@ -80,6 +81,7 @@ protected Publisher<Message> invoke(ReactiveCommandHandler m, CommandMessage cm,
return alternativeCommandHandler.invokeMethod(new CommandHandlerArgs<>(cm, new PathVariables(commandHandlerParams.getPathVars()), commandReplyToken));
}
};
reactiveCommandDispatcher.initialize();

invokeMessageHandler();

Expand All @@ -104,6 +106,7 @@ private Message makeMessage(String replyToChannel) {
@Test
public void shouldDispatchNotification() {
reactiveCommandDispatcher = new ReactiveCommandDispatcher("", commandHandlers, messageConsumer, commandReplyProducer);
reactiveCommandDispatcher.initialize();

when(commandHandler.invokeMethod(any())).thenReturn(Mono.empty());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;

import javax.annotation.PostConstruct;
import java.util.Optional;

public class ReactiveDomainEventDispatcher {
Expand All @@ -36,7 +35,6 @@ public ReactiveDomainEventDispatcher(String eventDispatcherId,
this.domainEventNameMapping = domainEventNameMapping;
}

@PostConstruct
public void initialize() {
logger.info("Initializing reactive domain event dispatcher");
messageConsumer.subscribe(eventDispatcherId, domainEventHandlers.getAggregateTypesAndEvents(), this::messageHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public ReactiveDomainEventDispatcherFactory(ReactiveMessageConsumer messageConsu
}

public ReactiveDomainEventDispatcher make(String eventDispatcherId, ReactiveDomainEventHandlers domainEventHandlers) {
return new ReactiveDomainEventDispatcher(eventDispatcherId, domainEventHandlers, messageConsumer, domainEventNameMapping);
ReactiveDomainEventDispatcher reactiveDomainEventDispatcher = new ReactiveDomainEventDispatcher(eventDispatcherId, domainEventHandlers, messageConsumer, domainEventNameMapping);
reactiveDomainEventDispatcher.initialize();
return reactiveDomainEventDispatcher;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.eventuate.tram.spring.commands.common.TramCommandsCommonAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.eventuate.tram.spring.commands.autoconfigure.EventuateTramCommandsAutoConfigure
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.eventuate.tram.spring.consumer.jdbc.TramConsumerJdbcAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.eventuate.tram.spring.events.common.TramEventsCommonAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.eventuate.tram.spring.events.autoconfigure.TramEventsPublisherAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.eventuate.tram.spring.events.autoconfigure.TramEventsSubscriberAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.eventuate.tram.spring.logging.LoggingMessageInterceptorAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
io.eventuate.tram.spring.messaging.autoconfigure.EventuateTramActiveMQMessageConsumerAutoConfiguration
io.eventuate.tram.spring.messaging.autoconfigure.EventuateTramKafkaMessageConsumerAutoConfiguration
io.eventuate.tram.spring.messaging.autoconfigure.EventuateTramRabbitMQMessageConsumerAutoConfiguration
io.eventuate.tram.spring.messaging.autoconfigure.EventuateTramRedisMessageConsumerAutoConfiguration
io.eventuate.tram.spring.messaging.autoconfigure.TramMessageProducerJdbcAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.eventuate.tram.spring.messaging.common.TramMessagingCommonAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.eventuate.tram.spring.reactive.commands.autoconfigure.EventuateReactiveTramCommandsAutoConfigure
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.eventuate.tram.spring.reactive.consumer.jdbc.ReactiveTramConsumerJdbcAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.eventuate.tram.spring.reactive.events.autoconfigure.ReactiveTramEventsPublisherAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.eventuate.tram.spring.reactive.events.autoconfigure.ReactiveTramEventsSubscriberAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

import io.eventuate.tram.consumer.common.reactive.ReactiveMessageConsumer;
import io.eventuate.tram.events.common.DomainEventNameMapping;
import io.eventuate.tram.events.subscriber.DomainEventDispatcher;
import io.eventuate.tram.events.subscriber.DomainEventDispatcherFactory;
import io.eventuate.tram.events.subscriber.DomainEventHandlers;
import io.eventuate.tram.messaging.consumer.MessageConsumer;
import io.eventuate.tram.reactive.events.subscriber.ReactiveDomainEventDispatcher;
import io.eventuate.tram.reactive.events.subscriber.ReactiveDomainEventDispatcherFactory;
import io.eventuate.tram.reactive.events.subscriber.ReactiveDomainEventHandlers;
Expand All @@ -18,6 +14,8 @@ public SpringReactiveDomainEventDispatcherFactory(ReactiveMessageConsumer messag

@Override
public ReactiveDomainEventDispatcher make(String eventDispatcherId, ReactiveDomainEventHandlers domainEventHandlers) {
return new ReactiveDomainEventDispatcher(eventDispatcherId, domainEventHandlers, messageConsumer, domainEventNameMapping);
ReactiveDomainEventDispatcher reactiveDomainEventDispatcher = new ReactiveDomainEventDispatcher(eventDispatcherId, domainEventHandlers, messageConsumer, domainEventNameMapping);
reactiveDomainEventDispatcher.initialize();
return reactiveDomainEventDispatcher;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
io.eventuate.tram.spring.reactive.messaging.autoconfigure.EventuateTramReactiveKafkaMessageConsumerAutoConfiguration
io.eventuate.tram.spring.reactive.messaging.autoconfigure.ReactiveTramMessageProducerJdbcAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.eventuate.tram.spring.reactive.optimisticlocking.OptimisticLockingDecoratorAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.eventuate.tram.messaging.producer.MessageProducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.contract.spec.Contract;
import org.springframework.cloud.contract.spec.internal.BodyMatcher;
Expand All @@ -19,14 +20,13 @@
import org.springframework.cloud.contract.stubrunner.BatchStubRunner;
import org.springframework.cloud.contract.verifier.util.*;

import javax.annotation.PostConstruct;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class EventuateTramRoutesConfigurer {
public class EventuateTramRoutesConfigurer implements InitializingBean {

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

Expand All @@ -44,7 +44,6 @@ public EventuateTramRoutesConfigurer(BatchStubRunner batchStubRunner) {

private int idCounter;

@PostConstruct
public void initialize() {
for (Collection<Contract> contracts : batchStubRunner.getContracts().values()) {
for (Contract contract : contracts) {
Expand Down Expand Up @@ -152,4 +151,9 @@ private boolean headersMatch(Message message, Contract groovyDsl) {
}
return matches;
}

@Override
public void afterPropertiesSet() {
initialize();
}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ include 'eventuate-tram-micronaut-commands'
include 'eventuate-tram-test-util'
include "eventuate-tram-testing-support"
include "eventuate-tram-spring-testing-support-cloud-contract"
include "eventuate-tram-aggregate-domain-events"
//include "eventuate-tram-aggregate-domain-events"
include 'eventuate-tram-consumer-kafka'
include 'eventuate-tram-reactive-consumer-kafka'
include 'eventuate-tram-spring-consumer-kafka'
Expand Down

0 comments on commit 4e86f96

Please sign in to comment.