we set up websocket topic with Spring websocket, and then the client side is using Stomp.js to subscribe it; it works fine if connect to the websocket service directly; but now we set up Kong as the API Gateway in front of the websocket service; it needs to set header "Host: websocket" when connect to it; But it doesn't work with Stomp.js;
var url=':8000/websocket/tracker';
var socket = new SockJS(url);
stompClient = Stomp.over(socket);
var thisheaders={
Host:'websocket'
};
stompClient.connect(thisheaders, function (frame) {
setConnected(true);
console.log('Connected: ' + frame);
stompClient.subscribe('/topic/greetings', function (greeting) {
showGreeting(JSON.parse(greeting.body).content);
});
});
Does anyone know how to add the headers for it? Or the Stomp.js just doesn't support to add headers?
we set up websocket topic with Spring websocket, and then the client side is using Stomp.js to subscribe it; it works fine if connect to the websocket service directly; but now we set up Kong as the API Gateway in front of the websocket service; it needs to set header "Host: websocket." when connect to it; But it doesn't work with Stomp.js;
var url='http://xx.xx.xx.xx:8000/websocket/tracker';
var socket = new SockJS(url);
stompClient = Stomp.over(socket);
var thisheaders={
Host:'websocket.'
};
stompClient.connect(thisheaders, function (frame) {
setConnected(true);
console.log('Connected: ' + frame);
stompClient.subscribe('/topic/greetings', function (greeting) {
showGreeting(JSON.parse(greeting.body).content);
});
});
Does anyone know how to add the headers for it? Or the Stomp.js just doesn't support to add headers?
Share Improve this question asked Oct 23, 2018 at 13:15 pankaj malikpankaj malik 1071 gold badge2 silver badges15 bronze badges1 Answer
Reset to default 1@pankaj malik.. try this
var url='http://xx.xx.xx.xx:8000/websocket/tracker';
var socket = new SockJS(url);
stompClient = Stomp.over(socket);
var thisheaders={
login: 'user',
passcode: 'AuWcecmbtSz2',
AuthToken: getItem('Authentication')//get your authentication token here
};
stompClient.connect(thisheaders, function (frame) {
setConnected(true);
console.log('Connected: ' + frame);
stompClient.subscribe('/topic/greetings', function (greeting) {
showGreeting(JSON.parse(greeting.body).content);
});
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745418980a4626882.html
评论列表(0条)