{"record":{"id":"6d2258cf14d06c24","repo":"apache/pulsar","slug":"attempting-to-send-totalmessages-messages-plea","errorCode":null,"errorMessage":"Attempting to send ${totalMessages} messages. Please do not send more than ${MAX_MESSAGES} messages","messagePattern":"Attempting to send (.+?) messages\\. Please do not send more than (.+?) messages","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-client-tools/src/main/java/org/apache/pulsar/client/cli/CmdProduce.java","lineNumber":273,"sourceCode":"        if (messages.size() == 0 && messageFileNames.size() == 0) {\n            throw new CommandLine.ParameterException(commandSpec.commandLine(),\n                    \"Please supply message content with either --messages or --files\");\n        }\n\n        if (keyValueEncodingType == null) {\n            keyValueEncodingType = KEY_VALUE_ENCODING_TYPE_NOT_SET;\n        } else if (!KEY_VALUE_ENCODING_TYPE_NOT_SET.equals(keyValueEncodingType)) {\n            // KeyValue schemas are not yet supported by the V5-based pulsar-client.\n            throw new IllegalArgumentException(\"KeyValue schemas (--key-value-encoding-type) are not \"\n                    + \"supported by this version of pulsar-client; produce with a plain value schema \"\n                    + \"(-vs bytes|string|avro:<def>|json:<def>) instead.\");\n        }\n\n        int totalMessages = (messages.size() + messageFileNames.size()) * numTimesProduce;\n        if (totalMessages > MAX_MESSAGES) {\n            String msg = \"Attempting to send \" + totalMessages + \" messages. Please do not send more than \"\n                    + MAX_MESSAGES + \" messages\";\n            throw new IllegalArgumentException(msg);\n        }\n\n        if (this.serviceURL.startsWith(\"ws\")) {\n            return publishToWebSocket(topic);\n        } else {\n            return publish(topic);\n        }\n    }\n\n    private int publish(String topic) {\n        int numMessagesSent = 0;\n        int returnCode = 0;\n\n        if (this.disableReplication) {\n            log.warn(\"--disable-replication has no effect on this version of pulsar-client and is ignored.\");\n        }\n\n        try (PulsarClient client = clientBuilder.build()) {","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-tools/src/main/java/org/apache/pulsar/client/cli/CmdProduce.java#L255-L291","documentation":"CmdProduce guards against accidental message floods: total messages = (inline messages + files) * numTimesProduce. If the total exceeds the CLI's MAX_MESSAGES cap, IllegalArgumentException is thrown before any client is created, protecting the broker from an accidental bulk publish.","triggerScenarios":"Passing many -m values or -f files combined with a large --num-times-produce (-n) so the product exceeds MAX_MESSAGES (e.g. -n 100000 with 10 messages).","commonSituations":"Stress-testing scripts that reuse a CLI designed for spot checks; mistyping -n (e.g. -n 1000000 instead of 1000); looping with a high multiplier to 'warm up' a topic.","solutions":["Lower --num-times-produce (-n) so totalMessages stays within the cap.","Reduce the number of --messages/--files entries in a single invocation and loop the command instead.","If you need bulk loads, use the official perf tool (pulsar-perf produce) rather than the CLI."],"exampleFix":"// before\npulsar-client produce t -m 'a' -m 'b' -n 100000   // 200000 > MAX_MESSAGES\n// after\npulsar-client produce t -m 'a' -m 'b' -n 100      // 200 <= MAX_MESSAGES","handlingStrategy":"validation","validationCode":"// compute the total first\nTOTAL=$(( $(printf '%s\\n' \"$MSGS\" | wc -l) * N )); [ \"$TOTAL\" -le 1000 ] || { echo \"too many messages: $TOTAL\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep -n (num-times-produce) small; the CLI is not a load generator.","Use pulsar-perf produce for bulk/stress publishing.","Compute (messages + files) * n before running and cap it."],"tags":["cli","limits","validation","bulk"],"backgroundTag":"limit-exceeded","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}