Search in sources :

Example 21 with MessageMetadata

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

the class RawBatchConverter method extractIdsAndKeys.

public static List<ImmutablePair<MessageId, String>> extractIdsAndKeys(RawMessage msg) throws IOException {
    checkArgument(msg.getMessageIdData().getBatchIndex() == -1);
    ByteBuf payload = msg.getHeadersAndPayload();
    MessageMetadata metadata = Commands.parseMessageMetadata(payload);
    int batchSize = metadata.getNumMessagesInBatch();
    metadata.recycle();
    List<ImmutablePair<MessageId, String>> idsAndKeys = new ArrayList<>();
    for (int i = 0; i < batchSize; i++) {
        SingleMessageMetadata.Builder singleMessageMetadataBuilder = SingleMessageMetadata.newBuilder();
        ByteBuf singleMessagePayload = Commands.deSerializeSingleMessageInBatch(payload, singleMessageMetadataBuilder, 0, batchSize);
        MessageId id = new BatchMessageIdImpl(msg.getMessageIdData().getLedgerId(), msg.getMessageIdData().getEntryId(), msg.getMessageIdData().getPartition(), i);
        if (!singleMessageMetadataBuilder.getCompactedOut()) {
            idsAndKeys.add(ImmutablePair.of(id, singleMessageMetadataBuilder.getPartitionKey()));
        }
        singleMessageMetadataBuilder.recycle();
        singleMessagePayload.release();
    }
    return idsAndKeys;
}
Also used : SingleMessageMetadata(org.apache.pulsar.common.api.proto.PulsarApi.SingleMessageMetadata) MessageMetadata(org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) SingleMessageMetadata(org.apache.pulsar.common.api.proto.PulsarApi.SingleMessageMetadata) ArrayList(java.util.ArrayList) BatchMessageIdImpl(org.apache.pulsar.client.impl.BatchMessageIdImpl) ByteBuf(io.netty.buffer.ByteBuf) MessageId(org.apache.pulsar.client.api.MessageId)

Aggregations

MessageMetadata (org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata)21 ByteBuf (io.netty.buffer.ByteBuf)15 Test (org.testng.annotations.Test)7 SingleMessageMetadata (org.apache.pulsar.common.api.proto.PulsarApi.SingleMessageMetadata)4 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)3 MessageId (org.apache.pulsar.client.api.MessageId)3 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)3 CommandProducerSuccess (org.apache.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess)3 IOException (java.io.IOException)2 Entry (org.apache.bookkeeper.mledger.Entry)2 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)2 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)2 ByteBufPair (org.apache.pulsar.common.api.ByteBufPair)2 OutputStream (java.io.OutputStream)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1