spring-webflux

Spring WebFlux create pool of no-blocking threads

偶尔善良 提交于 2020-01-02 12:49:49
问题 I decided to rewrite my web app on Java(previously it was on Python). In my app I used no-blocking I/O, I had worker pool(Celery + Eventlet threads) where I pass tasks which consists of hundreds of API calls. Now I'm using Spring WebFlux but I can't understand how I can create a workers pool to pass my tasks to that pool, and after get results and do some calculations. (I know about possibility to create ThreadPoolTaskExecutor, but the threads are blocking threads) 回答1: If you're using non

Spring WebFlux create pool of no-blocking threads

你说的曾经没有我的故事 提交于 2020-01-02 12:49:43
问题 I decided to rewrite my web app on Java(previously it was on Python). In my app I used no-blocking I/O, I had worker pool(Celery + Eventlet threads) where I pass tasks which consists of hundreds of API calls. Now I'm using Spring WebFlux but I can't understand how I can create a workers pool to pass my tasks to that pool, and after get results and do some calculations. (I know about possibility to create ThreadPoolTaskExecutor, but the threads are blocking threads) 回答1: If you're using non

RestTemplate vs WebClient benefits in Servlet based web-mvc app

孤人 提交于 2020-01-02 03:18:06
问题 I'm looking for a clarification on the bolded text in the statement below (I've provided the full paragraph for context only): The RestTemplate is not a good fit for use in non-blocking applications, and therefore Spring WebFlux application should always use the WebClient. The WebClient should also be preferred in Spring MVC , in most high concurrency scenarios, and for composing a sequence of remote, inter-dependent calls. Found here: https://docs.spring.io/spring/docs/current/spring

Difference between @Controller and RouterFunction in Spring 5 WebFlux

让人想犯罪 __ 提交于 2020-01-02 01:37:10
问题 There are two ways to expose HTTP endpoints in spring 5 now. @Controller or @RestController by making the controller's class, e.g. @RestController @RequestMapping("persons") public class PersonController { @Autowired private PersonRepo repo; @GetMapping("/{id}") public Mono<Person> personById(@PathVariable String id){ retrun repo.findById(id); } } Route in @Configuration class by using RouterFunctions: @Bean public RouterFunction<ServerResponse> personRoute(PersonRepo repo) { return route(GET

Configure HostnameVerifier with reactor netty for spring-webflux WebClient

瘦欲@ 提交于 2020-01-01 08:35:10
问题 I'm trying to configure spring-webflux WebClient (with reactor netty under the hood) with ssl and client hostname verification. I'm provided with javax.net.ssl.SSLContext, HostnameVerifier and a list of trusted hostnames (as string list). So far I've configured WebClient with my SSLContext, but I can't find a way to configure hostname verification. To state my problem: I have a set of trusted services hostnames (String list) and a HostnameVerifier. I want to configure my WebClient with it. Is

Get HandlerMethod from WebFilter in WebFlux

耗尽温柔 提交于 2019-12-31 05:03:31
问题 When implementing interceptor with Servlet API I got HandlerMethod out of the box: ... extends HandlerInterceptorAdapter @Override public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handlerMethod) throws Exception { Can I get access to HandlerMethod while implementing WebFilter instead of HandlerInterceptorAdapter ? In case of WebFilter I have: ... implements WebFilter { public Mono<Void> filter(ServerWebExchange serverWebExchange,

How to redirect a request in spring webflux?

穿精又带淫゛_ 提交于 2019-12-31 02:19:06
问题 how can I create a redirect rest web service in spring WebFlux? It seems that there is no redirect functionality in WebFlux yet! I want something like this: @Bean RouterFunction<ServerResponse> monoRouterFunction() { return route(GET("/redirect/{id}"),{ req -> req.Redirect( fetchAUrlFromDataBase() ) }) 回答1: @Bean RouterFunction<ServerResponse> routerFunction() { route(GET("/redirect"), { req -> ServerResponse.temporaryRedirect(URI.create(TargetUrl)) .build() } }) } Thanks you very much Johan

Reactive WebClient not emitting a response

时光怂恿深爱的人放手 提交于 2019-12-29 06:51:49
问题 I have a question about Spring Reactive WebClient... Few days ago I decided to play with the new reactive stuff in Spring Framework and I made one small project for scraping data only for personal purposes. (making multiple requests to one webpage and combining the results). I started using the new reactive WebClient for making requests but the problem I found is that the client not emitting response for every request. Sounds strange. Here is what I did for fetching data: private Mono<String>

Spring Boot 2.0 disable default security

我是研究僧i 提交于 2019-12-28 05:14:06
问题 I want to use Spring Security for JWT authentication. But it comes with default authentication. I am trying to disable it, but the old approach of doing this - disabling it through application.properties - is deprecated in 2.0. This is what I tried: @Configuration public class StackWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.httpBasic().disable(); // http.authorizeRequests().anyRequest()

how to log Spring 5 WebClient call

大城市里の小女人 提交于 2019-12-28 02:51:09
问题 I'm trying to log a request using Spring 5 WebClient. Do you have any idea how could I achieve that? (I'm using Spring 5 and Spring boot 2) The code looks like this at the moment: try { return webClient.get().uri(url, urlParams).exchange().flatMap(response -> response.bodyToMono(Test.class)) .map(test -> xxx.set(test)); } catch (RestClientException e) { log.error("Cannot get counter from opus", e); throw e; } 回答1: You can easily do it using ExchangeFilterFunction Just add the custom