Skip to content

Commit 594c22a

Browse files
committed
GH-181 - Create dedicated submodule for examples.
Move already existing example underneath that. Added examples for JDBC- and MongoDB-based event publication registry setups.
1 parent 94093a3 commit 594c22a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+897
-61
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ limitations under the License.
9999

100100
<modules>
101101
<module>spring-modulith-integration-test</module>
102-
<module>spring-modulith-example</module>
102+
<module>spring-modulith-examples</module>
103103
</modules>
104104

105105
</profile>
@@ -132,7 +132,7 @@ limitations under the License.
132132

133133
<modules>
134134
<module>spring-modulith-distribution</module>
135-
<module>spring-modulith-example</module>
135+
<module>spring-modulith-examples</module>
136136
<module>spring-modulith-integration-test</module>
137137
</modules>
138138

Lines changed: 29 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2-
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
32
<modelVersion>4.0.0</modelVersion>
43

54
<parent>
65
<groupId>org.springframework.boot</groupId>
76
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>3.0.3</version>
7+
<version>3.1.0-RC1</version>
98
<relativePath />
109
</parent>
1110

12-
<artifactId>spring-modulith-example</artifactId>
13-
<name>Spring Modulith - Example</name>
11+
<groupId>org.springframework.experimental</groupId>
12+
<artifactId>spring-modulith-examples</artifactId>
1413
<version>0.6.0-SNAPSHOT</version>
14+
<packaging>pom</packaging>
15+
16+
<name>Spring Modulith - Examples</name>
17+
18+
<modules>
19+
<module>spring-modulith-examples-epr-jdbc</module>
20+
<module>spring-modulith-examples-epr-mongodb</module>
21+
<module>spring-modulith-examples-full</module>
22+
</modules>
1523

1624
<properties>
1725
<java.version>17</java.version>
@@ -29,7 +37,7 @@
2937
<dependency>
3038
<groupId>org.jmolecules</groupId>
3139
<artifactId>jmolecules-bom</artifactId>
32-
<version>2022.2.2</version>
40+
<version>2022.3.0</version>
3341
<type>pom</type>
3442
<scope>import</scope>
3543
</dependency>
@@ -48,53 +56,6 @@
4856
<artifactId>spring-boot-starter-json</artifactId>
4957
</dependency>
5058

51-
<dependency>
52-
<groupId>org.springframework.experimental</groupId>
53-
<artifactId>spring-modulith-starter-jpa</artifactId>
54-
</dependency>
55-
56-
<dependency>
57-
<groupId>org.springframework.boot</groupId>
58-
<artifactId>spring-boot-starter-web</artifactId>
59-
</dependency>
60-
61-
<!-- Actuator -->
62-
63-
<dependency>
64-
<groupId>org.springframework.boot</groupId>
65-
<artifactId>spring-boot-starter-actuator</artifactId>
66-
</dependency>
67-
68-
<dependency>
69-
<groupId>org.springframework.experimental</groupId>
70-
<artifactId>spring-modulith-actuator</artifactId>
71-
</dependency>
72-
73-
<!-- jMolecules -->
74-
75-
<dependency>
76-
<groupId>org.jmolecules</groupId>
77-
<artifactId>jmolecules-ddd</artifactId>
78-
</dependency>
79-
80-
<dependency>
81-
<groupId>org.jmolecules</groupId>
82-
<artifactId>jmolecules-events</artifactId>
83-
</dependency>
84-
85-
<!-- Persistence -->
86-
87-
<dependency>
88-
<groupId>org.springframework.boot</groupId>
89-
<artifactId>spring-boot-starter-data-jpa</artifactId>
90-
</dependency>
91-
92-
<dependency>
93-
<groupId>com.h2database</groupId>
94-
<artifactId>h2</artifactId>
95-
<scope>runtime</scope>
96-
</dependency>
97-
9859
<!-- Testing -->
9960

10061
<dependency>
@@ -111,12 +72,6 @@
11172

11273
<!-- Infrastructure -->
11374

114-
<dependency>
115-
<groupId>org.springframework.boot</groupId>
116-
<artifactId>spring-boot-configuration-processor</artifactId>
117-
<optional>true</optional>
118-
</dependency>
119-
12075
<dependency>
12176
<groupId>org.projectlombok</groupId>
12277
<artifactId>lombok</artifactId>
@@ -126,6 +81,13 @@
12681
</dependencies>
12782

12883
<repositories>
84+
<repository>
85+
<id>spring-milestone</id>
86+
<url>https://repo.spring.io/milestone</url>
87+
<snapshots>
88+
<enabled>false</enabled>
89+
</snapshots>
90+
</repository>
12991
<repository>
13092
<id>spring-snapshot</id>
13193
<url>https://repo.spring.io/snapshot</url>
@@ -136,6 +98,13 @@
13698
</repositories>
13799

138100
<pluginRepositories>
101+
<pluginRepository>
102+
<id>spring-milestone</id>
103+
<url>https://repo.spring.io/milestone</url>
104+
<snapshots>
105+
<enabled>false</enabled>
106+
</snapshots>
107+
</pluginRepository>
139108
<pluginRepository>
140109
<id>spring-snapshot</id>
141110
<url>https://repo.spring.io/snapshot</url>
@@ -144,4 +113,5 @@
144113
</releases>
145114
</pluginRepository>
146115
</pluginRepositories>
116+
147117
</project>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.springframework.experimental</groupId>
7+
<artifactId>spring-modulith-examples</artifactId>
8+
<version>0.6.0-SNAPSHOT</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
12+
<artifactId>spring-modulith-examples-epr-jdbc</artifactId>
13+
<name>Spring Modulith - Examples - EPR JDBC Example</name>
14+
15+
<dependencies>
16+
17+
<dependency>
18+
<groupId>org.springframework.experimental</groupId>
19+
<artifactId>spring-modulith-starter-jdbc</artifactId>
20+
</dependency>
21+
22+
<!-- jMolecules -->
23+
24+
<dependency>
25+
<groupId>org.jmolecules</groupId>
26+
<artifactId>jmolecules-events</artifactId>
27+
</dependency>
28+
29+
<!-- Persistence -->
30+
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-data-jdbc</artifactId>
34+
</dependency>
35+
36+
<dependency>
37+
<groupId>org.testcontainers</groupId>
38+
<artifactId>junit-jupiter</artifactId>
39+
<scope>test</scope>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>org.postgresql</groupId>
44+
<artifactId>postgresql</artifactId>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>org.testcontainers</groupId>
49+
<artifactId>postgresql</artifactId>
50+
<scope>test</scope>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>org.springframework.boot</groupId>
55+
<artifactId>spring-boot-testcontainers</artifactId>
56+
<scope>test</scope>
57+
</dependency>
58+
59+
</dependencies>
60+
61+
</project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2022-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package example;
17+
18+
import org.springframework.boot.autoconfigure.SpringBootApplication;
19+
20+
/**
21+
* Spring Modulith example application
22+
*
23+
* @author Oliver Drotbohm
24+
*/
25+
@SpringBootApplication
26+
public class Application {
27+
28+
public static void main(String... args) throws Exception {}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2022-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package example.inventory;
17+
18+
import example.order.OrderCompleted;
19+
import lombok.RequiredArgsConstructor;
20+
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
23+
import org.springframework.context.ApplicationEventPublisher;
24+
import org.springframework.modulith.ApplicationModuleListener;
25+
import org.springframework.stereotype.Service;
26+
27+
/**
28+
* A Spring {@link Service} exposed by the inventory module.
29+
*
30+
* @author Oliver Drotbohm
31+
*/
32+
@Service
33+
@RequiredArgsConstructor
34+
class InventoryManagement {
35+
36+
private static final Logger LOG = LoggerFactory.getLogger(InventoryManagement.class);
37+
38+
private final ApplicationEventPublisher events;
39+
40+
@ApplicationModuleListener
41+
void on(OrderCompleted event) throws InterruptedException {
42+
43+
var orderId = event.orderId();
44+
45+
LOG.info("Received order completion for {}.", orderId);
46+
47+
// Simulate busy work
48+
Thread.sleep(1000);
49+
events.publishEvent(new InventoryUpdated(orderId));
50+
51+
LOG.info("Finished order completion for {}.", orderId);
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package example.inventory;
17+
18+
import java.util.UUID;
19+
20+
/**
21+
* @author Oliver Drotbohm
22+
*/
23+
public record InventoryUpdated(UUID orderId) {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2022-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package example.order;
17+
18+
import java.util.UUID;
19+
20+
import org.jmolecules.event.types.DomainEvent;
21+
22+
/**
23+
* @author Oliver Drotbohm
24+
*/
25+
public record OrderCompleted(UUID orderId) implements DomainEvent {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2022-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package example.order;
17+
18+
import lombok.NonNull;
19+
import lombok.RequiredArgsConstructor;
20+
21+
import java.util.UUID;
22+
23+
import org.springframework.context.ApplicationEventPublisher;
24+
import org.springframework.stereotype.Service;
25+
import org.springframework.transaction.annotation.Transactional;
26+
27+
/**
28+
* @author Oliver Drotbohm
29+
*/
30+
@Service
31+
@RequiredArgsConstructor
32+
public class OrderManagement {
33+
34+
private final @NonNull ApplicationEventPublisher events;
35+
36+
@Transactional
37+
public void complete() {
38+
events.publishEvent(new OrderCompleted(UUID.randomUUID()));
39+
}
40+
}

0 commit comments

Comments
 (0)