簡體   English   中英

如何從Mule獲取緩存事件密鑰

[英]How to get the Cache Event Key from Mule

我正在使用Anypoint Studio 6.1和Mule 3.8.1,並且具有使用默認事件密鑰生成的Mule托管存儲緩存策略。

如何在流程中獲取此鍵的值? 它存儲在哪里?

謝謝

默認情況下,如果您在緩存中未提供密鑰生成器表達式,則生成器將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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM