【发布时间】:2016-03-02 14:41:04
【问题描述】:
我正在使用带有 sockjs 和 stomp 的 spring websocket 4.2.4,我正在尝试从服务器向异步任务中的所有订阅者发送消息,但没有成功
我的班级是:
public class MyClass{
private timer;
public MyClass(){
this.timer = new Timer();
}
@Async
public void myMethod(){
timer.schedule(new MyReminder(), 1000);
}
@Async
private class MyReminder extends TimerTask{
@Autowired
SimpMessagingTemplate messageingTemplate;
@Override
public void run(){
messageingTemplate.convertAndSend("/app/subscribers","message");
}
}
}
但订阅者没有收到消息
有什么帮助吗?我做错了什么:(
* 编辑 *
我的消息代理:
public void configureMessageBroker(MessageBrokerRegistry config){
config.enableSimpleBroker("/topic","/myApp");
config.setApplicationDestinationPrefixes("/myApp");
}
当我订阅时:
subscribe("myApp/someRoute")
谢谢!!
** 编辑 2:**
感谢您帮助我解决问题:)
【问题讨论】:
标签: spring spring-mvc stomp spring-websocket sockjs