Newbie : ActiveMQ with Camel

2019-05-22 19:46发布

问题:

I'm pretty new to this topic and need some explanation...

We have a running ActiveMQ-Server, which should now be enhanced with Apache Camel routing and processing. Our whole configuration is XML based.

My first approach was to do a plain <import resource="camel.xml"> at the end of our activemq.xml, but this seems to be the wrong path.

These are the current transortConnectors:

<transportConnectors>
    <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
    <transportConnector name="openwire" uri="tcp://localdev:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    <transportConnector name="amqp" uri="amqp://localdev:5672?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    <transportConnector name="stomp" uri="stomp://localdev:61613?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    <transportConnector name="mqtt" uri="mqtt://localdev:1883?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    <transportConnector name="ws" uri="ws://localdev:61614?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    <transportConnector name="mqtt+ws" uri="ws://localdev:1884?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    <transportConnector name="vm" uri="vm://localdev" />
</transportConnectors>

And this is our camel.xml:

<beans
        xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="
     http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <camelContext id="camel" depends-on="broker-localdev" xmlns="http://camel.apache.org/schema/spring">
        <route id="devRawMap">
            <description>Redirect for test message</description>
            <from uri="activemq:topic:alpha.topic.DEV.INTERNAL.*.RAW"/>
            <to uri="activemq:queue:alpha.queue.DEV"/>
        </route>
        <route id="liveMap">
            <description>Redirect for Live data</description>
            <from uri="activemq:topic:devRoot.topic.LIVE.*.RAW"/>
            <to uri="activemq:queue:devRoot.queue.LIVE"/>
        </route>
    </camelContext>

    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent" >
        <property name="connectionFactory">
            <bean class="org.apache.activemq.ActiveMQConnectionFactory">
                <property name="brokerURL" value="vm://localdev?create=false"/>
                <property name="userName" value="user"/>
                <property name="password" value="pass"/>
            </bean>
        </property>
    </bean>
</beans>

Whatever configuration I make, the messages are not routed from topic to queue and I get the log messages:

Broker localhost not started so using localdev instead
Connector vm://localhost started

Am I following the wrong approach to this?

Any help is highly appreciated

[EDIT 01]

Is the problem maybe in having alot of persisted topics beingh loaded from kahadb alogn with using the RuntimeConfigurationPlugin? It takes a while until all topics are loaded and created, especial with having log4j set to debug. Furthermore the RuntimeConfigurationPlugin requires the broker to set "start=false" during init. see here

回答1:

your import <import resource="camel.xml"/> must be between broker and beans elements like this if the camel.xml is in the same folder than activemq.xml :

    </broker> 
    <import resource="camel.xml"/> 
</beans>

try by removing <import resource="camel.xml"/> and adding directly the content of camel.xml to the activemq.xml by removing <beans> element :

    </broker> 
    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"  depends-on="broker-localdev" >
        <route id="devRawMap">
            <description>Redirect for test message</description>
            <from uri="activemq:topic:alpha.topic.DEV.INTERNAL.*.RAW"/>
            <to uri="activemq:queue:alpha.queue.DEV"/>
        </route>
        <route id="liveMap">
            <description>Redirect for Live data</description>
            <from uri="activemq:topic:devRoot.topic.LIVE.*.RAW"/>
            <to uri="activemq:queue:devRoot.queue.LIVE"/>
        </route>
    </camelContext>

    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent" >
        <property name="connectionFactory">
            <bean class="org.apache.activemq.ActiveMQConnectionFactory">
                <property name="brokerURL" value="tcp://localhost:61616"/>
                <property name="userName" value="user"/>
                <property name="password" value="pass"/>
            </bean>
        </property>
    </bean>
</beans>