AnonHxy opened a new issue, #16619: URL: https://github.com/apache/pulsar/issues/16619
## Motivation The original discussion mail : https://lists.apache.org/thread/5svpl5qp3bfoztf5fvtojh51zbklcht2 Introduce the ability for producer to publish a non-batched message if there is only one message in the batch. There is useful to save the the `SingleMessageMetadata` space in entry and reduce workload of consumers to deserialize the `SingleMessageMetadata`, especially when sometime there is a mount of batched message with only one real message. ## API Changes When this feature applied, the returned type of `MessageId` may not be `BatchMessageIdImpl`, even if we have set the `enableBatching` as true. It is because that the producer will publish a single message as a non-batched message. Also, the consumer will deserialize the entry as a non-batched message, which will receive message with normal `MessageIdImpl` but not `BatchMessageIdImpl`. So this may cause `((BatchMessageIdImpl) messageId)` throw `ClassCastException`. we need to add a switch for the producer to enable or disable this feature ``` ProducerBuilder<T> batchingSingleMessage(boolean batchingSingleMessage); // default value is true ``` ## Implementation For `BatchMessageContainerImpl` : ``` public OpSendMsg createOpSendMsg() throws IOException { if (!producer.conf.isBatchingSingleMessage() && messages.size() == 1) { // If only one message, create OpSendMsg as non-batched publish. } // .... } ``` For `BatchMessageKeyBasedContainer`, there is no need to change, because it uses `BatchMessageContainerImpl` to create `OpSendMsg` ## Reject Alternatives - Always return `BatchMessageIdImpl` when `enableBatching` set as true, even if publish single message with non-batched message. Rejection reason: Consumer have to deserialize to check if there is `SingleMessageMetadata` from the payload -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
