paho.mqtt.python icon indicating copy to clipboard operation
paho.mqtt.python copied to clipboard

MQTT payload size

Open namyamalik opened this issue 4 years ago • 3 comments

I have noticed that when I publish a message which has a payload size of above ~12KB, the broker (Mosquitto) simply ignores the message and closes the client connection.

I am running the publisher client on Raspberry Pi OS & the broker on OpenWRT OS.

I have tried changing QoS levels. I have also tried modifying certain parameters in the mosquitto.conf file such as max_packet_size, max_queued_bytes, memory_limit, message_size_limit (even though these were all set to their maximum default values already).

This is a similar issue to https://github.com/eclipse/paho.mqtt.python/issues/107 but I am wondering if there is any fix?

namyamalik avatar Jan 25 '22 19:01 namyamalik

not really a problem with the library I think.

What version of MQTT are you using?

You may want to examine https://mosquitto.org/man/mosquitto-conf-5.html, specifically max_packet_size

sfphh4 avatar Feb 12 '22 13:02 sfphh4

It is not mosquitto related. It is the client. Used my local mosquitto but also 2 public MQTT brokers. In all the cases I cannot send 100kB (not sure where is the threshold; 10kB is OK, 100kB - is not). What's more - the same is working fine with Node.js 'mqtt' module or Python 'gmqtt'.

Another important fact is that for a big message mosquitto is logging 'Socket error on client ...'

paho-mqtt version 1.6.1 mqtt protocol does not matter

ghost avatar Mar 03 '22 22:03 ghost

This is an example that works for me. It connects, then in the connect callback it makes a subscription. In the subscribe callback it publishes a 100kB message to the topic it subscribed to. It reports when the client thinks the message has been published (I'm using QoS 1 here, so that means the broker has responded). When it receives the message from the broker it reports what size it is.

If it works for you then you might be able to see where the difference is with your code.

import paho.mqtt.client as mqtt

def on_connect(mqttc, obj, flags, rc):
    mqttc.subscribe("size/100kB", qos=1)

def on_subscribe(mqttc, obj, mid, granted_qos):
    print("Subscribed ok, now publishing")
    mqttc.publish("size/100kB", "0123456789"*10000, qos=1)

def on_publish(mqttc, obj, mid):
    print("Publish callback")

def on_message(mqttc, obj, msg):
    print("Received message %d bytes long" % (len(msg.payload)))
    mqttc.disconnect()

mqttc = mqtt.Client()
mqttc.on_connect = on_connect
mqttc.on_subscribe = on_subscribe
mqttc.on_publish = on_publish
mqttc.on_message = on_message

mqttc.connect("test.mosquitto.org", 1883, 60)

mqttc.loop_forever()

ralight avatar Mar 04 '22 00:03 ralight

Closing this as a test app was provided that appeared to work and there has been no feedback since then.

Note: This is part of an exercise to clean up old issues so that the project can move forwards. Due to the number of issues being worked through mistakes will be made; please feel free to reopen this issue (or comment) if you believe it's been closed in error.

MattBrittan avatar Jan 08 '24 03:01 MattBrittan