php-mqtt / laravel-client

An MQTT client library for Laravel.
MIT License
185 stars 19 forks source link

The broker did not acknowledge the connection attempt within the configured connection timeout period #45

Closed ckbsbal closed 1 year ago

ckbsbal commented 1 year ago

I am trying to connnect with hivemq broker but getting this connection error.

Namoshek commented 1 year ago

Sounds like a firewall issue to me. Please test the connection with telnet or something similar. If that doesn't yield results, I need more information regarding your setup (operating system, versions, MQTT configuration, etc.).

ckbsbal commented 1 year ago

I solved the issue by enabling the TLS in config thanks

ckbsbal commented 1 year ago

Every time when i publish a message its connect to broker each time . That means it every request it get connect to broker. how can i persist the connection?

i don't want to run all these below step again and again except from publishing

Connecting to broker. {"host":"bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud","port":8883,"clientId":"esp8266"} [2023-09-12 15:29:41] local.DEBUG: MQTT [bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud:8883] [esp8266] Using TLS for the connection to the broker. {"host":"bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud","port":8883,"clientId":"esp8266"} [2023-09-12 15:29:41] local.DEBUG: MQTT [bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud:8883] [esp8266] Enabling TLS on the existing socket connection. {"host":"bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud","port":8883,"clientId":"esp8266"} [2023-09-12 15:29:42] local.DEBUG: MQTT [bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud:8883] [esp8266] TLS enabled successfully. {"host":"bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud","port":8883,"clientId":"esp8266"} [2023-09-12 15:29:42] local.DEBUG: MQTT [bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud:8883] [esp8266] Socket opened and ready to use. {"host":"bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud","port":8883,"clientId":"esp8266"} [2023-09-12 15:29:42] local.DEBUG: MQTT [bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud:8883] [esp8266] Using the [password] flag for the connection. {"host":"bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud","port":8883,"clientId":"esp8266"} [2023-09-12 15:29:42] local.DEBUG: MQTT [bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud:8883] [esp8266] Using the [username] flag for the connection. {"host":"bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud","port":8883,"clientId":"esp8266"} [2023-09-12 15:29:42] local.DEBUG: MQTT [bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud:8883] [esp8266] Sending connection handshake to broker. {"host":"bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud","port":8883,"clientId":"esp8266"} [2023-09-12 15:29:42] local.DEBUG: MQTT [bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud:8883] [esp8266] Sent data over the socket: ,�MQIsdp���esp8266�{"host":"bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud","port":8883,"clientId":"esp8266","data":"\u0010,\u0000\u0006MQIsdp\u0003�\u0003�\u0000\u0007esp8266\u0000\u00"} [2023-09-12 15:29:42] local.DEBUG: MQTT [bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud:8883] [esp8266] Waiting for 1 bytes of data. {"host":"bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud","port":8883,"clientId":"esp8266","bytes":1} [2023-09-12 15:29:42] local.DEBUG: MQTT [bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud:8883] [esp8266] Read data from the socket: {"host":"bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud","port":8883,"clientId":"esp8266","data":" "} [2023-09-12 15:29:42] local.DEBUG: MQTT [bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud:8883] [esp8266] Read data from the socket (without blocking): �� {"host":"bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud","port":8883,"clientId":"esp8266","data":"\u0002\u0000\u0000"} [2023-09-12 15:29:42] local.INFO: MQTT [bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud:8883] [esp8266] Connection with broker established successfully. {"host":"bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud","port":8883,"clientId":"esp8266","errorCode":"0x00"} [2023-09-12 15:29:42] local.DEBUG: MQTT [bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud:8883] [esp8266] Publishing a message on topic [led_state]: 1 {"host":"bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud","port":8883,"clientId":"esp8266","topic":"led_state","message":"1","qos":0,"retain":false,"messageId":null,"isDuplicate":false} [2023-09-12 15:29:42] local.DEBUG: MQTT [bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud:8883] [esp8266] Sent data over the socket: 0 � led_state1 {"host":"bbf550b949034545af517b34983a136d.s1.eu.hivemq.cloud","port":8883,"clientId":"esp8266","data":"0\f\u0000\tled_state1"}

Namoshek commented 1 year ago

Since this MQTT client is not a PHP extension, the connection cannot be persisted across requests unless you use an event loop based web server like Laravel Octane where you cann register the MqttClient as singleton.

You can, however, publish messages via queue workers in queued jobs; the queue workers will have a persistent connection (if the MqttClient is registered as singleton). Only thing to keep in mind is that the connection will timeout (and reconnect configuration is required) if publish jobs are not processed regularly. This is true for each worker individually, of course, since every worker is its own PHP process.