vert-x3 / vertx-mqtt

Vert.x MQTT
Apache License 2.0
184 stars 86 forks source link

Can't connect to mosquitto 2.0 anymore #207

Closed cescoffier closed 3 years ago

cescoffier commented 3 years ago

With Vert.x 4.2.0.Beta1, I can't connect to Mosquitto anymore.

I uses this test:

package io.vertx.mutiny.mqtt;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;

import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;

import io.netty.handler.codec.mqtt.MqttConnectReturnCode;
import io.vertx.mqtt.MqttClientOptions;
import io.vertx.mutiny.core.Vertx;
import io.vertx.mutiny.mqtt.messages.MqttConnAckMessage;

public class MqttClientTest {

    @ClassRule
    public static GenericContainer<?> mosquitto = new GenericContainer<>("eclipse-mosquitto:2.0")
            .withExposedPorts(1883)
            .withClasspathResourceMapping("mosquitto.conf", "/mosquitto/config/mosquitto.conf", BindMode.READ_ONLY)
            .waitingFor(Wait.forLogMessage(".*mosquitto .* running.*", 1));
    private Vertx vertx;

    @Before
    public void setUp() {
        vertx = Vertx.vertx();
        assertThat(vertx, is(notNullValue()));
    }

    @After
    public void tearDown() {
        vertx.closeAndAwait();
    }

    @Test
    public void test() {
        MqttClient client = MqttClient.create(vertx, new MqttClientOptions().setAutoGeneratedClientId(true));
        MqttConnAckMessage connection = client
                .connect(mosquitto.getMappedPort(1883), mosquitto.getContainerIpAddress())
                .await().indefinitely();
        assertThat(connection, is(notNullValue()));
        assertThat(connection.code(), is(MqttConnectReturnCode.CONNECTION_ACCEPTED));
        client.disconnectAndAwait();
    }

}

With Vert.x 4.1.3, it connects and everything is fine. With 4.2.0.Beta1, the same test gets a failure with "Closed" as the message.

vietj commented 3 years ago

thanks

vietj commented 3 years ago

it is a migration issue to mosquitto 2.0, you need to add listener 1883 in mosquitto.conf see https://mosquitto.org/documentation/migrating-to-2-0/#listener-behaviour-changes

cescoffier commented 3 years ago

Hum, it was already using mosquitto 2.0 before, but if that works, I'm good with it.

vietj commented 3 years ago

When I looked at the wireshark capture, the server is closing the connection before receiving the CONNECT message sent by the client.

then I tried your reproducer with other Vert.x versions and it failed the same way.

you can run the image docker with your config and then do on the terminal : nc localhost 1883

you will see it gets automatically disconnected whatsoever (normally the server should hang waiting for the CONNECT msg sent by the client.

On Mon, Sep 6, 2021 at 7:17 PM Clement Escoffier @.***> wrote:

Hum, it was already using mosquitto 2.0 before, but if that works, I'm good with it.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/vert-x3/vertx-mqtt/issues/207#issuecomment-913780257, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABXDCSFVENC2PTXLYDTPTTUATZS5ANCNFSM5DL4CIFQ .

cescoffier commented 3 years ago

Ok.. so... the image hashes are different... Invisible update, great!

Anyway, thanks for your help! I've added the missing line and everything works.

vietj commented 3 years ago

no worries, I reused your code to add an integration test in vertx-mqtt with the mosquitto image :-)

On Tue, Sep 7, 2021 at 2:21 PM Clement Escoffier @.***> wrote:

Ok.. so... the image hashes are different... Invisible update, great!

Anyway, thanks for your help! I've added the missing line and everything works.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/vert-x3/vertx-mqtt/issues/207#issuecomment-914257461, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABXDCSEMBYZLRO6S53PLYLUAX7VXANCNFSM5DL4CIFQ .