【问题标题】:How to get the Cache Event Key from Mule如何从 Mule 获取缓存事件密钥
【发布时间】:2017-01-30 09:04:35
【问题描述】:

我正在使用 Anypoint Studio 6.1 和 Mule 3.8.1,并且有一个使用默认事件密钥生成的 mule 托管存储缓存策略。

如何在流中获取此键的值?它存储在哪里?

谢谢

【问题讨论】:

    标签: caching mule anypoint-studio


    【解决方案1】:

    默认情况下,如果您未在缓存中提供密钥生成器表达式,则生成器会提供 SHA 256 hash 作为密钥。
    参考:- https://github.com/mulesoft/mule/blob/mule-3.x/core/src/main/java/org/mule/keygenerator/SHA256MuleEventKeyGenerator.java
    此生成器计算 当前消息 字节有效负载的 SHA 256 hash

    您可以使用以下示例获取流程的缓存键列表:-

    <ee:object-store-caching-strategy name="cachingStrategy" doc:name="cachingStrategy">
       <managed-store storeName="myNonPersistentManagedObjectStore" maxEntries="-1" entryTTL="20000" expirationInterval="5000"/>
    </ee:object-store-caching-strategy>
    
    <flow name="keylist" doc:name="keylist">
             <http:listener config-ref="HTTP_Listener_Configuration" path="/getkeyvalue" doc:name="HTTP"/>
                <scripting:component doc:name="Initialise Database"> 
                <scripting:script engine="Groovy">
                    <scripting:text><![CDATA[
                 def keyValues = [];
                  for(a=0;a<muleContext.getRegistry().lookupObject("cachingStrategy").getStore().allKeys().size();a++)
                   {
                         keyValues = muleContext.getRegistry().lookupObject("cachingStrategy").getStore().allKeys().get(a);
    
                    }
    
                    if(keyValues.isEmpty())
                    {
                     return "Key is either null or expired !!!";
                    }
                    else
                    {
                     return "KeysList " + muleContext.getRegistry().lookupObject("cachingStrategy").getStore().allKeys().toString();
                    }           
    
                   ]]></scripting:text>
    
                </scripting:script>  
            </scripting:component>
           </flow>
    

    每当您将一些消息放入缓存中时,使用上述流程,您可以获得缓存范围默认提供为SHA 256 hash 的所有默认缓存键值列表

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-15
      • 1970-01-01
      • 2018-11-29
      相关资源
      最近更新 更多