Commit 44e36a5b authored by Bhanuchander Pathuri's avatar Bhanuchander Pathuri

improved the code by using webclient and scheuler

parent 4e161a31
package com.nisum.poc.Webflux.config;
import com.nisum.poc.Webflux.entity.Address;
import com.nisum.poc.Webflux.entity.Student;
import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketClientCompressionHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@Configuration
@EnableScheduling
@Slf4j
public class WebclientEx {
WebClient client = WebClient.create("http://localhost:4042");
public Flux<Student> getAllStudents(){
return client.get().uri("/allStudents").accept(MediaType.APPLICATION_JSON).retrieve().bodyToFlux(Student.class);
@Scheduled(initialDelay = 1000,fixedDelay = 2000)
public void getAllStudents(){
log.info("----------------------------------in scheduler method--------------------------------");
WebClient client = WebClient.create("http://localhost:4042");
Flux<Address> studentFlux = client.get().uri("/alladdress").accept(MediaType.TEXT_EVENT_STREAM).retrieve().bodyToFlux(Address.class);
studentFlux.filter(a -> a.getCity().equalsIgnoreCase("hyd")).subscribe(a -> System.out.println(a.toString()));
//return studentFlux;
}
}
......@@ -24,7 +24,6 @@ public class AddressController {
@PostMapping("/saveaddress")
public Mono<Address> createAddress(@RequestBody AddressPayload addressPayload){
return addressService.createAddress(addressPayload);
}
@GetMapping("/alladdress")
......
......@@ -13,6 +13,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
@Getter
@Document
@Builder
@ToString
//@Scope(scopeName="request",proxyMode = ScopedProxyMode.TARGET_CLASS)
public class Address {
......
db.name=StudentDatabase
db.host=mongodb://localhost:27017
server.port=4042
spring.profiles.active=local
\ No newline at end of file
#spring.profiles.active=local
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment