0

In Salesforce we fire a platform event and add a payload to a field Payload__c (LongText)to this platform event.

We created a streaming client in python which subscribes to this platform event and consumes the payload.

Because sometimes the payload is quite big, we came up with the idea to compress on salesforce side and decompress the payload on the python side.

We found the lib https://github.com/bilalfastian/LZ4String for Apex. So what we are currently doing is to compress the payload with the method: compressToBase64(payload) and store it as base64 in the platform event.

In python we tried in different ways but we where not able to decompress. Example with lib https://github.com/eduardtomasek/lz-string-python:

In Apex:

String test = 'Hello world';
String comp = LZString.compressToBase64 (test);
System.debug(comp);

// Output is 0oXjgLbmg7ZA7rqQ4pyw04gA

Now i try to decompress this string in python:

base64_message = '0oXjgLbmg7ZA7rqQ4pyw04gA'
w=x.decompresFromBase64(base64_message)
logger.error(w)

Output is just: -
Marc
  • 141
  • 1
  • 7
  • Have you done benchmarks to substantiate that compression adds any value here? Note that your example base64 consumes more bytes than the actual message. You're also going to cost yourself performance by trying to do bitwise manipulation in Apex, which is very poorly suited for that task. – David Reed Sep 30 '20 at 01:05
  • Hi David, yes we did. Was around 50% less data – Marc Nov 16 '20 at 15:56

0 Answers0