smartrent / jackalope

An opinionated MQTT client library based on Tortoise MQTT
Apache License 2.0
28 stars 5 forks source link

Implement ttl on work in the hare work list #12

Closed gausby closed 3 years ago

gausby commented 3 years ago

Some of the MQTT packages takes options, such as what QoS a subscription should be requested, or what QoS a publish should be send. This change introduce a work list opts list that can be used to store options for the work list (separate from the package opts). The first (and so far only) option we implement is a ttl on the work orders.

Time to live (ttl) implement a timeout on the messages stored in the hare work-list. If the ttl expire the message will get dropped; this helpful in situations where a message is accepted while the broker is down, only to come online later, at a point in time where the message would be irrelevant.

The following example would set up a publish that would get dropped if it stays in the queue for more than 2 seconds.

Hare.publish("foo/bar", "Hi, Tortoise", ttl: 2_000)

The default ttl is infinity—which is a very long time.