Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Use SockJS
- Stomp.WebSocketClass = SockJS;
- // Connection parameters
- var mq_username = "guest",
- mq_password = "guest",
- mq_vhost = "/",
- mq_url = 'http://' + window.location.hostname + ':15674/stomp',
- // The queue we will read. The /topic/ queues are temporary
- // queues that will be created when the client connects, and
- // removed when the client disconnects. They will receive
- // all messages published in the "amq.topic" exchange, with the
- // given routing key, in this case "mymessages"
- mq_queue = "/topic/mymessages";
- // This is where we print incomoing messages
- var output;
- // This will be called upon successful connection
- function on_connect() {
- output.innerHTML += 'Connected to RabbitMQ-Web-Stomp<br />';
- console.log(client);
- client.subscribe(mq_queue, on_message);
- }
- // This will be called upon a connection error
- function on_connect_error() {
- output.innerHTML += 'Connection failed!<br />';
- }
- // This will be called upon arrival of a message
- function on_message(m) {
- console.log('message received');
- console.log(m);
- output.innerHTML += m.body + '<br />';
- }
- // Create a client
- var client = Stomp.client(mq_url);
- window.onload = function () {
- // Fetch output panel
- output = document.getElementById("output");
- // Connect
- client.connect(
- mq_username,
- mq_password,
- on_connect,
- on_connect_error,
- mq_vhost
- );
- };
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="content-type" content="text/html; charset=utf-8">
- <title>Testing RabbitMQ Web Stomp</title>
- <!-- From: http://cdn.sockjs.org/ -->
- <script src="http://cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js"></script>
- <script src="resources/js/stomp.js"></script>
- <!-- From RabbitMQ-Web-Stomp examples -->
- <!-- Our example app -->
- <script src="listener-app.js"></script>
- <style>
- #output {
- border: 1px solid black;
- min-height: 100px;
- }
- </style>
- </head>
- <body>
- <h1>Waiting for messages</h1>
- <div id="output">
- <!-- incoming messages will be printed here -->
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement