81,114
社区成员
发帖
与我相关
我的任务
分享import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* Created by WD on 2017/4/17.
*/
@Component
public class TestJob {
private static final String TOPIC_REQUIRE= "/topic/require";
private static final String TOPIC_ONE= "/topic/one";
private static final String TOPIC_TWO= "/topic/two";
private static final String TOPIC_THREE= "/topic/three";
@Autowired
private SimpMessagingTemplate messagingTemplate;
/**
* 测试定时任务
*/
public void test() {
try {
messagingTemplate.convertAndSend(TOPIC_REQUIRE, new Date());
Double a = Math.random();
System.out.println("定时任务" + a);
}catch(Exception e){
System.out.println("webSocket推送异常");
}
}
} function webSocketConnect() {
//webSocket连接
//生成websocket对象
websocket = new SockJS('${basePath}/websocket');
//获得满足websocket定义的对象
stompClient = Stomp.over(websocket);
//连接服务端
debugger;
stompClient.connect({}, function (frame) {
//订阅
stompClient.subscribe("/topic/require", function (response) {
var require = response.body;
console.log(require);
});
});
}@Component
@EnableScheduling
public class TestJob {