骆驼动态路由无限EN-消息队列 [英] Dynamic routing in camel en-queues messages infinitely

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

问题描述

结果
我的工作骆驼的动态路由器派生并派遣相关的队列通过参考的http://骆驼。 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>

以下是我的动态路由器豆:结果

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.

在此先感谢!

推荐答案

  • http://camel.apache.org/dynamic-router.html

和看到提防盒子,它说的方法必须返回信号的动态路由器爆发。

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

所以在上面的code,那么这code线

So in your code above, then this code line

RecordObject record = obj.getRecordObject();

...的记录对象从来都不是,因此动态路由器保持持续下去。

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

如果你只想要这个动态路由的一次的再使用动态RECEIPIENT列表EIP代替,见

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

  • http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html
  • http://camel.apache.org/recipient-list.html

和你的XML路线

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆