Search in sources :

Example 1 with CompressionType

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

the class ConsumerImpl method uncompressPayloadIfNeeded.

private ByteBuf uncompressPayloadIfNeeded(MessageIdData messageId, MessageMetadata msgMetadata, ByteBuf payload, ClientCnx currentCnx) {
    CompressionType compressionType = msgMetadata.getCompression();
    CompressionCodec codec = codecProvider.getCodec(compressionType);
    int uncompressedSize = msgMetadata.getUncompressedSize();
    int payloadSize = payload.readableBytes();
    if (payloadSize > PulsarDecoder.MaxMessageSize) {
        // payload size is itself corrupted since it cannot be bigger than the MaxMessageSize
        log.error("[{}][{}] Got corrupted payload message size {} at {}", topic, subscription, payloadSize, messageId);
        discardCorruptedMessage(messageId, currentCnx, ValidationError.UncompressedSizeCorruption);
        return null;
    }
    try {
        ByteBuf uncompressedPayload = codec.decode(payload, uncompressedSize);
        return uncompressedPayload;
    } catch (IOException e) {
        log.error("[{}][{}] Failed to decompress message with {} at {}: {}", topic, subscription, compressionType, messageId, e.getMessage(), e);
        discardCorruptedMessage(messageId, currentCnx, ValidationError.DecompressionError);
        return null;
    }
}
Also used : CompressionCodec(org.apache.pulsar.common.compression.CompressionCodec) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf) CompressionType(org.apache.pulsar.common.api.proto.PulsarApi.CompressionType)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)1 IOException (java.io.IOException)1 CompressionType (org.apache.pulsar.common.api.proto.PulsarApi.CompressionType)1 CompressionCodec (org.apache.pulsar.common.compression.CompressionCodec)1