2014-01-20 50 views
1

我想根據我在Exchange屬性或消費者頭文件中設置的任何內容來選擇端點,並獲得了一些使用dynamicRoute的引用,基於我已經實現了,但是在控制檯和駱駝上下文中沒有關閉。 DefaultShutdownStrategy信息正在等待由於尚有1次飛行和正在申請的交流來完成駱駝動態路由在運行時使用交換屬性或頭文件獲取期望的端點

這裏是我的代碼

protected RouteBuilder createRouteBuilder() throws Exception { 
    return new RouteBuilder() { 
     public void configure() { 
      from("helloworld://foo").dynamicRouter(bean(MyRoutingAlg.class, "slip")); 
     } 
    }; 
} 

而且在MyRoutingAlg.class

package org.apache.camel.component; 

import java.util.Map; 
import org.apache.camel.Properties; 

public class MyRoutingAlg { 
    public synchronized String slip(String body, @Properties Map<String, Object> properties) { 
     int invoked = 0; 
     Object current = properties.get("invoked"); 
     if (current != null) { 
      System.out.println(">>>>>>>>>>>>"+Integer.valueOf(current.toString())); 
      invoked = Integer.valueOf(current.toString()); 
     } 
     invoked++; 
     // and store the state back on the properties 
     properties.put("invoked", invoked); 
     String address = (String)properties.get("address"); 
     if ("file://test".equals(address)) { 
      return "file://test"; 
     } 

     // no more so return null 
     return null; 
    } 
} 

回答

0

也許你的意思是這樣的?

public synchronized String slip(String body, @Properties Map<String, Object> properties) { 
    int invoked = 0; 
    Object current = properties.get("invoked"); 
    if (current != null) { 
     System.out.println(">>>>>>>>>>>>"+Integer.valueOf(current.toString())); 
     invoked = Integer.valueOf(current.toString()); 
    } 
    invoked++; 
    // and store the state back on the properties 
    properties.put("invoked", invoked); 
    String address = (String)properties.get("address"); 
    if (invoked == 1) { 
     return address; 
    } 

    // no more so return null 
    return null; 
} 
+0

感謝vikingsteve, 但仍然得到了同樣的信息和駱駝上下文不停止。 Msg:** [el-1)thread#2 - ShutdownTask] DefaultShutdownStrategy INFO正在等待,因爲仍有1個空中和待處理的交換完成,超時時間爲299秒。 – Sudhakar