如何在每个任务调用之间保留属性值

编程入门 行业动态 更新时间:2024-10-24 16:27:27
本文介绍了如何在每个任务调用之间保留属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用 WSO2 ESB 调度任务从外部系统获取数据,该任务每 5 秒调用一次我的代理服务.在我的代理服务中,我使用了属性名称startTime"和endTime",这意味着我想从startTime"获取数据到endTime".startTime"和endTime"应该在每次任务调用时增加 5 秒.但似乎 ESB 无法在每个任务调用之间存储这些属性(startTime 和 endTime).我尝试使用脚本编写startTime":

I used WSO2 ESB schedule task to fetch data from external system, the task call my proxy service every 5 seconds. In my proxy service, I used a property name "startTime" and "endTime", it means I want to fetch data from "startTime" to "endTime". "startTime" and "endTime" should be increase 5 seconds every task call. But it seems ESB cannot store these properties(startTime and endTime) between every task call. I try to use the script to write the "startTime" :

importPackage(Packages.apache.synapse.config); var id = mc.getProperty("id"); var res = "conf/data_task/"+id ; var startTimeInReg = mc.getProperty("_endTime"); mc.getConfiguration().getRegistry().updateResource(res+"/startTime", startTimeInReg.toString());

得到它

<property expression="get-property('registry', fn:concat('conf/data_task/',get-property('id'),'/startTime'))" name="startTimeInReg" scope="default" type="STRING"/>

我可以得到startTime",但它的值保持不变,我发现在 2 或 3 次调度任务调用之后(可能超过 15 秒),startTime 的值发生了变化.

I can get the "startTime", but it remain the same value , and I found that after 2 or 3 times schedule task call ( maybe elaps more than 15s ), the value of startTime change.

我认为这可能是由 ESB 缓存引起的,如何在调用 updateResource 方法后立即提交 startTime 值的更改.或者如何解决这个问题.

I think this maybe caused by ESB caching , how I can commit the changing of the startTime value immediately after updateResource method called. Or how can solve this issue.

推荐答案

尝试将您的价值保存在治理注册表中:

Try to save your value in the governance registry :

mc.getConfiguration().getRegistry().newResource("gov:/trunk/test/MyCounter.txt",false); // create the resource the 1st time, does nothing the others mc.getConfiguration().getRegistry().updateResource("gov:/trunk/test/MyCounter.txt", startTimeInReg.toString());

另一种解决方案,看看这个创建全局"计数器(在 ESB 重新启动时丢失)的示例:

An other solution, have a look at this sample that create a "global" counter (lost when the ESB is restarted) :

<script language="js"><![CDATA[ var curValue = mc.getEnvironment().getServerContextInformation().getProperty("MyCounter"); if (curValue == null) { curValue = 0; } else { curValue++; } mc.getEnvironment().getServerContextInformation().addProperty("MyCounter",curValue); mc.setProperty("MyCounter",curValue); ]]></script>

更多推荐

如何在每个任务调用之间保留属性值

本文发布于:2023-11-12 01:38:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580144.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   在每个

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!