Rabbitmq stomp连接失败

时间:2016-09-20 07:49:43

标签: rabbitmq stomp

我是一个完全的初学者,尝试使用rabbitmq,stomp和sock js创建一个基本的Web消息服务,我遵循一个教程并完成了所有写的东西,但连接仍然失败。我无法弄清楚为什么会有任何帮助

这是我的listenr-app.js文件:

// 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
  );
};

这是我的html文件:

<!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>

0 个答案:

没有答案