Activemq 订阅同一主题导致异常行为

Activemq 订阅同一主题导致异常行为,activemq,mqtt,Activemq,Mqtt,如果我一次又一次地订阅同一个主题,有什么问题吗。我有一个主题chatWith/u31我感觉当我重新启动订阅同一主题的应用程序时,mqtt is会产生一些问题,如: 要么消息未传递到一端,要么消息未接收到另一端,传递的消息和到达的消息都被调用,客户端断开连接 这是我的客户机代码,使用的是paho,而代理是activemq $(document).ready(function(){ var myUserId = "u56"; var statusTopic = "UserStatus/"+m

如果我一次又一次地订阅同一个主题,有什么问题吗。我有一个主题
chatWith/u31
我感觉当我重新启动订阅同一主题的应用程序时,mqtt is会产生一些问题,如:

要么消息未传递到一端,要么消息未接收到另一端,传递的消息和到达的消息都被调用,客户端断开连接

这是我的客户机代码,使用的是
paho
,而代理是
activemq

$(document).ready(function(){
  var myUserId = "u56";
  var statusTopic = "UserStatus/"+myUserId;
  $("#connect_clientId").val("example-"+(Math.floor(Math.random() * 100000)));
  if( !window.WebSocket) {
    $("#connect").html("\
        <h1>Get a new Web Browser!</h1>\
        <p>\
        Your browser does not support WebSockets. This example will not work properly.<br>\
        Please use a Web Browser with WebSockets support (WebKit or Google Chrome).\
        </p>\
    ");
  } else {

    var client, destination;

    $('#connect_form').submit(function() {
      var host = $("#connect_host").val();    
      var port = $("#connect_port").val();
      var clientId = $("#connect_clientId").val();
      var user = $("#connect_user").val();
      var password = $("#connect_password").val();

      destination = $("#destination").val();


      client = new Messaging.Client(host, Number(port), clientId);

      client.onConnect = onConnect;

      client.onMessageArrived = onMessageArrived;
      client.onMessageDelivered = onMessageDelivered;
      client.onConnectionLost = onConnectionLost;            

      client.connect({
        userName:user, 
        password:password, 
        onSuccess:onConnect, 
        onFailure:onFailure
      }); 
      return false;
    });  


  function createByteMessage(payload, destination) {
    var enc = stringToUint(JSON.stringify(payload));
    var message = new Messaging.Message(uintToString(enc)); 
    message.destinationName = destination;
    return message;    
  }

    var onConnect = function(frame) {
      debug("connected to MQTT");
      $('#connect').fadeOut({ duration: 'fast' });
      $('#connected').fadeIn();
      var message = createByteMessage({
        id: 'USER_STATUS',
        'status': 'Online',
        'sender': myUserId
      }, statusTopic);
      message.retained = true;
      client.send(message);       
      client.subscribe(destination);

    };  

    // this allows to display debug logs directly on the web page
    var debug = function(str) {
      $("#debug").append(document.createTextNode(str + "\n"));
    };  

    $('#disconnect').click(function() {
      client.disconnect();
      $('#connected').fadeOut({ duration: 'fast' });
      $('#connect').fadeIn();
      $("#messages").html("")
      return false;
    });

    $('#send_form').submit(function() {
      var text = $('#send_form_input').val();
      if (text) {
        var payload = {
          'id': Math.floor(Math.random()*10000+1),
          'text': text,
          'time': new Date(),
          'sender': '111',
          'senderName': 'currentUser.name'
        };
        var enc = stringToUint(JSON.stringify(payload));
        var message = new Messaging.Message(uintToString(enc));   
        message.destinationName = destination;
        client.send(message); 


        $('#send_form_input').val("");
      }
      return false;
    });

  function stringToUint(string) {
      var string = btoa(unescape(encodeURIComponent(string))),
          charList = string.split(''),
          uintArray = [];
      for (var i = 0; i < charList.length; i++) {
          uintArray.push(charList[i].charCodeAt(0));
      }
      return new Uint8Array(uintArray);
  }

  function uintToString(uintArray) {
      var encodedString = String.fromCharCode.apply(null, uintArray),
          decodedString = decodeURIComponent(escape(atob(encodedString)));
      return decodedString;
  }    

    function onFailure(failure) {
      debug("failure");
      debug(failure.errorMessage);
    }  

    function onMessageDelivered(message) {
      console.log("onMessageDelivered: "+message.payloadString);
    }

    function onMessageArrived(message) {
      console.log("onMessageArrived: "+message.payloadString);
      var p = document.createElement("p");
      var t = document.createTextNode(message.payloadString);
      p.appendChild(t);
      $("#messages").append(p);
    }

    function onConnectionLost(responseObject) {
      if (responseObject.errorCode !== 0) {
        debug(client.clientId + ": " + responseObject.errorCode + "\n");
      }
    }    

  }
});    
$(文档).ready(函数(){
var myUserId=“u56”;
var statusTopic=“UserStatus/”+myUserId;
$(“#connect_clientId”).val(“示例-”+(Math.floor(Math.random()*100000));
如果(!window.WebSocket){
$(“#连接”).html\
获得一个新的网络浏览器\
\
您的浏览器不支持WebSocket。此示例无法正常工作。
\ 请使用支持WebSocket的Web浏览器(WebKit或Google Chrome)\

\ "); }否则{ var客户端,目的地; $(“#连接表单”).submit(函数(){ var host=$(“#连接_主机”).val(); var port=$(“#连接_端口”).val(); var clientId=$(“#connect_clientId”).val(); var user=$(“#连接_用户”).val(); var password=$(“#连接_密码”).val(); destination=$(“#destination”).val(); client=新消息。client(主机、号码(端口)、clientId); client.onConnect=onConnect; client.onMessageArrived=onMessageArrived; client.onMessageDelivered=onMessageDelivered; client.onConnectionLost=onConnectionLost; client.connect({ 用户名:user, 密码:密码, onSuccess:onConnect, onFailure:onFailure }); 返回false; }); 函数createByteMessage(有效负载、目标){ var enc=stringToUint(JSON.stringify(有效负载)); var message=新消息。消息(uintToString(enc)); message.destinationName=目的地; 返回消息; } var onConnect=功能(帧){ 调试(“连接到MQTT”); $('#connect').fadeOut({duration:'fast'}); $(“#已连接”).fadeIn(); var message=createByteMessage({ id:“用户状态”, “状态”:“联机”, “发件人”:myUserId },主题); message.retained=true; 客户端。发送(消息); client.subscribe(目的地); }; //这允许直接在网页上显示调试日志 变量调试=函数(str){ $(“#调试”).append(document.createTextNode(str+“\n”); }; $(“#断开连接”)。单击(函数(){ client.disconnect(); $('#connected').fadeOut({duration:'fast'}); $('#connect').fadeIn(); $(“#消息”).html(“”) 返回false; }); $(“#发送表单”).submit(函数(){ var text=$('#发送表单输入').val(); 如果(文本){ var有效载荷={ “id”:Math.floor(Math.random()*10000+1), “文本”:文本, “时间”:新日期(), “发件人”:“111”, “senderName”:“currentUser.name” }; var enc=stringToUint(JSON.stringify(有效负载)); var message=新消息。消息(uintToString(enc)); message.destinationName=目的地; 客户端。发送(消息); $('send#form_input').val(“”); } 返回false; }); 函数stringToUint(字符串){ var string=btoa(unescape(encodeURIComponent(string)), charList=string.split(“”), uintArray=[]; 对于(var i=0;i

问题在于,如果使用相同的
目标
主题运行应用程序,并且
状态主题
应用程序工作正常。但每次我以不同的订阅方式启动应用程序时,它都可以正常工作。

您必须给出更多关于您正在做什么的上下文。显示代码,说出您正在使用的代理。我们不是通灵者我更新了我的问题