-
Notifications
You must be signed in to change notification settings - Fork 21
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
Laravel queue:work and $mqqt->disconnect() #18
Comments
Thank you for reporting this! I should be able to change the behavior of In your case, it might be better to not disconnect at all and use an increased timeout to keep the connection alive, at least if you publish messages frequently (at most every 5 minutes). Connecting to the broker is a relatively expensive and time consuming task. |
That's also a solution for this problem. Great library, love it.
I'm using a middleware which checks if the MQTT is available (on certain routes) with connect/disconnect. The backend is part of a system. The MQTT is just there to communicate with a PLC system. In my example, the user has changed some silo's and the PLC needs to know which ones. |
This is a huge tip for the users of this library. It can safe some frustrated hours.
I have an API. When an endpoint is called, it starts a job on the queue. In this job, a MQTT message is published. The code below is the code that runs in the job.
The first job process goes great. But when I do a second request. The job failes. You get an exception that there is no connection.
The problem is that the Laravel queue worker keeps it's app state. In the MQTT class, it stores the connections in an array. When you call $mqtt->disconnect(). The connection is closed, but remains in the connections array.
When trying to reopen the connection on the second process, it fails. The socket is not open.
You have to call MQTT::disconnect(). This closes the socket and removes connection from the array.
The text was updated successfully, but these errors were encountered: