Netty websocket和Rest在同一Java应用程序中 [英] Netty websocket and Rest in same Java application
问题描述
我有一个现有的Java应用程序,它正在公开REST服务.我想在同一个应用程序中添加一个新功能,以处理Web套接字请求(使用netty)以及现有的REST服务.如何在不更改REST服务的情况下做到这一点?
I have an exisiting Java application which is exposing REST services. I want to add a new feature in the same application to handle web socket requests (using netty) along with the exisiting REST services. How can I do that without changing my REST services?
推荐答案
有两种方法可以在不更改REST服务的情况下进行操作:
There are two ways to do this without changing your REST service:
-
我建议您设置一个普通的netty websocket服务器,并在另一个端口上并行运行它(这可能在同一应用程序中发生).
I would suggest you setup a normal netty websocket server and run it parallel on another port (this can happen in the same application).
一个更复杂,效率低下的解决方案是编写一个netty http/websocket服务器,该服务器在默认端口(80/443)上运行并将所有REST请求发送到您的REST服务.因此,基本上,您将编写一种同时托管websocket服务器的HTTP代理(也可能在同一应用程序中发生).
A more complicated an inefficient solution would be to write a netty http/websocket server which runs on the default port (80/443) and sends all REST requests to your REST service. So basically you would write a sort of HTTP proxy which also hosts the websocket server (could also happen in the same application).
此处是如何编写Netty WebSocket服务器的示例.
Here is an example of how to write a netty websocket server.
这篇关于Netty websocket和Rest在同一Java应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!