40009: Message too large

max_message_size_exceeded

A message was rejected because it exceeded the maximum permitted size. When several messages are published in a single call, the limit applies to their combined size rather than to each one individually.

What you should do

Reduce the size of what you publish so it falls within the limit. Because it is rejected outright and not retried, it has to be made smaller to get through. If you publish several messages in a single call, the limit applies to their combined size, so sending fewer messages per call is one way to do that.

The default maximum is 64 KB, but the exact figure depends on your account; check it against your account's limits. If your use case genuinely needs larger messages, you can request a higher limit.

Why it happens

Every published message has a maximum size, set by your account's limits, and this error means the payload exceeded it. The size counts the message's data together with its name, client ID, and any extras, so all of these contribute to the total. Publishing an array of messages in one call is measured as a single payload, so a batch of individually small messages can still exceed the limit in aggregate.

This is about total size in bytes. A publish rejected for containing too many messages, rather than too large a payload, is reported as 40034 instead.

What you'll see

The publish is rejected and the message is not delivered. The error is reported with code 40009 and HTTP status 413, with a message of the form Maximum message length exceeded (size was <n> bytes, limit is <n> bytes).