2

这个问题是 4 个月前提出的。

https://stackoverflow.com/posts/16241300/edit

任何人?

“我在 mule flow 中编写了一个石英代码,每 5 分钟消耗一次队列中的所有消息。

<quartz:inbound-endpoint jobName="abc" cronExpression="0 0/1 * * * ?" doc:name="Quartz">
               <quartz:endpoint-polling-job>
                     <quartz:job-endpoint ref="jmsEndPoint" />
               </quartz:endpoint-polling-job>
        </quartz:inbound-endpoint>

但是即使队列中有 5 条消息,上面的代码一次也只消耗一条消息。

我的要求是每 5 分钟运行一次作业并消耗队列中的所有消息。

另一个要求是使用消息有效负载中的唯一标识符过滤掉重复消息。

任何帮助将不胜感激。"

编辑:JMS 端点

<jms:endpoint name="jmsEndPoint" queue="MyQueue" connector-ref="connector"/>
4

3 回答 3

2

队列是基于事件的,旨在仅返回一条消息(先进先出)。为了使用 Mule 流中队列中的所有消息,一种方法是创建一个自定义组件,该组件将以编程方式使用队列中的 jms 消息,直到没有更多消息为止。

为了过滤重复消息,请考虑使用 Mule 的幂等路由器:

http://www.mulesoft.org/documentation/display/current/Routing+Message+Processors#RoutingMessageProcessors-IdempotentMessageFilter

高温高压

于 2013-09-06T13:45:09.187 回答
1

Looking at your code it looks like you will need to read it like this:

muleEventContext.requestEvent("MyQueue", -1);

If you want to filter on id you can do this:

<idempotent-message-filter idExpression="#[message:id]-#[header:foo]">
    <simple-text-file-store directory="./idempotent"/>
 </idempotent-message-filter>
于 2013-09-12T13:20:49.060 回答
0

在您的 Mule-config xml 中:

  <quartz:connector name="quartzConnector">
    <receiver-threading-profile
        maxThreadsActive="1" />
  </quartz:connector>

  <flow name="DelayedMessageProcessing">
    <quartz:inbound-endpoint name="qEP6"
                             cronExpression="${some.cron.expression}"
                             jobName="DelayedProcessing"
                             connector-ref="quartzConnector">
      <jms:transaction action="ALWAYS_BEGIN" />
      <quartz:event-generator-job />
    </quartz:inbound-endpoint

    <component class="com.something.myComponent" />
  </flow>

..和Java组件:

package com.something;

import org.mule.api.MuleEventContext;
import org.mule.api.MuleException;
import org.mule.api.MuleMessage;
import org.mule.api.lifecycle.Callable;

public class MyComponent implements Callable {

    public Object onCall(final MuleEventContext muleEventContext) throws Exception {
        MuleMessage delayedMessage = fetchMessage(muleEventContext);

        while (delayedMessage != null) {
            //You might have to copy properties from inbound to outbound scope here..
            muleEventContext.dispatchEvent(delayedMessage, "some.jms.endpoint");
            delayedMessage = fetchMessage(muleEventContext);
        }

        return null;
    }

    private MuleMessage fetchMessage(final MuleEventContext muleEventContext) throws MuleException {
        return muleEventContext.requestEvent("some.delayed.jms.endpoint", 3000);
    }
}
于 2014-12-12T08:03:16.860 回答