SpringBoot Websocket错误-o.s.m.s.b.DefaultSubscriptionRegistry:GenericMessage中没有目的地

时间:2018-11-29 10:18:03

标签: angularjs spring-boot websocket spring-websocket

我正在尝试基于SpringBoot Websockets作为后端和Angular Client作为前端构建聊天应用程序。现在,如果我将角度代码嵌入到SpringBoot应用程序中,则一切运行正常。 但是,如果我尝试使用电子锻造将angualr应用程序作为独立客户端运行,则会出现以下错误:

o.s.m.s.b.DefaultSubscriptionRegistry    : No destination in GenericMessage 

MessageController.java

   /**
    * Process message.
    *
    * @param message the message
    */
   //This is intended to particular user;
   @MessageMapping("/users/message")
   public void processMessage( MessageBean message )
   {
      message.setMessageType( MessageTypeEnum.CREATE_CHANNEL );
      Map< String, Object > response;
      String responseMessage = "Connection request sent successfully";
      try
      {
         String channel = userService.generateConnectionString( message.getRecieverId() );
         boolean isError = false;
         if ( channel == null )
         {
            isError = true;
            responseMessage = "Unable to sent request, please try again";
         }
         message.setText( channel );
         response = generateResponse( isError, message, responseMessage );
         if ( !isError )
         {
            messagingTemplate.convertAndSend( "/queue/room/" + message.getRecieverId(), response );
            messagingTemplate.convertAndSend( "/queue/room/" + message.getSenderId(), response );
         }
         else
         {
            messagingTemplate.convertAndSend( "/queue/room/" + message.getSenderId(), response );
         }

      }
      catch ( Exception e )
      {
         responseMessage = "Unable to sent request, please try again";
         response = generateResponse( true, null, responseMessage );
         messagingTemplate.convertAndSend( "/queue/room/" + message.getSenderId(), response );
         e.printStackTrace();
      }
   }

// AngularJS代码段:

$scope.attempHandhsake = function(targetUser)
        {
            $scope.searchList = [];
            var message = {};
            message.senderId = $scope.user.id;
            message.senderName = $scope.user.firstname + " " + $scope.user.lastname;
            message.usernameSender = $scope.user.username;
            message.recieverId = targetUser.id;
            message.recieverName = targetUser.firstname + " " + targetUser.lastname;
            message.usernameReciever = targetUser.username;
            var sendObject = JSON.stringify(message);
            client.send("/app/users/message",sendObject,{});
        }

1 个答案:

答案 0 :(得分:1)

您不应该将函数client.send的第二个参数设为第三个参数,反之亦然吗?

换句话说,函数$scope.attemptHandshake的最后一行应该看起来像这样

 client.send("/app/users/message",{},sendObject);