我正在关注一些教程here,以了解如何在已部署的Jboss EAP 6.4服务器上使用camel路由。我当前应用程序的目标非常简单,因为我想从ActiveMQ主题中读取并将其注销。下面的代码总结了我的行动:
package com.mycompany;
import javax.ejb.Startup;
import javax.enterprise.context.ApplicationScoped;
import javax.jms.ConnectionFactory;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.cdi.ContextName;
import org.apache.camel.component.jms.JmsComponent;
@ApplicationScoped
@Startup
@ContextName("com.mycompany")
public class CamelRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
System.out.println("### we are in the main");
final ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
getContext().addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(factory));
System.out.println("#### route being called");
from("jms:topic:activemq/topic/myTopic").log("###### we are in here with this message ${body}");
}
}
我还有一个Launcher类来测试我的路线:
package com.mycompany;
import org.apache.camel.main.Main;
public class Launcher {
public static void main(final String... args) throws Exception {
final Main main = new Main();
main.addRouteBuilder(new CamelRoute());
main.run(args);
}
}
如果我通过以下maven命令启动路由,我可以收到发送到activemq主题的所有消息。所以我知道,如果我手动启动路线,我至少可以检索数据。
mvn clean install exec:java -Dexec.mainClass=com.mycompany.Launcher
但是,一旦我将我的应用程序部署到服务器(作为jar,启用),同样不能说。我的system.out语句都没有在日志中显而易见。我几乎感到好像缺少额外的配置来“启动”应用程序。
注意:我在CamelRoute类中添加了用于启动的EJB注释,但这并没有解决问题。我错过了一些明显的东西吗?
我部署jar后,从jboss eap 6.4 log输出:
04:18:21,390 INFO [org.jboss.as.repository] (HttpManagementService-threads - 49) JBAS014900: Content added at location C:\bin\jboss-fuse\jboss-eap-6.4\standalone\data\content\99\f271f8372007ee6a2bce37668656acb80ef160\content
04:18:21,427 INFO [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015876: Starting deployment of "camel-java-1.0.0-SNAPSHOT.jar" (runtime-name: "camel-java-1.0.0-SNAPSHOT.jar")
04:18:21,431 INFO [org.wildfly.extension.camel] (MSC service thread 1-4) @ContextName annotation found
04:18:21,442 WARN [org.jboss.weld.deployer] (MSC service thread 1-6) JBAS016012: Deployment deployment "camel-java-1.0.0-SNAPSHOT.jar" contains CDI annotations but beans.xml was not found.
04:18:21,464 INFO [org.jboss.as.server] (HttpManagementService-threads - 49) JBAS015859: Deployed "camel-java-1.0.0-SNAPSHOT.jar" (runtime-name : "camel-java-1.0.0-SNAPSHOT.jar")
答案 0 :(得分:1)
日志输出中有一个指针,指出了此问题的可能原因:
JBAS016012: Deployment deployment "camel-java-1.0.0-SNAPSHOT.jar" contains CDI annotations but beans.xml was not found.
您需要确保在JAR中添加META-INF/beans.xml
。直到CDI 1.1才添加隐式bean档案。 EAP 6.x / JavaEE 6使用CDI 1.0。如果部署中不存在beans.xml,则Camel CDI应用程序将永远不会被提升并启动。