骆驼中的动态路由无限地排队消息

骆驼中的动态路由无限地排队消息

本文介绍了骆驼中的动态路由无限地排队消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在研究骆驼的动态路由器,通过引用 http://camel 来派生和分派到相关队列.apache.org/dynamic-router.html

以下是骆驼配置xml:

Following is the camel config xml:

<route id="dynamicRouter" autoStartup="true">
    <from uri="vm://service1?concurrentConsumers=10&amp;timeout=0" />
    <choice>
        <when>
            <simple>${body.documentStatus} == 'SUCCESS' </simple>
            <log message="routing to dynamic router" />
            <dynamicRouter>
            <!-- use a method call on a bean as dynamic router -->
            <method ref="messageRouter" method="route" />
            </dynamicRouter>
        </when>
    </choice>
</route>

以下是我的动态路由器 bean:

Following is my dynamic router bean:

公共类 MessageRouter {

public class MessageRouter {

private static final String QUEUE_BROKER = "activemq";
private static final String DEFAULT_QUEUE = "queue";
/**
 *
 * @param obj
 *            message
 * @return the dynamically generated queue name
 */
public String route(ServiceObject obj) {
    RecordObject record = obj.getRecordObject();

    if(record != null){
        return QUEUE_BROKER + ":"
                + record.getId() + "." + DEFAULT_QUEUE;
    }
    return null;
}

}

我能够在动态创建的队列中排队消息,但消息正在无限排队.
在确定可能是什么原因方面的任何帮助都会有很大帮助.

I am able to en-queue messages in dynamically created queue but messages are getting enqueued infinitely.
Any help in identifying what could be the reason would be of great help.

提前致谢!!!

推荐答案

阅读关于动态路由器的文档

Read the documentation about dynamic router at

并看到小心框,它说该方法必须返回null 以向动态路由器发出信号以使其中断.

And see the beware box, it says the method must return null to signal to the dynamic router to break out.

所以在你上面的代码中,然后是这行代码

So in your code above, then this code line

RecordObject record = obj.getRecordObject();

...record 对象永远不会null,因此动态路由器会永远运行.

... the record object is never null and therefore the dynamic router keeps going forever.

如果您只想要此动态路由一次,请改用动态收件人列表 eip,请参阅

If you only want this dynamic routing one time then use the dynamic receipient list eip instead, see

而你的 xml 路由是

And your xml route is

<recipientList>
<!-- use a method call on a bean as dynamic router -->
<method ref="messageRouter" method="route" />
</recipientList>

这篇关于骆驼中的动态路由无限地排队消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 07:01