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

#188 fix auto-configuration loading in Spring Boot 3 #189

Merged
merged 2 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ workflows:
- eventuate-gradle-build-and-test/build-and-test:
name: mysql-binlog-kafka
script: ./build-and-test-all-mysql-binlog-kafka.sh
- eventuate-gradle-build-and-test/build-and-test:
name: mysql-binlog-kafka-spring-boot-3
script: ./build-and-test-all-mysql-kafka-spring-boot-3.sh
- eventuate-gradle-build-and-test/build-and-test:
name: mysql-binlog-redis
script: ./build-and-test-all-mysql-binlog-redis.sh
Expand All @@ -21,6 +24,9 @@ workflows:
- eventuate-gradle-build-and-test/build-and-test:
name: mysql-binlog-kafka-dbid
script: TEST_DB_ID=yes ./build-and-test-all-mysql-binlog-kafka.sh
- eventuate-gradle-build-and-test/build-and-test:
name: mysql-binlog-kafka-dbid-spring-boot3
script: TEST_DB_ID=yes ./build-and-test-all-mysql-kafka-spring-boot-3.sh
- eventuate-gradle-build-and-test/build-and-test:
name: mysql-binlog-redis-dbid
script: TEST_DB_ID=yes ./build-and-test-all-mysql-binlog-redis.sh
Expand All @@ -38,10 +44,12 @@ workflows:
- publish
requires:
- mysql-binlog-kafka
- mysql-binlog-kafka-spring-boot-3
- mysql-binlog-redis
- postgres-wal-rabbitmq
- mssql-polling-activemq
- mysql-binlog-kafka-dbid
- mysql-binlog-kafka-dbid-spring-boot3
- mysql-binlog-redis-dbid
- postgres-wal-rabbitmq-dbid
- mssql-polling-activemq-dbid
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ out
.settings
bin
.DS_Store
.java-version
10 changes: 10 additions & 0 deletions build-and-test-all-mysql-kafka-spring-boot-3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! /bin/bash

set -e

export DATABASE=mysql
export MODE=binlog
export BROKER=kafka
export COORDINATOR=zookeeper

./_build-and-test-all.sh -P springBootVersion=3.0.1
10 changes: 7 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ apply plugin: "io.eventuate.plugins.gradle.publish.EventuatePublish"

allprojects {

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenCentral()
maven { url "https://repo.spring.io/milestone" }
Expand All @@ -45,6 +42,13 @@ allprojects {
}
}

subprojects { project ->
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(project.ext.get("springBootVersion").startsWith("3") ? 17 : 8));
}
}
}

gradle.projectsEvaluated {
task aggregateJavaDocs(type: Javadoc) {
Expand Down
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"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't download this anymore

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"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this module is not used anywhere

//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