reactive

Spring Cloud Gateway配置自定义异常返回

北城以北 提交于 2020-08-10 12:10:46
0. 前言   最近搞微服务的全家桶,用到的Spring Cloud Gateway 这个组件。需要对这个网关抛出的异常进行自定义。网关的异常处理跟单体SpringBoot的全局异常处理还有点不一样。   单体全局异常处理,是采用@RestControllerAdvice 这个注解来实现的。微服务Gateway是采用另外的方式来实现的。 1. 单体自定义异常返回    CustomException.java 1 package com.wunaozai.config.advice; 2 3 /** 4 * 自定义异常类(运行时异常) 5 * @author wunaozai 6 * @date 2018-06-27 7 */ 8 public class CustomException extends RuntimeException { 9 10 private static final long serialVersionUID = 6304501072268270030L ; 11 12 public CustomException(String msg) { 13 this (500 , msg); 14 } 15 public CustomException( int code, String msg) { 16 this (code, msg, null ); 17

探索Java9 模块系统和反应流

↘锁芯ラ 提交于 2020-08-09 21:27:09
Java9 新特性 ,Java 模块化,Java 反应流 Reactive,Jigsaw 目录 模块系统 模块描述符 模块化应用程序示例 编译和执行 向后兼容 反应流 Flow类 内部实现 一个简单的应用 应用Processor API使用 总结 模块系统 Java平台模块系统(JPMS)是Java9中的特性,它是Jigsaw项目的产物。简而言之,它以更简单和易于维护的方式来组织包和类型。 直到Java8,系统仍面临与类型系统相关的两个问题: 1.所有的组件(大多是Jar包)都处在classpath中,没有任何的显式依赖申明。诸如Maven之类的构建工具可以在开发过程中帮助组织这些构件。然而,在运行时却没有这样的支持工具。你最终可能会遇到calsspath中缺少某个类,或者更严重的是存在同个类的两个版本,向这样的错误很难诊断。 2.在API级别上不支持封装。所有的public的类在整个应用中都可以访问,经管事实上这些类只是想供一部分其他类调用。另一方面,私有的类和私有的成员也不是私有的,因为你可以使用反射来绕过访问限制。 这些就是Java 模块系统要应对的地方。Oralce的Java平台首席架构师Mark Reinhold描述了Java模块系统的目标: 1.可靠的配置 - 用程序组件相互声明显式依赖的方法替换脆弱,容易出错的类路径机制。 2.强大的封装 -

如何实现vue3.0的响应式呢?本文实战教你

风流意气都作罢 提交于 2020-08-09 11:16:06
之前写了两篇vue2.0的响应式原理,链接在此,对响应式原理不清楚的请先看下面两篇 和尤雨溪一起进阶vue 和尤雨溪一起进阶vue(二) 现在来写一个简单的3.0的版本吧 大家都知道,2.0的响应式用的是 Object.defineProperty ,结合发布订阅模式实现的,3.0已经用 Proxy 改写了 Proxy是es6提供的新语法,Proxy 对象用于定义基本操作的自定义行为(如属性查找、赋值、枚举、函数调用等)。 语法: const p = new Proxy(target, handler) target 要使用 Proxy 包装的目标对象(可以是任何类型的对象,包括原生数组,函数,甚至另一个代理)。 handler 一个通常以函数作为属性的对象,各属性中的函数分别定义了在执行各种操作时代理 p 的行为。 handler的方法有很多, 感兴趣的可以移步到MDN,这里重点介绍下面几个 handler.has() in 操作符的捕捉器。 handler.get() 属性读取操作的捕捉器。 handler.set() 属性设置操作的捕捉器。 handler.deleteProperty() delete 操作符的捕捉器。 handler.ownKeys() Object.getOwnPropertyNames 方法和 Object.getOwnPropertySymbols

今天来介绍java 各版本的新特性,一篇文章让你了解

倖福魔咒の 提交于 2020-08-09 02:56:20
java8 新特性 Java8 主要包括的新特性有: 函数式接口 如果一个接口只有一个抽象方法,那么该接口就成为一个函数式接口。同时java还配套引入@FunctionalInterface注解, 该注解主要式用于强制表示一个接口必须是一个函数式接口,但是不是必须的。 @FunctionalInterface public interface DemoFuncInterface1 { void apply(); } public interface DemoFuncInterface2 { void apply(); } public interface DemoFuncInterface3 { void apply(); void apply2(); } public interface DemoFuncInterface4 { default void apply() {}; } 上面4个例子中DemoFuncInterface1、DemoFuncInterface2都是 函数式接口。但是第三个、第四个都不是,而且将@FunctionalInterface标记 在第三、第四个上编译都会报错。 使用函数式接口demo: public class testDemo{ public void testFunc(DemoFuncInterface demoFuncInterface ,

Flink:What is stream processing?

ⅰ亾dé卋堺 提交于 2020-08-08 04:08:52
Ververica was founded by the original creators of Apache Flink®, and we’ve spent a long time solving problems in the stream processing space. In this introductory write-up, we’ll provide our perspective on stream processing and where Apache Flink fits in. Stream processing is the processing of data in motion , or in other words, computing on data directly as it is produced or received. The majority of data are born as continuous streams: sensor events, user activity on a website, financial trades, and so on – all these data are created as a series of events over time. Before stream processing,

Reactor 3 (6): 背压 Backpressure 使用

拜拜、爱过 提交于 2020-08-07 09:50:27
有这样的情况,上游传递到下游的数据需要进行处理,然而上游推送的速度又很快,下游由于资源等原因来不及处理;如果这时还是通过不限制上游速度的方式推送数据,就会出问题,因此Reactive Streams有两一种处理方式,就是通过request的机制向上游传递信号,并指定接收数量;通过这种方法将 push 模型转化为 push-pull hybrid ,这就是backpressure的用法。 通过编写Subscriber实现backpressure 下面介绍backpressure比较原始的写法,通过构建Subscriber控制request的大小: @Test public void rawBackPressure ( ) { Flux < String > flux = Flux . range ( 1 , 10 ) . map ( i - > String . valueOf ( i ) ) . log ( ) ; flux . subscribe ( new Subscriber < String > ( ) { private int count = 0 ; private Subscription subscription ; private int requestCount = 2 ; @Override public void onSubscribe (

vue3 reactive 对比 react useState 以及 ramda 和 lodash 的取舍问题

ⅰ亾dé卋堺 提交于 2020-08-05 20:25:38
vue3 的 reactive 和 react的useState有着根本上的不同 const { ref, reactive, watch } = require("vue"); let s1 = reactive({ x: 0 }); let s2 = reactive({ x: 0 }); let s3 = s2; watch([s1], (newS1) => { console.log("watch s1", newS1); }); watch([s2], (newS2) => { console.log("watch s2", newS2); }); watch([s3], (newS3) => { console.log("watch s3", newS3); }); setTimeout(() => { s1.x = 2; s2 = { x: 111, }; s3.x = 444; }, 1000); 上述代码的输出如下, s1的watch生效了, 而s3的修改触发了两次watch 单独设置s2并不会出现任何输出 setTimeout(() => { s2 = { x: 111, }; }, 1000); 对比react 采用的比较方式是===比较, 所以在原对象上的修改会被忽视, 而ramda每次总是返回新对象的特点正好契合react的方式 import React,

Reactive Programming: Spring WebFlux: How to build a chain of micro-service calls?

对着背影说爱祢 提交于 2020-08-05 10:23:11
问题 Spring Boot Application: a @RestController receives the following payload: { "cartoon": "The Little Mermaid", "characterNames": ["Ariel", "Prince Eric", "Sebastian", "Flounder"] } I need to process it in the following way: Get the unique Id for each character name: make an HTTP call to "cartoon-characters" microservice, that returns ids by names Transform data received by the controller: replace character names with appropriate ids that were received on the previous step from "cartoon

An equivalent to computed properties using @Published in Swift Combine?

给你一囗甜甜゛ 提交于 2020-08-01 05:32:06
问题 In imperative Swift, it is common to use computed properties to provide convenient access to data without duplicating state. Let's say I have this class made for imperative MVC use: class ImperativeUserManager { private(set) var currentUser: User? { didSet { if oldValue != currentUser { NotificationCenter.default.post(name: NSNotification.Name("userStateDidChange"), object: nil) // Observers that receive this notification might then check either currentUser or userIsLoggedIn for the latest

Render Dynamic Tabs with Dynamic Plots from loop in Shiny

℡╲_俬逩灬. 提交于 2020-07-23 06:55:27
问题 I'm trying to populate dynamically generated tabs with plots made from a loop but can't get the tabs to populate with all of the plots generated in the loop. shinyUI(pageWithSidebar( headerPanel("Dynamic number of plots"), sidebarPanel( ), mainPanel( # This is the dynamic UI for the plots uiOutput("IndividualPlots") ) )) server <- function(input, output) { output$IndividualPlots <- renderUI({ if (is.null(input$data_cqt0)) { return() } plot_content() shiny:::buildTabset( id = "t", lapply(1