Search in sources :

Example 1 with SingleMessageMetadata

use of org.apache.pulsar.common.api.proto.PulsarApi.SingleMessageMetadata in project incubator-pulsar by apache.

the class PersistentTopicsImpl method getIndividualMsgsFromBatch.

private List<Message<byte[]>> getIndividualMsgsFromBatch(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);
        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<>(batchMsgId, properties, singleMessagePayload, Schema.IDENTITY));
        } catch (Exception ex) {
            log.error("Exception occured while trying to get BatchMsgId: {}", batchMsgId, ex);
        }
        buf.release();
        singleMessageMetadataBuilder.recycle();
    }
    return ret;
}
Also used : KeyValue(org.apache.pulsar.common.api.proto.PulsarApi.KeyValue) Message(org.apache.pulsar.client.api.Message) SingleMessageMetadata(org.apache.pulsar.common.api.proto.PulsarApi.SingleMessageMetadata) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) NotFoundException(org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException) ClientErrorException(javax.ws.rs.ClientErrorException) WebApplicationException(javax.ws.rs.WebApplicationException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) ExecutionException(java.util.concurrent.ExecutionException) ServerErrorException(javax.ws.rs.ServerErrorException)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 ServerErrorException (javax.ws.rs.ServerErrorException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)1 NotFoundException (org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException)1 Message (org.apache.pulsar.client.api.Message)1 KeyValue (org.apache.pulsar.common.api.proto.PulsarApi.KeyValue)1 SingleMessageMetadata (org.apache.pulsar.common.api.proto.PulsarApi.SingleMessageMetadata)1