xHasKx / luamqtt

luamqtt - Pure-lua MQTT v3.1.1 and v5.0 client
https://xhaskx.github.io/luamqtt/
MIT License
154 stars 41 forks source link

how to set keepAlive ? #12

Closed daveliang closed 5 years ago

daveliang commented 5 years ago

1553155818(1)

daveliang commented 5 years ago

5 minute will be offline

xHasKx commented 5 years ago

keepAlive is not available in luamqtt for now - it's requires some async network operations to send PING packets in background. I'm working on the new version of this lib providing some kind of io loop, which allows to run any background operations like PING's every keepAlive seconds

daveliang commented 5 years ago

When will this keepAlive version be release? I need it urgently.

xHasKx commented 5 years ago

I don't have any ETA. Will be added when I'll have enough free time at home

whitetiger21022014 commented 5 years ago

Hi @xHasKx , With receiving mode, If your luamqtt does not support keepalive, it means MQTT client will does not send PINGREG and the MQTT broker will always auto-disconnect after duration time? B/c I test with RabbitMQ and the connection is auto-disconnect after 120 seconds

Or keepalive still depends on MQTT broker Thanks,

xHasKx commented 5 years ago

@whitetiger21022014, current implementation of luamqtt is working on simplest network sockets available in lua - a luasocket module, which sockets are in blocking mode by default. That means, the lua script with MQTT client is blocked within read() syscall, waiting for next packet from MQTT broker. In that mode there is no way for script to awake and send a PINGREQ to broker. Which leads to broker is closing such inactive connection in some timeout (120 seconds usually) - this is common to all brokers.

@whitetiger21022014, @daveliang, I'm working on the next version of the luamqtt module without such long-term blocking in read() syscall. It will provide a configurable parameter for keepAlive per each MQTT client started from lua script.

I hope it will be released on this week or at weekends.

xHasKx commented 5 years ago

@whitetiger21022014, @daveliang, I've rolled out the new v2.0.0 version of this lib with keepAlive interval support. Here is your parameter: https://github.com/xHasKx/luamqtt/blob/master/mqtt/client.lua?ts=4#L80

Also please note that a lot of argumetns and some methods was changed. For example, now ssl=true should be replaced with secure=true in MQTT client construction arguments

Please post here a feedback and close issue