Skip to content

Commit

Permalink
feat: add spring-boot support
Browse files Browse the repository at this point in the history
Signed-off-by: Eddú Meléndez <eddu.melendez@gmail.com>
  • Loading branch information
eddumelendez committed Jan 22, 2022
1 parent 4784f03 commit 433aafe
Show file tree
Hide file tree
Showing 22 changed files with 622 additions and 113 deletions.
25 changes: 25 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,31 @@
<artifactId>cloudevents-spring</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-spring-boot-autoconfigure</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-rsocket-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-web-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-webflux-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>io.cloudevents.sql</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/restful-ws-spring-boot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mvn spring-boot:run
You can try sending a request using `curl`:

```shell
curl -X POST -v -d '{"username": "slinkydeveloper", "firstName": "Francesco", "lastName": "Guardiani", "age": 23}' \ ~
curl -X POST -v -d '{"username": "slinkydeveloper", "firstName": "Francesco", "lastName": "Guardiani", "age": 23}' \
-H'Content-type: application/json' \
-H'Ce-id: 1' \
-H'Ce-source: cloud-event-example' \
Expand Down
16 changes: 1 addition & 15 deletions examples/spring-function/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,9 @@
<artifactId>spring-cloud-function-web</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-spring</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-http-basic</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-json-jackson</artifactId>
<artifactId>cloudevents-webflux-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.codec.CodecCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.codec.CodecConfigurer;

import io.cloudevents.CloudEvent;
import io.cloudevents.core.builder.CloudEventBuilder;
import io.cloudevents.spring.messaging.CloudEventMessageConverter;
import io.cloudevents.spring.webflux.CloudEventHttpMessageReader;
import io.cloudevents.spring.webflux.CloudEventHttpMessageWriter;

@SpringBootApplication
public class DemoApplication {
Expand All @@ -34,31 +28,4 @@ public Function<CloudEvent, CloudEvent> events() {
.build();
}

/**
* Configure a MessageConverter for Spring Cloud Function to pick up and use to
* convert to and from CloudEvent and Message.
*/
@Configuration
public static class CloudEventMessageConverterConfiguration {
@Bean
public CloudEventMessageConverter cloudEventMessageConverter() {
return new CloudEventMessageConverter();
}
}

/**
* Configure an HTTP reader and writer so that we can process CloudEvents over
* HTTP via Spring Webflux.
*/
@Configuration
public static class CloudEventHandlerConfiguration implements CodecCustomizer {

@Override
public void customize(CodecConfigurer configurer) {
configurer.customCodecs().register(new CloudEventHttpMessageReader());
configurer.customCodecs().register(new CloudEventHttpMessageWriter());
}

}

}
18 changes: 2 additions & 16 deletions examples/spring-reactive/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,9 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-spring</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-http-basic</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-json-jackson</artifactId>
<artifactId>cloudevents-webflux-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand All @@ -63,5 +49,5 @@
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@
import io.cloudevents.CloudEvent;
import io.cloudevents.core.builder.CloudEventBuilder;
import io.cloudevents.spring.http.CloudEventHttpUtils;
import io.cloudevents.spring.webflux.CloudEventHttpMessageReader;
import io.cloudevents.spring.webflux.CloudEventHttpMessageWriter;
import reactor.core.publisher.Mono;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.codec.CodecCustomizer;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.http.codec.CodecConfigurer;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
Expand Down Expand Up @@ -53,15 +48,4 @@ public Mono<CloudEvent> event(@RequestBody Mono<CloudEvent> body) {
.build());
}

@Configuration
public static class CloudEventHandlerConfiguration implements CodecCustomizer {

@Override
public void customize(CodecConfigurer configurer) {
configurer.customCodecs().register(new CloudEventHttpMessageReader());
configurer.customCodecs().register(new CloudEventHttpMessageWriter());
}

}

}
}
13 changes: 2 additions & 11 deletions examples/spring-rsocket/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,9 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-rsocket</artifactId>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-spring</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-json-jackson</artifactId>
<artifactId>cloudevents-rsocket-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand All @@ -58,5 +49,5 @@
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@

import io.cloudevents.CloudEvent;
import io.cloudevents.core.builder.CloudEventBuilder;
import io.cloudevents.spring.codec.CloudEventDecoder;
import io.cloudevents.spring.codec.CloudEventEncoder;
import reactor.core.publisher.Mono;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.rsocket.messaging.RSocketStrategiesCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.rsocket.RSocketStrategies.Builder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;

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

@Bean
@Order(-1)
public RSocketStrategiesCustomizer cloudEventsCustomizer() {
return new RSocketStrategiesCustomizer() {
@Override
public void customize(Builder strategies) {
strategies.encoder(new CloudEventEncoder());
strategies.decoder(new CloudEventDecoder());
}
};

}

}
}
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
<module>http/restful-ws</module>
<module>kafka</module>
<module>spring</module>
<module>spring-boot/autoconfigure</module>
<module>spring-boot/rsocket-starter</module>
<module>spring-boot/starter</module>
<module>spring-boot/web-starter</module>
<module>spring-boot/webflux-starter</module>
<module>sql</module>
<module>bom</module>
</modules>
Expand All @@ -92,8 +97,22 @@
<!-- Dependencies -->
<assertj-core.version>3.16.1</assertj-core.version>
<junit-jupiter.version>5.7.0</junit-jupiter.version>
<spring-boot.version>2.5.9</spring-boot.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>

</dependencies>
</dependencyManagement>

<distributionManagement>
<site>
<id>site</id>
Expand Down Expand Up @@ -168,6 +187,7 @@
<link>https://qpid.apache.org/releases/qpid-proton-j-0.33.7/api/</link>
<link>https://fasterxml.github.io/jackson-databind/javadoc/2.10/</link>
</links>
<skippedModules>cloudevents-spring-boot-starter</skippedModules>
</configuration>
<executions>
<execution>
Expand Down
104 changes: 104 additions & 0 deletions spring-boot/autoconfigure/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2018-Present The CloudEvents Authors
~ <p>
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~ <p>
~ http://www.apache.org/licenses/LICENSE-2.0
~ <p>
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-parent</artifactId>
<version>2.4.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>cloudevents-spring-boot-autoconfigure</artifactId>
<name>CloudEvents - Spring Boot Autoconfigure</name>
<packaging>jar</packaging>

<properties>
<module-name>io.cloudevents.springboot.autoconfigure</module-name>
</properties>

<dependencies>

<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-spring</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure-processor</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-rsocket</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<optional>true</optional>
</dependency>

<!-- Test deps -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-core</artifactId>
<classifier>tests</classifier>
<type>test-jar</type>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

</dependencies>
</project>
Loading

0 comments on commit 433aafe

Please sign in to comment.