我对Camel很新,但基本上,我有一个名为populate的函数bean。 Camel无法调用此方法,也无法在路径中激活任何内容。我不知道我做错了什么,有人可以帮忙吗?
我尝试使用populate()并填充我的路线,我也试图摆脱@Handler。
Logger也没有被调用,我只是把它放在那里看看会发生什么。
这是我的路线,然后我会发布我的豆。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="mockSql" class="tutorial.simple.route.MockSql"/>
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start"/>
<log loggingLevel="DEBUG" message="logger" id="123" customId="true"/>
<to uri="bean:mockSql?method=populate()"/>
</route>
</camelContext>
</beans>
继承我的豆子:
package tutorial.simple.route;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.camel.Handler;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
public class MockSql {
private static final Logger log = Logger.getLogger("mockSql");
public MockSql(){
log.setLevel(Level.DEBUG);
log.debug("constructed mock sql");
}
@Handler
public ArrayList populate(){
ArrayList <HashMap> ary = new ArrayList<HashMap>();
HashMap<String, String> hm = new HashMap();
HashMap<String, String> hm2 = new HashMap();
hm.put("n1", "j1");
hm2.put("n2", "j2");
ary.add(hm);
ary.add(hm2);
log.debug("populated mock sql");
return ary;
}
}
输出:
[pache.camel.spring.Main.main()] MainSupport INFO Apache Camel 2.12.0.redhat-610379开始 [pache.camel.spring.Main.main()] mockSql DEBUG构造了mock sql [pache.camel.spring.Main.main()] SpringCamelContext INFO Apache Camel 2.12.0.redhat-610379(CamelContext:camel)正在启动 [pache.camel.spring.Main.main()] ManagedManagementStrategy INFO JMX已启用 [pache.camel.spring.Main.main()] DefaultTypeConverter INFO已加载176种类型的转换器 [pache.camel.spring.Main.main()] SpringCamelContext INFO AllowUseOriginalMessage已启用。如果不需要访问原始邮件,则建议关闭此选项,因为它可能会提高性能。 [pache.camel.spring.Main.main()] SpringCamelContext INFO StreamCaching未使用。如果使用流,则建议启用流缓存。在http://camel.apache.org/stream-caching.html查看更多详情 [pache.camel.spring.Main.main()] SpringCamelContext INFO路由:route1已启动并消耗:Endpoint [direct:// start] [pache.camel.spring.Main.main()] SpringCamelContext INFO总共1条路由,其中1条已启动。 [pache.camel.spring.Main.main()] SpringCamelContext INFO Apache Camel 2.12.0.redhat-610379(CamelContext:camel)在0.324秒内启动
答案 0 :(得分:1)
direct
端点只能从其他路由触发,例如:
<route>
<from uri="<other endpoint>"/>
...
<to uri="direct:start"/>
</route>
所以在你的情况下,路线永远不会被触发。