Advertisement
joshualim

Untitled

Jan 7th, 2014
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. ///////////////////// CUSTOM SCRIPT BEGIN ////////////////////
  2.  
  3. // Connection parameters
  4. var client; //Variable client must be declared outside connect()
  5.  
  6. var mq_username = "guest",
  7. mq_password = "guest",
  8. mq_vhost = "/",
  9. mq_url = 'http://localhost:15674/stomp';
  10.  
  11. // This will be called upon successful connection
  12. function on_connect() {}
  13.  
  14. // This will be called upon arrival of a message
  15. function on_message(m) {}
  16.  
  17. // This will be called upon a connection error
  18.  
  19. function on_connect_error(error) {
  20. try {
  21. client.disconnect(function () {
  22. $('#debug').append('Disconnected!' + "<br>");
  23. varmessage = 'Disconnected!' + "<br>";
  24. });
  25. $('#debug').append('Reconnecting...' + "<br>");
  26. varmessage = 'Reconnecting...' + "<br>";
  27. setTimeout("Connect();", 5000); //Pause 5000ms before reconnecting
  28. } catch (err) {
  29. $('#debug').append('Exception:' + err.message + "<br>");
  30. varmessage = 'Exception:' + err.message + "<br>";
  31. }
  32. }
  33.  
  34. function Connect() {
  35. console.log('Connecting...');
  36. // Connect
  37. var ws = new SockJS(mq_url);
  38. client = Stomp.over(ws);
  39. client.heartbeat.outgoing = 0;
  40. client.heartbeat.incoming = 0;
  41. client.debug = function (str) {
  42. $("#debug").append(str + "<br>");
  43. varmessage = str;
  44. };
  45. client.connect(
  46. mq_username, mq_password, on_connect, on_connect_error, mq_vhost);
  47. }
  48.  
  49. Connect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement