SSEemitter vs Flux in spring boot - spring-boot

I am having confusion between the SSEemitter and flux in spring Boot for sending one way asynchronous message to the client.
Want to know the use cases for both the terms with respect to Spring boot

One is using reactive/Flux and another is not. Here SSEemitter based implementation. You don't need reactive background. Reactive can take some time to understand if you haven't done it earlier.

Related

Clear difference between spring web and spring web flux

I know this question has been asked a lot but i'm not able to find a CLEAR answer to my question.
The main difference i see between spring web and spring web flux is the use of Mono and Flux and ReactiveRepository. My question is : What is the difference ? (other than a syntax difference). I assume everything is different in the background but do we see these differences? Can we make something with flux that we cannot make with web mvc ?
I made a simple spring boot application using flux (playing with mono and flux) but only the syntax change, for me, i don't see any differences.
Thanks :)
Spring Reactive Gives the overview of WebFlux and Webflux is for asynchronous reactive programming & implements the Reactive Stream specification and webflux is for NIO uses cases.

SpringBoot FeignClient vs WebClient

I want to consume a couple of rest services. Before I have used RestTemplate, but now I want to know What is main diffrences of SpringBoot FeignClient and WebClient?
when they should be used?
To be able to answer “when” one needs to understand the capabilities of each.
Spring WebClient is a non-blocking reactive client to make HTTP requests. Hence if you intend to use Spring Reactive Stream API to stream data asynchronously then this is the way to go. Think event-driven architecture. WebClient is part of the Spring WebFlux library.
[Feign]3 is a declarative REST library that uses annotations based architecture with thread-per-request model. This means that the thread will block until the feign client receives the response. The problem with the blocking code is it must wait until the consuming thread completes, hence think memory and CPU cycles.
So use Spring WebClient when needing non-blocking HTTP requests otherwise Feign due to simple usage model.
(Note: There is no reason as to why one cannot use WebClient for blocking operations but Feign is more mature and it’s annotation based model makes it easier)
The main difference is that WebClient supports Reactive calls.
You can achieve that with 3rd party feign clients like https://github.com/Playtika/feign-reactive but basically for a reactive way you should consider using WebClient with some neat async connector like Jetty. On the other hand, If you want a blocking way with minimal hassle then Feign could be your best choice.
WebClient is a non-blocking reactive.
Feign is blocking.

Spring boot reactive WebClient calling legacy endpoint

In a Spring Boot (2.2.2.RELEASE) application, I have reactive endpoints (returning Mono or Flux), each of them is using reactive WebClient for calling another service. This "other" service is legacy (non-reactive) one.
Here is my question:
Is there a benefit of using Webflux (reactive WebClient) if my reactive endpoint is calling this non-reactive endpoint which does blocking stuff?
Is my reactive endpoint still reactive?
If we're talking about HTTP endpoints, we can call them with blocking or non-blocking (asynchronous) clients, but not fully reactive.
If your "new" application is reactive, you have to use non-blocking client (WebClient in your case), otherwise you will block NIO-threads and loose all the advantages of the reactive approach. The fact that the “other” application is blocking doesn't matter, you can still get a less resource-intensive "new" application.
They are
1. Not fully.
2. Your request is not full reactive until you change legacy APIs
Explanation:
End-to-End Reactive pattern only help into to the performance side
Currently you’re using reactive client this helps to connect to server in two way communication.
First set of APIs are reactive so web server layer is now reactive but data layer (Legacy APIs ) not reactive

Spring boot Kafka messaging. How to use SpEL to manage handler access

I'm using Kafka in Spring Boot project. There are a lot of benefits in case you have simple flow (to use #KafkaListener, #KafkaHandler) and spring prepares almost everything for development.
In my application I have different handlers for the same message data. I want to use SpEL to manage handlers manipulating header data, but I've not detected corresponding API for that.
So my question: is it possible to manage my handlers via SpEL in case I have special headers for that (Header for example "X-OPERATION_TYPE":"patch")? How?
P.S.
I can make workarounds using GoF Strategy as example, but I hope spring already has solution for that case.
There is not such a "conditional routing" in Spring for Apache Kafka, but you can do that routing manually in the single #KafkaListener with plain if...else or switch.
For more comprehensive routing logic it would be better to take a look into Spring Integration: https://docs.spring.io/spring-integration/docs/5.0.9.RELEASE/reference/html/messaging-routing-chapter.html

Consuming CometD messages with spring webflux

We have a system which publishes messages via cometD.
I wrote a simple java program to establish a connection to the server
then use the bearer token returned from the login to and consume messages
But I want to move this to a Webflux project, but unsure where to start, I can see there is out of box JMS-webflux wrapper, can I use this or is it best to build something similar ?
I'm very new to cometD and have only used simple webflux components,
I can also just use Spring boot, but ideally just like a JmsReceiver or similar
Thanks

Resources