如何声明和使用“全局属性”?在WSO2 ESB中? (超出消息处理器定义的顺序的属性) [英] How can I declare and use a "global property" in WSO2 ESB? (a property that is outside the sequence defined by a message processor)

查看:110
本文介绍了如何声明和使用“全局属性”?在WSO2 ESB中? (超出消息处理器定义的顺序的属性)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对如何在 WSO2 ESB 中存储诸如全局属性之类的内容存在以下疑问。我尝试解释一下自己的情况。



我有一个消息处理器,其中定义了一个每秒执行一次的序列,如下所示:

 <?xml version = 1.0 encoding = UTF-8?> 
< messageProcessor class = org.apache.synapse.message.processor.impl.forwarder.ScheduledMessageForwardingProcessor messageStore = glisMessageStore name = glisMessageProcessor targetEndpoint = glisEndpoint xmlns = http:// ws。 apache.org/ns/synapse
< parameter name = client.retry.interval> 100< / parameter>
< parameter name = max.delivery.attempts> 4< / parameter>
< parameter name = member.count> 1< / parameter>
< parameter name = message.processor.reply.sequence> glisResponseSequence< / parameter>
< parameter name = max.delivery.drop> Disabled< / parameter>
< parameter name = interval> 10< / parameter>
< parameter name = is.active> true< / parameter>
< / messageProcessor>

进入此 glisResponseSequence.xml ,我将执行对外部Web服务的调用。在这个序列中,我必须做一些怪异的事情。



我必须按照以下序列示意图中的说明进行操作:

 <?xml version = 1.0 encoding = UTF-8?> 
< sequence name = transferProcessorSequence onError = transferFromErrorSequence trace = disable xmlns = http://ws.apache.org/ns/synapse>
< log level = full />
.............................................. ....................
................................... ......................................................
...... ................................................... ..........
1)从名为 sleepingTime
的全局属性中检索值2)如果sleepingTime!= NULL,则执行使用该值
$的Java脚本b $ b 3)呼叫外部Web服务:
< call>
< endpoint key = transferFromGLISAPI />
< / call>

4)设置sleepingTime的新值 GLOBAL PROPERTY(从响应头中检索)

............ ................................................... ....
................................................... ........................
...................... ............................................
< / sequence>

因此,按照我的顺序,我有一个呼叫调解人。在完成此呼叫中介器之后,我必须设置一个类似于 global属性的东西,并从响应标头中获取一个值(获取该值对我来说不是问题)。当消息处理器将再次执行此序列时,此全局属性的值将在我的呼叫中介器之前再次使用。



我该怎么办?我的疑问是:



1)我在哪里定义此全局属性?我认为我必须在 glisResponseSequence.xml 消息处理器执行的序列)之外声明它。我可以将其声明为另一个序列吗?



2)此全局属性的正确作用域是什么? / p>

对我来说,存储调解器对外部Web服务执行http请求并在下一次调用之前再次使用它之后获得的值非常重要。 glisResponseSequence.xml 序列由消息处理器再次执行。我可以做吗?另一个解决方案是将此日期存储在数据库中,但是,如果可能的话,我更喜欢使用诸如全局属性之类的东西。

解决方案

您可以在序列中使用此javascript:

 < script language = js>< !! [CDATA [ 
var myValue = 12;

//创建或更新属性
mc.getEnvironment()。getServerContextInformation()。addProperty( GlobalProperty,myValue);

//获取属性
var globalProperty = mc.getEnvironment()。getServerContextInformation()。getProperty( GlobalProperty);

//通过$ ctx为调解提供价值:GlobalProperty
mc.setProperty( GlobalProperty,globalProperty);
]]>< / script>


I have the following doubt related how to store something like a global property in WSO2 ESB. I try to explain my situation.

I have a message processor in which is defined a sequence that is executed every second, something like this:

<?xml version="1.0" encoding="UTF-8"?>
<messageProcessor class="org.apache.synapse.message.processor.impl.forwarder.ScheduledMessageForwardingProcessor" messageStore="glisMessageStore" name="glisMessageProcessor" targetEndpoint="glisEndpoint" xmlns="http://ws.apache.org/ns/synapse">
    <parameter name="client.retry.interval">100</parameter>
    <parameter name="max.delivery.attempts">4</parameter>
    <parameter name="member.count">1</parameter>
    <parameter name="message.processor.reply.sequence">glisResponseSequence</parameter>
    <parameter name="max.delivery.drop">Disabled</parameter>
    <parameter name="interval">10</parameter>
    <parameter name="is.active">true</parameter>
</messageProcessor>

Into this glisResponseSequence.xml I perform a call to an external web service. In this sequence I have to do something that is a little "weird".

I have to do something like explained in the following sequence schematisation:

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="transferProcessorSequence" onError="transferFromErrorSequence" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <log level="full"/>
    ..................................................................
    ..................................................................
    ..................................................................
    1) RETRIEVE THE VALUE FROM A "GLOBAL PROPERTY" NAMED sleepingTime
    2) IF sleepingTime != NULL PERFORM A JAVASCRIPT THAT USE THIS VALUE

    3) CALL EXTERNAL WEB SERVICE:
    <call>
        <endpoint key="transferFromGLISAPI"/>
    </call>

    4) SET THE NEW VALUE OF THE sleepingTime "GLOBAL PROPERTY" (it is retrieved from the response header)

    ..................................................................
    ..................................................................
    ..................................................................
</sequence>

So, in my sequence I have a call mediator. After this call mediator I have to set something like a global property with a value retrieved from the response header (obtain this value is not a problem for me). The value of this global property will be used again before my call mediator when the message processor will execute again this sequence.

How can I do it? My doubt are:

1) Where have I to define this global property? I think that I have to declare it outside this glisResponseSequence.xml (the sequence executed by the message processor). Can I declare it into another sequence?

2) What is the correct scope for this global property?

It is very important to me store a value that I obtain after that the call mediator perform the http request to the external web service and use it again before the next call (when the glisResponseSequence.xml sequence is executed again by the message processor). Can I do it? Another solution could be store this date on the database but, if it is possibile, I prefer use something like a global property.

解决方案

You can use this javascript inside your sequence :

    <script language="js"><![CDATA[
        var myValue = 12;

        // create or update the property
        mc.getEnvironment().getServerContextInformation().addProperty("GlobalProperty",myValue);

        // get the property                     
        var globalProperty = mc.getEnvironment().getServerContextInformation().getProperty("GlobalProperty");

        // provide it's value to your mediation with $ctx:GlobalProperty
        mc.setProperty("GlobalProperty",globalProperty);
    ]]></script>

这篇关于如何声明和使用“全局属性”?在WSO2 ESB中? (超出消息处理器定义的顺序的属性)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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