2014-09-27 25 views
0

我正在開發一個項目,我們決定添加一些使用jms和hornetq作爲提供者的交互。
我對駱駝相當陌生,所以遇到一些問題,如果你可能指的是微不足道的。
目標是初始化連接工廠並添加jms組件。但是,據我所知,它不能直接在路由配置器中完成。所以我創建了camel-config.xml並將其放置到resources /目錄。
我以下列方式填充它:在模式中找不到任何組件:jms

<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所以它是XML我發現,不使用彈簧的唯一的例子。 在路線配置器我用routeBuilder.from("jms:queue:top").to("...");

然而,當我開始它拋出FailedToCreateEndpointException並指出
「與架構沒有找到組件:JMS」項目。
我想這個xml文件根本就沒有用過,但我無法理解如何指向它。期待聽到任何建議。

+0

這實際上*是*使用Spring,正如彼得說,它需要被引導或替換。但是,在其他任何事情之前,請確認您實際上是否添加了camel-jms依賴項。這是您錯過類路徑中的組件時所遇到的錯誤類型。 – kaqqao 2014-09-29 17:37:11

回答

1

<beans/> XML是一種Spring配置,必須以某種方式自舉。您可以查看找到的的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));