public static MessageId fromByteArray(byte[] data) throws IOException { checkNotNull(data); ByteBufCodedInputStream inputStream = ByteBufCodedInputStream.get(Unpooled.wrappedBuffer(data, 0, data.length)); PulsarApi.MessageIdData.Builder builder = PulsarApi.MessageIdData.newBuilder(); PulsarApi.MessageIdData idData; try { idData = builder.mergeFrom(inputStream, null).build(); } catch (UninitializedMessageException e) { throw new IOException(e); } MessageIdImpl messageId; if (idData.hasBatchIndex()) { messageId = new BatchMessageIdImpl(idData.getLedgerId(), idData.getEntryId(), idData.getPartition(), idData.getBatchIndex()); } else { messageId = new MessageIdImpl(idData.getLedgerId(), idData.getEntryId(), idData.getPartition()); } inputStream.recycle(); builder.recycle(); idData.recycle(); return messageId; }
public static MessageId fromByteArrayWithTopic(byte[] data, TopicName topicName) throws IOException { checkNotNull(data); ByteBufCodedInputStream inputStream = ByteBufCodedInputStream.get(Unpooled.wrappedBuffer(data, 0, data.length)); PulsarApi.MessageIdData.Builder builder = PulsarApi.MessageIdData.newBuilder(); PulsarApi.MessageIdData idData; try { idData = builder.mergeFrom(inputStream, null).build(); } catch (UninitializedMessageException e) { throw new IOException(e); } MessageId messageId; if (idData.hasBatchIndex()) { messageId = new BatchMessageIdImpl(idData.getLedgerId(), idData.getEntryId(), idData.getPartition(), idData.getBatchIndex()); } 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); } inputStream.recycle(); builder.recycle(); idData.recycle(); return messageId; }
final MessageIdImpl startMessageId = subscribe.hasStartMessageId() ? new BatchMessageIdImpl( subscribe.getStartMessageId().getLedgerId(), subscribe.getStartMessageId().getEntryId(), subscribe.getStartMessageId().getPartition(), subscribe.getStartMessageId().getBatchIndex()) : null; final String subscription = subscribe.getSubscription();
BiPredicate<String, MessageId> filter) throws IOException { checkArgument(msg.getMessageIdData().getBatchIndex() == -1);
public static MessageId fromByteArrayWithTopic(byte[] data, TopicName topicName) throws IOException { checkNotNull(data); ByteBufCodedInputStream inputStream = ByteBufCodedInputStream.get(Unpooled.wrappedBuffer(data, 0, data.length)); PulsarApi.MessageIdData.Builder builder = PulsarApi.MessageIdData.newBuilder(); PulsarApi.MessageIdData idData; try { idData = builder.mergeFrom(inputStream, null).build(); } catch (UninitializedMessageException e) { throw new IOException(e); } MessageId messageId; if (idData.hasBatchIndex()) { messageId = new BatchMessageIdImpl(idData.getLedgerId(), idData.getEntryId(), idData.getPartition(), idData.getBatchIndex()); } 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); } inputStream.recycle(); builder.recycle(); idData.recycle(); return messageId; }
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(); CompressionType compressionType = metadata.getCompression(); CompressionCodec codec = CompressionCodecProvider.getCompressionCodec(compressionType); int uncompressedSize = metadata.getUncompressedSize(); ByteBuf uncompressedPayload = codec.decode(payload, uncompressedSize); 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(uncompressedPayload, 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(); } uncompressedPayload.release(); return idsAndKeys; }
public static MessageId fromByteArray(byte[] data) throws IOException { checkNotNull(data); ByteBufCodedInputStream inputStream = ByteBufCodedInputStream.get(Unpooled.wrappedBuffer(data, 0, data.length)); PulsarApi.MessageIdData.Builder builder = PulsarApi.MessageIdData.newBuilder(); PulsarApi.MessageIdData idData; try { idData = builder.mergeFrom(inputStream, null).build(); } catch (UninitializedMessageException e) { throw new IOException(e); } MessageIdImpl messageId; if (idData.hasBatchIndex()) { messageId = new BatchMessageIdImpl(idData.getLedgerId(), idData.getEntryId(), idData.getPartition(), idData.getBatchIndex()); } else { messageId = new MessageIdImpl(idData.getLedgerId(), idData.getEntryId(), idData.getPartition()); } inputStream.recycle(); builder.recycle(); idData.recycle(); return messageId; }
public Builder mergeFrom(org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData other) { if (other == org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData.getDefaultInstance()) return this; if (other.hasLedgerId()) { setLedgerId(other.getLedgerId()); } if (other.hasEntryId()) { setEntryId(other.getEntryId()); } if (other.hasPartition()) { setPartition(other.getPartition()); } if (other.hasBatchIndex()) { setBatchIndex(other.getBatchIndex()); } return this; }
@Override public MessageId getMessageId() { return new BatchMessageIdImpl(id.getLedgerId(), id.getEntryId(), id.getPartition(), id.getBatchIndex()); }
public Builder mergeFrom(org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData other) { if (other == org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData.getDefaultInstance()) return this; if (other.hasLedgerId()) { setLedgerId(other.getLedgerId()); } if (other.hasEntryId()) { setEntryId(other.getEntryId()); } if (other.hasPartition()) { setPartition(other.getPartition()); } if (other.hasBatchIndex()) { setBatchIndex(other.getBatchIndex()); } return this; }