我想用两个变量LAST_POLL_START和LAST_POLL_END丰富当前消息。这些变量然后将用于构建另一个jdbc查询。

但是,我不明白如何使用浓缩器。我尝试过的代码在下面,它受hereMule's blog上找到的代码的启发。在我看来,这应该可行。我正在使用mule-3.2.0,并且jdbc查询有效并返回正确的值。

<flow name="MasterFlow" processingStrategy="synchronous">
    <quartz:inbound-endpoint jobName="cronJobPoolTime" cronExpression="0 0/1 * * * ?">
        <quartz:endpoint-polling-job>
            <quartz:job-endpoint ref="jdbc_quartzDummy"/>
        </quartz:endpoint-polling-job>
    </quartz:inbound-endpoint>
    <flow-ref name="GetPollingTimes" />
    <!-- Do other things -->
</flow>

<!-- Below is needed when using Quartz trigger -->
<jdbc:endpoint name="jdbc_quartzDummy" connector-ref="tabuConnector" queryKey="quartzDummy" />

<flow name="GetPollingTimes">
    <enricher>
        <jdbc:outbound-endpoint queryKey="getPollTimes" exchange-pattern="request-response" />
        <enrich target="#[variable:last_poll_start]" source="#[map-payload:LAST_POLL_START]"/>
        <enrich target="#[variable:last_poll_end]" source="#[map-payload:LAST_POLL_END]"/>
    </enricher>
    <logger level="INFO" message="last_poll_start = #[variable:last_poll_start]" />
</flow>


错误消息是:

WARN  2011-12-27 15:38:00,831 [scheduler-ESB_Worker-1] org.mule.DefaultMuleMessage: setProperty(key, value) called with null value; removing key: last_poll_start; please report the following stack trace to [email protected]
java.lang.Throwable
    at org.mule.DefaultMuleMessage.setProperty(DefaultMuleMessage.java:456)
    at org.mule.expression.VariableExpressionEnricher.enrich(VariableExpressionEnricher.java:24)
    at org.mule.expression.DefaultExpressionManager.enrich(DefaultExpressionManager.java:248)
    at org.mule.expression.DefaultExpressionManager.enrich(DefaultExpressionManager.java:237)
    at org.mule.enricher.MessageEnricher.enrich(MessageEnricher.java:69)
    at org.mule.enricher.MessageEnricher.process(MessageEnricher.java:43)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:64)
    at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:105)
    at org.mule.processor.AsyncInterceptingMessageProcessor.process(AsyncInterceptingMessageProcessor.java:90)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:64)
    at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:105)
    at org.mule.interceptor.AbstractEnvelopeInterceptor.process(AbstractEnvelopeInterceptor.java:55)
    at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:105)
    at org.mule.processor.AbstractFilteringMessageProcessor.process(AbstractFilteringMessageProcessor.java:41)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:64)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:56)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:64)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:87)
    at org.mule.construct.Flow.process(Flow.java:64)
    at org.mule.config.spring.factories.FlowRefFactoryBean$1.process(FlowRefFactoryBean.java:44)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:64)
    at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:105)
    at org.mule.interceptor.AbstractEnvelopeInterceptor.process(AbstractEnvelopeInterceptor.java:55)
    at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:105)
    at org.mule.processor.AbstractFilteringMessageProcessor.process(AbstractFilteringMessageProcessor.java:41)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:64)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:56)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:64)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:87)
    at org.mule.construct.AbstractPipeline$1.process(AbstractPipeline.java:138)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:64)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:56)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:64)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:87)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:64)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:56)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:64)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:87)
    at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:190)
    at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:163)
    at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:150)
    at org.mule.transport.quartz.jobs.EndpointPollingJob$1.doInTransaction(EndpointPollingJob.java:162)
    at org.mule.transport.quartz.jobs.EndpointPollingJob$1.doInTransaction(EndpointPollingJob.java:125)
    at org.mule.transaction.TransactionTemplate.execute(TransactionTemplate.java:45)
    at org.mule.transport.quartz.jobs.EndpointPollingJob.doExecute(EndpointPollingJob.java:169)
    at org.mule.transport.quartz.jobs.AbstractJob.execute(AbstractJob.java:36)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:534)


将扩充源更改为#[有效负载]:

<enrich target="#[variable:last_poll_start]" source="#[payload]"/>
<logger level="INFO" message="last_poll_start = #[variable:last_poll_start]" />


产生(从日志文件):

org.mule.api.processor.LoggerMessageProcessor: last_poll_start = [{LAST_POLL_START=2011-12-21, LAST_POLL_END=2000-01-01}]

最佳答案

受先前答案的启发,我注意到有可能在richer中使用groovy语法。如果有人遇到这个问题,这是解决方案。

<flow name="GetPollingTimes">
    <enricher>
        <jdbc:outbound-endpoint queryKey="getPollTimes" exchange-pattern="request-response" />
        <enrich target="#[variable:last_poll_start]" source="#[groovy:payload.last_poll_start]"/>
        <enrich target="#[variable:last_poll_end]" source="#[groovy:payload.last_poll_end]"/>
    </enricher>
</flow>

关于esb - 来自JDBC源的Mule消息丰富器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8645964/

10-13 07:02