How to fix mosquitto mid values?

2.5k views Asked by At

I use the mosquitto mqtt broker and have a question about its message id (mid) values as follows.

I send a message to test channel that has a mid of "1234", but the PUBACK mid is printed as another value

I want to print mid "1234"

What do I need to modify in the mosquitto source?

1435417408: Received PUBLISH from adventures (d0, q1, r0, m1234, 'test', ... (5 bytes)) 
1435417408: Sending PUBLISH to myclientid_49 (d0, q1, r0, m3, 'test', ... (5 bytes)) 
1435417408: Sending PUBLISH to myclientid_20 (d0, q1, r0, m2, 'test', ... (5 bytes)) 
1435417408: Sending PUBACK to adventures (Mid: 1234) 
1435417408: Received DISCONNECT from adventures 
1435417409: Received PUBACK from myclientid_49 (Mid: 3) 
1435417409: Received PUBACK from myclientid_20 (Mid: 2)
1

There are 1 answers

1
ralight On

Let me just go through your broker logs for you.

This line is your published message received from the adventures client. You can see m1234 which is saying that the message id is 1234, like you said.

1435417408: Received PUBLISH from adventures (d0, q1, r0, m1234, 'test', ... (5 bytes))

These two lines show the message being sent to two clients that are subscribed to the test topic. They have message id 3 and 2 respectively. Note that message ids are handled separately for different clients and message directions.

1435417408: Sending PUBLISH to myclientid_49 (d0, q1, r0, m3, 'test', ... (5 bytes)) 
1435417408: Sending PUBLISH to myclientid_20 (d0, q1, r0, m2, 'test', ... (5 bytes)) 

This is the broker sending the PUBACK back to the original client. You'll see again that the message id is 1234.

1435417408: Sending PUBACK to adventures (Mid: 1234)

This is the disconnect message from the original client.

1435417408: Received DISCONNECT from adventures

And this is the subscribing clients sending a PUBACK back to the broker, repeating the mid 3 and 2 from above.

1435417409: Received PUBACK from myclientid_49 (Mid: 3) 
1435417409: Received PUBACK from myclientid_20 (Mid: 2)

In conclusion, I think it all makes sense.