spring-webflux

Cannot use 'subscribe' or 'subscribeWith' with 'ReactorNettyWebSocketClient' in Kotlin

穿精又带淫゛_ 提交于 2019-12-13 03:35:14
问题 The Kotlin code below successfully connects to a Spring WebFlux server, sends a message and prints each message sent via the stream that is returned. fun main(args: Array<String>) { val uri = URI("ws://localhost:8080/myservice") val client = ReactorNettyWebSocketClient() val input = Flux.just(readMsg()) client.execute(uri) { session -> session.send(input.map(session::textMessage)) .thenMany( session.receive() .map(WebSocketMessage::getPayloadAsText) .doOnNext(::println) // want to replace

How to deploy Spring Cloud Gateway 2.1 on Jboss or Tomcat?

…衆ロ難τιáo~ 提交于 2019-12-13 03:06:02
问题 I want to a deploy Spring Cloud Gateway but it is built on Spring Framework 5, Project Reactor. Can I create a WAR file and deploy it on a traditional application server such as Jboss or Tomcat. The Spring documentation in this page says it is possible. Spring WebFlux is supported on Tomcat, Jetty, Servlet 3.1+ containers Note: this is Spring Cloud Gateway project link https://spring.io/projects/spring-cloud-gateway 回答1: I don't think this is possible, as Spring Cloud Gateway is itself a

Netty Server isn't used in Spring Boot 2 with Reactive starter

二次信任 提交于 2019-12-13 03:05:45
问题 I'm developing a reactive project using Spring Boot 2 and reactive starters. My problem is that when I start the app, the Tomcat server it's started instead of Netty. Here is my dependencies task from build.gradle file: dependencies { compile("org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}") compile("org.springframework.boot:spring-boot-starter-webflux:${springBootVersion}") compile("org.springframework.boot:spring-boot-starter-hateoas:${springBootVersion}")

SpringBoot Webflux cannot return application/xml

≡放荡痞女 提交于 2019-12-13 01:09:21
问题 In my reactive REST API I'm trying to return an XML response. However, I always get a JSON , namely 406 NOT_ACCEPTABLE . Any idea why? @RestController @RequestMapping(path = "/xml", produces = APPLICATION_XML_VALUE) public class RestApi { @GetMapping(path = "/get") public Publisher<ResponseEntity> get() { return Mono.just(ResponseEntity.ok().contentType(APPLICATION_XML).body(new Datta("test"))); } @PostMapping(path = "/post", consumes = APPLICATION_XML_VALUE) public Publisher<ResponseEntity

Backpressure for REST endpoints with Spring Functional Web Framework

家住魔仙堡 提交于 2019-12-12 23:33:22
问题 If I understood correctly, HTTP endpoints implemented with Akka Streams apply backpressure to HTTP clients by not reading from the socket used for communicating with the client. Is this also true for HTTP endpoints implemented with Spring's Functional Web Framework? If not, how would I signal HTTP clients to slow down? 回答1: Yes, Spring 5, with its Web Reactive module, implements the reactive streams spec with Reactor. Supporting backpressure is part of it. Note that both the annotation-based

Spring Webflux and Observable responses not working

走远了吗. 提交于 2019-12-12 18:17:33
问题 I just created a simple Spring Boot application using spring-boot-starter-webflux with version 2.0.0.BUILD-SNAPSHOT which brings spring-webflux version 5.0.0.BUILD-SNAPSHOT and same for Spring Core, Beans, Context, etc. If I create a simple @RestController and provide a @GetMapping that simply returns a Flux<String> , then everything works as expected. However, if I change from Flux to RxJava's Observable , I get this error: org.springframework.web.HttpMediaTypeNotAcceptableException: Could

HTTP Response Exception Handling in Spring 5 Reactive

心不动则不痛 提交于 2019-12-12 13:19:27
问题 I'm developing some reactive microservices using Spring Boot 2 and Spring 5 with WebFlux reactive starter. I'm facing the following problem: I want to handle all HTTP Statuses that I receive from calling another REST Services and throws an exception when I receive some bad HTTP Status. For example, when I call an endpoint and I receive an 404 HTTP Status, I want to throw an exception and that exception to be handled in some ExceptionHandler class, just like the way it was in Spring 4 with

WebFlux functional: How to detect an empty Flux and return 404?

情到浓时终转凉″ 提交于 2019-12-12 07:58:25
问题 I'm having the following simplified handler function (Spring WebFlux and the functional API using Kotlin). However, I need a hint how to detect an empty Flux and then use noContent() for 404, when the Flux is empty. fun findByLastname(request: ServerRequest): Mono<ServerResponse> { val lastnameOpt = request.queryParam("lastname") val customerFlux = if (lastnameOpt.isPresent) { service.findByLastname(lastnameOpt.get()) } else { service.findAll() } // How can I detect an empty Flux and then

How can I support an HTTP Proxy using Spring 5 WebClient?

﹥>﹥吖頭↗ 提交于 2019-12-12 07:48:44
问题 I am using Spring 5 WebClient. I want to know if it is possible to configure it to use an HTTP Proxy, or if there is a way of changing it's default configuration to do so. 回答1: This is something that the underlying client library should support. When using Reactor Netty, you can do something like: HttpClient httpClient = HttpClient.create() .tcpConfiguration(tcpClient -> tcpClient.proxy(proxy -> proxy.type(ProxyProvider.Proxy.HTTP).host("myproxyhost"))); ReactorClientHttpConnector connector =

Calling Micro-service using WebClient Sprint 5 reactor web

Deadly 提交于 2019-12-12 04:23:59
问题 I am calling a micro-service in my rest controller. It works fine when ever there is a successful response from the Micro-service but if there is some error response I fails to pass on the error response back to user. Below is the sample code. @GetMapping("/{id}/users/all") public Mono<Employee> findAllProfiles(@PathVariable("id") UUID organisationId, @RequestHeader(name = "Authorization", required = false) String oauthJwt) { return webClient.get().uri(prepareUrl("{id}/users/all"),