在这篇文章中,我们将了解如何通过 Spring Data Reactive Repositories 和 MongoDB 使用 Reactive Programming 配置和实现数据库操作以在本地运行,然后了解如何通过 Platform.sh 将其顺利迁移到云端。
反应式编程是一种编程范式,它提倡异步、非阻塞、事件驱动的数据处理方法。反应式编程涉及将数据和事件建模为可观察的数据流,并实施数据处理例程以对这些流中的变化做出反应。
为了说明 Reactive MongoDB,我们将创建一个应用程序来处理和存储希腊神话中的商品。为了使用 Reactive MongoDB,我们需要将依赖项添加到我们的 pom.xml。
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4
<modelVersion>4.0.0</modelVersion>
5
6
<groupId>sh.platform.example</groupId>
7
<artifactId>template-spring-mongodb-reactive</artifactId>
8
<version>0.0.1</version>
9
10
<properties>
11
<platform.sh.version>2.2.3</platform.sh.version>
12
<java.version>1.8</java.version>
13
</properties>
14
15
<parent>
16
<groupId>org.springframework.boot</groupId>
17
<artifactId>spring-boot-starter-parent</artifactId>
18
<version>2.2.6.RELEASE</version>
19
</parent>
20
21
<dependencies>
22
<dependency>
23
<groupId>org.springframework.boot</groupId>
24
<artifactId>spring-boot-starter-webflux</artifactId>
25
</dependency>
26
<dependency>
27
<groupId>org.springframework.boot</groupId>
28
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
29
</dependency>
30
<dependency>
31
<groupId>org.springframework.boot</groupId>
32
<artifactId>spring-boot-starter-test</artifactId>
33
<scope>test</scope>
34
</dependency>
35
</dependencies>
36
37
<build>
38
<f