js 连接rabbitMq 实现消息推送 后台是 java springMVC框架
Spring + STOMP + RabbitMQ消息推送
不是Spring boot框架
Spring Boot WEB用的也是SpringMVC, 下载Stomp,里面有websocket连接的例子。
1. 开启RabbitMQ
2. js直接连接就行,当然要引入stomp的引用
例子:这个需要stomp.js以及jquery.js
client = Stomp.client(url);
client.connect(login, passcode, function(frame) {
client.subscribe(destination, function(message) {
var p = document.createElement("p");
p.appendChild(document.createTextNode(message.body));
$("#messages").append(p);
});
});
return false;
});