【问题标题】:unable to de-queue previous messages from a queue无法从队列中出列先前的消息
【发布时间】:2019-01-13 19:37:17
【问题描述】:

我正在使用 stomp over websocket 创建一个带有 android 和 spring 的聊天应用程序。当我向特定客户端发送多条消息时,它仅显示队列中的最后一条消息,而不是所有先前的消息。我想查看队列中的所有消息。

客户端

mStompClient =Stomp.over(WebSocket.class, "url");
    mStompClient.connect();


    mStompClient.topic("/topic/queue"+clientid).subscribe(topicMessage -> {


        textView.setText(topicMessage.getPayload());

    });

服务器端

@MessageMapping("/chat")
@SendTo("/topic/queue")

 public String sendMessage(String msg) {


    simpMessagingTemplate.convertAndSend("/topic/queue"+clientid,msg );

    return "";
}

【问题讨论】:

    标签: java android rest


    【解决方案1】:

    在我看来,您应该保留之前发送的数据,然后从队列中追加新的传入消息并异步馈送数据存储。

    1. 步骤:用户打开聊天窗口,然后从数据库中获取数据。
    2. 步骤:向队列发送消息,消费者应监听队列并将新消息提供给聊天窗口和数据存储。
    3. 步骤:如果用户退出应用程序,无论发生什么。您可以展示数据存储中的数据。

    【讨论】:

      猜你喜欢
      • 2015-11-22
      • 2013-08-01
      • 2014-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多