npm install mqtt
keepalive 값은 60임.const defaultConnectOptions = {
keepalive: 60,
reschedulePings: true,
protocolId: 'MQTT',
protocolVersion: 4,
reconnectPeriod: 1000,
connectTimeout: 30 * 1000,
clean: true,
resubscribe: true,
writeCache: true
}
사용
const client = mqtt.connect(MQTTURL, {
clientId: `mqttjs_${Math.random().toString(16).substr(2, 8)}`, // id 값 겹치면 안됨
username: mqttConfig.userName,
password: mqttConfig.password,
keepalive: 60, // 0 이면 keepAlive 체킹 안하는건데 그러면 브로커에서 리소스 많이 먹어서 적당한 값을 적용하는게 좋다.
});