带有Java和观察者模式的Jersey的RESTful Web服务 [英] RESTful Webservice with Jersey in Java and observer pattern

查看:128
本文介绍了带有Java和观察者模式的Jersey的RESTful Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为学校项目实施n层体系结构应用程序. 客户端和服务器之间的通信是通过RESTful Web服务完成的. 我使用 Jersey Java 中实现了这一点.我唯一的问题是,如何在服务器上注册客户端以接收更改通知(例如通常使用观察者模式或侦听/发布模式来完成).我是否还需要在客户端实施服务,然后注册要由服务器调用的URL,然后在发生更改时调用这些URL?

I'm trying to implement an n-tier architecture application for a school project. The communication between the clients and the server is done with a RESTful Webservice. I Used Jersey to implement this in Java. The only question I have is, how to register the clients at the server to receive notification of changes (like normally done with the observer pattern or listen/publish pattern). Do i need to implement a service on the client side aswell and then register the URL to be called by the server and then call these URLs when changes occur?

感谢您的帮助!

推荐答案

通常,在基于http的 client-server 方案中,服务器总是响应请求.服务器无法在没有客户端请求的情况下发送任何内容(通知).但是在某些情况下,服务器会在没有客户端请求的情况下将数据推送到客户端,因此 服务器推送 出现了.

Typically, in http based client-server scheme, server always responds to a request. There is no way server can send anything (notification) without client request it. But there are use cases for server pushing the data to client without client requesting and hence Server-Push came into picture.

泽西岛 的形式提供服务器推送服务器发送的事件(SSE) .该文档说,

Jersey provides Server Push in the form of Server-Sent Events (SSE). The documentation says,

服务器发送事件(SSE)是一种允许服务器执行以下操作的机制: 一旦 客户端与服务器之间的连接是由客户端建立的

Server-Sent Events (SSE) is a mechanism that allows server to asynchronously push the data from the server to the client once the client-server connection is established by the client

请注意,客户端需要先先建立与服务器的连接.您可以将第一个客户请求称为注册.建立连接后,服务器可以向客户端发送/推送数据.链接的提及内容也有一个工作示例.

Please note that the client needs to establish connection with the server first. You might call that first client request as Registration. Once the connection is established, the server can send/push data to client. The linked mention also has a working example as well.

这篇关于带有Java和观察者模式的Jersey的RESTful Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆