# Server address unresolved - cannot connect to rabbitmq server using hivemq client

**URL:** <https://community.hivemq.com/t/server-address-unresolved-cannot-connect-to-rabbitmq-server-using-hivemq-client/1243>\
**Category:** HiveMQ Client Library\
**Created:** [June 1, 2022, 8:00am UTC](https://community.hivemq.com/t/server-address-unresolved-cannot-connect-to-rabbitmq-server-using-hivemq-client/1243 "2022-06-01T08:00:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeNo](https://avatars.discourse-cdn.com/v4/letter/p/e9bcb4/32.png) [@PeNo](https://community.hivemq.com/u/PeNo)\
**Post date:** [June 1, 2022, 8:00am UTC](https://community.hivemq.com/t/server-address-unresolved-cannot-connect-to-rabbitmq-server-using-hivemq-client/1243/1 "2022-06-01T08:00:09Z")

</div>

Hi, I am running a rabbitmq mqtt ws local cluster of servers.  
When using paho I connect with tcp://127.0.0.1:8085.  
RabbitMQ documentation says I should use ws://127.0.0.1:8085/ws.  
When connecting with HiveMQ client (in Java) I apply:

.serverHost(“tcp://localhost”)  
.serverPort(8085).

Connection is not established. When debugging the transport config I see that serverAddress is:  
tcp://localhost/ \< unresolved \> :8085

 ![grafik](https://canada1.discourse-cdn.com/flex035/uploads/hivemq1/original/1X/bbe82f3171ce57c59ba912870394950f31d10f3b.png)

Where and how do I replace the unresolved please? Thank you.

---

<div class="post-metadata">

**Author:** ![michael\_w](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/michael_w/32/200_2.png) [@michael\_w](https://community.hivemq.com/u/michael_w)\
**Post date:** [June 2, 2022, 10:05am UTC](https://community.hivemq.com/t/server-address-unresolved-cannot-connect-to-rabbitmq-server-using-hivemq-client/1243/2 "2022-06-02T10:05:19Z")

</div>

Hi @PeNo,

the `tcp://` part is only needed in the Paho client.

This should be the code for the HiveMQ client to connect to a websocket:

```auto
final Mqtt5AsyncClient client = Mqtt5Client.builder()
        .serverHost("localhost")
        .serverPort(8085)
        .webSocketConfig(MqttWebSocketConfig.builder().subprotocol("mqtt").serverPath("/ws").build())
        .buildAsync();

client.connect().get();

```

Greetings,  
Michael from the HiveMQ team

---

<div class="post-metadata">

**Author:** ![PeNo](https://avatars.discourse-cdn.com/v4/letter/p/e9bcb4/32.png) [@PeNo](https://community.hivemq.com/u/PeNo)\
**Post date:** [June 7, 2022, 7:55am UTC](https://community.hivemq.com/t/server-address-unresolved-cannot-connect-to-rabbitmq-server-using-hivemq-client/1243/3 "2022-06-07T07:55:09Z")

</div>

Hi Michael,

thank you for your reply. But it does not work. I guess first problem might be as per rabbit mq docs:  
_RabbitMQ supports MQTT **3.1.1** via a plugin that ships in the core distribution._ vs suggested client Mqtt5.

As soon as I employ the MqttWebSocketConfig it does not work:

```
       MqttWebSocketConfig ws = MqttWebSocketConfig.builder()
                .subprotocol("mqtt")
                .serverPath("/ws")
                .build();

        client = Mqtt3Client.builder()
                .automaticReconnectWithDefaultConfig()
                .addConnectedListener(context -> LOG.info("MQTT WS HIVE PUB CONNECTED."))
                .addDisconnectedListener(context -> LOG.warn("MQTT WS HIVE PUB NOT CONNECTED"))

                .identifier("MQTT_HIVE_PUB1")

                .serverHost("localhost")
                .serverPort(8085)
                .webSocketConfig(ws)

                .simpleAuth()
                .username(rabbitConnectionDetail.getUsername())
                .password(rabbitConnectionDetail.getPassword().getBytes(StandardCharsets.UTF_8))
                .applySimpleAuth()

                .buildAsync();

        client.connectWith()
                .cleanSession(true)
                .keepAlive(rabbitConnectionDetail.getKeepAlive())
                .send();

```

When I use it like below, the connection is created, but I guess this is no ws…

```
MqttClientTransportConfig transportConfig = MqttClientTransportConfig.builder()
                .serverHost("ws")
                .serverAddress(new InetSocketAddress("localhost", 8085))
                .mqttConnectTimeout(rabbitConnectionDetail.getMqttConnectionTimeout(), TimeUnit.SECONDS)
                .build();

        client = Mqtt3Client.builder()
                .automaticReconnectWithDefaultConfig()
                .addConnectedListener(context -> LOG.info("MQTT WS HIVE PUB CONNECTED."))
                .addDisconnectedListener(context -> LOG.warn("MQTT WS HIVE PUB NOT CONNECTED"))

                .identifier("MQTT_HIVE_PUB1")

                .transportConfig(transportConfig)
                *.THE REST IS IDENTICAL AS ABOVE..*

```

Any suggestions, please? Thank you…

---

<div class="post-metadata">

**Author:** ![PeNo](https://avatars.discourse-cdn.com/v4/letter/p/e9bcb4/32.png) [@PeNo](https://community.hivemq.com/u/PeNo)\
**Post date:** [June 8, 2022, 7:21am UTC](https://community.hivemq.com/t/server-address-unresolved-cannot-connect-to-rabbitmq-server-using-hivemq-client/1243/4 "2022-06-08T07:21:17Z")

</div>

Hi @michael_w, thank you for your reply. However it does not work. First thing that might make problem is that RabbitMQ currently supports MQTT v 3.1.1. and your suggested client is v5.

I use following code which works (below) - however this comes completely without MqttWebSocketConfig. Can you see any problem with it, please? My RabbitMQ cluster is using MQTT 3.1.1 over WS

```
    MqttClientTransportConfig transportConfig = MqttClientTransportConfig.builder()
                .serverHost("ws")
                .serverAddress(new InetSocketAddress("localhost", 8085))
                .mqttConnectTimeout(rabbitConnectionDetail.getMqttConnectionTimeout(), TimeUnit.SECONDS)
                .build();

        client = Mqtt3Client.builder()
                .automaticReconnectWithDefaultConfig()
                .addConnectedListener(context -> LOG.info("MQTT WS HIVE PUB CONNECTED."))
                .addDisconnectedListener(context -> LOG.warn("MQTT WS HIVE PUB NOT CONNECTED"))

                .identifier("MQTT_HIVE_PUB1")

                .transportConfig(transportConfig)
                .simpleAuth()
                .username(rabbitConnectionDetail.getUsername())
                .password(rabbitConnectionDetail.getPassword().getBytes(StandardCharsets.UTF_8))
                .applySimpleAuth()

                .buildAsync();

        client.connectWith()
                .cleanSession(true)
                .keepAlive(rabbitConnectionDetail.getKeepAlive())
                .send();
```

---

<div class="post-metadata">

**Author:** ![michael\_w](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/michael_w/32/200_2.png) [@michael\_w](https://community.hivemq.com/u/michael_w)\
**Post date:** [June 8, 2022, 7:44am UTC](https://community.hivemq.com/t/server-address-unresolved-cannot-connect-to-rabbitmq-server-using-hivemq-client/1243/5 "2022-06-08T07:44:32Z")

</div>

Hi @PeNo,

if you can connect with the standard TCP then the endpoint you are connecting to is most likely not a WebSocket endpoint. I looked up the RabbitMQ documentation they write a [plugin](https://www.rabbitmq.com/web-mqtt.html) needs to be installed in order that MQTT over WebSocket works. Just to be clear you installed that plugin?

Greetings,  
Michael

---

<div class="post-metadata">

**Author:** ![PeNo](https://avatars.discourse-cdn.com/v4/letter/p/e9bcb4/32.png) [@PeNo](https://community.hivemq.com/u/PeNo)\
**Post date:** [June 8, 2022, 8:12am UTC](https://community.hivemq.com/t/server-address-unresolved-cannot-connect-to-rabbitmq-server-using-hivemq-client/1243/6 "2022-06-08T08:12:28Z")

</div>

Hi @michael_w , thank you for leading me to fix the issue. Maybe for future reference:  
I am using following setup:  
 ![grafik](https://canada1.discourse-cdn.com/flex035/uploads/hivemq1/original/1X/4d87e609a97b8718f8003b6804ca3ff73fb4c183.png)  
The RabbitMq servers are in Docker containers. Obviously I was exposing external:internal ports in a wrong way like this  
8085:1883 for mqtt  
Correct is:  
8085:80 for mqtt\_ws aka http/web-mqtt on the picture.  
Now everything works. Thank you.
