STOMP web套接字回调不'不起作用
STOMP web socket callback doesn't work
我正在尝试使用STOMP javascript web套接字连接到mqtt浏览器。已建立连接。但是我的代码中的回调函数没有被调用?但是ping消息是发送的。
我正在使用一个url作为主机地址。这是我的密码。
<!DOCTYPE html>
<html>
<head>
<script src="http://cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js"></script>
<script src="stomp.js"></script>
<script>
var ws = new SockJS('http://108.567.234.143:9876/stomp');
var client = Stomp.over(ws);
client.connect('username', 'pw', connect_callback, on_error);
client.heartbeat.outgoing = 20000; // client will send heartbeats every 20000ms
client.heartbeat.incoming = 0; // client does not want to receive heartbeats
// from the server
var connect_callback = function() {
alert("Connected to rabbitMQ");
var subscription = client.subscribe("CRICKET", subs_callback);
console.log('subscribe to CRICKET');
};
var on_error = function(error) {
console.log('error');
};
var subs_callback = function(message) {
// called when the client receives a STOMP message from the server
if (message.body) {
alert("got message with body " + message.body)
//console.log('got message with body' + message.body);
} else {
alert("got empty message");
}
};
console.log('message.body');
</script>
</head>
<body>
hello world
</body>
</html>
我无法订阅某个主题。请告诉我怎么了?这是控制台日志
感谢
回调是在使用后定义的。
.connect()
函数很可能默默地忽略了未定义的函数,所以您没有看到任何错误。
在定义回调之后将.connect()
移动到应该可以解决此问题。
var ws = new SockJS('http://108.567.234.143:9876/stomp');
var client = Stomp.over(ws);
client.heartbeat.outgoing = 20000; // client will send heartbeats every 20000ms
client.heartbeat.incoming = 0; // client does not want to receive heartbeats
// from the server
var connect_callback = function() {
alert("Connected to rabbitMQ");
var subscription = client.subscribe("CRICKET", subs_callback);
console.log('subscribe to CRICKET');
};
var on_error = function(error) {
console.log('error');
};
var subs_callback = function(message) {
// called when the client receives a STOMP message from the server
if (message.body) {
alert("got message with body " + message.body)
//console.log('got message with body' + message.body);
} else {
alert("got empty message");
}
};
client.connect('username', 'pw', connect_callback, on_error);
console.log('message.body');
相关文章:
- suitecrm的web到lead形式在wordpress中不起作用
- Web控制台命令不起作用
- WebMethod在ASP.Net Web角色(Web窗体)中不起作用
- JavaScript onScroll在谷歌应用程序脚本web应用程序中不起作用
- STOMP web套接字回调不'不起作用
- 脚本在web浏览器控件中不起作用
- Web音频-AudioParam调度功能不起作用
- web驱动程序的示例不起作用
- Web方法只有在标记为静态时才有效,否则就不起作用;t
- 引导图示符在java Web应用程序中不起作用
- XMLHttpRequest在Google Chrome Packaged Web App中不起作用
- 在 Web 视图上自动启动 html5 视频,在 Android 4.2.2 上不起作用
- 成功提交 Web 表单后,Javascript 重置功能将不起作用
- Windows.Scroll事件在Android Web View上不起作用
- JavaScript 在 MVC Web 应用程序中不起作用
- Web套接字在分配给全局变量时不起作用
- 移动 Web 服务不起作用
- JavaScript Web Worker close() 不起作用
- 奇怪的Javascript在移动到Web服务器时不起作用
- jQuery animate:scrolltop 在 Firefox 或 Web Explorer 中不起作用