moquette icon indicating copy to clipboard operation
moquette copied to clipboard

Does this broker has bridge support? if yes can you tell me how to configure and achive it .

Open keshavck opened this issue 4 years ago • 13 comments

i tried similar steps as mosquito but failed to do so i want to communicate with my another broker

the config file looks this way

connection client-1234567 address localhost:1883 bridge_protocol_version mqttv311 topic sensor/# out 1 topic control/# in 1

keshavck avatar Jan 28 '21 15:01 keshavck

Hello all, I have the same question.

In a pure Mosquitto environment there is no problem between the communication of two brokers where one broker is configures as MQTT-Bridge. (See below)

TEST PASSED :.. MQTT Explorer <--> mosquitto broker <---> mosquitto broker bridge <--> MQTT Explorer

this works fine

When I change my environment like below ( just replace one mosquite borker with mosqutte) it fails

FAILED : MQTT Explorer <--> mosquette broker <---> mosquitto broker bridge <--> MQTT Explorer

The Mosquitto-Bridge broker is not able to connect to the mosuette.

Analyses of the problem shows the following:

mosquitto tries to establish a connection and sends the the protocoll version for MQTT 3.1.1 . This is normally encodeded in the MQTT header protocol header as 0x04 . In case of an MQTT bridge config the mosquitto-bridge-broker sends 0x84.

As you see the highest bit ( 2^7) is set to 1.

I think this is the reason why the mosquette rejects the connect because 0x04 is expected.

Unfortunately I did not find any definition of the bit 2^7 in the protocoll version bye.

Call to action:

Would be great is someone has a solution for this --> like special config setting in moquette

OR let let me know if I should open an issue for this

Many thanks in advance Cheers Reinhold

rjaekle-ms avatar Nov 29 '21 09:11 rjaekle-ms

I've been confused by an incorrect MQTT protocol header a while back, and after a lot of debugging I found out that the side that initiated the connection was trying to use SSL. Since the SSL handshake comes before the MQTT header, the server side that was looking for an MQTT header was confused by the SSL header and thus throw a fit. So, make sure your configuration is set up for SSL on both sides, or on neither side!

hylkevds avatar Nov 29 '21 09:11 hylkevds

Many thanks for the hint, I will double check.

As far as I see it is not an connection problem. I see in Wireshark the the mosquitto-bridge brokers sends an MQTT-Protocoll Version 3.1.1 which is encoded as 0x84. So the connection ewas established. I tested it where SLL was NOT used on boths sides..

So my guess is that there is some kind of magic MQTT-bridge protocoll .. unfortunatelly I did not find any details about siuch an protocoll ( like specifgication) Might I need to take a closer look to the source code for both borker implementation.

At least I found this in the moquette sources of MQTTConnection.java

void processConnect(MqttConnectMessage msg) {
        MqttConnectPayload payload = msg.payload();
        String clientId = payload.clientIdentifier();
        final String username = payload.userName();
        LOG.trace("Processing CONNECT message. CId: {} username: {}", clientId, username);

        if (isNotProtocolVersion(msg, MqttVersion.MQTT_3_1) && isNotProtocolVersion(msg, MqttVersion.MQTT_3_1_1)) {
            LOG.warn("MQTT protocol version is not valid. CId: {}", clientId);
            abortConnection(CONNECTION_REFUSED_UNACCEPTABLE_PROTOCOL_VERSION);
            return;
        }

So it look like that the received protocol header byte is 08x then connection is rejected.

I will check the logging information again because the moquette is running as an embedded broker.. I need some time to figure it out asking some experts who did the originbal coding.

Many thanks for your support. I will update the isseu when I found someting Cheers

rjaekle-ms avatar Nov 29 '21 09:11 rjaekle-ms

There is no "MQTT-bridge protocoll" that is standardised in the MQTT spec.

Here is a typical MQTT connect packet:

0000   00 00 03 04 00 06 00 00 00 00 00 00 00 00 08 00   ................
0010   45 00 00 75 d4 0e 40 00 40 06 68 72 7f 00 00 01   E..u..@[email protected]....
0020   7f 00 00 01 eb 28 07 5c f8 64 11 b9 34 0f 33 16   .....(.\.d..4.3.
0030   80 18 02 00 fe 69 00 00 01 01 08 0a a5 e6 46 2c   .....i........F,
0040   a5 e6 44 f8 10 3f 00 04 4d 51 54 54 04 00 00 1e   ..D..?..MQTT....
0050   00 33 46 52 4f 53 54 2d 4d 51 54 54 2d 42 75 73   .3FROST-MQTT-Bus
0060   2d 32 36 62 62 37 35 34 32 2d 36 38 33 32 2d 34   -26bb7542-6832-4
0070   37 63 37 2d 38 33 39 35 2d 62 36 66 63 30 64 30   7c7-8395-b6fc0d0
0080   36 65 33 39 38                                    6e398

The actual packet content is:

0040               10 3f 00 04 4d 51 54 54 04 00 00 1e       .?..MQTT....
0050   00 33 46 52 4f 53 54 2d 4d 51 54 54 2d 42 75 73   .3FROST-MQTT-Bus
0060   2d 32 36 62 62 37 35 34 32 2d 36 38 33 32 2d 34   -26bb7542-6832-4
0070   37 63 37 2d 38 33 39 35 2d 62 36 66 63 30 64 30   7c7-8395-b6fc0d0
0080   36 65 33 39 38                                    6e398

Comparing with the spec: 0x10: CONNECT Packet fixed header 0x3f: Length of the rest of the MQTT packet 0x00: Length MSB (0) 0x04: Length LSB (4) 0x4d: M 0x51: Q 0x54: T 0x54: T 0x04: Version 4 (is 3.1.1)

So if your packet starts with 0x84 it's not MQTT... Hence my suspicion of SSL... What did you get in wireshark?

hylkevds avatar Nov 29 '21 13:11 hylkevds

Hello @hylkevds thanks for the update and I agree with you. I did also not find any hint about a special Bridge Protocol. But here is what I got in wireshard.

By default mosquitto send a frame like below: Mosquitto-default

This is what you posted in your prev. reply.

Now when I configure mosquitto as a bridge I see the following in wireshark:

Mosquitto-Bridge

As you see the protocol headre is set to 0x84 and not as expected as 0x40.

That's why I think that mosquitto does something special here. For me it looks like that mosquittor is doings somthing which is not in the MQTT spec.

Not sure if all works fix it would be better to mask the protocol byte the "0x7F= to delete the MSB before checking the protocol version. To get moquette working with a mosquitto bridge .. might we can introduce the mask-function as a configuration... just an idea.. it is not perfect I know. What doy ou think?

The best would be that I discsuss this with the mosquitto community first adn post thge outcome of the discussion here. Does this make sense to you ?

Thanks again for your great support Regards

Reinhold

rjaekle-ms avatar Nov 29 '21 14:11 rjaekle-ms

Ah, indeed, that's a totally different MQTT version number! I guess mosquitto does some extra things when a connection is made using that version number. If they have documentation specifying exactly how that works, it may be possible to also implement it in Moquette...

hylkevds avatar Nov 29 '21 14:11 hylkevds

I just started a issue-thread with the mosquitto team .. ;-) might be they can help here. As soon I have any news I will udpate this issue and let you know the outcome.

Many thanks for your time

rjaekle-ms avatar Nov 29 '21 14:11 rjaekle-ms

Good news.

I was able to fix my problem.

I changed the parameter try_private false in the mosquitto bridge config file and then the MSB will not be set in the MQTT header in the connection phase.

As far as I understand; the intention of this parameter is as follow:

If the parameter is set to false then the bridge connectes as a normal MQTT client. In case of true the bridge indicates that this is not a normal MQTT Client .. it is a bridge. This helps mosquitto brokers to avoid endless loops in case of multiple MQTT bridge brokers are in a kind of ring configuration.

A Ring configuration make sense to introduce redundancy to minimize network failure.

see also mosquitto issue: https://github.com/eclipse/mosquitto/issues/2394

rjaekle-ms avatar Dec 01 '21 09:12 rjaekle-ms

Problem is fixed . I will close the issue

I expect: In mid/long term it might be good to discuss the MQTT protocol spec. to figure out how far MQTT-Bridge-Broker and loop-detection should be part of the spec.

rjaekle-ms avatar Dec 01 '21 09:12 rjaekle-ms

Are you sure you are able to establish the bridge connection from the Moquette broker to the Mosquito broker?. If so please share the config file here.

Moquette-->Mosquito

keshavck avatar Jan 25 '22 08:01 keshavck

Hello keshavck yes. I works.

The general configuration settings for the mosquitto bridge are explained - for example- on ( https://tewarid.github.io/2019/04/03/installing-and-configuring-the-mosquitto-mqtt-broker.html)

The trick is that you need to set the parameter try_privat in mosquitto.conf to falsethe like : try_private false The default value is true.

This is all what you need to do.

You may take a look mosquitto issue: eclipse/mosquitto#2394 which explains the details

Hope this helps

rjaekle-ms avatar Jan 25 '22 09:01 rjaekle-ms

You mentioning connecting from mosquitto to moquette? i mean the configuration goes into mosquitto.conf not the moquette. I'm looking for solution or configuration where I add initiate bridge connection from moquette broker not on the mosquito broker

keshavck avatar Jan 25 '22 10:01 keshavck

I think moquette cannot be used as Bridge... I tried only mosquitto bridge Please no that MQTT Bridge is not part of the standards as fa as I know

rjaekle-ms avatar Jan 25 '22 10:01 rjaekle-ms