JAVA-14288 Rename spring-5-reactive-modules to spring-reactive-modules (#12659)
* JAVA-14288 Rename spring-5-reactive-modules to spring-reactive-modules * JAVA-14288 Remove failing module * JAVA-14288 Revert commenting spring-cloud-openfeign-2 module
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
## Spring Reactive
|
||||
|
||||
This module contains modules about Spring Reactive
|
||||
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung.spring.reactive</groupId>
|
||||
<artifactId>spring-reactive-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>spring-reactive-modules</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>spring-5-data-reactive</module>
|
||||
<module>spring-5-reactive</module>
|
||||
<module>spring-5-reactive-2</module>
|
||||
<module>spring-5-reactive-3</module>
|
||||
<module>spring-5-reactive-client</module>
|
||||
<module>spring-5-reactive-oauth</module>
|
||||
<module>spring-5-reactive-security</module>
|
||||
<module>spring-reactive</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit</groupId>
|
||||
<artifactId>junit-bom</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<properties>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,10 @@
|
||||
## Spring Data Reactive Project
|
||||
|
||||
This module contains articles about reactive Spring 5 Data
|
||||
|
||||
### The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
### Relevant Articles
|
||||
- [A Quick Look at R2DBC with Spring Data](https://www.baeldung.com/spring-data-r2dbc)
|
||||
- [Spring Data Reactive Repositories with Couchbase](https://www.baeldung.com/spring-data-reactive-couchbase)
|
||||
@@ -0,0 +1,155 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>spring-5-data-reactive</artifactId>
|
||||
<name>spring-5-data-reactive</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung.spring.reactive</groupId>
|
||||
<artifactId>spring-reactive-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-bom</artifactId>
|
||||
<version>${log4j2.version}</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-core</artifactId>
|
||||
<version>${reactor-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-couchbase-reactive</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.reactivex.rxjava2</groupId>
|
||||
<artifactId>rxjava</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
</dependency>
|
||||
<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-webflux</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
<version>${spring-tx.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-r2dbc</artifactId>
|
||||
<version>${spring-data-r2dbc.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.r2dbc</groupId>
|
||||
<artifactId>r2dbc-h2</artifactId>
|
||||
<version>${r2dbc-h2.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${httpclient.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.couchbase.mock</groupId>
|
||||
<artifactId>CouchbaseMock</artifactId>
|
||||
<version>${couchbaseMock.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
<executions>
|
||||
<!-- Replacing default-compile as it is treated specially by maven -->
|
||||
<execution>
|
||||
<id>default-compile</id>
|
||||
<phase>none</phase>
|
||||
</execution>
|
||||
<!-- Replacing default-testCompile as it is treated specially by maven -->
|
||||
<execution>
|
||||
<id>default-testCompile</id>
|
||||
<phase>none</phase>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>java-compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>java-test-compile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<spring-tx.version>5.2.2.RELEASE</spring-tx.version>
|
||||
<spring-data-r2dbc.version>1.0.0.RELEASE</spring-data-r2dbc.version>
|
||||
<r2dbc-h2.version>0.8.1.RELEASE</r2dbc-h2.version>
|
||||
<httpclient.version>4.5.2</httpclient.version>
|
||||
<couchbaseMock.version>1.5.23</couchbaseMock.version>
|
||||
<reactor-core.version>3.3.1.RELEASE</reactor-core.version>
|
||||
<!-- This spring-boot.version is set manually, For upgrading this please refer http://team.baeldung.com/browse/JAVA-2802 -->
|
||||
<spring-boot.version>2.2.6.RELEASE</spring-boot.version>
|
||||
<log4j2.version>2.17.1</log4j2.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.couchbase;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
|
||||
|
||||
@SpringBootApplication(exclude = MongoAutoConfiguration.class)
|
||||
public class ReactiveCouchbaseApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ReactiveCouchbaseApplication.class, args);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package com.baeldung.couchbase.configuration;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
@PropertySource("classpath:couchbase.properties")
|
||||
public class CouchbaseProperties {
|
||||
|
||||
private final List<String> bootstrapHosts;
|
||||
private final String bucketName;
|
||||
private final String bucketPassword;
|
||||
private final int port;
|
||||
|
||||
public CouchbaseProperties(@Value("${spring.couchbase.bootstrap-hosts}") final List<String> bootstrapHosts, @Value("${spring.couchbase.bucket.name}") final String bucketName, @Value("${spring.couchbase.bucket.password}") final String bucketPassword,
|
||||
@Value("${spring.couchbase.port}") final int port) {
|
||||
this.bootstrapHosts = Collections.unmodifiableList(bootstrapHosts);
|
||||
this.bucketName = bucketName;
|
||||
this.bucketPassword = bucketPassword;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public List<String> getBootstrapHosts() {
|
||||
return bootstrapHosts;
|
||||
}
|
||||
|
||||
public String getBucketName() {
|
||||
return bucketName;
|
||||
}
|
||||
|
||||
public String getBucketPassword() {
|
||||
return bucketPassword;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.couchbase.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.data.couchbase.repository.config.EnableReactiveCouchbaseRepositories;
|
||||
|
||||
@Configuration
|
||||
@EnableReactiveCouchbaseRepositories("com.baeldung.couchbase.domain.repository.n1ql")
|
||||
@Primary
|
||||
public class N1QLReactiveCouchbaseConfiguration extends ReactiveCouchbaseConfiguration {
|
||||
|
||||
public N1QLReactiveCouchbaseConfiguration(CouchbaseProperties couchbaseProperties) {
|
||||
super(couchbaseProperties);
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package com.baeldung.couchbase.configuration;
|
||||
|
||||
import com.couchbase.client.java.env.CouchbaseEnvironment;
|
||||
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.couchbase.config.AbstractReactiveCouchbaseConfiguration;
|
||||
import org.springframework.data.couchbase.config.BeanNames;
|
||||
import org.springframework.data.couchbase.repository.support.IndexManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ReactiveCouchbaseConfiguration extends AbstractReactiveCouchbaseConfiguration {
|
||||
|
||||
private CouchbaseProperties couchbaseProperties;
|
||||
|
||||
public ReactiveCouchbaseConfiguration(final CouchbaseProperties couchbaseProperties) {
|
||||
this.couchbaseProperties = couchbaseProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getBootstrapHosts() {
|
||||
return couchbaseProperties.getBootstrapHosts();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBucketName() {
|
||||
return couchbaseProperties.getBucketName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBucketPassword() {
|
||||
return couchbaseProperties.getBucketPassword();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CouchbaseEnvironment couchbaseEnvironment() {
|
||||
return DefaultCouchbaseEnvironment
|
||||
.builder()
|
||||
.bootstrapHttpDirectPort(couchbaseProperties.getPort())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean(name = BeanNames.COUCHBASE_INDEX_MANAGER)
|
||||
public IndexManager couchbaseIndexManager() {
|
||||
return new IndexManager(true, true, false);
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.couchbase.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.couchbase.repository.config.EnableReactiveCouchbaseRepositories;
|
||||
|
||||
@Configuration
|
||||
@EnableReactiveCouchbaseRepositories("com.baeldung.couchbase.domain.repository.view")
|
||||
public class ViewReactiveCouchbaseConfiguration extends ReactiveCouchbaseConfiguration {
|
||||
|
||||
public ViewReactiveCouchbaseConfiguration(CouchbaseProperties couchbaseProperties) {
|
||||
super(couchbaseProperties);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package com.baeldung.couchbase.domain;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.couchbase.core.mapping.Document;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@Document
|
||||
public class Person {
|
||||
|
||||
@Id private UUID id;
|
||||
private String firstName;
|
||||
|
||||
public Person(final UUID id, final String firstName) {
|
||||
this.id = id;
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
private Person() {
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Person person = (Person) o;
|
||||
return Objects.equals(id, person.id) && Objects.equals(firstName, person.firstName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, firstName);
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.baeldung.couchbase.domain.repository.n1ql;
|
||||
|
||||
import com.baeldung.couchbase.domain.Person;
|
||||
import org.springframework.data.couchbase.core.query.N1qlPrimaryIndexed;
|
||||
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Repository
|
||||
@N1qlPrimaryIndexed
|
||||
public interface N1QLPersonRepository extends ReactiveCrudRepository<Person, UUID> {
|
||||
|
||||
Flux<Person> findAllByFirstName(final String firstName);
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.couchbase.domain.repository.n1ql;
|
||||
|
||||
import com.baeldung.couchbase.domain.Person;
|
||||
import org.springframework.data.couchbase.core.query.N1qlPrimaryIndexed;
|
||||
import org.springframework.data.repository.reactive.ReactiveSortingRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Repository
|
||||
@N1qlPrimaryIndexed
|
||||
public interface N1QLSortingPersonRepository extends ReactiveSortingRepository<Person, UUID> {
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.baeldung.couchbase.domain.repository.view;
|
||||
|
||||
import com.baeldung.couchbase.domain.Person;
|
||||
import org.springframework.data.couchbase.core.query.View;
|
||||
import org.springframework.data.couchbase.core.query.ViewIndexed;
|
||||
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Repository
|
||||
@ViewIndexed(designDoc = ViewPersonRepository.DESIGN_DOCUMENT)
|
||||
public interface ViewPersonRepository extends ReactiveCrudRepository<Person, UUID> {
|
||||
|
||||
String DESIGN_DOCUMENT = "person";
|
||||
|
||||
@View(designDocument = ViewPersonRepository.DESIGN_DOCUMENT)
|
||||
Flux<Person> findByFirstName(String firstName);
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.r2dbc;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = "com.baeldung.r2dbc")
|
||||
public class R2dbcApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(R2dbcApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.baeldung.r2dbc.configuration;
|
||||
|
||||
import io.r2dbc.h2.H2ConnectionConfiguration;
|
||||
import io.r2dbc.h2.H2ConnectionFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration;
|
||||
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
|
||||
|
||||
@Configuration
|
||||
@EnableR2dbcRepositories(basePackages = "com.baeldung.r2dbc.repository")
|
||||
public class R2DBCConfiguration extends AbstractR2dbcConfiguration {
|
||||
@Bean
|
||||
public H2ConnectionFactory connectionFactory() {
|
||||
return new H2ConnectionFactory(
|
||||
H2ConnectionConfiguration.builder()
|
||||
.url("mem:testdb;DB_CLOSE_DELAY=-1;TRACE_LEVEL_FILE=4")
|
||||
.username("sa")
|
||||
.build());
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.baeldung.r2dbc.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table
|
||||
public class Player {
|
||||
@Id
|
||||
Integer id;
|
||||
String name;
|
||||
Integer age;
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.r2dbc.repository;
|
||||
|
||||
import org.springframework.data.r2dbc.repository.Query;
|
||||
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
|
||||
|
||||
import com.baeldung.r2dbc.model.Player;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
public interface PlayerRepository extends ReactiveCrudRepository<Player, Integer> {
|
||||
|
||||
@Query("select id, name, age from player where name = $1")
|
||||
Flux<Player> findAllByName(String name);
|
||||
|
||||
@Query("select * from player where age = $1")
|
||||
Flux<Player> findByAge(int age);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
spring.couchbase.bucket.name=default
|
||||
spring.couchbase.bootstrap-hosts=localhost
|
||||
spring.couchbase.port=8091
|
||||
spring.couchbase.bucket.password=123456
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.r2dbc.R2dbcApplication;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = R2dbcApplication.class)
|
||||
public class SpringContextTest {
|
||||
|
||||
@Test
|
||||
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.baeldung.couchbase.domain.repository;
|
||||
|
||||
import com.baeldung.couchbase.configuration.CouchbaseProperties;
|
||||
import com.couchbase.mock.Bucket;
|
||||
import com.couchbase.mock.BucketConfiguration;
|
||||
import com.couchbase.mock.CouchbaseMock;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.Collections;
|
||||
|
||||
@TestConfiguration
|
||||
public class CouchbaseMockConfiguration {
|
||||
|
||||
private CouchbaseMock couchbaseMock;
|
||||
|
||||
public CouchbaseMockConfiguration(final CouchbaseProperties couchbaseProperties) {
|
||||
final BucketConfiguration bucketConfiguration = new BucketConfiguration();
|
||||
bucketConfiguration.numNodes = 1;
|
||||
bucketConfiguration.numReplicas = 1;
|
||||
bucketConfiguration.numVBuckets = 1024;
|
||||
bucketConfiguration.name = couchbaseProperties.getBucketName();
|
||||
bucketConfiguration.type = Bucket.BucketType.COUCHBASE;
|
||||
bucketConfiguration.password = couchbaseProperties.getBucketPassword();
|
||||
|
||||
try {
|
||||
couchbaseMock = new CouchbaseMock(couchbaseProperties.getPort(), Collections.singletonList(bucketConfiguration));
|
||||
} catch (final IOException ex) {
|
||||
throw new UncheckedIOException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void postConstruct() {
|
||||
try {
|
||||
couchbaseMock.start();
|
||||
} catch (final IOException ex) {
|
||||
throw new UncheckedIOException(ex);
|
||||
}
|
||||
try {
|
||||
couchbaseMock.waitForStartup();
|
||||
} catch (final InterruptedException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void preDestroy() {
|
||||
couchbaseMock.stop();
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.baeldung.couchbase.domain.repository.n1ql;
|
||||
|
||||
import com.baeldung.couchbase.domain.Person;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(properties = {"spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration"})
|
||||
public class N1QLPersonRepositoryLiveTest {
|
||||
|
||||
@Autowired private N1QLPersonRepository personRepository;
|
||||
|
||||
@Test
|
||||
public void shouldFindAll_byLastName() {
|
||||
//Given
|
||||
final String firstName = "John";
|
||||
final Person matchingPerson = new Person(UUID.randomUUID(), firstName);
|
||||
final Person nonMatchingPerson = new Person(UUID.randomUUID(), "NotJohn");
|
||||
wrap(() -> {
|
||||
personRepository
|
||||
.save(matchingPerson)
|
||||
.subscribe();
|
||||
personRepository
|
||||
.save(nonMatchingPerson)
|
||||
.subscribe();
|
||||
//When
|
||||
final Flux<Person> allByFirstName = personRepository.findAllByFirstName(firstName);
|
||||
//Then
|
||||
StepVerifier
|
||||
.create(allByFirstName)
|
||||
.expectNext(matchingPerson)
|
||||
.verifyComplete();
|
||||
|
||||
}, matchingPerson, nonMatchingPerson);
|
||||
}
|
||||
|
||||
private void wrap(final Runnable runnable, final Person... people) {
|
||||
try {
|
||||
runnable.run();
|
||||
} finally {
|
||||
for (final Person person : people) {
|
||||
personRepository
|
||||
.delete(person)
|
||||
.subscribe();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package com.baeldung.couchbase.domain.repository.n1ql;
|
||||
|
||||
import com.baeldung.couchbase.domain.Person;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(properties = {"spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration"})
|
||||
public class N1QLSortingPersonRepositoryLiveTest {
|
||||
|
||||
@Autowired private N1QLSortingPersonRepository personRepository;
|
||||
|
||||
@Test
|
||||
public void shouldFindAll_sortedByFirstName() {
|
||||
//Given
|
||||
final Person firstPerson = new Person(UUID.randomUUID(), "John");
|
||||
final Person secondPerson = new Person(UUID.randomUUID(), "Mikki");
|
||||
wrap(() -> {
|
||||
personRepository
|
||||
.save(firstPerson)
|
||||
.subscribe();
|
||||
personRepository
|
||||
.save(secondPerson)
|
||||
.subscribe();
|
||||
//When
|
||||
final Flux<Person> allByFirstName = personRepository.findAll(Sort.by(Sort.Direction.DESC, "firstName"));
|
||||
//Then
|
||||
StepVerifier
|
||||
.create(allByFirstName)
|
||||
.expectNextMatches(person -> person
|
||||
.getFirstName()
|
||||
.equals(secondPerson.getFirstName()))
|
||||
.expectNextMatches(person -> person
|
||||
.getFirstName()
|
||||
.equals(firstPerson.getFirstName()))
|
||||
.verifyComplete();
|
||||
}, firstPerson, secondPerson);
|
||||
}
|
||||
|
||||
//workaround for deleteAll()
|
||||
private void wrap(final Runnable runnable, final Person... people) {
|
||||
try {
|
||||
runnable.run();
|
||||
} finally {
|
||||
for (final Person person : people) {
|
||||
personRepository
|
||||
.delete(person)
|
||||
.subscribe();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package com.baeldung.couchbase.domain.repository.view;
|
||||
|
||||
import com.baeldung.couchbase.configuration.CouchbaseProperties;
|
||||
import com.baeldung.couchbase.configuration.ViewReactiveCouchbaseConfiguration;
|
||||
import com.baeldung.couchbase.domain.Person;
|
||||
import com.baeldung.couchbase.domain.repository.CouchbaseMockConfiguration;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(properties = { "spring.couchbase.port=10010", "spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration,org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration" },
|
||||
classes = { CouchbaseMockConfiguration.class, ViewReactiveCouchbaseConfiguration.class, CouchbaseProperties.class })
|
||||
public class ViewPersonRepositoryIntegrationTest {
|
||||
|
||||
@Autowired private ViewPersonRepository personRepository;
|
||||
|
||||
@Test
|
||||
public void shouldSavePerson_findById_thenDeleteIt() {
|
||||
//Given
|
||||
final UUID id = UUID.randomUUID();
|
||||
final Person person = new Person(id, "John");
|
||||
wrap(() -> {
|
||||
personRepository
|
||||
.save(person)
|
||||
.subscribe();
|
||||
//When
|
||||
final Mono<Person> byId = personRepository.findById(id);
|
||||
//Then
|
||||
StepVerifier
|
||||
.create(byId)
|
||||
.expectNextMatches(result -> result
|
||||
.getId()
|
||||
.equals(id))
|
||||
.expectComplete()
|
||||
.verify();
|
||||
}, person);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindAll_thenDeleteIt() {
|
||||
//Given
|
||||
final Person person = new Person(UUID.randomUUID(), "John");
|
||||
final Person secondPerson = new Person(UUID.randomUUID(), "Mikki");
|
||||
wrap(() -> {
|
||||
personRepository
|
||||
.save(person)
|
||||
.subscribe();
|
||||
personRepository
|
||||
.save(secondPerson)
|
||||
.subscribe();
|
||||
//When
|
||||
final Flux<Person> all = personRepository.findAll();
|
||||
//Then
|
||||
StepVerifier
|
||||
.create(all)
|
||||
.expectNextCount(2)
|
||||
.verifyComplete();
|
||||
}, person, secondPerson);
|
||||
}
|
||||
|
||||
private void wrap(final Runnable runnable, final Person... people) {
|
||||
try {
|
||||
runnable.run();
|
||||
} finally {
|
||||
for (final Person person : people) {
|
||||
personRepository
|
||||
.delete(person)
|
||||
.subscribe();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
package com.baeldung.r2dbc;
|
||||
|
||||
|
||||
import com.baeldung.r2dbc.model.Player;
|
||||
import com.baeldung.r2dbc.repository.PlayerRepository;
|
||||
import io.r2dbc.h2.H2ConnectionFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.r2dbc.core.DatabaseClient;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Hooks;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class R2dbcApplicationIntegrationTest {
|
||||
|
||||
|
||||
@Autowired
|
||||
PlayerRepository playerRepository;
|
||||
|
||||
@Autowired
|
||||
DatabaseClient client;
|
||||
|
||||
@Autowired
|
||||
H2ConnectionFactory factory;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
|
||||
Hooks.onOperatorDebug();
|
||||
|
||||
List<String> statements = Arrays.asList(//
|
||||
"DROP TABLE IF EXISTS player;",
|
||||
"CREATE table player (id INT AUTO_INCREMENT NOT NULL, name VARCHAR2, age INT NOT NULL);");
|
||||
|
||||
statements.forEach(it -> client.execute(it) //
|
||||
.fetch() //
|
||||
.rowsUpdated() //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(1) //
|
||||
.verifyComplete());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeleteAll_then0IsExpected() {
|
||||
|
||||
|
||||
playerRepository.deleteAll()
|
||||
.as(StepVerifier::create)
|
||||
.expectNextCount(0)
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsert6_then6AreExpected() {
|
||||
|
||||
insertPlayers();
|
||||
|
||||
playerRepository.findAll()
|
||||
.as(StepVerifier::create)
|
||||
.expectNextCount(6)
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSearchForCR7_then1IsExpected() {
|
||||
|
||||
insertPlayers();
|
||||
|
||||
playerRepository.findAllByName("CR7")
|
||||
.as(StepVerifier::create)
|
||||
.expectNextCount(1)
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSearchFor32YearsOld_then2AreExpected() {
|
||||
insertPlayers();
|
||||
|
||||
playerRepository.findByAge(32)
|
||||
.as(StepVerifier::create)
|
||||
.expectNextCount(2)
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBatchHas2Operations_then2AreExpected() {
|
||||
Mono.from(factory.create())
|
||||
.flatMapMany(connection -> Flux.from(connection
|
||||
.createBatch()
|
||||
.add("select * from player")
|
||||
.add("select * from player")
|
||||
.execute()))
|
||||
.as(StepVerifier::create)
|
||||
.expectNextCount(2)
|
||||
.verifyComplete();
|
||||
|
||||
}
|
||||
|
||||
private void insertPlayers() {
|
||||
List<Player> players = Arrays.asList(
|
||||
new Player(null, "Kaka", 37),
|
||||
new Player(null, "Messi", 32),
|
||||
new Player(null, "Mbappé", 20),
|
||||
new Player(null, "CR7", 34),
|
||||
new Player(null, "Lewandowski", 30),
|
||||
new Player(null, "Cavani", 32)
|
||||
);
|
||||
|
||||
playerRepository.saveAll(players).subscribe();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#folders#
|
||||
.idea
|
||||
/target
|
||||
/neoDb*
|
||||
/data
|
||||
/src/main/webapp/WEB-INF/classes
|
||||
*/META-INF/*
|
||||
|
||||
# Packaged files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
@@ -0,0 +1,10 @@
|
||||
## Spring 5 Reactive Project
|
||||
|
||||
This module contains articles about reactive Spring 5.
|
||||
|
||||
- [Validation for Functional Endpoints in Spring 5](https://www.baeldung.com/spring-functional-endpoints-validation)
|
||||
- [Testing Reactive Streams Using StepVerifier and TestPublisher](https://www.baeldung.com/reactive-streams-step-verifier-test-publisher)
|
||||
- [Static Content in Spring WebFlux](https://www.baeldung.com/spring-webflux-static-content)
|
||||
- [Server-Sent Events in Spring](https://www.baeldung.com/spring-server-sent-events)
|
||||
- [Backpressure Mechanism in Spring WebFlux](https://www.baeldung.com/spring-webflux-backpressure)
|
||||
- More articles: [[<-- prev]](../spring-5-reactive) [[next -->]](../spring-5-reactive-3)
|
||||
@@ -0,0 +1,117 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>spring-5-reactive-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>spring-5-reactive-2</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>spring 5 sample project about new features</description>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung.spring.reactive</groupId>
|
||||
<artifactId>spring-reactive-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectreactor</groupId>
|
||||
<artifactId>reactor-spring</artifactId>
|
||||
<version>${reactor-spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.tomakehurst</groupId>
|
||||
<artifactId>wiremock-jre8</artifactId>
|
||||
<version>${wiremock.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<mainClass>com.baeldung.webclient.WebClientApplication</mainClass>
|
||||
<layout>JAR</layout>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>integration-lite-first</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<logback.configurationFile>${project.basedir}/src/test/resources/logback-test.xml</logback.configurationFile>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>integration-lite-second</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<logback.configurationFile>${project.basedir}/src/test/resources/logback-test.xml</logback.configurationFile>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<properties>
|
||||
<reactor-spring.version>1.0.1.RELEASE</reactor-spring.version>
|
||||
<wiremock.version>2.24.0</wiremock.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.baeldung.reactive.serversentevents.consumer;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisReactiveAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.security.config.web.server.ServerHttpSecurity;
|
||||
import org.springframework.security.web.server.SecurityWebFilterChain;
|
||||
|
||||
@SpringBootApplication(exclude = { RedisReactiveAutoConfiguration.class })
|
||||
@EnableAsync
|
||||
public class ConsumerSSEApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication app = new SpringApplication(ConsumerSSEApplication.class);
|
||||
app.setDefaultProperties(Collections.singletonMap("server.port", "8082"));
|
||||
app.run(args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SecurityWebFilterChain sseConsumerSpringSecurityFilterChain(ServerHttpSecurity http) {
|
||||
http.authorizeExchange()
|
||||
.anyExchange()
|
||||
.permitAll();
|
||||
return http.build();
|
||||
}
|
||||
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package com.baeldung.reactive.serversentevents.consumer.controller;
|
||||
|
||||
import java.time.LocalTime;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.codec.ServerSentEvent;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/sse-consumer")
|
||||
public class ClientController {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ClientController.class);
|
||||
private WebClient client = WebClient.create("http://localhost:8081/sse-server");
|
||||
|
||||
@GetMapping("/launch-sse-client")
|
||||
public String launchSSEFromSSEWebClient() {
|
||||
consumeSSE();
|
||||
return "LAUNCHED EVENT CLIENT!!! Check the logs...";
|
||||
}
|
||||
|
||||
@GetMapping("/launch-flux-client")
|
||||
public String launchcFluxFromSSEWebClient() {
|
||||
consumeFlux();
|
||||
return "LAUNCHED EVENT CLIENT!!! Check the logs...";
|
||||
}
|
||||
|
||||
@GetMapping("/launch-sse-from-flux-endpoint-client")
|
||||
public String launchFluxFromFluxWebClient() {
|
||||
consumeSSEFromFluxEndpoint();
|
||||
return "LAUNCHED EVENT CLIENT!!! Check the logs...";
|
||||
}
|
||||
|
||||
@Async
|
||||
public void consumeSSE() {
|
||||
ParameterizedTypeReference<ServerSentEvent<String>> type = new ParameterizedTypeReference<ServerSentEvent<String>>() {
|
||||
};
|
||||
|
||||
Flux<ServerSentEvent<String>> eventStream = client.get()
|
||||
.uri("/stream-sse")
|
||||
.retrieve()
|
||||
.bodyToFlux(type);
|
||||
|
||||
eventStream.subscribe(content -> logger.info("Current time: {} - Received SSE: name[{}], id [{}], content[{}] ", LocalTime.now(), content.event(), content.id(), content.data()), error -> logger.error("Error receiving SSE: {}", error),
|
||||
() -> logger.info("Completed!!!"));
|
||||
}
|
||||
|
||||
@Async
|
||||
public void consumeFlux() {
|
||||
Flux<String> stringStream = client.get()
|
||||
.uri("/stream-flux")
|
||||
.accept(MediaType.TEXT_EVENT_STREAM)
|
||||
.retrieve()
|
||||
.bodyToFlux(String.class);
|
||||
|
||||
stringStream.subscribe(content -> logger.info("Current time: {} - Received content: {} ", LocalTime.now(), content), error -> logger.error("Error retrieving content: {}", error), () -> logger.info("Completed!!!"));
|
||||
}
|
||||
|
||||
@Async
|
||||
public void consumeSSEFromFluxEndpoint() {
|
||||
ParameterizedTypeReference<ServerSentEvent<String>> type = new ParameterizedTypeReference<ServerSentEvent<String>>() {
|
||||
};
|
||||
|
||||
Flux<ServerSentEvent<String>> eventStream = client.get()
|
||||
.uri("/stream-flux")
|
||||
.accept(MediaType.TEXT_EVENT_STREAM)
|
||||
.retrieve()
|
||||
.bodyToFlux(type);
|
||||
|
||||
eventStream.subscribe(content -> logger.info("Current time: {} - Received SSE: name[{}], id [{}], content[{}] ", LocalTime.now(), content.event(), content.id(), content.data()), error -> logger.error("Error receiving SSE: {}", error),
|
||||
() -> logger.info("Completed!!!"));
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user