更新或版本控制 Web 服务的策略? [英] Strategies for updating or versioning web services?

查看:13
本文介绍了更新或版本控制 Web 服务的策略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣了解有关如何处理不同版本的 Web 服务的最佳实践.

I'm interested to hear the best practices on how different versions of web services are handled.

澄清一下,如果您将某些 Web 方法公开为 Web 服务,那么您想要添加特性/功能,从而更改这些方法调用的签名,您将如何以一种不会的方式处理此问题?不中断当前调用该服务的所有客户?

To clarify, if you've got some web methods exposed as a web service, then you want to add a feature/functionality and thus change the signature of those method calls, how do you handle this in a manner that doesn't break all of your clients who currently call the service?

您是否在不同的 URL 上部署服务?

Do you deploy the service on a different URL?

您是否在方法名称本身中添加了一个版本(MyMethod、MyMethodv2 等 - 呃..)

Do you put a version in the method name itself (MyMethod, MyMethodv2 etc. - ugh..)

您是否将版本作为方法调用的一部分与参数列表一起传递?

Do you pass in a version as part of the method call along with a parameter list?

有谁知道谷歌或亚马逊如何通过他们广泛的网络服务库来处理这种情况?

Does anyone know how Google or Amazon handle this scenario with their extensive Web Service library?

到目前为止,我在这个 来自 Oracle 的文章.还有 这篇关于某些 Java 细节的博客条目很有用.我仍然很想知道其他一些方法.

So far I found some good info in this article from Oracle. Also this blog entry on some Java specifics was useful. I'm still curious to see some of the other approaches.

推荐答案

对 Web 服务进行版本控制的典型方法是让客户端指定所需的版本.您可以允许简单的约束,例如>2.0"、<1.5"或=1.1".自然地,您希望尽量减少支持的版本数量,以确保您的理智.如果客户未指定版本,则假定为最新版本.

The typical way of versioning a web service is to have clients specify the version desired. You may allow for for simple constraints, like ">2.0", "<1.5", or "=1.1". Naturally, you want to minimize the number of supported versions for your own sanity. If a client doesn't specify a version, you assume the latest.

提供版本的技术各不相同.有些人提倡使用 URL,有些人鼓励使用标头,有些人可能会将其作为 api 调用的参数包含在内.不过,几乎没有人会更改方法的名称.这相当于 OSGi 链接所讨论的包"或命名空间"版本控制.它会使升级变得非常困难,并且比对实际服务进行任何更改更能阻碍人们升级.

Techniques for providing the version vary. Some advocate using the URL, others encourage headers, some might include it as a parameter of the api call. Almost none would change the name of the method, though. Thats equivalent to the "package" or "namespace" versioning the OSGi link talks about. It'll make upgrading very difficult, and impede people from upgrading more so than any changes to the actual service.

这还取决于您访问网络服务的方式.如果您使用 REST,那么保持 URL 干净并使用标头是最有意义的(如果需要,将其作为查询参数进行破解是微不足道的).如果您使用的是 SOAP/XMLRPC/whatever-RPC,那么将它放在 URL 中通常没问题.

It also depends on how you access your webservices. If you're using REST, then keeping the URL's clean and using headers makes the most sense (and it'd be trivial to hack it in as a query parameter, if need be). If you're using SOAP/XMLRPC/whatever-RPC, then putting it in the URL is usually fine.

编辑 5/2011 FWIW,虽然我不同意,Apigee 的博客推荐将版本放在 URL 中.

Edit 5/2011 FWIW, though I disagree, Apigee's blog recommends putting the version in the URL.

客户端如何指定版本通常很简单.更复杂的是如何同时运行所有版本.大多数语言都无法将同一库/模块/类/函数的多个版本加载到同一运行时环境中(无论是 VM、进程还是您拥有的任何东西).您提供的 OSGi 链接是 Java 允许这样做的解决方案.

How the client specifies the version is usually pretty easy. Whats more complicated is how you run all the versions concurrently. Most languages don't have a way of loading multiple versions of the same library/module/class/function into the same runtime environment (be it a VM, process, or what have you). The OSGi link you provided is Java's solution to allow this.

在实践中,OSGi 在大多数情况下都是过大的.将弃用的请求代理到另一个服务器或进程通常更容易.

In practice, OSGi will be overkill for most situations. Its usually easier to proxy deprecated requests to another server or process.

不过,版本化"您的服务的最佳方法是为它们构建可扩展性和灵活性,以便它们保持向前和向后兼容.这并不意味着所有版本都必须相互兼容,而是连续的版本应该相互兼容.

The best way to "version" your services, though, is to build extensibility and flexibility into them so they remain forwards and backwards compatible. That doesn't mean that all versions must be compatible with each other, but consecutive versions should be compatible with each other.

这篇关于更新或版本控制 Web 服务的策略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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