activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kureckam <mkure...@fractech.net>
Subject Unable to receive topic message
Date Wed, 27 Jul 2011 13:49:09 GMT
I've implemented a modified version of an example from the "ActiveMQ in
Action" book and don't understand why I'm not receiving a message.  The code
is running on tomcat as embedded broker and to test it I'm using ActiveMQ's
web console to send a message via link http://localhost:8161/admin/send.jsp,
Destination set as START and type set to Topic. I added output to verify
listener class was instantiated and it is.

*/WEB-INF/web.xml*
<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/jms-context.xml</param-value>
  </context-param>

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

  <servlet>
    <servlet-name>jms-webapp</servlet-name>
   
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>jms-webapp</servlet-name>
    <url-pattern>*.html</url-pattern>
  </servlet-mapping>

  <resource-ref>
    <description>JMS Connection</description>
    <res-ref-name>jms/ConnectionFactory</res-ref-name>
    <res-type>javax.jms.ConnectionFactory</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
  </resource-ref>
  
  <message-destination-ref>
   
<message-destination-ref-name>jms/FooQueue</message-destination-ref-name>
    <message-destination-type>javax.jms.Topic</message-destination-type>
    <message-destination-usage>Produces</message-destination-usage>
    <message-destination-link>jms/FooQueue</message-destination-link>
  </message-destination-ref>
</web-app>

*/WEB-INF/jms-webapp-servlet.xml*
<?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"
  xmlns:p="http://www.springframework.org/schema/p"
  xsi:schemaLocation="
  http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
  <context:component-scan
base-package="org.apache.activemq.book.ch8.jms.web" />
  <bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"
/>
</beans>

*/WEB-INF/spring/jms-context.xml*
<?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:jee="http://www.springframework.org/schema/jee"
  xmlns:jms="http://www.springframework.org/schema/jms"
  xmlns:p="http://www.springframework.org/schema/p"
  xsi:schemaLocation="
    http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd
    http://www.springframework.org/schema/jms
http://www.springframework.org/schema/jms/spring-jms.xsd">
  
  <jee:jndi-lookup id="connectionFactory"
    jndi-name="java:comp/env/jms/ConnectionFactory"
    cache="true"
    resource-ref="true"
    lookup-on-startup="true"
    expected-type="org.apache.activemq.ActiveMQConnectionFactory"
    proxy-interface="javax.jms.ConnectionFactory">
  </jee:jndi-lookup>
  
  <jee:jndi-lookup id="fooQueue"
    jndi-name="java:comp/env/jms/FooQueue"
    cache="true"
    resource-ref="true"
    lookup-on-startup="true"
    expected-type="org.apache.activemq.command.ActiveMQTopic"
    proxy-interface="javax.jms.Topic">
  </jee:jndi-lookup>
 
  <bean id="singleConnectionFactory"
    class="org.springframework.jms.connection.SingleConnectionFactory"
    p:targetConnectionFactory-ref="connectionFactory" />
 
  <bean id="jmsMessageDelegate" 
    class="org.apache.activemq.book.ch8.jms.delegate.JmsMessageDelegate" />
  
  <bean id="myMessageListener"
    class="org.springframework.jms.listener.adapter.MessageListenerAdapter" 
    p:delegate-ref="jmsMessageDelegate" 
    p:defaultListenerMethod="handleMessage">
  </bean>
  
  <jms:listener-container
    container-type="default" 
    connection-factory="singleConnectionFactory"
    destination-type="topic"
    acknowledge="auto">
    <jms:listener destination="START" ref="myMessageListener" />
  </jms:listener-container>
</beans>

*/META-INF/context.xml*
<Context reloadable="true">
   <Resource
      auth="Container"
      name="jms/ConnectionFactory"
      type="org.apache.activemq.ActiveMQConnectionFactory"
      description="JMS Connection Factory"
      factory="org.apache.activemq.jndi.JNDIReferenceFactory"
      brokerURL="vm://localhost:61616"
      brokerName="MyActiveMQBroker" />
   <Resource
      auth="Container"
      name="jms/FooQueue"
      type="org.apache.activemq.command.ActiveMQTopic"
      description="JMS queue"
      factory="org.apache.activemq.jndi.JNDIReferenceFactory"
      physicalName="START" />
</Context>

*src/org.apache.activemq.book.ch8.jms.delegate/JmsMessageDelegate.java*
package org.apache.activemq.book.ch8.jms.delegate;

public class JmsMessageDelegate {
   public JmsMessageDelegate() {
      System.out.println("JmsMessageDelegate CONSTRUCTED");
   }

   public void handleMessage(String message) {
      System.out.println("Consumed message with payload: " + message);
   }
}

--
View this message in context: http://activemq.2283324.n4.nabble.com/Unable-to-receive-topic-message-tp3698560p3698560.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Mime
View raw message