wso2 - 处理程序和序列 [英] wso2 - handlers and sequence

查看:35
本文介绍了wso2 - 处理程序和序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 WSO2 api manager,handlers 和 sequence 有什么区别或关系.

For WSO2 api manager, what is the difference or relation between handlers and sequence.

我想为每个 api 设置一些要遵循的条件.根据条件,它将检查 api 请求是否已通过条件.如果我需要使用序列或处理程序,我不确定这一点.

I want to put some conditions for each api to follow. Based on condition it will check if api request has passed the condition or not. I am not sure for this if I need to use sequence or handlers.

推荐答案

这个答案假设用户所说的序列"是指中介序列",它通过 APIManagerExtensionHandler 处理程序运行(中介可以是全局的或每个 API,但据我所知,它是在同一个地方执行的).

This answer assumes that by "sequence" the user means "mediation sequence," which are run via the APIManagerExtensionHandler handler (mediation can be global or per-API, but to the best of my knowledge it is executed in the same place).

中介序列和处理程序都是在网关收到响应或请求后运行的代码扩展.处理程序扩展了 org.apache.synapse.rest.AbstractHandler 类,需要实现 AbstractHandler.handleRequestAbstractHandler.handleResponse;中介者扩展了 org.apache.synapse.mediators.AbstractMediator 类并且需要实现 AbstractMediator.mediate.

Both mediation sequences and handlers are code extensions that run after the gateway receives a response or request. Handlers extend the org.apache.synapse.rest.AbstractHandlerclass, requiring implementation of AbstractHandler.handleRequest and AbstractHandler.handleResponse; mediators extend org.apache.synapse.mediators.AbstractMediator class and require implementing AbstractMediator.mediate.

自定义处理程序和中介序列之间的主要区别在于,使用自定义处理程序需要您编写自己的 Java 类,然后打包和部署您的处理程序.如果使用预定义的中介器(由 WSO2 的 ESB 提供)的组合可以满足您的要求,那么您可以编写一个 XML 序列来定义中介任务,而无需新代码.

The primary difference between a custom handler and a mediation sequence is that using a custom handler requires you to write your own Java class, then package and deploy your handler. If your requirements can be satisfied with a combination of predefined mediators (provided by WSO2's ESB) then you can write an XML sequence to define the mediation tasks, with no new code needed.

根据我的经验,以下是处理程序和中介序列之间的主要区别.应根据您的具体要求确定使用其中一种.

In my experience, here are the primary differences between handlers and mediation sequences. Using one over the other should be determined by your specific requirements.

处理程序

  • 严格来说是每个 API",但可以通过包含在 velocity-template.xml 文件中将它们添加到每个 API.
  • 可以相对于其他处理程序以任何顺序执行.
  • 除了在 API 定义序列中包含处理程序外,不需要序列.所有任务都必须包含在 Java 代码中.

中介序列

  • 可以配置为全局或特定于 API.
  • 可以相对于其他中介序列以任何顺序执行,但不能在其他处理程序之前进行中介,除非所有其他中介也这样做(除非您编写自定义中介处理程序).
  • 允许您调用 XML 树中的其他预定义调解器来描述调解任务.除非预定义的中介器(由 WSO2 的 ESB 提供)不能满足您的要求,否则您无需编写任何自定义代码.
  • Can be configured to be global or API specific.
  • Can be executed in any order with respect to other mediation sequences, but cannot mediate before other handlers unless all other mediators also do so (unless you write a custom mediation handler).
  • Allow you to invoke other predefined mediators within an XML tree to describe the mediation tasks. Unless the predefined mediators (provided by WSO2's ESB) do not satisfy your requirements, you won't have to write any custom code.

简而言之:如果现有中介的某种组合将实现您的目标,则使用中介序列最有意义(即使是接近但不完全"的情况,编写自定义中介比创建完全新处理程序).如果您需要更高级别的自定义或需要在执行所有 其他中介之前或之后进行中介,则应考虑编写处理程序.

In short: if some combination of existing mediators will achieve your goal, using mediation sequences makes the most sense (even if it's a case of "close, but not quite," writing a custom mediator can be easier than creating an entirely new handler). If you require an increased level of customization or require mediation to occur before or after all other mediation is executed, you should consider writing a handler.

实际回答特定问题:您可以相当轻松地使用中介序列对请求标头中的值进行逻辑检查.如果您需要读取正文内容,这些检查会变得有点困难……在这种情况下,自定义处理程序基本上是您唯一的选择.

to actually answer the specific question: you can do logical checks of values in request headers using a mediation sequence fairly easily. These checks become a bit more difficult to do if you need to read body content... in which case a custom handler is essentially your only option.

这篇关于wso2 - 处理程序和序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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