pointearth opened a new issue #9892:
URL: https://github.com/apache/pulsar/issues/9892
**Is your feature request related to a problem? Please describe.**
We can prodcue a Generic message with pulsar.client.api:
`RecordSchemaBuilder recordSchemaBuilder =
SchemaBuilder.record(USER_CONST.SCHEMA_NAME);
recordSchemaBuilder.field(USER_CONST.AGE).type(SchemaType.INT32);
recordSchemaBuilder.field(USER_CONST.NAME).type(SchemaType.STRING);
recordSchemaBuilder.field(USER_CONST.JSON_FOR_EVENT).type(SchemaType.STRING);
SchemaInfo schemaInfo = recordSchemaBuilder.build(SchemaType.AVRO);
GenericSchema userSchema = Schema.generic(schemaInfo);
Producer<GenericRecord> producer = pulsarClient.newProducer(
userSchema)
.topic(TOPIC_CONST.TOPIC_FUN_GENERIC)
.create();
User user = new User();
user.age = 27;
user.name = "Simon Generic";
Gson gson = new Gson();
String jsonForEvent = gson.toJson(user);
GenericRecordBuilder genericRecordBuilder =
userSchema.newRecordBuilder();
GenericRecord genericRecord = genericRecordBuilder
.set(USER_CONST.AGE, user.age)
.set(USER_CONST.NAME,user.name)
.set(USER_CONST.JSON_FOR_EVENT, jsonForEvent)
.build();`
but, I am trying many ways to produce dynamic object into pulsar, just like:
`public class FunWrapGeneric implements Function<String, GenericRecord> {
@Override
public GenericRecord process(String input, Context context) throws
Exception {`
but I always got failed. Can we support this? because I don't want to define
a particular wrap class to wrap a POJO class. because the only different thing
between this wrap class and the POJO class is wrap class always add a json
field to any POJO class.
**Describe the solution you'd like**
1. Add GenericRecord support for pulsar function
`public class FunWrapGeneric implements Function<String, GenericRecord>`
2. or Add an override of pulsar function want a Generic class as a parameter
of pulsar function
`FunWrapGeneric implements Function<String,Schema>`
cc @sijie @codelipenghui
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]