简体   繁体   中英

how can i make spring websocket + node.js client

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

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"}');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM