Spring Boot 2 & Spring 5 Container confusion

2019-09-16 19:21发布

问题:

I have a Spring boot 1.4.3 project. Recently I have come up with a requirement where I have to send logs from server to my web application and print the logs on the web page. I am aware of WebSockets but I was looking for better solutions and I came across, Reactive Programming and gRPC.

Spring is supporting Reactive Programming in Spring version 5, but I am quite confused between gRPC and Reactive Programming. gRPC features Bi-Directional streaming which is built on top of Netty and provides the same facility as pushing data from the server to clients like Reactive Programming. So which one should I use, If you can clear me on this confusion it would be really great.

Also, If I move to Spring Boot 2 which supports Spring Version 5, the project will be running on Netty. My confusion is, do I have to run my application on different containers like for normal REST endpoints on Jetty server and for Reactive API on netty server or Spring will handle this for me out of the box by handling reactive requests on netty and remaining general REST API on the jetty server, because as far as I know Netty is not a Servlet Container.

回答1:

One key feature of reactive programming is back pressure, and back pressure that's implemented in a non-blocking manner. At the time of writing, gRPC doesn't support this.

There's also much more to reactive programming than the communication between a client and a server. To be truly reactive, you need to be reactive from end to end. This includes reactive access to your data store, etc. As far as I know, this isn't something that's tackled by gRPC.

You shouldn't try to mix the use of a traditional Servlet-based web framework (such as Spring MVC) with use of WebFlux (Spring's reactive web framework). You should either write a 100% reactive web application or a 100% Servlet-based web application.