$ ping bitbucket.org
PING bitbucket.org (18.234.32.156) 56(84) bytes of data.
^C
--- bitbucket.org ping statistics ---
5 packets transmitted, 0 received, 100% packet loss, time 4090ms
$ wget bitbucket.org
--2023-06-01 12:24:23-- http://bitbucket.org/
Resolving bitbucket.org (bitbucket.org)... 18.234.32.155, 18.234.32.157, 18.234.32.156, ...
Connecting to bitbucket.org (bitbucket.org)|18.234.32.155|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://bitbucket.org/ [following]
--2023-06-01 12:24:24-- https://bitbucket.org/
Connecting to bitbucket.org (bitbucket.org)|18.234.32.155|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 117240 (114K) [text/html]
Saving to: ‘index.html’
index.html 100%[=======================================================================================================================>] 114,49K 318KB/s in 0,4s
2023-06-01 12:24:25 (318 KB/s) - ‘index.html’ saved [117240/117240]
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import java.time.Duration;
import java.util.stream.IntStream;
@Slf4j
@RequiredArgsConstructor
@RestController
public class WebFluxDemo {
private final ObjectMapper objectMapper;
@GetMapping("/getMyObjs")
Flux<MyObj> getMyObjs() {
return Flux.fromStream(IntStream.range(1, 6).boxed()
.map(String::valueOf)
)
.map(MyObj::new)
.delayElements(Duration.ofSeconds(1))
.log()
;
}
@GetMapping("/getMyObjsAsString")
Flux<String> getMyObjsAsString() {
return Flux.fromStream(IntStream.range(1, 6).boxed()
.map(String::valueOf))
.map(MyObj::new)
.map(this::mapToObj)
.delayElements(Duration.ofSeconds(1))
.log()
;
}
@SneakyThrows
private String mapToObj(MyObj myObj) {
return objectMapper.writeValueAsString(myObj);
}
private record MyObj(String id) {
}
}