forked from eventuate-tram/eventuate-tram-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eventuate-tram#185 Use Flyway DB eventuate-tram#186 Upgrade to Spring…
… Cloud Contract 3.x
- Loading branch information
Showing
16 changed files
with
230 additions
and
102 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
dependencies { | ||
implementation "org.flywaydb:flyway-core:$flywayVersion" | ||
implementation "org.flywaydb:flyway-mysql:$flywayVersion" | ||
|
||
implementation "org.springframework.boot:spring-boot-starter:$springBootVersion" | ||
implementation "io.eventuate.common:eventuate-common-jdbc:$eventuateCommonVersion" | ||
implementation "io.eventuate.common:eventuate-common-flyway:$eventuateCommonVersion" | ||
} |
14 changes: 14 additions & 0 deletions
14
.../main/java/io/eventuate/tram/spring/flyway/EventuateTramFlywayMigrationConfiguration.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,14 @@ | ||
package io.eventuate.tram.spring.flyway; | ||
|
||
import io.eventuate.common.jdbc.OutboxPartitioningSpec; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class EventuateTramFlywayMigrationConfiguration { | ||
|
||
@Bean | ||
public V1005__MyMigration v1005__myMigration(OutboxPartitioningSpec outboxPartitioningSpec) { | ||
return new V1005__MyMigration(outboxPartitioningSpec); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...uate-tram-spring-flyway/src/main/java/io/eventuate/tram/spring/flyway/ScriptExecutor.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,48 @@ | ||
package io.eventuate.tram.spring.flyway; | ||
|
||
import org.springframework.core.io.DefaultResourceLoader; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.core.io.ResourceLoader; | ||
import org.springframework.util.FileCopyUtils; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
import java.io.UncheckedIOException; | ||
import java.sql.SQLException; | ||
import java.util.Map; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
||
public class ScriptExecutor { | ||
public static String readFileToString(String path) { | ||
ResourceLoader resourceLoader = new DefaultResourceLoader(); | ||
Resource resource = resourceLoader.getResource(path); | ||
try (Reader reader = new InputStreamReader(resource.getInputStream(), UTF_8)) { | ||
return FileCopyUtils.copyToString(reader); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
|
||
public void executeScript(Map<String, String> replacements, String script, SqlExecutor sqlExecutor) { | ||
|
||
String s = readFileToString(script); | ||
|
||
for (Map.Entry<String, String> entry : replacements.entrySet()) | ||
s = s.replace("${" + entry.getKey() + "}", entry.getValue()); | ||
|
||
String[] t = s.split(";"); | ||
|
||
for (String statement : t) { | ||
if (!statement.startsWith("USE ") && statement.trim().length() > 0) { | ||
System.out.println(statement); | ||
try { | ||
sqlExecutor.execute(statement); | ||
} catch (SQLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
eventuate-tram-spring-flyway/src/main/java/io/eventuate/tram/spring/flyway/SqlExecutor.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,7 @@ | ||
package io.eventuate.tram.spring.flyway; | ||
|
||
import java.sql.SQLException; | ||
|
||
interface SqlExecutor { | ||
void execute(String ddl) throws SQLException; | ||
} |
36 changes: 36 additions & 0 deletions
36
...-tram-spring-flyway/src/main/java/io/eventuate/tram/spring/flyway/V1005__MyMigration.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,36 @@ | ||
package io.eventuate.tram.spring.flyway; | ||
|
||
import io.eventuate.common.jdbc.OutboxPartitioningSpec; | ||
import org.flywaydb.core.api.migration.BaseJavaMigration; | ||
import org.flywaydb.core.api.migration.Context; | ||
import org.springframework.boot.jdbc.DatabaseDriver; | ||
|
||
import java.sql.Connection; | ||
import java.util.Collections; | ||
|
||
public class V1005__MyMigration extends BaseJavaMigration { | ||
|
||
private OutboxPartitioningSpec outboxPartitioningSpec; | ||
private ScriptExecutor scriptExecutor; | ||
|
||
public V1005__MyMigration(OutboxPartitioningSpec outboxPartitioningSpec) { | ||
this.outboxPartitioningSpec = outboxPartitioningSpec; | ||
this.scriptExecutor = new ScriptExecutor(); | ||
} | ||
|
||
@Override | ||
public void migrate(Context context) throws Exception { | ||
System.out.println("Hi-flyway"); | ||
|
||
Connection connection = context.getConnection(); | ||
DatabaseDriver driver = DatabaseDriver.fromJdbcUrl(connection.getMetaData().getURL()); | ||
String driverId = driver.getId(); | ||
|
||
SqlExecutor sqlExecutor = statement -> connection.prepareStatement(statement).execute(); | ||
|
||
outboxPartitioningSpec.outboxTableSuffixes().forEach(suffix -> | ||
scriptExecutor.executeScript(Collections.singletonMap("EVENTUATE_OUTBOX_SUFFIX", suffix.suffixAsString), | ||
"flyway-templates/" + driverId + "/3.create-message-table.sql", sqlExecutor)); | ||
} | ||
|
||
} |
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,4 @@ | ||
dependencies { | ||
implementation project(":eventuate-tram-messaging") | ||
implementation "org.springframework.boot:spring-boot-starter:$springBootVersion" | ||
} |
21 changes: 21 additions & 0 deletions
21
...ing-logging/src/main/java/io/eventuate/tram/spring/logging/LoggingMessageInterceptor.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,21 @@ | ||
package io.eventuate.tram.spring.logging; | ||
|
||
import io.eventuate.tram.messaging.common.Message; | ||
import io.eventuate.tram.messaging.common.MessageInterceptor; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class LoggingMessageInterceptor implements MessageInterceptor { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger("io.eventuate.activity"); | ||
|
||
@Override | ||
public void postSend(Message message, Exception e) { | ||
logger.info("Message Sent: {}", message); | ||
} | ||
|
||
@Override | ||
public void preHandle(String subscriberId, Message message) { | ||
logger.info("message received: {} {}", subscriberId, message); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ain/java/io/eventuate/tram/spring/logging/LoggingMessageInterceptorAutoConfiguration.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,13 @@ | ||
package io.eventuate.tram.spring.logging; | ||
|
||
import io.eventuate.tram.messaging.common.MessageInterceptor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class LoggingMessageInterceptorAutoConfiguration { | ||
@Bean | ||
public MessageInterceptor messageLoggingInterceptor() { | ||
return new LoggingMessageInterceptor(); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
eventuate-tram-spring-logging/src/main/resources/META-INF/spring.factories
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,2 @@ | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ | ||
io.eventuate.tram.spring.logging.LoggingMessageInterceptorAutoConfiguration |
28 changes: 5 additions & 23 deletions
28
eventuate-tram-spring-testing-support-cloud-contract/build.gradle
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 |
---|---|---|
@@ -1,28 +1,10 @@ | ||
|
||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
} | ||
dependencies { | ||
classpath "io.spring.gradle:dependency-management-plugin:$springDependencyManagementPluginVersion" | ||
// if using Stub Runner (consumer side) only remove this dependency | ||
classpath "org.springframework.cloud:spring-cloud-contract-gradle-plugin:$springCloudContractDependenciesVersion" | ||
} | ||
} | ||
|
||
apply plugin: "io.spring.dependency-management" | ||
|
||
dependencyManagement { | ||
imports { | ||
mavenBom "org.springframework.cloud:spring-cloud-contract-dependencies:$springCloudContractDependenciesVersion" | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
compile project(":eventuate-tram-messaging") | ||
compile project(":eventuate-tram-commands") | ||
compile "org.springframework.cloud:spring-cloud-starter-contract-verifier:$springCloudContractDependenciesVersion" | ||
compile project(":eventuate-tram-spring-in-memory") | ||
compile "org.springframework.cloud:spring-cloud-starter-contract-stub-runner:$springCloudContractDependenciesVersion" | ||
|
||
compile project(":eventuate-tram-testing-support") | ||
|
||
compile 'org.springframework.cloud:spring-cloud-starter-contract-verifier' | ||
compile "org.springframework.cloud:spring-cloud-starter-contract-stub-runner" | ||
} |
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
Oops, something went wrong.