var stompClient = null; function connect() { var socket = new SockJS('http://localhost:8081/amp/websocket'); stompClient = Stomp.over(socket); stompClient.connect({}, function (frame) { console.log('Connected: ' + frame); stompClient.subscribe('/public/transactions', function (msg) { var msgJ = JSON.parse(msg.body); console.log('/public/transactions', msgJ); }); stompClient.subscribe('/channel/transactions', function (msg) { var msgJ = JSON.parse(msg.body); console.log('/channel/transactions', msgJ); }); }); } function disconnect() { if (stompClient !== null) { stompClient.disconnect(); } setConnected(false); console.log("Disconnected"); } $(document).ready(function() { connect(); });