java - Camel as a JMS to JMS bridge - Not showing as an AMQ consumer -
i'm pretty new jms , have requirement bridge between amq , wmq, saw in camel documentation rather using jms jms bridge recommend use camel.
to start i'm trying application take messages off amq , log doing whenever start application in jetty doesn't show consumer on apitotopsqueue , hence doesn't take messages off queue.
my application-context.xml (which loads camel-context)
<?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: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://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:property-placeholder location="classpath:tops-bridge.properties" /> <import resource="classpath:camel-context.xml" /> <bean id="log4jinitialization" class="org.springframework.beans.factory.config.methodinvokingfactorybean"> <property name="targetclass" value="org.springframework.util.log4jconfigurer" /> <property name="targetmethod" value="initlogging" /> <property name="arguments"> <list> <value>classpath:log4j.xml</value> <value>60000</value> <!-- refresh log4j config every 60 seconds --> </list> </property> </bean> </beans>
then camel-context.xml (i've been commenting in , out random code tutorials might seem odd)
<?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:broker="http://activemq.apache.org/schema/core" 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://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"> <camel:camelcontext id="defaultcamelcontext"> <camel:routebuilder ref="bridgerouteconfig"/> <!--<camel:jmxagent id="agent" createconnector="true"/>--> </camel:camelcontext> <bean id="bridgerouteconfig" class="com.caci.asg.rail.tops.bridge.topsbridgeroutebuilder"> <constructor-arg name="amqtobridgequeue" value="${topsbridgeroutebuilder.route.amqtobridgeroute}"/> <constructor-arg name="bridgetowmqqueue" value="${topsbridgeroutebuilder.route.bridgetowmqroute}"/> <constructor-arg name="wmqtobridgequeue" value="${topsbridgeroutebuilder.route.wmqtobridgeroute}"/> <constructor-arg name="bridgetoamqqueue" value="${topsbridgeroutebuilder.route.bridgetoamqroute}"/> </bean> <bean id="jmsfactory" class="org.apache.activemq.activemqconnectionfactory"> <property name="brokerurl" value="${application.activemq.url}"/> <property name="useasyncsend" value="true"/> </bean> <bean id="pooledconnectionfactory" class="org.apache.activemq.pool.pooledconnectionfactory" init-method="start" destroy-method="stop"> <property name="maxconnections" value="8"/> <property name="connectionfactory" ref="jmsfactory"/> </bean> <bean id="jmsconfig" class="org.apache.camel.component.jms.jmsconfiguration"> <property name="connectionfactory" ref="pooledconnectionfactory"/> <property name="concurrentconsumers" value="10"/> </bean> <!-- lets configure activemq jms broker server --> <broker:broker usejmx="true" persistent="false" brokername="mybroker"> <broker:transportconnectors> <!-- expose vm transport in-jvm transport between amq , camel on server side --> <broker:transportconnector name="vm" uri="vm://mybroker"/> <!-- expose tcp transport clients use --> <broker:transportconnector name="tcp" uri="${application.activemq.url}"/> </broker:transportconnectors> </broker:broker> <!-- lets configure camel activemq use embedded activemq broker declared above --> <bean id="jms" class="org.apache.activemq.camel.component.activemqcomponent"> <property name="brokerurl" value="vm://mybroker"/> </bean> </beans>
the camel-context.xml makes use of properties follows (the ones referring wmq placeholders @ moment until amq working).
application.activemq.url=tcp://localhost:61616 topsbridgeroutebuilder.route.amqtobridgeroute=jms:apitotopsqueue topsbridgeroutebuilder.route.bridgetowmqroute=mq:towmq topsbridgeroutebuilder.route.wmqtobridgeroute=mq:fromwmq topsbridgeroutebuilder.route.bridgetoamqroute=jms:topstoapiqueue
the route builder in java follows
import org.apache.camel.logginglevel; import org.apache.camel.builder.routebuilder; public class topsbridgeroutebuilder extends routebuilder { private final string amqtobridgequeue; private final string bridgetowmqqueue; private final string wmqtobridgequeue; private final string bridgetoamqqueue; public topsbridgeroutebuilder(string amqtobridgequeue, string bridgetowmqqueue, string wmqtobridgequeue, string bridgetoamqqueue) { this.amqtobridgequeue = amqtobridgequeue; this.bridgetowmqqueue = bridgetowmqqueue; this.wmqtobridgequeue = wmqtobridgequeue; this.bridgetoamqqueue = bridgetoamqqueue; } @override public void configure() throws exception { // from(amqtobridgequeue).to(bridgetowmqqueue).log(logginglevel.info, "message moving " + bridgetowmqqueue); // from(wmqtobridgequeue).to(bridgetoamqqueue).log(logginglevel.info, "message moving " + bridgetoamqqueue); from(amqtobridgequeue).log(logginglevel.warn, "consuming message from" + amqtobridgequeue); } }
so i'm not sure why isn't listed consumer of apitotopsqueue when start jetty. pom includes dependencies amq/wmq/camel libraries. dependencies follows (inheriting version/scope parent pom)
<dependency> <groupid>org.apache.camel</groupid> <artifactid>camel-core</artifactid> </dependency> <dependency> <groupid>org.apache.camel</groupid> <artifactid>camel-spring</artifactid> </dependency> <dependency> <groupid>org.apache.camel</groupid> <artifactid>camel-jms</artifactid> </dependency> <dependency> <groupid>com.ibm.mq</groupid> <artifactid>com.ibm.mq.jmqi</artifactid> </dependency> <dependency> <groupid>com.ibm.mq</groupid> <artifactid>com.ibm.mqjms</artifactid> </dependency> <dependency> <groupid>com.ibm.mq</groupid> <artifactid>connector</artifactid> </dependency> <dependency> <groupid>com.ibm.mq</groupid> <artifactid>dhbcore</artifactid> </dependency> <dependency> <groupid>org.apache.activemq</groupid> <artifactid>activemq-all</artifactid> </dependency> <dependency> <groupid>org.apache.activemq</groupid> <artifactid>activemq-pool</artifactid> </dependency>
i wrote test see put messages on , take them off amq bridge - worked , on amq admin page see enqueued/dequeued message count incremented.
import org.apache.activemq.activemqconnectionfactory; import org.junit.test; import static org.hamcrest.core.is.is; import static org.junit.assert.assertthat; import javax.jms.*; public class topsbridgeroutebuildertest { @test public void testamessageaddedtoamqcanberetrieved() throws jmsexception { string brokerurl = "tcp://localhost:61616"; string amqqueue = "apitotopsqueue"; string messagetosend = "test message"; // put message on amq activemqconnectionfactory connectionfactory = new activemqconnectionfactory(brokerurl); connection connection = connectionfactory.createconnection(); connection.start(); session session = connection.createsession(false, session.auto_acknowledge); destination destination = session.createqueue(amqqueue); messageproducer producer = session.createproducer(destination); producer.setdeliverymode(deliverymode.non_persistent); textmessage tm = session.createtextmessage(messagetosend); producer.send(tm); // create read consumer take message off queue activemqconnectionfactory connectionfactoryreadonly = new activemqconnectionfactory(brokerurl); connection connectionreadonly = connectionfactoryreadonly.createconnection(); connectionreadonly.start(); session sessionreadonly = connectionreadonly.createsession(false, session.auto_acknowledge); messageconsumer consumer = sessionreadonly.createconsumer(destination); final textmessage message = (textmessage) consumer.receive(); system.out.println("message retrieved = " + message.gettext()); assertthat(message.gettext(), is(messagetosend)); } }
is there wrong in configuration means camel routing isn't working or looking @ amq when start jetty?
thanks.
turns out missing section in web.xml. lesson learnt future!
<listener> <listener-class> org.springframework.web.context.contextloaderlistener </listener-class> </listener>
Comments
Post a Comment