简体   繁体   English

如何使用cocoaMQTT在iOS中使订户脱机

[英]How to make a subscriber offline in iOS using cocoaMQTT

I am working on iOS using swift. 我正在使用swift在iOS上工作。 I am using cocoa mqtt protocol using in my iOS app. 我在我的iOS应用中使用可可mqtt协议。 I am also using Activemq for message broker. 我还将Activemq用于消息代理。

Objective 目的

I have subscribed on a topic that is made on ActiveMQ . 我已经订阅了ActiveMQ上的一个主题。 After that when I unsubscribe from topic on ActiveMQ then I want to the user remain subscriber of the topic but do not receive the messages. 之后,当我取消订阅ActiveMQ上的主题时,我希望用户仍然是该主题的订阅者,但不接收消息。 It gets offline. 它脱机。

I want that when subscriber again gets active than he can consume the pending messages from the topic. 我希望订户再次活跃时,他可以使用该主题中的待处理消息。

Problem Statement 问题陈述

When I unsubscribe from the topic, the user is no longer a subscriber of topic and all the messages that are sent on the topic gets lost ( I do not receive them) that I get in the period on unsubscription. 当我取消订阅该主题时,该用户不再是该主题的订阅者,并且在该主题上发送的所有消息都丢失了(我没有收到),这是我在取消订阅期间收到的。

One solution to this problem would be using the retained messaging functionality built right into MQTT. 解决此问题的一种方法是使用MQTT中内置的保留消息传递功能。 You will then receive the last message published on every topic, even when you've already received them in a previous session. 然后,即使您在上一个会话中已经收到它们,您也将收到有关每个主题的最新消息。

Another solution would be to use QoS 1 or 2 on the sent messages. 另一种解决方案是在发送的消息上使用QoS 1或2。 If your app connects with cleanSession set to false and the messages were published with QoS 1 or 2, you will receive the messages sent while disconnected from the broker. 如果您的应用程序在cleanSession设置为false连接,并且消息以QoS 1或2发布,则您将收到与代理断开连接时发送的消息。

Learn more about MQTT QoS here . 在此处了解有关MQTT QoS的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM