You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/04/11 02:45:35 UTC

[GitHub] [pulsar] liudezhi2098 opened a new issue #6714: cannot be correctly parsed batch message from http response

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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [pulsar] jiazhai commented on issue #6714: cannot be correctly parsed batch message from http response

Posted by GitBox <gi...@apache.org>.
jiazhai commented on issue #6714: cannot be correctly parsed batch message from http response
URL: https://github.com/apache/pulsar/issues/6714#issuecomment-612341371
 
 
   Thanks @liudezhi2098 for the issue and fix

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [pulsar] liudezhi2098 closed issue #6714: cannot be correctly parsed batch message from http response

Posted by GitBox <gi...@apache.org>.
liudezhi2098 closed issue #6714: cannot be correctly parsed batch message from http response
URL: https://github.com/apache/pulsar/issues/6714
 
 
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services