Announcement Announcement Module
Collapse
No announcement yet.
setting Destination at runtime? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • setting Destination at runtime?

    I am trying to set/change my MDP destination at run-time based on business rules.

    In my message listener, I have created:
    @Autowired
    private ActiveMQQueue playerDestination;

    and in my context I have:

    <bean id="playerDestination" class="org.apache.activemq.command.ActiveMQQueue">
    <constructor-arg index="0" value="Consumer.A.VirtualTopic.TEST" />
    </bean>


    But the bean is not found on startup.

    Here is my whole Listener:

    Code:
    public class StatusUpdateService implements MessageListener {
    
        public transient Log log = LogFactory.getLog(this.getClass());
        
        @Autowired
        private ActiveMQQueue playerDestination;
    
        private String name;
    
        private int seat;
    
        /**
         * Process Table Status Update Messages
         * 
         * @param message
         *            JMS Message from Table Server.
         */
        public void onMessage(Message message) {
            log.info("//----- " + name + " -----------------------------//");
            ActiveMQTextMessage mapMessage = (ActiveMQTextMessage) message;
    
            try {
                log.info(mapMessage.toString());
    
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        
        public void setDestination(String destinationName){
            playerDestination.setPhysicalName("Consumer."+seat+".VirtualTopic.TEST");
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public int getSeat() {
            return seat;
        }
    
        public void setSeat(int seat) {
            this.seat = seat;
        }
    
    } // The End...

  • #2
    Can anyone help here?

    I have tried to create a unit test for my situation.

    Code:
        @Test
        public void testChangeMessageDestination() throws Exception {
            log.info("Send a test message to Table Service");
            
            log.info("***** testChangeMessageDestination() ********************************");
    
            
            DefaultMessageListenerContainer container = (DefaultMessageListenerContainer)context.getBean("jmsContainer1");
            assertNotNull(container);
            container.setDestinationName("Consumer.1.VirtualTopic.Table.BAD");
            assertEquals("Consumer.1.VirtualTopic.Table.BAD", container.getDestinationName());
            
            resultClient1.expectedMessageCount(0);
    
            // Send the test message to make Server Service create our Status Message
            producerTemplate.sendBody("jms:queue:bets",
                    ExchangePattern.InOnly, 22);
            
            // now lets assert that the mock endpoint received messages
            resultClient1.assertIsSatisfied();
    
            log.info("* no message received yet.---------------------------------");
    
            container.setDestinationName("Consumer.1.VirtualTopic.Table.1");
            assertEquals("Consumer.1.VirtualTopic.Table.1", container.getDestinationName());
    
            resultClient1.expectedMinimumMessageCount(1);
    
            // Send the test message to make Server Service create our Status Message
            producerTemplate.sendBody("jms:queue:bets",
                    ExchangePattern.InOnly, 22);
            
            // now lets assert that the mock endpoint received messages
            resultClient1.assertIsSatisfied();
    
    
        }
    This seemed what I want.
    But this test fails to ever get a message even though I have another similar test that does. So the issue is setting the destination.
    Last edited by mickknutson; Aug 31st, 2009, 12:33 PM.

    Comment

    Working...
    X