GithubHelp home page GithubHelp logo

Comments (18)

Sammers21 avatar Sammers21 commented on July 17, 2024

Hi @ctron , actually automatic reconnection is not supported yet. But, you can implement it with MqttClient#closeHandler(just call connect on closeHandler triggering). The field in MqttClientOptions is useless, please, ignore it.

If you'd like to fix it - feel free to contribute.

from vertx-mqtt.

ctron avatar ctron commented on July 17, 2024

Well it can't be implemented 100% with the close handler as it looks to me.

When the connection succeeds, then the close handler will be called. However when the initial connection doesn't succeed, only the Future is completed with a failure:

if (done.failed()) {
  log.error(String.format("Can't connect to %s:%d", host, port), done.cause());
  if (connectHandler != null) {
    connectHandler.handle(Future.failedFuture(done.cause()));
}

However, listening to the result of the future for a failure is not possible, because in this case you will also be noted over the closeHandler and the Future. So for some (not for all) condition you might be notified twice for a broken connection.

I think this could be fixed by simply calling the close handler in addition to finishing the Future with a failure in the "if" mentioned above.

from vertx-mqtt.

Sammers21 avatar Sammers21 commented on July 17, 2024

That is a great idea and as a benefit, it would be way more easy to implement 100% reconnection. But, there is the other side... to call closeHandler when we failed in the attempt to establish TCP connection. I think that it is logical to not call closeHandler when a connection has not been established yet because we have just nothing to close.

from vertx-mqtt.

Sammers21 avatar Sammers21 commented on July 17, 2024

Btw, @ppatierno, what do you think about it?

from vertx-mqtt.

ctron avatar ctron commented on July 17, 2024

Well if you don't call the closeHandler when it was not connected, then you can't implement re-connect that way. But if you always do call the closeHandler, then you can check locally (in your state) if you had a successful connection before.

The most important thing might be some proper documentation in the javadoc to explain this. If this is all that it needs, I am happy to amend the PR for more documentation.

from vertx-mqtt.

vietj avatar vietj commented on July 17, 2024

keep in mind that Vert.x NetClient already supports connect retries when the connection fails (not when it is disconnected as this is protocol related)

from vertx-mqtt.

ctron avatar ctron commented on July 17, 2024

But I did understand @Sammers21 that this is not supported with the MQTT client.

from vertx-mqtt.

ppatierno avatar ppatierno commented on July 17, 2024

At TCP level the retries on connection failures work (thanks to the underlying NetClient). If you set the reconnectAttempts in the MqttClientOptions and try to connect to the server when it's not listening at all, you can see the SYN RST ACK sequence more times (the number of attempts) so it means that the NetClient is re-trying connection at TCP level. I guess that what you want is a reconnection when the already established connection with the server is closed (for some reason) and a new one should be established. Is that right ? It is something different from the reconnectAttempts feature.

from vertx-mqtt.

vietj avatar vietj commented on July 17, 2024

@ppatierno that's my opinion too, reconnection on an established socket is only possible if it makes sense for the protocol, I don't know about MQTT

from vertx-mqtt.

ctron avatar ctron commented on July 17, 2024

As a user of MQTTClient I don't want to distinguish between TCP and MQTT layer when I configure reconnect. If my desire is to "keep the MQTT connection open", then I would expect the client to take care of that and re-establish a connection on the TCP and MQTT layer for me.

If that is not supported by the MQTTClient (which is ok to me), then I would expect the documentation of setReconnectAttempts to be different (currently: "Set the value of reconnect attempts") to reflect that this is "just" the initial TCP connection.

However I don't see a real benefit to only implement re-connect for the initial TCP open and leave the MQTT re-connect to the user.

from vertx-mqtt.

ppatierno avatar ppatierno commented on July 17, 2024

@ctron I totally agree with you. The re-connect feature at TCP level comes from the underlying NetClient so it was already there. The current MQTTClient doesn't provide an out-of-box reconnect feature and I agree that it's a missing point. What do you think if I close this issue and open a new issure related to develop such a missing feature (I'll reference the current issue from there then).

from vertx-mqtt.

vietj avatar vietj commented on July 17, 2024

that being said, it could be simply implemented with a close handler that reconnects when it is called.

from vertx-mqtt.

ppatierno avatar ppatierno commented on July 17, 2024

@vietj this is what @ctron is trying to achive but even providing the #69 PR because the closeHandler isn't called when TCP connection isn't established. I have some doubts about that for the meaning of the closeHandler ... a connection was closed which is not true when a connection isn't established.

from vertx-mqtt.

vietj avatar vietj commented on July 17, 2024

I think that you don't need to do that, because vertx NetClient already takes care of re-connect failures, so you only need to handle the case when the connection is closed after being established

from vertx-mqtt.

vietj avatar vietj commented on July 17, 2024

overall I'm wondering if that would not make sense to have an MQTT connection pool that would perform reconnect in such situations

from vertx-mqtt.

ppatierno avatar ppatierno commented on July 17, 2024

It's clear that it's not an issue but just a missing feature, I'm going to close this one.

from vertx-mqtt.

abccbaandy avatar abccbaandy commented on July 17, 2024

I think reconnect is a important feature, and not just for reconnect, we need resubscribe feature too.

from vertx-mqtt.

abccbaandy avatar abccbaandy commented on July 17, 2024

But I know it's a miss feature in most of mqtt component :P

for ex:
https://issues.apache.org/jira/browse/CAMEL-11691

from vertx-mqtt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.