MessageImpl(String topic, MessageIdImpl messageId, MessageMetadata msgMetadata, ByteBuf payload, Optional<EncryptionContext> encryptionCtx, ClientCnx cnx, Schema<T> schema, int redeliveryCount) { this.msgMetadataBuilder = MessageMetadata.newBuilder(msgMetadata); this.messageId = messageId; this.topic = topic; this.cnx = cnx; this.redeliveryCount = redeliveryCount; // Need to make a copy since the passed payload is using a ref-count buffer that we don't know when could // release, since the Message is passed to the user. Also, the passed ByteBuf is coming from network and is // backed by a direct buffer which we could not expose as a byte[] this.payload = Unpooled.copiedBuffer(payload); this.encryptionCtx = encryptionCtx; if (msgMetadata.getPropertiesCount() > 0) { this.properties = Collections.unmodifiableMap(msgMetadataBuilder.getPropertiesList().stream() .collect(Collectors.toMap(KeyValue::getKey, KeyValue::getValue))); } else { properties = Collections.emptyMap(); } this.schema = schema; }
public static MessageMetadata parseMessageMetadata(ByteBuf buffer) { try { // initially reader-index may point to start_of_checksum : increment reader-index to start_of_metadata to parse // metadata skipChecksumIfPresent(buffer); int metadataSize = (int) buffer.readUnsignedInt(); int writerIndex = buffer.writerIndex(); buffer.writerIndex(buffer.readerIndex() + metadataSize); ByteBufCodedInputStream stream = ByteBufCodedInputStream.get(buffer); MessageMetadata.Builder messageMetadataBuilder = MessageMetadata.newBuilder(); MessageMetadata res = messageMetadataBuilder.mergeFrom(stream, null).build(); buffer.writerIndex(writerIndex); messageMetadataBuilder.recycle(); stream.recycle(); return res; } catch (IOException e) { throw new RuntimeException(e); } }
MessageImpl(String topic, BatchMessageIdImpl batchMessageIdImpl, MessageMetadata msgMetadata, PulsarApi.SingleMessageMetadata singleMessageMetadata, ByteBuf payload, Optional<EncryptionContext> encryptionCtx, ClientCnx cnx, Schema<T> schema, int redeliveryCount) { this.msgMetadataBuilder = MessageMetadata.newBuilder(msgMetadata); this.messageId = batchMessageIdImpl; this.topic = topic; this.cnx = cnx; this.redeliveryCount = redeliveryCount; this.payload = Unpooled.copiedBuffer(payload); this.encryptionCtx = encryptionCtx; if (singleMessageMetadata.getPropertiesCount() > 0) { Map<String, String> properties = Maps.newTreeMap(); for (KeyValue entry : singleMessageMetadata.getPropertiesList()) { properties.put(entry.getKey(), entry.getValue()); } this.properties = Collections.unmodifiableMap(properties); } else { properties = Collections.emptyMap(); } if (singleMessageMetadata.hasPartitionKey()) { msgMetadataBuilder.setPartitionKeyB64Encoded(singleMessageMetadata.getPartitionKeyB64Encoded()); msgMetadataBuilder.setPartitionKey(singleMessageMetadata.getPartitionKey()); } if (singleMessageMetadata.hasEventTime()) { msgMetadataBuilder.setEventTime(singleMessageMetadata.getEventTime()); } this.schema = schema; }
public static Builder newBuilder(org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata prototype) { return newBuilder().mergeFrom(prototype); } public Builder toBuilder() { return newBuilder(this); }
public static MessageImpl<byte[]> deserialize(ByteBuf headersAndPayload) throws IOException { @SuppressWarnings("unchecked") MessageImpl<byte[]> msg = (MessageImpl<byte[]>) RECYCLER.get(); MessageMetadata msgMetadata = Commands.parseMessageMetadata(headersAndPayload); msg.msgMetadataBuilder = MessageMetadata.newBuilder(msgMetadata); msgMetadata.recycle(); msg.payload = headersAndPayload; msg.messageId = null; msg.topic = null; msg.cnx = null; msg.properties = Collections.emptyMap(); return msg; }
public static org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata parseDelimitedFrom( java.io.InputStream input, org.apache.pulsar.shaded.com.google.protobuf.v241.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { Builder builder = newBuilder(); if (builder.mergeDelimitedFrom(input, extensionRegistry)) { return builder.buildParsed(); } else { return null; } } public static org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata parseFrom(
public static org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata parseFrom( java.io.InputStream input, org.apache.pulsar.shaded.com.google.protobuf.v241.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { return newBuilder().mergeFrom(input, extensionRegistry) .buildParsed(); } public static org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata parseDelimitedFrom(java.io.InputStream input)
public static org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata parseFrom( org.apache.pulsar.shaded.com.google.protobuf.v241.CodedInputStream input, org.apache.pulsar.shaded.com.google.protobuf.v241.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { return newBuilder().mergeFrom(input, extensionRegistry) .buildParsed(); }
public static org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { Builder builder = newBuilder(); if (builder.mergeDelimitedFrom(input)) { return builder.buildParsed(); } else { return null; } } public static org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata parseDelimitedFrom(
public static org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata parseFrom( byte[] data, org.apache.pulsar.shaded.com.google.protobuf.v241.ExtensionRegistryLite extensionRegistry) throws org.apache.pulsar.shaded.com.google.protobuf.v241.InvalidProtocolBufferException { return newBuilder().mergeFrom(data, extensionRegistry) .buildParsed(); } public static org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata parseFrom(java.io.InputStream input)
public Builder toBuilder() { return newBuilder(this); }
public static MessageImpl<byte[]> deserialize(ByteBuf headersAndPayload) throws IOException { @SuppressWarnings("unchecked") MessageImpl<byte[]> msg = (MessageImpl<byte[]>) RECYCLER.get(); MessageMetadata msgMetadata = Commands.parseMessageMetadata(headersAndPayload); msg.msgMetadataBuilder = MessageMetadata.newBuilder(msgMetadata); msgMetadata.recycle(); msg.payload = headersAndPayload; msg.messageId = null; msg.topic = null; msg.cnx = null; msg.properties = Collections.emptyMap(); return msg; }
public static Builder newBuilder(org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata prototype) { return newBuilder().mergeFrom(prototype); } public Builder toBuilder() { return newBuilder(this); }
public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder(org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata prototype) {
public static org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata parseFrom( org.apache.pulsar.shaded.com.google.protobuf.v241.CodedInputStream input, org.apache.pulsar.shaded.com.google.protobuf.v241.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { return newBuilder().mergeFrom(input, extensionRegistry) .buildParsed(); }
public static org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { Builder builder = newBuilder(); if (builder.mergeDelimitedFrom(input)) { return builder.buildParsed(); } else { return null; } } public static org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata parseDelimitedFrom(
public static org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata parseFrom( byte[] data, org.apache.pulsar.shaded.com.google.protobuf.v241.ExtensionRegistryLite extensionRegistry) throws org.apache.pulsar.shaded.com.google.protobuf.v241.InvalidProtocolBufferException { return newBuilder().mergeFrom(data, extensionRegistry) .buildParsed(); } public static org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata parseFrom(java.io.InputStream input)
public static org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata parseDelimitedFrom( java.io.InputStream input, org.apache.pulsar.shaded.com.google.protobuf.v241.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { Builder builder = newBuilder(); if (builder.mergeDelimitedFrom(input, extensionRegistry)) { return builder.buildParsed(); } else { return null; } } public static org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata parseFrom(
public ByteBuf getMessageWithMetadata(byte[] data) throws IOException { MessageMetadata messageData = MessageMetadata.newBuilder().setPublishTime(System.currentTimeMillis()) .setProducerName("prod-name").setSequenceId(0).build(); ByteBuf payload = Unpooled.wrappedBuffer(data, 0, data.length); int msgMetadataSize = messageData.getSerializedSize(); int headersSize = 4 + msgMetadataSize; ByteBuf headers = PooledByteBufAllocator.DEFAULT.buffer(headersSize, headersSize); ByteBufCodedOutputStream outStream = ByteBufCodedOutputStream.get(headers); headers.writeInt(msgMetadataSize); messageData.writeTo(outStream); outStream.recycle(); return ByteBufPair.coalesce(ByteBufPair.get(headers, payload)); }
public static org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata parseFrom( java.io.InputStream input, org.apache.pulsar.shaded.com.google.protobuf.v241.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { return newBuilder().mergeFrom(input, extensionRegistry) .buildParsed(); } public static org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata parseDelimitedFrom(java.io.InputStream input)