Search code examples
springjmsactivemq-classicopenxava

How to implment JMS listener with activemq and spring into my OpenXava application


I have working with JMS listeners (for receiving messages) into standard webapps some time ago, normally using JSF (ICEfaces) for the webapp and spring, activemq, etc., for the JMS integration.

Now, I'm trying to do the same into an OpenXava application. So, this is what I have done at the moment:

  • I have created the listeners.xml into the WEB-INF (same place of the web.xml, which I can't modify because OpenXava), with this content (content to be auto added to web.xml by OpenXava):

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

<context-param>  
    <param-name>contextConfigLocation</param-name>  
    <param-value>  
        classpath:applicationContext.xml
    </param-value>  
</context-param>

  • I have created the applicationContext.xml (I have tested placing it in the OpenXava application src folder and also into the WEB-INF), with the following content:

    <!-- Create the topic to connect to -->
    <bean id="TTCTopic" class="org.apache.activemq.command.ActiveMQTopic">
        <property name="physicalName" value="com.comp.app.message.tags"/>
    </bean>
    
    <!-- JMS Connection Factory -->
    <bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
        <property name="brokerURL" value="tcp://127.0.0.1:1100"/>
    </bean>
    
    <!-- Spring Helper to listen to a JMS Destination -->
    <bean id="jmsContainer"
        class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        <property name="connectionFactory" ref="connectionFactory" />
        <property name="destination" ref="TTCTopic" />
        <property name="messageListener" ref="messageReceiver" />
    </bean>
    

  • Then, I have created my listener class (com.comp.app.listeners.MessageReceiver) which implements the JMS MessageListener interface, and which has the code to process the message received.

  • Also, I did place into the WEB-INF/Lib of my OpenXava application the spring and activemq jars and also I added the references in the project's classpath for each jar.

Finally, I'm not getting any kind of error.

So, after all the problem is: The spring context is not being added to the OpenXava web.xml as is supposed to do... because the spring context is not created, therefore the JMS listener is never created.

So, what I'm missing here? ... is there a better way to do this?

Thanks in advance,


Solution

  • My advice is to create a very simple OpenXava project and follow the Spring integration instruction step by step, when it works you can try it against your real project.

    However, your option of not using Spring is better.