Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring4WebSocket订阅一个主题_Spring_Websocket_Spring Websocket - Fatal编程技术网

Spring4WebSocket订阅一个主题

Spring4WebSocket订阅一个主题,spring,websocket,spring-websocket,Spring,Websocket,Spring Websocket,是否可以使用spring消息传递将spring托管bean中的方法映射到主题订阅 我已经看了这里的例子: 包括示例stock应用程序,但看起来所有主题订阅都在客户端。也可以在服务器端订阅主题吗?您可以使用JMS订阅主题 public class ExampleListener implements MessageListener { public void onMessage(Message message) { if (message instanceof TextM

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

我已经看了这里的例子:
包括示例stock应用程序,但看起来所有主题订阅都在客户端。也可以在服务器端订阅主题吗?

您可以使用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>
公共类ExampleListener实现MessageListener{
消息(消息消息)上的公共无效{
如果(文本消息的消息实例){
试一试{
System.out.println(((TextMessage)message.getText());
}
捕获(JMEX){
抛出新的运行时异常(ex);
}
}
否则{
抛出新的IllegalArgumentException(“消息必须是TextMessage类型”);
}
}
}
详情如下: