问题
how can i create a websocket stomp client (WebSocketStompClient) in node.js like i do in java with this lines..
WebSocketStompClient stompClient = new WebSocketStompClient(new SockJsClient(createTransportClient()));
stompClient.setMessageConverter(new MappingJackson2MessageConverter());
StompSession stompSession = stompClient.connect("ws://localhost:8081/stomp", new StompSessionHandlerAdapter() {
}).get(10, SECONDS);
i´ve tried several websocket projects in node.js, but none of them work
回答1:
i get it!. this work fine with Spring boot websocket + stomp + StockJS
var Stomp = require('stompjs')
var SockJS = require('sockjs-client')
var url = 'http://localhost:8081/stomp';
console.log('connecting to '+url);
var sock= new SockJS(url);
var stompClient = Stomp.over(sock);
var callback = function(message){
console.log('received message: '+message);
};
sock.onopen = function() {
console.log('open');
};
sock.onmessage = function(e) {
console.log('message', e.data);
sock.close();
};
sock.onclose = function() {
console.log('close');
};
stompClient.connect({},function (frame) {
stompClient.subscribe('/user/queue/reply', callback);
stompClient.send('/app/chat/este/es/el/chat/java/*/java/*',{},'{"name":"from nodejs"}');
});
来源:https://stackoverflow.com/questions/54786323/how-can-i-make-spring-websocket-node-js-client