使用Spring Boot优选的方法将JavaFX与Stomp Websocket客户端集成的替代方式

huangapple go评论76阅读模式
英文:

Alternative way to integrate JavaFX with a Stomp Websocket Client, preferably Spring Boot

问题

我正在开发一个使用JavaFX应用程序(Gradle,Intellij)的应用,通过WebSocket连接到应用服务器远程执行一些操作。服务器使用Spring Boot开发,并作为STOMP WebSocket实现。客户端部分应该以某种方式集成到现有的JavaFX应用程序中。

JavaFX和Spring Boot的集成有很好的文档。这篇帖子在Stackoverflow上不是太新,但Spring博客中也有这篇文章,还有一些其他基于相同思想的材料,比如:samydavic博客,这个GitHub项目这篇帖子来自同一人。所提出的解决方案非常优雅,但实际上将JavaFX应用程序更改为Spring Boot应用程序,对我正在开发的应用程序来说可能过于复杂,基本上是向服务器发送一个JSON对象并接收另一个作为响应。有一些有用的工具,比如FxWeaverspring-boot-starter-javafx,但它们都需要额外的依赖项和更多的处理。

我的问题是:是否可以推荐任何替代解决方案,以便让我的现有JavaFX应用程序添加一个简单的STOMP WebSocket客户端(如果有的话)?

我正在考虑的一个选项是使用Spring Boot WebSocket客户端,并通过TCP套接字将其连接到JavaFX应用程序(因为它们都在同一台计算机上运行),这非常容易实现;WebSocket客户端将作为JavaFX应用程序的消息代理。

英文:

I am developing a JavaFX application (Gradle, Intellij) that performs some operations remotely by connecting to an application server via WebSocket. The server is developed using Spring Boot and implemented as a STOMP WebSocket. The client part shall be somehow integrated into the existing JavaFX application.
The integration of JavaFX and Spring Boot has good documentation. This post on Stackoverflow is not too recent, but there is this post on Spring blog, but also some other material based on the same idea like: samydavic blog, this project on GitHub and this post from the same person. The solution presented is very elegant but actually changes the JavaFX application to a Spring Boot application and looks too complex for the kind of application I am developing, which basically sends a json object to the server and receives another one as response. There are some useful tools like FxWeaver, spring-boot-starter-javafx but again, the are additional dependencies and more stuff to handle.

My question is: what alternative solution can be recommended (if any) to let my existing JavaFX application to have a simple stomp websocket client added?

An option which I am considering is to have a Spring Boot websocket client and to have it connected to the JavaFX application via a socket over TCP (since they will both run on the same machine) which is very easy to implement; the websocket client would work as a message broker for JavaFx application.

答案1

得分: 2

这是主观的,所以这是一个观点,没有真正的对错答案。

如果不想要第三方的东西,比如fxweaver、spring-boot-starter-javafx,你可以直接集成JavaFX和Spring Boot。一旦完成,你可以使用Spring Boot的适当启动项目作为依赖项来添加你需要的功能。

如果你只想使用原始的WebSocket,那么根本不需要Spring,因为WebSocket客户端的功能在JDK中

使用原生WebSocket似乎很简单,但可能比你预期的要棘手,因为它是一个没有定义消息协议的低级系统。如果你确实想要使用stomp代替WebSocket,可能不会特别复杂,不过无论哪种方式都会有一定的学习曲线。

英文:

This is subjective, so it is an opinion, there is not really a right or wrong answer.

You don't need 3rd party things like fxweaver, spring-boot-starter-javafx if you don't want them. You can integrate JavaFX and spring boot directly. Once that is done you can use the appropriate starter projects from spring boot as dependencies to add the functionality you need.

If you just want to use raw web sockets, you don't need spring at all, as the functionality for websocket clients is in the JDK.

Working with native web sockets seems simple but can be trickier than you expect because it is a low-level system without a defined protocol for messaging. If you do want to use stomp over websockets instead, it may not be overly complex, though there is a learning curve either way.

huangapple
  • 本文由 发表于 2023年2月24日 05:52:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75550700.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定