Skip to content

Commit 433aafe

Browse files
committed
feat: add spring-boot support
Signed-off-by: Eddú Meléndez <eddu.melendez@gmail.com>
1 parent 4784f03 commit 433aafe

File tree

22 files changed

+622
-113
lines changed

22 files changed

+622
-113
lines changed

bom/pom.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,31 @@
8181
<artifactId>cloudevents-spring</artifactId>
8282
<version>${project.version}</version>
8383
</dependency>
84+
<dependency>
85+
<groupId>io.cloudevents</groupId>
86+
<artifactId>cloudevents-spring-boot-autoconfigure</artifactId>
87+
<version>${project.version}</version>
88+
</dependency>
89+
<dependency>
90+
<groupId>io.cloudevents</groupId>
91+
<artifactId>cloudevents-rsocket-spring-boot-starter</artifactId>
92+
<version>${project.version}</version>
93+
</dependency>
94+
<dependency>
95+
<groupId>io.cloudevents</groupId>
96+
<artifactId>cloudevents-spring-boot-starter</artifactId>
97+
<version>${project.version}</version>
98+
</dependency>
99+
<dependency>
100+
<groupId>io.cloudevents</groupId>
101+
<artifactId>cloudevents-web-spring-boot-starter</artifactId>
102+
<version>${project.version}</version>
103+
</dependency>
104+
<dependency>
105+
<groupId>io.cloudevents</groupId>
106+
<artifactId>cloudevents-webflux-spring-boot-starter</artifactId>
107+
<version>${project.version}</version>
108+
</dependency>
84109
<dependency>
85110
<groupId>io.cloudevents</groupId>
86111
<artifactId>io.cloudevents.sql</artifactId>

examples/restful-ws-spring-boot/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mvn spring-boot:run
1111
You can try sending a request using `curl`:
1212

1313
```shell
14-
curl -X POST -v -d '{"username": "slinkydeveloper", "firstName": "Francesco", "lastName": "Guardiani", "age": 23}' \ ~
14+
curl -X POST -v -d '{"username": "slinkydeveloper", "firstName": "Francesco", "lastName": "Guardiani", "age": 23}' \
1515
-H'Content-type: application/json' \
1616
-H'Ce-id: 1' \
1717
-H'Ce-source: cloud-event-example' \

examples/spring-function/pom.xml

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,9 @@
3333
<artifactId>spring-cloud-function-web</artifactId>
3434
<version>3.1.1</version>
3535
</dependency>
36-
<dependency>
37-
<groupId>org.springframework.boot</groupId>
38-
<artifactId>spring-boot-starter-webflux</artifactId>
39-
</dependency>
40-
<dependency>
41-
<groupId>io.cloudevents</groupId>
42-
<artifactId>cloudevents-spring</artifactId>
43-
<version>${project.version}</version>
44-
</dependency>
45-
<dependency>
46-
<groupId>io.cloudevents</groupId>
47-
<artifactId>cloudevents-http-basic</artifactId>
48-
<version>${project.version}</version>
49-
</dependency>
5036
<dependency>
5137
<groupId>io.cloudevents</groupId>
52-
<artifactId>cloudevents-json-jackson</artifactId>
38+
<artifactId>cloudevents-webflux-spring-boot-starter</artifactId>
5339
<version>${project.version}</version>
5440
</dependency>
5541
<dependency>

examples/spring-function/src/main/java/io/cloudevents/examples/spring/DemoApplication.java

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,10 @@
66

77
import org.springframework.boot.SpringApplication;
88
import org.springframework.boot.autoconfigure.SpringBootApplication;
9-
import org.springframework.boot.web.codec.CodecCustomizer;
109
import org.springframework.context.annotation.Bean;
11-
import org.springframework.context.annotation.Configuration;
12-
import org.springframework.http.codec.CodecConfigurer;
1310

1411
import io.cloudevents.CloudEvent;
1512
import io.cloudevents.core.builder.CloudEventBuilder;
16-
import io.cloudevents.spring.messaging.CloudEventMessageConverter;
17-
import io.cloudevents.spring.webflux.CloudEventHttpMessageReader;
18-
import io.cloudevents.spring.webflux.CloudEventHttpMessageWriter;
1913

2014
@SpringBootApplication
2115
public class DemoApplication {
@@ -34,31 +28,4 @@ public Function<CloudEvent, CloudEvent> events() {
3428
.build();
3529
}
3630

37-
/**
38-
* Configure a MessageConverter for Spring Cloud Function to pick up and use to
39-
* convert to and from CloudEvent and Message.
40-
*/
41-
@Configuration
42-
public static class CloudEventMessageConverterConfiguration {
43-
@Bean
44-
public CloudEventMessageConverter cloudEventMessageConverter() {
45-
return new CloudEventMessageConverter();
46-
}
47-
}
48-
49-
/**
50-
* Configure an HTTP reader and writer so that we can process CloudEvents over
51-
* HTTP via Spring Webflux.
52-
*/
53-
@Configuration
54-
public static class CloudEventHandlerConfiguration implements CodecCustomizer {
55-
56-
@Override
57-
public void customize(CodecConfigurer configurer) {
58-
configurer.customCodecs().register(new CloudEventHttpMessageReader());
59-
configurer.customCodecs().register(new CloudEventHttpMessageWriter());
60-
}
61-
62-
}
63-
6431
}

examples/spring-reactive/pom.xml

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,9 @@
2828
</dependencyManagement>
2929

3030
<dependencies>
31-
<dependency>
32-
<groupId>org.springframework.boot</groupId>
33-
<artifactId>spring-boot-starter-webflux</artifactId>
34-
</dependency>
35-
<dependency>
36-
<groupId>io.cloudevents</groupId>
37-
<artifactId>cloudevents-spring</artifactId>
38-
<version>${project.version}</version>
39-
</dependency>
40-
<dependency>
41-
<groupId>io.cloudevents</groupId>
42-
<artifactId>cloudevents-http-basic</artifactId>
43-
<version>${project.version}</version>
44-
</dependency>
4531
<dependency>
4632
<groupId>io.cloudevents</groupId>
47-
<artifactId>cloudevents-json-jackson</artifactId>
33+
<artifactId>cloudevents-webflux-spring-boot-starter</artifactId>
4834
<version>${project.version}</version>
4935
</dependency>
5036
<dependency>
@@ -63,5 +49,5 @@
6349
</plugin>
6450
</plugins>
6551
</build>
66-
52+
6753
</project>

examples/spring-reactive/src/main/java/io/cloudevents/examples/spring/DemoApplication.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,12 @@
66
import io.cloudevents.CloudEvent;
77
import io.cloudevents.core.builder.CloudEventBuilder;
88
import io.cloudevents.spring.http.CloudEventHttpUtils;
9-
import io.cloudevents.spring.webflux.CloudEventHttpMessageReader;
10-
import io.cloudevents.spring.webflux.CloudEventHttpMessageWriter;
119
import reactor.core.publisher.Mono;
1210

1311
import org.springframework.boot.SpringApplication;
1412
import org.springframework.boot.autoconfigure.SpringBootApplication;
15-
import org.springframework.boot.web.codec.CodecCustomizer;
16-
import org.springframework.context.annotation.Configuration;
1713
import org.springframework.http.HttpHeaders;
1814
import org.springframework.http.ResponseEntity;
19-
import org.springframework.http.codec.CodecConfigurer;
2015
import org.springframework.web.bind.annotation.PostMapping;
2116
import org.springframework.web.bind.annotation.RequestBody;
2217
import org.springframework.web.bind.annotation.RequestHeader;
@@ -53,15 +48,4 @@ public Mono<CloudEvent> event(@RequestBody Mono<CloudEvent> body) {
5348
.build());
5449
}
5550

56-
@Configuration
57-
public static class CloudEventHandlerConfiguration implements CodecCustomizer {
58-
59-
@Override
60-
public void customize(CodecConfigurer configurer) {
61-
configurer.customCodecs().register(new CloudEventHttpMessageReader());
62-
configurer.customCodecs().register(new CloudEventHttpMessageWriter());
63-
}
64-
65-
}
66-
67-
}
51+
}

examples/spring-rsocket/pom.xml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,9 @@
2828
</dependencyManagement>
2929

3030
<dependencies>
31-
<dependency>
32-
<groupId>org.springframework.boot</groupId>
33-
<artifactId>spring-boot-starter-rsocket</artifactId>
34-
</dependency>
35-
<dependency>
36-
<groupId>io.cloudevents</groupId>
37-
<artifactId>cloudevents-spring</artifactId>
38-
<version>${project.version}</version>
39-
</dependency>
4031
<dependency>
4132
<groupId>io.cloudevents</groupId>
42-
<artifactId>cloudevents-json-jackson</artifactId>
33+
<artifactId>cloudevents-rsocket-spring-boot-starter</artifactId>
4334
<version>${project.version}</version>
4435
</dependency>
4536
<dependency>
@@ -58,5 +49,5 @@
5849
</plugin>
5950
</plugins>
6051
</build>
61-
52+
6253
</project>

examples/spring-rsocket/src/main/java/io/cloudevents/examples/spring/DemoApplication.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,11 @@
55

66
import io.cloudevents.CloudEvent;
77
import io.cloudevents.core.builder.CloudEventBuilder;
8-
import io.cloudevents.spring.codec.CloudEventDecoder;
9-
import io.cloudevents.spring.codec.CloudEventEncoder;
108
import reactor.core.publisher.Mono;
119

1210
import org.springframework.boot.SpringApplication;
1311
import org.springframework.boot.autoconfigure.SpringBootApplication;
14-
import org.springframework.boot.rsocket.messaging.RSocketStrategiesCustomizer;
15-
import org.springframework.context.annotation.Bean;
16-
import org.springframework.core.annotation.Order;
1712
import org.springframework.messaging.handler.annotation.MessageMapping;
18-
import org.springframework.messaging.rsocket.RSocketStrategies.Builder;
1913
import org.springframework.stereotype.Controller;
2014
import org.springframework.web.bind.annotation.RequestBody;
2115

@@ -38,17 +32,4 @@ public Mono<CloudEvent> event(@RequestBody Mono<CloudEvent> body) {
3832
.build());
3933
}
4034

41-
@Bean
42-
@Order(-1)
43-
public RSocketStrategiesCustomizer cloudEventsCustomizer() {
44-
return new RSocketStrategiesCustomizer() {
45-
@Override
46-
public void customize(Builder strategies) {
47-
strategies.encoder(new CloudEventEncoder());
48-
strategies.decoder(new CloudEventDecoder());
49-
}
50-
};
51-
52-
}
53-
54-
}
35+
}

pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@
7676
<module>http/restful-ws</module>
7777
<module>kafka</module>
7878
<module>spring</module>
79+
<module>spring-boot/autoconfigure</module>
80+
<module>spring-boot/rsocket-starter</module>
81+
<module>spring-boot/starter</module>
82+
<module>spring-boot/web-starter</module>
83+
<module>spring-boot/webflux-starter</module>
7984
<module>sql</module>
8085
<module>bom</module>
8186
</modules>
@@ -92,8 +97,22 @@
9297
<!-- Dependencies -->
9398
<assertj-core.version>3.16.1</assertj-core.version>
9499
<junit-jupiter.version>5.7.0</junit-jupiter.version>
100+
<spring-boot.version>2.5.9</spring-boot.version>
95101
</properties>
96102

103+
<dependencyManagement>
104+
<dependencies>
105+
<dependency>
106+
<groupId>org.springframework.boot</groupId>
107+
<artifactId>spring-boot-dependencies</artifactId>
108+
<version>${spring-boot.version}</version>
109+
<scope>import</scope>
110+
<type>pom</type>
111+
</dependency>
112+
113+
</dependencies>
114+
</dependencyManagement>
115+
97116
<distributionManagement>
98117
<site>
99118
<id>site</id>
@@ -168,6 +187,7 @@
168187
<link>https://qpid.apache.org/releases/qpid-proton-j-0.33.7/api/</link>
169188
<link>https://fasterxml.github.io/jackson-databind/javadoc/2.10/</link>
170189
</links>
190+
<skippedModules>cloudevents-spring-boot-starter</skippedModules>
171191
</configuration>
172192
<executions>
173193
<execution>

spring-boot/autoconfigure/pom.xml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2018-Present The CloudEvents Authors
4+
~ <p>
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~ <p>
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~ <p>
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
~
17+
-->
18+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
22+
<parent>
23+
<groupId>io.cloudevents</groupId>
24+
<artifactId>cloudevents-parent</artifactId>
25+
<version>2.4.0-SNAPSHOT</version>
26+
<relativePath>../../pom.xml</relativePath>
27+
</parent>
28+
29+
<artifactId>cloudevents-spring-boot-autoconfigure</artifactId>
30+
<name>CloudEvents - Spring Boot Autoconfigure</name>
31+
<packaging>jar</packaging>
32+
33+
<properties>
34+
<module-name>io.cloudevents.springboot.autoconfigure</module-name>
35+
</properties>
36+
37+
<dependencies>
38+
39+
<dependency>
40+
<groupId>io.cloudevents</groupId>
41+
<artifactId>cloudevents-core</artifactId>
42+
<version>${project.version}</version>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>io.cloudevents</groupId>
47+
<artifactId>cloudevents-spring</artifactId>
48+
<version>${project.version}</version>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-autoconfigure</artifactId>
54+
<optional>true</optional>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>org.springframework.boot</groupId>
59+
<artifactId>spring-boot-autoconfigure-processor</artifactId>
60+
<optional>true</optional>
61+
</dependency>
62+
63+
<dependency>
64+
<groupId>org.springframework.boot</groupId>
65+
<artifactId>spring-boot-configuration-processor</artifactId>
66+
<optional>true</optional>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>org.springframework.boot</groupId>
71+
<artifactId>spring-boot-starter-rsocket</artifactId>
72+
<optional>true</optional>
73+
</dependency>
74+
75+
<dependency>
76+
<groupId>org.springframework.boot</groupId>
77+
<artifactId>spring-boot-starter-webflux</artifactId>
78+
<optional>true</optional>
79+
</dependency>
80+
81+
<!-- Test deps -->
82+
<dependency>
83+
<groupId>org.springframework.boot</groupId>
84+
<artifactId>spring-boot-starter-test</artifactId>
85+
<scope>test</scope>
86+
</dependency>
87+
88+
<dependency>
89+
<groupId>org.springframework.boot</groupId>
90+
<artifactId>spring-boot-starter-web</artifactId>
91+
<scope>test</scope>
92+
</dependency>
93+
94+
<dependency>
95+
<groupId>io.cloudevents</groupId>
96+
<artifactId>cloudevents-core</artifactId>
97+
<classifier>tests</classifier>
98+
<type>test-jar</type>
99+
<version>${project.version}</version>
100+
<scope>test</scope>
101+
</dependency>
102+
103+
</dependencies>
104+
</project>

0 commit comments

Comments
 (0)