R Dub
R Dub

Reputation: 688

Apache Camel message multiplexer integration pattern

I am trying to determine the best way to combine message streams from two hornetq broker instances into a single stream for processing, using Apache Camel and Spring. This is essentially the opposite of the Camel reciepient list pattern; but instead of one to many I need many to one. One idea is to implement this functionality with the direct component:

<?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>

Question: Is the above approach recommended when a many->1 integration pattern is required? If multiple Apache Camel solutions exist, what are the key performance impacts of each approach?

Runtime environment:

Notes:

Upvotes: 3

Views: 881

Answers (1)

hveiga
hveiga

Reputation: 6915

I think that your approach is valid for your scenario. However, maybe direct is not the component you need to use for this if you are running in different JVMs.

There are different components for internal queues: Direct, Direct-VM, SEDA, VM, Disruptor... but I believe all of them are if you are running in the JVM (and some of the if you just running in the same CamelContext). For more info: How do the direct, event, seda and vm endpoints compare

If you are going to have different CamelContexts across different JVM will need to use a different component.

Upvotes: 2

Related Questions