0

是否可以使用spring消息将spring托管bean中的方法映射到主题订阅?

我在这里查看了示例:http: //assets.spring.io/wp/WebSocketBlogPost.html 包括示例股票应用程序,但看起来所有主题订阅都在客户端。是否也可以在服务器端订阅主题?

4

1 回答 1

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

于 2014-05-17T12:05:39.817 回答