reactive

学习WebFlux时常见的问题

帅比萌擦擦* 提交于 2019-12-09 11:52:02
前言 只有光头才能变强。 文本已收录至我的GitHub精选文章,欢迎Star : https://github.com/ZhongFuCheng3y/3y 回顾一下上篇我对WebFlux的入门,如果没读过的同学建议读一下再来看本篇文章,上一篇文章花了我很多的心血~~ 外行人都能看懂的WebFlux,错过了血亏 开局再来一张图,内容全靠编: 这篇主要写写我初学时对WebFlux的一些疑问,不知道大家在看上一篇文章的时候有没有相应的问题呢? 这次学WebFlux主要的动力是公司组内分享,写了一个PPT,有需要的同学在我的公众号( Java3y )下回复“PPT”即可获取。 一、本来就能实现异步非阻塞,为啥要用WebFlux? 相信有过相关了解的同学都知道, Servlet 3.1 就已经支持异步非阻塞了。 我们可以以 自维护线程池的方式实现异步 说白了就是Tomcat的线程处理请求,然后把这个请求分发到自维护的线程处理,Tomcat的请求线程返回 1@WebServlet(value = "/nonBlockingThreadPoolAsync", asyncSupported = true) 2public class NonBlockingAsyncHelloServlet extends HttpServlet { 3 4 private static

Akka构建Reactive应用《one》

喜你入骨 提交于 2019-12-09 09:50:01
看到这Akka的官网,描述使用java或者scala构建响应式,并发和分布式应用更加简单,听着很高级的样子,下面的小字写着消息驱动,但是在quickstart里面又写容错事件驱动,就是这么钻牛角尖。 Actors是的Akka的执行单位,Actor模型是一个抽象概念,它使得编写并发的、并行的和分布式的系统变得更加容易。官方给了一个 “helloworld” 示例,演示了基本知识,我们可以在如下的页面创建一个项目,点开旁边的 show all akka projects 可以看到所有的示例(https://developer.lightbend.com/start/?group=akka)。 作为小白,就是这个最基础的这个,然后下载过来是个 zip 包,解压一下,执行以下命令: $ chmod u+x ./sbt $ chmod u+x ./sbt-dist/bin/sbt 然后在这个目录中,我们执行 ./sbt 或者 sbt.bat(windows 环境)来下载项目依赖的包,不过真的是够慢的哈。 然后执行 reStart 来构建项目和运行 Hello World,可以看到以下的输出,还可以看到 Actor 和我们打的招呼。 在 akka 的 quickstart 里面还给我们画了一张图,看怎么运行的 main 类里面创建一个 akka.actor.ActorSystem,构建

学习WebFlux时常见的问题

流过昼夜 提交于 2019-12-08 17:14:37
前言 只有光头才能变强。 文本已收录至我的GitHub精选文章,欢迎Star : https://github.com/ZhongFuCheng3y/3y 回顾一下上篇我对WebFlux的入门,如果没读过的同学建议读一下再来看本篇文章,上一篇文章花了我很多的心血~~ 外行人都能看懂的WebFlux,错过了血亏 开局再来一张图,内容全靠编: 这篇主要写写我初学时对WebFlux的一些疑问,不知道大家在看上一篇文章的时候有没有相应的问题呢? 这次学WebFlux主要的动力是公司组内分享,写了一个PPT,有需要的同学在我的公众号( Java3y )下回复“PPT”即可获取。 一、本来就能实现异步非阻塞,为啥要用WebFlux? 相信有过相关了解的同学都知道, Servlet 3.1 就已经支持异步非阻塞了。 我们可以以 自维护线程池的方式实现异步 说白了就是Tomcat的线程处理请求,然后把这个请求分发到自维护的线程处理,Tomcat的请求线程返回 1@WebServlet(value = "/nonBlockingThreadPoolAsync", asyncSupported = true) 2public class NonBlockingAsyncHelloServlet extends HttpServlet { 3 4 private static

reactive field in Class Shiny R

て烟熏妆下的殇ゞ 提交于 2019-12-08 10:40:21
问题 Is it possible to create a reactive field in class or a class which notify app when her field change ? I got this class which is a model for my shinyApp: CatalogModele <- setRefClass("CatalogModele", fields = list(catalogs = "list"), methods = list( initialize = function(catalogs_args = list()) { catalogs <<- catalogs_args }, add_catalog = function(key, value) { catalogs[[key]] <<- value } ) ) I would like to update some shiny widgets when i use "add_catalog()" on my global object. I tried

Can a Subscriber act as a Publisher?

蓝咒 提交于 2019-12-08 09:12:23
In terms of Reactive Streams, there is a Publisher and it could have as many Subscribers. But suppose, a subscriber gets a message from Publisher. Now this Subscriber(say Subs1) changes/modifies the message and passes it to some other Subscriber(say Subs2), which consumes the modified message. So can this Subs1 subscriber can act as a Publisher which can pass on message to new Subs2 subscriber? I am not sure if it possible or not, but the scenario is possible i think. If its possible, please suggest a possible way to do this. If we want to transform incoming message and pass it further to the

Can a Subscriber act as a Publisher?

核能气质少年 提交于 2019-12-08 08:47:19
问题 In terms of Reactive Streams, there is a Publisher and it could have as many Subscribers. But suppose, a subscriber gets a message from Publisher. Now this Subscriber(say Subs1) changes/modifies the message and passes it to some other Subscriber(say Subs2), which consumes the modified message. So can this Subs1 subscriber can act as a Publisher which can pass on message to new Subs2 subscriber? I am not sure if it possible or not, but the scenario is possible i think. If its possible, please

How to use debounce with reactiveValues in shiny

送分小仙女□ 提交于 2019-12-08 05:11:24
问题 I understand that I can use debounce with reactive() like this, and this is the sort of behaviour I need, but I want to use reactiveValues() instead. ui <- fluidPage( textInput(inputId = "text", label = "To see how quickly..."), textOutput(outputId = "text") ) server <- function(input, output, session) { text_input <- reactive({ input$text }) debounce(text_input, 2000) output$text <- renderText({ text_input() }) } shinyApp(ui, server) } But I would prefer to use reactiveValues() rather than

Reactive WebClient GET Request with text/html response

纵然是瞬间 提交于 2019-12-07 20:58:51
问题 Currently I’m having an issue with new Spring 5 WebClient and I need some help to sort it out. The issue is: I request some url that returns json response with content type text/html;charset=utf-8 . But unfortunately I’m still getting an exception: org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'text/html;charset=utf-8' not supported . So I can’t convert response to DTO. For request I use following code: Flux<SomeDTO> response = WebClient.create("https:/

RxJS not all Subscribers receive all events

Deadly 提交于 2019-12-07 20:03:59
问题 I'm working on an exercise about RxJS. And there's something very strange happening: typoStream.subscribe(x => console.log('wont get executed')); wordCompletedStream.subscribe(nextStream); typoStream.subscribe(x => console.log('will get executed')); When the application runs the first console.log won't get printed and the second one will. Regardless of what the streams are and how they interact - this should never happen, right? Why is it important when I subscribe to an observable - shouldn

How to set and handle timeout in Spring WebClient?

故事扮演 提交于 2019-12-07 17:10:28
Spring docs says it is required to configure http client for WebClient manually to set timeouts: https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux-client-builder-reactor-timeout . But since WebClient returns reactive Mono, it's possible (api-wise) to apply .timeout method. Does it have the same effect? Moreover, when one uses .timeout method, Reactor's TimeoutException is expected. Will the same error appear in the stream if configuration is done manually i.e. will doOnError(TimeoutException.class, ...) work? My findings Setting a timeout in a http