1、响应式编程式什么?为什么现在都认为这个是微服务的趋势?
先挖个坑吧,给个简单的公式。
响应式编程=数据流+变化传递+声明式
2、下面废话不多说直接上代码
WebFlux的核心Reactor的实现思路和介绍可跳转
因为是初探所以尽量给全代码,课详细了解引用的具体是什么类或者域,因为是自己简单实验,所以难免有错误,有同样也在研究的童靴如发现有错误请指教。
首先是项目启动类,与Spring Boot类似
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.reactive.config.EnableWebFlux;
@SpringBootApplication
@EnableWebFlux
public class WebfluxDemoApplication {
public static void main(String[] args) {
SpringApplication.run(WebfluxDemoApplication.class, args);
}
}
然后是我的针对web交互的一些配置。
主要是在Codec中增加了对LocalDateTime相关类和我自定义的两类枚举接口的序列化和反序列化的配置
package com.example.demo.config;
import static com.example.demo.utils.LocalDateTimeUtils.DATE_FORMATTER;
import static com.example.demo.utils.LocalDateTimeUtils.DATE_TIME_FORMATTER;
import static com.example.demo.utils.LocalDateTimeUtils.TIME_FORMATTER;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.http.codec.ServerCodecConfigurer;
imp