Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configure offline publishing in v2 #96

Closed
shravan097 opened this issue Jul 31, 2020 · 14 comments
Closed

configure offline publishing in v2 #96

shravan097 opened this issue Jul 31, 2020 · 14 comments
Labels
feature-request A feature should be added or improved. p2 This is a standard priority issue

Comments

@shravan097
Copy link

Is your feature request related to a problem? Please describe.
I did not see if offline publishing was enabled by default.

Describe the solution you'd like
As in python sdk v1, it would be nice to see something like configureOfflinePublishQueueing method.

Describe alternatives you've considered
I would have a Queue of my own maintaining if the message was published or not.

Additional context
https://github.com/aws/aws-iot-device-sdk-python/blob/master/samples/basicPubSub/basicPubSub.py#L101

@shravan097 shravan097 added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jul 31, 2020
@graebm
Copy link
Contributor

graebm commented Aug 3, 2020

The current behavior is:

  • All published messages are queued before sending, regardless of whether the client is offline or online.
  • When the client gets online (or if it is already online) the messages from the queue are sent in order.
  • HOWEVER: If the client WAS online, and goes offline, at that moment it cancels every PUBLISH and SUBSCRIBE in its queue.

We understand this is inconsistent. The user probably wants either:

  1. messages are always queued until they can be sent
  2. messages fail if the client is offline, or goes offline before they are sent.

We are very actively evaluating changing this. I will keep this issue open and we'll update when we've made changes (or formalized the current behavior)

If you want to take full control of your destiny right now, you could build a queue of your own that sends 1 message at a time to the client. If it succeeds, then send the next. If it fails, then retry. This also gives you the opportunity to have full control over the length of time a message can be queued, the number of messages that will be queued, etc.

@graebm graebm added the investigating Issue is being investigated and/or work is in progress to resolve the issue. label Aug 3, 2020
@jmklix jmklix removed the needs-triage This issue or PR still needs to be triaged. label Aug 4, 2020
@samvandamme
Copy link

samvandamme commented Sep 5, 2020

If you want to take full control of your destiny right now, you could build a queue of your own that sends 1 message at a time to the client. If it succeeds, then send the next. If it fails, then retry. This also gives you the opportunity to have full control over the length of time a message can be queued, the number of messages that will be queued, etc.

Hi @graebm. How would you go about that? If my device publishes messages, but it's offline, I would think those messages stay in soms sort of queue? Is there a way to access this queue and purge certain messages from it if they have not been published yet?

Thank you

@jmklix
Copy link
Member

jmklix commented Nov 16, 2020

@samvandamme you can set quality of service (qos) to at most once (0).
qos=mqtt.QoS.AT_MOST_ONCE
On the same device subscribe to the topic that you are publishing to. Then to make sure messages are sent you maintain a list of messages that you have published. Only remove them when you have received back the message on the topic.

@dg-eparizzi
Copy link

The current behavior is:

  • All published messages are queued before sending, regardless of whether the client is offline or online.
  • When the client gets online (or if it is already online) the messages from the queue are sent in order.
  • HOWEVER: If the client WAS online, and goes offline, at that moment it cancels every PUBLISH and SUBSCRIBE in its queue.

We understand this is inconsistent. The user probably wants either:

  1. messages are always queued until they can be sent
  2. messages fail if the client is offline, or goes offline before they are sent.

We are very actively evaluating changing this. I will keep this issue open and we'll update when we've made changes (or formalized the current behavior)

If you want to take full control of your destiny right now, you could build a queue of your own that sends 1 message at a time to the client. If it succeeds, then send the next. If it fails, then retry. This also gives you the opportunity to have full control over the length of time a message can be queued, the number of messages that will be queued, etc.

So what's the recommended approach to handle devices going offline for some periods of time?

Assuming I have a device sending messages every 5 seconds, the device is online, messages are reaching AWS IoT Core. Then, the device lost connection for 10 minutes and then goes online again. What happens with all those messages that were tried to publish during the 10 minutes offline period? Do they get published as soon as the device goes online again or are they lost for ever?

@jmklix
Copy link
Member

jmklix commented Feb 2, 2021

The first few messages will be lost while the sdk hasn't realized that it is no longer disconnected. All subsequent messages would be save in the queue and sent when connection is restored.

When testing this I lost the first 5 messages when using the pubsub, which sends messages every second. So you would only loose one message most of the time.

@jmklix jmklix removed the investigating Issue is being investigated and/or work is in progress to resolve the issue. label Feb 2, 2021
@nicholashughes
Copy link

I'd also like to understand this in greater detail. As mentioned above, messages that are published while offline go into the queue and then are published when the connection goes back online.

How many messages are stored in the offline queue? The previous SDK allowed you to choose, infinite, none, or a specified amount. I can't find any documentation about this. It sounds like infinite but I'd like to know. The previous SDK also allowed you to drop from the top or bottom of the queue. Is that possible now?

The previous SDK also allowed you to choose a drain rate for messages stored in the queue. Is this configurable now? If not, what is the value?

@Blake-James
Copy link

@graebm Are you able to let us know if there is anything currently on the roadmap for this?
Should we expect any sort of controls over the offline queue in addition to the default behaviour described here?

@Infinity1high
Copy link

Agree, previous SDK allowed more, that is weird to build smth that is missing features and claiming this solution is better

@Divya-nemuri
Copy link

Divya-nemuri commented Aug 24, 2022

i want to know the connection status of the client, while publishing the data if there is no internet connection i wanna store data in the local, i was trying to get the status. i tried with publish_future,data = MQTT_CONNECTION.publish()
was checking publish_future.result() if data is published it is returning packet id but if i disconnect the internet connection it is just stopping the execution there. i tried reading the future.result() of MQTT_CONNECTION which is always "session_present":True.

is there any way to get the connection status or the message published status.

@Divya-nemuri
Copy link

The current behavior is:

  • All published messages are queued before sending, regardless of whether the client is offline or online.
  • When the client gets online (or if it is already online) the messages from the queue are sent in order.
  • HOWEVER: If the client WAS online, and goes offline, at that moment it cancels every PUBLISH and SUBSCRIBE in its queue.

We understand this is inconsistent. The user probably wants either:

  1. messages are always queued until they can be sent
  2. messages fail if the client is offline, or goes offline before they are sent.

We are very actively evaluating changing this. I will keep this issue open and we'll update when we've made changes (or formalized the current behavior)

If you want to take full control of your destiny right now, you could build a queue of your own that sends 1 message at a time to the client. If it succeeds, then send the next. If it fails, then retry. This also gives you the opportunity to have full control over the length of time a message can be queued, the number of messages that will be queued, etc.

How to check if the message sent to the client is succeeded or not

@jmklix
Copy link
Member

jmklix commented Aug 24, 2022

@Divya-nemuri you can have the client publish a message indicating that it has received a message

Also for connection status:

If you want another device/program to know if a device is online you will want to use Lifecycle events.

If you want a device to know when it is online/online you will want to use on_connection_interrupted.

@jmklix jmklix added the p2 This is a standard priority issue label Nov 7, 2022
@juvi87
Copy link

juvi87 commented May 15, 2024

has there been any progress on this?

@jmklix
Copy link
Member

jmklix commented May 17, 2024

With mqtt5 you can now configure the offline_queue_behavior. Check our API docs here for more info, but here is how it currently works:

class awscrt.mqtt5.ClientOperationQueueBehaviorType(value)

Controls how disconnects affect the queued and in-progress operations tracked by the client. Also controls how operations are handled while the client is not connected. In particular, if the client is not connected, then any operation that would be failed on disconnect (according to these rules) will be rejected.

DEFAULT = 0
Default client operation queue behavior. Maps to FAIL_QOS0_PUBLISH_ON_DISCONNECT.

FAIL_NON_QOS1_PUBLISH_ON_DISCONNECT = 1
Re-queues QoS 1+ publishes on disconnect; un-acked publishes go to the front while unprocessed publishes stay in place. All other operations (QoS 0 publishes, subscribe, unsubscribe) are failed.

FAIL_QOS0_PUBLISH_ON_DISCONNECT = 2
QoS 0 publishes that are not complete at the time of disconnection are failed. Un-acked QoS 1+ publishes are re-queued at the head of the line for immediate retransmission on a session resumption. All other operations are requeued in original order behind any retransmissions.

FAIL_ALL_ON_DISCONNECT = 3
All operations that are not complete at the time of disconnection are failed, except operations that the MQTT5 spec requires to be retransmitted (un-acked QoS1+ publishes).

@jmklix jmklix closed this as completed May 17, 2024
Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

10 participants