Search in sources :

Example 21 with MessageIdData

use of org.apache.pulsar.common.api.proto.MessageIdData in project pulsar by apache.

the class ChunkMessageIdImpl method toByteArray.

@Override
public byte[] toByteArray() {
    // write last chunk message id
    MessageIdData msgId = super.writeMessageIdData(null, -1, 0);
    // write first chunk message id
    msgId.setFirstChunkMessageId();
    firstChunkMsgId.writeMessageIdData(msgId.getFirstChunkMessageId(), -1, 0);
    int size = msgId.getSerializedSize();
    ByteBuf serialized = Unpooled.buffer(size, size);
    msgId.writeTo(serialized);
    return serialized.array();
}
Also used : MessageIdData(org.apache.pulsar.common.api.proto.MessageIdData) ByteBuf(io.netty.buffer.ByteBuf)

Example 22 with MessageIdData

use of org.apache.pulsar.common.api.proto.MessageIdData in project pulsar by apache.

the class MessageIdImpl method fromByteArrayWithTopic.

public static MessageId fromByteArrayWithTopic(byte[] data, TopicName topicName) throws IOException {
    Objects.requireNonNull(data);
    MessageIdData idData = LOCAL_MESSAGE_ID.get();
    try {
        idData.parseFrom(Unpooled.wrappedBuffer(data, 0, data.length), data.length);
    } catch (Exception e) {
        throw new IOException(e);
    }
    MessageId messageId;
    if (idData.hasBatchIndex()) {
        messageId = new BatchMessageIdImpl(idData.getLedgerId(), idData.getEntryId(), idData.getPartition(), idData.getBatchIndex(), idData.getBatchSize(), BatchMessageAcker.newAcker(idData.getBatchSize()));
    } else {
        messageId = new MessageIdImpl(idData.getLedgerId(), idData.getEntryId(), idData.getPartition());
    }
    if (idData.getPartition() > -1 && topicName != null) {
        messageId = new TopicMessageIdImpl(topicName.getPartition(idData.getPartition()).toString(), topicName.toString(), messageId);
    }
    return messageId;
}
Also used : MessageIdData(org.apache.pulsar.common.api.proto.MessageIdData) IOException(java.io.IOException) IOException(java.io.IOException) MessageId(org.apache.pulsar.client.api.MessageId)

Example 23 with MessageIdData

use of org.apache.pulsar.common.api.proto.MessageIdData in project pulsar by apache.

the class Commands method newAck.

public static ByteBuf newAck(long consumerId, long ledgerId, long entryId, BitSetRecyclable ackSet, AckType ackType, ValidationError validationError, Map<String, Long> properties, long txnIdLeastBits, long txnIdMostBits, long requestId, int batchSize) {
    BaseCommand cmd = localCmd(Type.ACK);
    CommandAck ack = cmd.setAck().setConsumerId(consumerId).setAckType(ackType);
    MessageIdData messageIdData = ack.addMessageId().setLedgerId(ledgerId).setEntryId(entryId);
    if (ackSet != null) {
        long[] as = ackSet.toLongArray();
        for (int i = 0; i < as.length; i++) {
            messageIdData.addAckSet(as[i]);
        }
    }
    if (batchSize >= 0) {
        messageIdData.setBatchSize(batchSize);
    }
    if (validationError != null) {
        ack.setValidationError(validationError);
    }
    if (txnIdMostBits >= 0) {
        ack.setTxnidMostBits(txnIdMostBits);
    }
    if (txnIdLeastBits >= 0) {
        ack.setTxnidLeastBits(txnIdLeastBits);
    }
    if (requestId >= 0) {
        ack.setRequestId(requestId);
    }
    if (!properties.isEmpty()) {
        properties.forEach((k, v) -> {
            ack.addProperty().setKey(k).setValue(v);
        });
    }
    return serializeWithSize(cmd);
}
Also used : CommandAck(org.apache.pulsar.common.api.proto.CommandAck) MessageIdData(org.apache.pulsar.common.api.proto.MessageIdData) BaseCommand(org.apache.pulsar.common.api.proto.BaseCommand)

Example 24 with MessageIdData

use of org.apache.pulsar.common.api.proto.MessageIdData in project pulsar by apache.

the class RawMessageImpl method deserializeFrom.

public static RawMessage deserializeFrom(ByteBuf buffer) {
    int idSize = buffer.readInt();
    MessageIdData id = new MessageIdData();
    id.parseFrom(buffer, idSize);
    int payloadAndMetadataSize = buffer.readInt();
    ByteBuf metadataAndPayload = buffer.slice(buffer.readerIndex(), payloadAndMetadataSize);
    return new RawMessageImpl(id, metadataAndPayload);
}
Also used : MessageIdData(org.apache.pulsar.common.api.proto.MessageIdData) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

MessageIdData (org.apache.pulsar.common.api.proto.MessageIdData)24 ByteBuf (io.netty.buffer.ByteBuf)12 CompletableFuture (java.util.concurrent.CompletableFuture)8 PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)8 ArrayList (java.util.ArrayList)7 Collections (java.util.Collections)6 List (java.util.List)6 MessageId (org.apache.pulsar.client.api.MessageId)6 FutureUtil (org.apache.pulsar.common.util.FutureUtil)6 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)5 Map (java.util.Map)5 Objects (java.util.Objects)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 Collectors (java.util.stream.Collectors)5 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)5 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)5 CommandAck (org.apache.pulsar.common.api.proto.CommandAck)5 InitialPosition (org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition)5 MessageMetadata (org.apache.pulsar.common.api.proto.MessageMetadata)5 IOException (java.io.IOException)4