2014-01-23 2 views
0

Я использую Camel. Пожалуйста, дайте мне знать, подходит ли следующий подход.ConnectionFactories for Producer & Consumer

CCF для Producer

<?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 ... как правило, либо PooledConnectionFactory Amq или CachingConnectionFactory в Spring

для Потребителей вы должны использовать 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

Как настроить в Camel? Как уже упоминалось в этом вопросе, это правильный способ настройки потребителей в Camel? Whereever Я видел пример ActiveMQ, JMSComponent получает URL-адрес брокера как ctor arg. Как вы настраиваете ConnectionFactory? Потому что я использую HornetQ в качестве JMS-провайдера – jaks

Смежные вопросы