eolivelli opened a new pull request #9956:
URL: https://github.com/apache/pulsar/pull/9956
This is a draft patch on top of #9895 that adds support for returning an
implementation of GenericRecord named PrimitiveRecord that wraps primitive data
types and allows Schema.AUTO_CONSUME() to deal with primitive data types.
Example: writing using "String" schema and consume as: String, Object and
GenericRecord
```
Producer<String> producer = pulsarClient
.newProducer(Schema.STRING)
.topic(topic)
.create();
Consumer<String> consumer = pulsarClient.newConsumer(Schema.STRING)
.subscriptionName("test-sub")
.topic(topic)
.subscribe();
Consumer<Object> consumer2 =
pulsarClient.newConsumer(Schema.OBJECT())
.subscriptionName("test-sub2")
.topic(topic)
.subscribe();
// use GenericRecord even for primitive types
// it will be a PrimitiveRecord
Consumer<GenericRecord> consumer3 =
pulsarClient.newConsumer(Schema.AUTO_CONSUME())
.subscriptionName("test-sub3")
.topic(topic)
.subscribe();
producer.send("foo");
Message<String> message = consumer.receive();
Message<Object> message2 = consumer2.receive();
Message<GenericRecord> message3 = consumer3.receive();
assertEquals("foo", message.getValue());
assertEquals("foo", message2.getValue());
assertTrue(message3.getValue() instanceof PrimitiveRecord);
assertEquals(SchemaType.STRING, message3.getValue().getSchemaType());
assertEquals("foo", message3.getValue().getNativeRecord());
```
----------------------------------------------------------------
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]