hnail opened a new pull request #8372:
URL: https://github.com/apache/pulsar/pull/8372
### **warnning**
> this PR depend on [PR-8246](https://github.com/apache/pulsar/pull/8246)
and haven't finish unit test case , please don't review or merge.
### Motivation
support Protobuf Native Schema Support for [PIP-Add ProtobufNative Schema
Support
](https://docs.google.com/document/d/1XR_MNOuSXyig-CKsdVhr6IXvFwziBRdSoS3oEUiLFe8/edit?usp=sharing)
#### set ProtobufNative schema Example
```
SchemaDefinition def = SchemaDefinition.<JsonGen.User>builder()
.withAlwaysAllowNull(true)
.withPojo(AdnMonitor.AdnJson.class)
.build();
Schema schema = Schema.PROTOBUFNATIVE(def);
admin.schemas().createSchema(topic, schema.getSchemaInfo());
```
#### POJO schema consumer Example
```
Consumer<AdnMonitor.AdnJson> consumer =
client.newConsumer(Schema.PROTOBUFNATIVE(AdnMonitor.AdnJson.class)).topic(topic)
.subscriptionName("my-subscription-name").subscriptionInitialPosition(SubscriptionInitialPosition.Earliest).subscribe();
while (!consumer.hasReachedEndOfTopic()){
Message<AdnMonitor.AdnJson> msg = consumer.receive();
AdnMonitor.AdnJson adnJson = msg.getValue();
System.out.println("getPlatform : "+ adnJson.getPlatform());
}
```
#### ProtobufNative AUTO_CONSUME Example
```
Consumer<GenericRecord> consumer =
client.newConsumer(Schema.AUTO_CONSUME()).topic(topic)
.subscriptionName("my-subscription-nameaaa").subscriptionInitialPosition(SubscriptionInitialPosition.Earliest)
.subscribe();
while (!consumer.hasReachedEndOfTopic()){
Message<GenericRecord> msg = consumer.receive() ;
// System.out.println("GenericRecord
:"+msg.getValue().toString());
GenericRecord genericRecord = msg.getValue();
System.out.println(genericRecord.getField("platform"));
GenericProtobufNativeRecord genericProtobufNativeRecord =
(GenericProtobufNativeRecord)genericRecord;
DynamicMessage dynamicMessage =
genericProtobufNativeRecord.getProtobufRecord();
String platform =
dynamicMessage.getField(dynamicMessage.getDescriptorForType().findFieldByName("platform")).toString();
System.out.println("platform : "+ platform);
}
```
### Modifications
//TODO
----------------------------------------------------------------
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]