REST 中基于事件的交互风格 [英] Event Based interaction style in REST

查看:28
本文介绍了REST 中基于事件的交互风格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在努力解决一个涉及 REST 的设计问题.我正在设计的应用程序需要发送事件并支持发布/订阅风格的交互.我无法在不打破 REST 的无状态交互"约束的情况下设计出提供这些交互风格的设计.我并不像某些人那样反对投票(投票很糟糕),但我的应用程序需要基于事件和发布/订阅风格的交互(投票不是我的选择).所以,我的问题是:

I am currently struggling with a design issue involving REST. The application I am designing has a requirement to send out events and also support pub/sub style of interaction. I am unable to come up with a design to provide these interaction style without breaking the REST’s "Stateless interaction" constraint. I am not against polling as some people seem to be (polling sucks) , but my application demands a event based and pub/sub style of interaction (polling is not an option for me). So, my question is:

  1. 我可以设计一个支持基于事件和发布/订阅交互的 RESTful 应用程序而不破坏 REST 约束吗?
  2. REST 风格是否适合这种交互风格?

推荐答案

我推荐 Distributed Observer Pattern 由 Duncan Cragg 撰写,值得一读(有点难以理解,但值得努力).

I'd recommend the Distributed Observer Pattern by Duncan Cragg as a good read (bit difficult to grok but worth the effort).

正如其他人指出的那样,您可能需要使用轮询,但正如您所说,订阅者可以注册自己的兴趣(POST 以创建订阅).如果您将订阅视为自己的资源,即发布者和订阅者之间的合同,那么我不会将其视为破坏 REST 约束(请参阅 <第 217 页的状态和无状态)一个 href="https://rads.stackoverflow.com/amzn/click/com/0596529260" rel="noreferrer" rel="nofollow noreferrer">RESTful Web Services 应用之间的区别和资源状态)

As others have indicated its likely you'll need to use polling but as you rightly say subscribers could register their own interest (POST to create subscription). If you view the subscription as its own resource, a contract between the publisher and subscriber, then I wouldn't view it as a breaking REST constraints (see State and Statelessness at page 217 of RESTful Web Services for the difference between application and resource state)

这篇关于REST 中基于事件的交互风格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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