Skip to main content

I am successfully authenticating and able to subscribe just fine using PubSub API to the account platform event. 

 

Making unary calls with PublishAsync are successfully sending, i am receiving the replayId and CorrelationId back, however these platform events are not appearing. Interestingly Streaming Monitor creates the alert that an event has fired, however does not show up in the graph. 

 

I am triggering a simple flow using flow builder from this platform event which works fine when triggering via Apex/Streaming Monitor. I am getting flow errors. Error ID 712146348-203459 (1391829016) 

 

I am using Avro, basing my code from the Java and Go samples (there is no C# publishing sample - only subscribing) 

 

I have generated code using Avro.CodeGen from the schema retrieved from the GetSchemaInfoAsync endpoint from the proto file. I have spent a long time reading through the docs and code. The only thing i could find was 

https://developer.salesforce.com/docs/platform/pub-sub-api/guide/event-avro-serialization.html

 

"Pub/Sub API doesn’t validate the Avro format of the event payload that’s passed in to the 

Publish or PublishStream

 calls. It’s up to the client to make sure that the event payload is in Avro format and that it’s valid. The Publish and PublishStream calls complete successfully even if an event payload isn’t in valid Avro format. Because an event with an invalid payload fails to deserialize, a subscriber must filter out the events with invalid payloads." 

 

But i am unaware of way to debug this or validate. Im using  Avro.IO.BinaryEncoder which i believe is the same as the Java implementation. Any help would be greatly appreciated. Thanks. 

1 个回答
  1. 4月4日 16:31

    Hi Matthew,

    The most likely root cause is an Avro serialization format mismatch between the C# Apache.Avro library and what the Salesforce Pub/Sub API expects. Here are the key things to verify and fix:

    1. Byte buffer setup for BinaryEncoder - The C# Apache.Avro library requires you to write to a MemoryStream and then pass the byte array correctly. A common mistake is not flushing or closing the encoder before reading the bytes. Make sure you are doing:

    var stream = new MemoryStream(); var encoder = new BinaryEncoder(stream); var writer = new GenericDatumWriter(schema); writer.Write(record, encoder); encoder.Flush(); byte[] avroBytes = stream.ToArray();

    2. The payload in PublishRequest must be wrapped correctly - The ProducerEvent.Payload field should be the raw Avro-serialized bytes. Do NOT include the Avro schema header (5-byte magic + schema fingerprint) that some serializers add. The Pub/Sub API handles schema resolution separately via SchemaId.

    3. Verify the SchemaId in your publish request matches the schema returned by GetSchemaInfo - If you are caching the schema, ensure it matches the currently active schema for your Platform Event. A mismatched SchemaId will cause silent deserialization failures.

    4. The error ID 712146348-203459 in your Flow - This is a Flow runtime error, not a Platform Event publish error. The event IS being published (Streaming Monitor confirms fire), but the Flow trigger is failing during execution. Check the Flow error details in Setup, Apex Jobs, or the debug log to identify the actual Flow error.

    5. Validate your Avro payload - To debug, try subscribing back to your own published event using the PubSub API Subscribe call. If the subscriber receives valid data, the publish is working. If the subscriber gets an error or null values, the Avro encoding is malformed.

    Hope this helps you isolate the issue!

    Mani G | Principal/Founder | https://Keneland.com

0/9000