Announcement Announcement Module
Collapse
No announcement yet.
Each published message is received 3 times. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Each published message is received 3 times.

    Hello,

    I have a simple scenario, where a message in one web is being published to a topic. However, on the receiving side, I am picking it up 3 times each time its published. Any ideas as to what may be causing this?

    Publisher:
    Code:
    public class JMSSender {
    	private JmsTemplate jmsTemplate;
    
    	public JMSSender(JmsTemplate jmsTemplate) {
    		this.jmsTemplate = jmsTemplate;
    	}
    
    	public void sendMessage(Object obj) {
    		jmsTemplate.convertAndSend(obj);		
    	}
    }
    
    // client configuration
    
    	<bean name="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
    		<property name="jndiName" value="java:ConnectionFactory" />
    	</bean>
    
    	<bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
    		<property name="connectionFactory" ref="jmsConnectionFactory" />
    	</bean>
    
    	<bean id="messageProducer" class="com.diamelle.hr.struts.action.JMSSender">
    		<constructor-arg ref="messageTemplate" />
    	</bean>
    	
    	<bean name="messageTemplate" class="org.springframework.jms.core.JmsTemplate">
    		<property name="connectionFactory" ref="jmsConnectionFactory" />
    		<property name="defaultDestination" ref="destination" />
    		<property name="receiveTimeout" value="1" />
    	</bean>
    
    	<bean name="destination" class="org.springframework.jndi.JndiObjectFactoryBean">
    		<property name="jndiName" value="topic/provisionTopic" />
    	</bean>
    Listener:

    Code:
    	public void onMessage(Message message)  {
    		Users user = null;
    
    		try{
    			log.debug("message received: " + ((ObjectMessage) message).getObject()); 
    			
    			ObjectMessage objMsg = (ObjectMessage) message;
    			if ( objMsg.getObject() instanceof Users ) {
    				user = (Users)objMsg.getObject();
    				processMsg(user);
    			}
    			
    	    } catch (JMSException ex) {
    	        throw new RuntimeException(ex);
    	    } 
    
    	}
    
    
    // listener configuration
    
    	<bean id="userMsgListener" class="diamelle.common.user.UserMessageListener">
    		<property name="userMgr" ref="userManager" />
    	</bean>
    	
    	<bean id="userMsgListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    		<property name="concurrentConsumers" value="1"/>
    		<property name="connectionFactory" ref="jmsConnectionFactory"/>
    		<property name="transactionManager" ref="jmsTransactionManager" />
    		<property name="destination" ref="provDestination"/>
    		<property name="messageListener" ref="userMsgListener"/>
    	</bean>
    	
    	<bean name="provDestination" class="org.springframework.jndi.JndiObjectFactoryBean">
    		<property name="jndiName" value="topic/provisionTopic" />
    	</bean>	
    	<bean name="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
    		<property name="jndiName" value="java:ConnectionFactory" />
    	</bean>
    
    	<bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
    		<property name="connectionFactory" ref="jmsConnectionFactory" />
    	</bean>

  • #2
    I built a little test scenario using your configuration files and it worked. I used ActiveMQ broker and ActiveMQQueue as destination.

    So, I suppose it has to do with destination settings.

    Comment


    • #3
      Andrei,

      thanks. Perhaps its an issue with the message in jboss 4.2. I will dig deeper and try to isolate the cause of this.

      Regards
      suneet

      Comment


      • #4
        Just a thought here, but we ran into this a while ago, too.

        Any chance that the config you're using i being imported into other applicationContext.xml files? In that case, you get one listener for every context that imports.

        Comment


        • #5
          Thanks very much for the tip. That is exactly what the problem was.

          Regards
          Suneet

          Comment

          Working...
          X