2014-05-16 92 views

回答

0

您可以使用JMS訂閱該主題。

public class ExampleListener implements MessageListener { 

    public void onMessage(Message message) { 
     if (message instanceof TextMessage) { 
      try { 
       System.out.println(((TextMessage) message).getText()); 
      } 
      catch (JMSException ex) { 
       throw new RuntimeException(ex); 
      } 
     } 
     else { 
      throw new IllegalArgumentException("Message must be of type TextMessage"); 
     } 
    } 
} 





    <!-- this is the Message Driven POJO (MDP) --> 
    <bean id="messageListener" class="jmsexample.ExampleListener" /> 

    <!-- and this is the message listener container --> 
    <bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> 
     <property name="connectionFactory" ref="connectionFactory"/> 
     <property name="destination" ref="destination"/> 
     <property name="messageListener" ref="messageListener" /> 
    </bean> 

這裏更多:http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/jms.html