2014-01-23 66 views
0

我正在使用駱駝。請讓我知道以下方法是否正常。生產者和消費者的連接因子

CCF對生產者

<?xml version="1.0" encoding="UTF-8"?> 
<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" 
    xmlns:context="http://www.springframework.org/schema/context" 
    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 
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

    <bean id="hornetConnectionFactory" class="org.hornetq.jms.client.HornetQJMSConnectionFactory"> 
     <constructor-arg name="ha" value="false"></constructor-arg> 
     <constructor-arg> 
      <bean id="transportConfiguration" class="org.hornetq.api.core.TransportConfiguration"> 
       <constructor-arg 
        value="org.hornetq.core.remoting.impl.netty.NettyConnectorFactory" /> 
       <constructor-arg> 
        <map key-type="java.lang.String" value-type="java.lang.Object"> 
         <entry key="host" value="127.0.0.1" /> 
         <entry key="port" value="5445" /> 
        </map> 
       </constructor-arg> 
      </bean> 
     </constructor-arg> 
    </bean> 

    <!-- ConnectionFactory Definition --> 
    <bean id="connectionFactory" 
     class="org.springframework.jms.connection.CachingConnectionFactory"> 
     <constructor-arg ref="hornetConnectionFactory" /> 
    </bean> 

    <bean id="jms" class="org.apache.camel.component.jms.JmsComponent"> 
     <property name="connectionFactory" ref="connectionFactory" /> 
    </bean> 

    <context:component-scan base-package="com.camlin.producer" /> 

    <camel:camelContext id="camel-server"> 
     <camel:package>com.camlin.producer</camel:package> 
    </camel:camelContext> 
</beans> 

對消費者普通CF,

<?xml version="1.0" encoding="UTF-8"?> 
<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" 
    xmlns:context="http://www.springframework.org/schema/context" 
    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 
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

    <bean id="hornetConnectionFactory" class="org.hornetq.jms.client.HornetQJMSConnectionFactory"> 
     <constructor-arg name="ha" value="false"></constructor-arg> 
     <constructor-arg> 
      <bean id="transportConfiguration" class="org.hornetq.api.core.TransportConfiguration"> 
       <constructor-arg 
        value="org.hornetq.core.remoting.impl.netty.NettyConnectorFactory" /> 
       <constructor-arg> 
        <map key-type="java.lang.String" value-type="java.lang.Object"> 
         <entry key="host" value="127.0.0.1" /> 
         <entry key="port" value="5445" /> 
        </map> 
       </constructor-arg> 
      </bean> 
     </constructor-arg> 
    </bean> 

    <bean id="jms" class="org.apache.camel.component.jms.JmsComponent"> 
     <property name="connectionFactory" ref="hornetConnectionFactory" /> 
    </bean> 

    <context:component-scan base-package="com.camlin.consumer" /> 

    <camel:camelContext id="camel-consumer"> 
     <camel:package>com.camlin.consumer</camel:package> 

     <camel:route id="one"> 
      <camel:from uri="jms:queue:request?selector=type='1'" /> 
      <camel:to uri="bean:consumerBean?method=receive1" /> 
     </camel:route> 

     <camel:route id="two"> 
      <camel:from uri="jms:queue:request?selector=type='2'" /> 
      <camel:to uri="bean:consumerBean?method=receive2" /> 
     </camel:route> 
    </camel:camelContext> 
</beans> 

回答

0

的生產者,應使用JMS連接池......通常要麼AMQ的PooledConnectionFactory或Spring的CachingConnectionFactory

對於消費者,您應該在可能的情況下使用Spring的DefaultMessageListenerContainer而不是JmsTemplate.receive()

看到JmsTemplate的最佳做法:http://activemq.apache.org/jmstemplate-gotchas.html

和本文的詳細細節在這裏:http://codedependents.com/2009/10/16/efficient-lightweight-jms-with-spring-and-activemq/

+0

如何在駱駝配置?正如問題中提到的,這是配置駱駝消費者的正確方法嗎?無論我看到ActiveMQ示例,JMSComponent都會將代理URL作爲ctor arg。如何使用ConnectionFactory進行配置?因爲我使用HornetQ作爲JMS提供者 – jaks