本文介绍了将JaxRS REST服务与WebSocket集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在尝试开发一种实现发布者-订阅模式的社交网络(类似于Twitter的做法):用户可以关注人们,因此在发送其关注者的新出版物时会收到通知.

I'm attempting to develop a social network that implements publisher-subscribe pattern (kind of like Twitter does): users can follow people, therefore being notified when a new publication of their followers is sent.

我现在所拥有的就是通过JaxRS实现的可运行的REST服务,它在Tomcat 7上运行,提供用于登录,注册,获取配置文件数据和提交帖子的服务. Servlet映射是通过web.xml完成​​的

All I have now is a working REST service implemented with JaxRS, running over Tomcat 7, offering services for login, register, getting profiles data and submitting posts. Servlet Mapping is done via web.xml

我的JaxRS应用配置

RestServices

Web.xml

但是应用程序的权重来自pubsub部分.这就是事情变得混乱的地方.

But the weight of the application comes from the pubsub part. And here is where things become messy.

在谈论技术和实现之前,此发布订阅的生命周期:

Before speaking of technologies and implementation, the life cycle of this pubsub:

让A和B成为该应用程序的某些用户,而A跟随(订阅)B.

Let be A and B some users of the app and A follows (is subscribed to) B.

  1. A导航到他的时间轴",因此在服务器上注册了WebSocket端点,当他被邀请发布任何内容的人发布消息时,他将从该WebSocket端点接收通知. (A,他本人会是这个话题?)
  2. B发布了新帖子,并通过HTTP POST/post发送到JaxRS服务.
  3. 服务器将出版物存储在数据库中,然后通过WebSocket将其发送给侦听订户.由于A还活着并且正在聆听,因此通过他的WebSocket/topic发送出版物.
  4. A收到有关新出版物的通知.

我已经使用Java内置WebSockets(javax.websocket),Spring websockets(通过STOMP)和JavaScript内置了SockJS.我知道JaxRS有一个称为服务器发送事件"的东西,其作用类似于websockets,但是我对如何初始化和使用它们完全迷失了.

I've worked with Java built-in WebSockets (javax.websocket), Spring websockets (via STOMP) and JavaScript either built-in and SockJS. I know JaxRS has something called Server Sent Events that act like websockets but I'm absolutely lost on how to initialize and work with them.

我的疑问:

1)我可以将Spring Websockets与我的JaxRS服务器混合",如何对其进行初始化?

1) Could I "mix" e.g Spring Websockets with my JaxRS server and how would it be initialized?

2)使用JaxRS和SSE,我可以在服务器上动态创建WS端点吗?

2) With JaxRS and SSE, can I dynamically create WS endpoints on the server?

预先感谢

推荐答案

最后使用泽西岛的服务器发送事件进行了变通,尽管IE不支持,但可以满足我的需要

Finally made a workaround using Jersey's Server Sent Events, though not supported by IE, but works for what I needed

这是 SSEProvider 和 SSEDispatcher

等级依赖性

前端连接处理程序

HTML5 SSE

这篇关于将JaxRS REST服务与WebSocket集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 23:25