Advertisement
Guest User

Untitled

a guest
Sep 20th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. // Use SockJS
  2. Stomp.WebSocketClass = SockJS;
  3.  
  4. // Connection parameters
  5. var mq_username = "guest",
  6. mq_password = "guest",
  7. mq_vhost = "/",
  8. mq_url = 'http://' + window.location.hostname + ':15674/stomp',
  9.  
  10. // The queue we will read. The /topic/ queues are temporary
  11. // queues that will be created when the client connects, and
  12. // removed when the client disconnects. They will receive
  13. // all messages published in the "amq.topic" exchange, with the
  14. // given routing key, in this case "mymessages"
  15. mq_queue = "/topic/mymessages";
  16.  
  17. // This is where we print incomoing messages
  18. var output;
  19.  
  20. // This will be called upon successful connection
  21. function on_connect() {
  22. output.innerHTML += 'Connected to RabbitMQ-Web-Stomp<br />';
  23. console.log(client);
  24. client.subscribe(mq_queue, on_message);
  25. }
  26.  
  27. // This will be called upon a connection error
  28. function on_connect_error() {
  29. output.innerHTML += 'Connection failed!<br />';
  30. }
  31.  
  32. // This will be called upon arrival of a message
  33. function on_message(m) {
  34. console.log('message received');
  35. console.log(m);
  36. output.innerHTML += m.body + '<br />';
  37. }
  38.  
  39. // Create a client
  40. var client = Stomp.client(mq_url);
  41.  
  42. window.onload = function () {
  43. // Fetch output panel
  44. output = document.getElementById("output");
  45.  
  46. // Connect
  47. client.connect(
  48. mq_username,
  49. mq_password,
  50. on_connect,
  51. on_connect_error,
  52. mq_vhost
  53. );
  54. };
  55.  
  56. <!DOCTYPE html>
  57. <html>
  58. <head>
  59. <meta http-equiv="content-type" content="text/html; charset=utf-8">
  60. <title>Testing RabbitMQ Web Stomp</title>
  61.  
  62. <!-- From: http://cdn.sockjs.org/ -->
  63. <script src="http://cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js"></script>
  64.  
  65. <script src="resources/js/stomp.js"></script>
  66.  
  67. <!-- From RabbitMQ-Web-Stomp examples -->
  68.  
  69.  
  70. <!-- Our example app -->
  71. <script src="listener-app.js"></script>
  72.  
  73. <style>
  74. #output {
  75. border: 1px solid black;
  76. min-height: 100px;
  77. }
  78. </style>
  79. </head>
  80. <body>
  81.  
  82. <h1>Waiting for messages</h1>
  83.  
  84. <div id="output">
  85. <!-- incoming messages will be printed here -->
  86. </div>
  87.  
  88.  
  89. </body>
  90. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement