我正在尝试确定使用Apache Camel和Spring将来自两个hornetq broker实例的消息流组合为一个流进行处理的最佳方式。这基本上与Camel接收列表模式相反;但我需要的不是一对多。一个想法是用直接组件实现这个功能:
<?xml version="1.0" encoding="UTF-8"/>
<beans xmlns="..."
xmlns="...">
<!-- JMS Connection 1 -->
<bean id="jndiTemplate1" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
...Connection 1 Specific Information...
</props>
</property>
</bean>
<bean id="jmsTopicConnectionFactory1"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate1"/>
</property>
<property name="jndiName">
<value>java:jms/RemoteConnectionFactory</value>
</property>
</bean>
<bean id="jms1" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="jmsTopicConnectionFactory1"/>
</bean>
<!-- JMS Connection 2 -->
<bean id="jndiTemplate2" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
...Connection 2 Specific Information...
</props>
</property>
</bean>
<bean id="jmsTopicConnectionFactory2"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate2"/>
</property>
<property name="jndiName">
<value>java:jms/RemoteConnectionFactory</value>
</property>
</bean>
<bean id="jms2" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="jmsTopicConnectionFactory2"/>
</bean>
<!-- Camel route many to 1 using direct component -->
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="hornetQ_broker_1">
<from uri="jms1:topic:testTopic1">
<to uri="direct:process_message">
</route>
<route id="hornetQ_broker_2">
<from uri="jms2:topic:testTopic2">
<to uri="direct:process_message">
</route>
<route id="message_processor">
<from uri="direct:process_message">
<log message="message_processor received message">
</route>
</camelContext>
</beans>
问题:当需要多->1集成模式时,是否推荐上述方法?如果存在多个ApacheCamel解决方案,那么每种方法对性能的关键影响是什么
运行时环境:
- HornetQ的经纪人是JBoss EAP6
- 部署到FuseSource 4.4.1的Camel上下文
- 每个实体都存在于一个单独的服务器/jvm上
注:
- 无法对hornetQ broker实例进行集群
- hornetQ代理实例不包含重复的数据
我认为您的方法对您的场景是有效的。然而,如果您在不同的JVM中运行,那么direct可能不是您需要使用的组件。
内部队列有不同的组件:Direct、Direct VM、SEDA、VM、Disruptor。。。但我相信所有这些都是在JVM中运行的(还有一些是在同一个CamelContext中运行的)。更多信息:direct、event、seda和vm端点如何比较
如果要在不同的JVM中使用不同的CamelContext,则需要使用不同的组件。