Mule 4 缓存范围。如何根据特定条件停止 mule 缓存
Mule 4 Cache Scope. How to stop mule cache for based on certain conditions
我想在我的 mule 应用程序中使用缓存。流程很简单,我是根据邮件查询数据库,我只想存储 returns 一些行的结果。我提到了这个问题 but this solution is working for mule 3 only as Mule 4 uses repeatable streams。
我尝试实施以下解决方法:
- 将缓存范围包装在 try 范围内。
- 当我不想存储缓存时引发错误。
- 错误继续错误仅针对该错误类型
它正确地执行了流程,没有将结果存储在缓存中并且也给出了成功的响应但是它抛出了一个错误(可能在某些异步进程中)并且我在我的日志中看到了这个
ERROR 2020-11-20 17:54:36,923 [[MuleRuntime].uber.03: cachingStrategy_null @302bcf75] [processor: testFlow1/processors/1/processors/0/processors/1; event: 594def80-2b2b-11eb-a1d0-a0d37a4d6fab] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler:
********************************************************************************
Message : The mapper returned a null value.
Element : testFlow1/processors/1/processors/0 @ test:test.xml:131 (Cache)
Element DSL : <ee:cache doc:name="Cache" doc:id="8c09cdc7-4fc9-4de1-a961-f74323f6ea7b" cachingStrategy-ref="Caching_Strategy">
<logger level="INFO" doc:name="Copy_of_Logger" doc:id="c539273d-7da2-4a20-bbdc-11f9fd4424cc" message="inside cache scope."></logger>
<ee:transform doc:name="Transform Message" doc:id="be16423b-c018-4949-b441-e81c6abc65ef">
<ee:message>
<ee:set-payload>%dw 2.0
output application/json
---
if(payload.store) {
id: payload.id,
time: now()
}
else {}</ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="cacheEntry">%dw 2.0
output application/java
...
Root Exception stack trace:
java.lang.NullPointerException: The mapper returned a null value.
at java.util.Objects.requireNonNull(Objects.java:228)
at reactor.core.* (4 elements filtered from stack; set debug level logging or '-Dmule.verbose.exceptions=true' for everything)(Unknown Source)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.mule.service.scheduler.internal.AbstractRunnableFutureDecorator.doRun(AbstractRunnableFutureDecorator.java:111)
at org.mule.service.scheduler.internal.RunnableFutureDecorator.run(RunnableFutureDecorator.java:54)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
我也附上了我的流程片段。
您可以使用 Invalidate Key 操作在将密钥添加到缓存后将其删除。
应该添加在缓存范围之后。
我想在我的 mule 应用程序中使用缓存。流程很简单,我是根据邮件查询数据库,我只想存储 returns 一些行的结果。我提到了这个问题
我尝试实施以下解决方法:
- 将缓存范围包装在 try 范围内。
- 当我不想存储缓存时引发错误。
- 错误继续错误仅针对该错误类型
它正确地执行了流程,没有将结果存储在缓存中并且也给出了成功的响应但是它抛出了一个错误(可能在某些异步进程中)并且我在我的日志中看到了这个
ERROR 2020-11-20 17:54:36,923 [[MuleRuntime].uber.03: cachingStrategy_null @302bcf75] [processor: testFlow1/processors/1/processors/0/processors/1; event: 594def80-2b2b-11eb-a1d0-a0d37a4d6fab] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler:
********************************************************************************
Message : The mapper returned a null value.
Element : testFlow1/processors/1/processors/0 @ test:test.xml:131 (Cache)
Element DSL : <ee:cache doc:name="Cache" doc:id="8c09cdc7-4fc9-4de1-a961-f74323f6ea7b" cachingStrategy-ref="Caching_Strategy">
<logger level="INFO" doc:name="Copy_of_Logger" doc:id="c539273d-7da2-4a20-bbdc-11f9fd4424cc" message="inside cache scope."></logger>
<ee:transform doc:name="Transform Message" doc:id="be16423b-c018-4949-b441-e81c6abc65ef">
<ee:message>
<ee:set-payload>%dw 2.0
output application/json
---
if(payload.store) {
id: payload.id,
time: now()
}
else {}</ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="cacheEntry">%dw 2.0
output application/java
...
Root Exception stack trace:
java.lang.NullPointerException: The mapper returned a null value.
at java.util.Objects.requireNonNull(Objects.java:228)
at reactor.core.* (4 elements filtered from stack; set debug level logging or '-Dmule.verbose.exceptions=true' for everything)(Unknown Source)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.mule.service.scheduler.internal.AbstractRunnableFutureDecorator.doRun(AbstractRunnableFutureDecorator.java:111)
at org.mule.service.scheduler.internal.RunnableFutureDecorator.run(RunnableFutureDecorator.java:54)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
我也附上了我的流程片段。
您可以使用 Invalidate Key 操作在将密钥添加到缓存后将其删除。
应该添加在缓存范围之后。