我正在开展一个项目,我们决定使用jms和hornetq作为提供者添加一些交互
我对Camel很新,所以如果你提到的话,我会遇到一些问题。
目标是初始化连接工厂并添加jms组件。但是,据我所知,它不能直接在路由配置器中完成。所以我创建了camel-config.xml并将其放在resources /目录中
我用以下方式填写:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
<prop key="java.naming.provider.url">jnp://localhost:1099</prop>
<prop key="java.naming.factory.url.pkgs">org.jnp.interfaces:org.jboss.naming</prop>
</props>
</property>
</bean>
<bean id="jmsQueueConnectionFactory"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate"/>
</property>
<property name="jndiName">
<value>ConnectionFactory</value>
</property>
</bean>
<bean name="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="jmsQueueConnectionFactory"/>
</bean>
</beans>
该项目不使用Spring,因此它是我发现的没有使用Spring的唯一例子。
在路由配置器中,我使用routeBuilder.from("jms:queue:top").to("...");
但是,当我启动项目时,它会抛出FailedToCreateEndpointException并声明
&#34;没有找到架构的组件:jms&#34;。
我想xml文件根本就没用过,但我不能理解如何指向它。
期待听到任何建议。
答案 0 :(得分:1)
<beans/>
XML是一种必须以某种方式引导的Spring配置。您可以查看找到here的Tomcat ActiveMQ示例,了解如何在servlet环境中执行此操作。请特别关注web.xml
:
<!-- location of spring XML files -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:broker.xml,
classpath:camel-config.xml
</param-value>
</context-param>
<!-- the listener that kick-starts Spring, which loads the XML files and start our application -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
当然,您也可以使用仅Java设置,如下所示:
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
ModelCamelContext context = new DefaultCamelContext();
context.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));