GPrabhudas commented on a change in pull request #560:
URL: https://github.com/apache/pulsar-client-go/pull/560#discussion_r696566948



##########
File path: pulsar/internal/commands.go
##########
@@ -221,9 +222,21 @@ func serializeBatch(wb Buffer,
        cmdSend *pb.BaseCommand,
        msgMetadata *pb.MessageMetadata,
        uncompressedPayload Buffer,
-       compressionProvider compression.Provider) {
+       compressionProvider compression.Provider,
+       encryptor crypto.Encryptor) {
        // Wire format
        // [TOTAL_SIZE] [CMD_SIZE][CMD] [MAGIC_NUMBER][CHECKSUM] 
[METADATA_SIZE][METADATA] [PAYLOAD]
+
+       // compress the payload
+       compressedPayload := compressionProvider.Compress(nil, 
uncompressedPayload.ReadableSlice())
+
+       // encrypt the compressed payload
+       encryptedPayload, err := encryptor.Encrypt(compressedPayload, 
crypto.NewMessageMetadataSupplier(msgMetadata))
+       if err != nil {
+               // error occurred while encrypting the payload, 
ProducerCryptoFailureAction is set to Fail
+               panic(fmt.Sprintf("Encryption of message failed, 
ProducerCryptoFailureAction is set to Fail. Error :%v", err))

Review comment:
       @cckellogg 
   > This code will check if the message was added and if not it returns an 
error through the callback.
   > 
https://github.com/apache/pulsar-client-go/blob/master/pulsar/producer_partition.go#L434
   
   We do not encrypt the message when it is added to batch, but [encryption 
happens](https://github.com/Fanatics/pulsar-client-go/blob/encryption-support-ext-producer/pulsar/internal/commands.go#L235)
 on serializing batch when flush method is triggered.
   
   So to avoid panic, we can return an error from below flush methods and 
report the same error to client.
   
   
[Flush](https://github.com/apache/pulsar-client-go/blob/master/pulsar/internal/batch_builder.go#L54)
   
[FlushBatches](https://github.com/apache/pulsar-client-go/blob/master/pulsar/internal/batch_builder.go#L58)
   
   
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to