BewareMyPower commented on issue #15036:
URL: https://github.com/apache/pulsar/issues/15036#issuecomment-1091863190
I also tried to use `AUTO_CONSUME` schema to consume messages from C++
client now.
```java
final String topic = "ProtobufSchemaTest-testEndToEnd";
try (PulsarClient client =
PulsarClient.builder().serviceUrl("pulsar://localhost:6650").build()) {
Consumer<GenericRecord> consumer =
client.newConsumer(Schema.AUTO_CONSUME())
.topic(topic)
.subscriptionInitialPosition(SubscriptionInitialPosition.Earliest)
.subscriptionName("my-sub-auto-consume")
.subscribe();
while (true) {
Message<GenericRecord> msg = consumer.receive(1,
TimeUnit.SECONDS);
if (msg == null) {
break;
}
try {
DynamicMessage message = ((GenericProtobufNativeRecord)
msg.getValue()).getProtobufRecord();
Descriptors.FieldDescriptor fieldDescriptor =
message.getDescriptorForType().findFieldByName("testEnum");
if (fieldDescriptor == null) continue;
System.out.println("enum value: " +
message.getField(fieldDescriptor));
} catch (ClassCastException e) {
System.out.println(" failed to convert value to
GenericProtobufNativeRecord: "
+ e.getMessage());
}
}
}
```
The output is
```
enum value: FAILOVER
```
So it works well now.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]