liudezhi2098 opened a new issue #6714: cannot be correctly parsed batch message 
from http response
URL: https://github.com/apache/pulsar/issues/6714
 
 
   **Describe the bug**
   when get batch message from http response,  only get the first message.
   
   method: 
   `List<Message<byte[]>> getIndividualMsgsFromBatch(String topic, String 
msgId, byte[] data,
                                                                Map<String, 
String> properties`
   
   **To Reproduce**
   ```java
      private List<Message<byte[]>> getIndividualMsgsFromBatch(String topic, 
String msgId, byte[] data,
                                                                Map<String, 
String> properties) {
           List<Message<byte[]>> ret = new ArrayList<>();
           int batchSize = Integer.parseInt(properties.get(BATCH_HEADER));
           for (int i = 0; i < batchSize; i++) {
               String batchMsgId = msgId + ":" + i;
               PulsarApi.SingleMessageMetadata.Builder 
singleMessageMetadataBuilder = PulsarApi.SingleMessageMetadata
                       .newBuilder();
               ByteBuf buf = Unpooled.wrappedBuffer(data); // here you need to 
move out of the loop
               try {
                   ByteBuf singleMessagePayload = 
Commands.deSerializeSingleMessageInBatch(buf, singleMessageMetadataBuilder, i,
                           batchSize);
                   SingleMessageMetadata singleMessageMetadata = 
singleMessageMetadataBuilder.build();
                   if (singleMessageMetadata.getPropertiesCount() > 0) {
                       for (KeyValue entry : 
singleMessageMetadata.getPropertiesList()) {
                           properties.put(entry.getKey(), entry.getValue());
                       }
                   }
                   ret.add(new MessageImpl<>(topic, batchMsgId, properties, 
singleMessagePayload, Schema.BYTES));
               } catch (Exception ex) {
                   log.error("Exception occured while trying to get BatchMsgId: 
{}", batchMsgId, ex);
               }
               buf.release();
               singleMessageMetadataBuilder.recycle();
           }
           return ret;
       }
   ```
   
   
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to