samriddhi
08/19/2025, 9:19 PMAUTO_CONSUME - works great for reading any schema
• ❌ Output: Need exact schema match, but AUTO_PRODUCE doesn't exist
The challenge: To avoid static schemas, I need to get schema info from Pulsar Admin at runtime, but Pulsar Functions don't have access to PulsarAdmin (getting errors when trying).
Questions:
1. What's the recommended pattern for schema-agnostic functions?
2. How do I discover output topic schema at runtime without Admin access?
3. Any alternatives to runtime schema discovery for generic functions?
Goal: One function that works with multiple topic pairs having different schemas (Avro→Avro, JSON→JSON, Avro→JSON, etc.) without recompiling.
Anyone solved this or know the best practices?Neng
08/19/2025, 10:14 PMcontext.getCurrentRecord().getSchema()Neng
08/19/2025, 10:38 PMGenericRecord , and then use Object getField(String fieldName); to access each field:
public class DemoFunction implements Function<GenericObject, ??> {
public Record<GenericObject> process(GenericObject input, Context context) throws Exception {
...
input.getField("FIELD_NAME");
...
}
}samriddhi
08/20/2025, 11:33 AMRadim Hatlapatka
08/20/2025, 3:17 PMAUTO_PRODUCE_BYTES => https://pulsar.apache.org/api/client/4.0.x/org/apache/pulsar/client/api/Schema.html#AUTO_PRODUCE_BYTES() ?Radim Hatlapatka
08/20/2025, 3:20 PMLari Hotari
08/21/2025, 7:18 AM• ❌ Output: Need exact schema match, butIn Pulsar Functions, AUTO_PRODUCE_BYTES maps to AUTO_PUBLISH: https://github.com/apache/pulsar/blob/d3c615c494ddd3d2c0ba6005951e486d7b76e7f3/pul[…]/org/apache/pulsar/functions/instance/JavaInstanceRunnable.javadoesn't existAUTO_PRODUCE
Neng
08/21/2025, 3:56 PMFunctionRecordBuilder recordBuilder =
context.newOutputRecordBuilder(outputSchema).destinationTopic(targetTopic);
...
recordBuilder.value(outputObject);
return recordBuilder.build();
it returns a Record<GenericObject>