@Override public SchemaInfo getSchemaInfo() { ensureSchemaInitialized(); return schema.getSchemaInfo(); }
public <T> CompletableFuture<Reader<T>> createReaderAsync(ReaderConfigurationData<T> conf, Schema<T> schema) { if (schema instanceof AutoConsumeSchema) { AutoConsumeSchema autoConsumeSchema = (AutoConsumeSchema) schema; return lookup.getSchema(TopicName.get(conf.getTopicName())) .thenCompose(schemaInfoOptional -> { if (schemaInfoOptional.isPresent() && schemaInfoOptional.get().getType() == SchemaType.AVRO) { GenericSchema genericSchema = GenericSchema.of(schemaInfoOptional.get()); log.info("Auto detected schema for topic {} : {}", conf.getTopicName(), new String(schemaInfoOptional.get().getSchema(), UTF_8)); autoConsumeSchema.setSchema(genericSchema); return doCreateReaderAsync(conf, schema); } else { return FutureUtil.failedFuture( new PulsarClientException.LookupException("Currently schema detection only works for topics with avro schemas")); } }); } else { return doCreateReaderAsync(conf, schema); } } <T> CompletableFuture<Reader<T>> doCreateReaderAsync(ReaderConfigurationData<T> conf, Schema<T> schema) {
static Schema<GenericRecord> AUTO_CONSUME() { return new AutoConsumeSchema(); }
@Override public void validate(byte[] message) { ensureSchemaInitialized(); schema.validate(message); }
private <T> CompletableFuture<Consumer<T>> singleTopicSubscribeAsync(ConsumerConfigurationData<T> conf, Schema<T> schema, ConsumerInterceptors<T> interceptors) { if (schema instanceof AutoConsumeSchema) { AutoConsumeSchema autoConsumeSchema = (AutoConsumeSchema) schema; return lookup.getSchema(TopicName.get(conf.getSingleTopic())) .thenCompose(schemaInfoOptional -> { if (schemaInfoOptional.isPresent() && schemaInfoOptional.get().getType() == SchemaType.AVRO) { GenericSchema genericSchema = GenericSchema.of(schemaInfoOptional.get()); log.info("Auto detected schema for topic {} : {}", conf.getSingleTopic(), new String(schemaInfoOptional.get().getSchema(), UTF_8)); autoConsumeSchema.setSchema(genericSchema); return doSingleTopicSubscribeAsync(conf, schema, interceptors); } else { return FutureUtil.failedFuture( new PulsarClientException.LookupException("Currently schema detection only works for topics with avro schemas")); } }); } else { return doSingleTopicSubscribeAsync(conf, schema, interceptors); } }
@Override public GenericRecord decode(byte[] bytes) { ensureSchemaInitialized(); return schema.decode(bytes); }
public <T> CompletableFuture<Reader<T>> createReaderAsync(ReaderConfigurationData<T> conf, Schema<T> schema) { if (schema instanceof AutoConsumeSchema) { AutoConsumeSchema autoConsumeSchema = (AutoConsumeSchema) schema; return lookup.getSchema(TopicName.get(conf.getTopicName())) .thenCompose(schemaInfoOptional -> { if (schemaInfoOptional.isPresent() && schemaInfoOptional.get().getType() == SchemaType.AVRO) { GenericSchema genericSchema = GenericSchema.of(schemaInfoOptional.get()); log.info("Auto detected schema for topic {} : {}", conf.getTopicName(), new String(schemaInfoOptional.get().getSchema(), UTF_8)); autoConsumeSchema.setSchema(genericSchema); return doCreateReaderAsync(conf, schema); } else { return FutureUtil.failedFuture( new PulsarClientException.LookupException("Currently schema detection only works for topics with avro schemas")); } }); } else { return doCreateReaderAsync(conf, schema); } } <T> CompletableFuture<Reader<T>> doCreateReaderAsync(ReaderConfigurationData<T> conf, Schema<T> schema) {
@Override public byte[] encode(GenericRecord message) { ensureSchemaInitialized(); return schema.encode(message); }
private <T> CompletableFuture<Consumer<T>> singleTopicSubscribeAsync(ConsumerConfigurationData<T> conf, Schema<T> schema, ConsumerInterceptors<T> interceptors) { if (schema instanceof AutoConsumeSchema) { AutoConsumeSchema autoConsumeSchema = (AutoConsumeSchema) schema; return lookup.getSchema(TopicName.get(conf.getSingleTopic())) .thenCompose(schemaInfoOptional -> { if (schemaInfoOptional.isPresent() && schemaInfoOptional.get().getType() == SchemaType.AVRO) { GenericSchema genericSchema = GenericSchema.of(schemaInfoOptional.get()); log.info("Auto detected schema for topic {} : {}", conf.getSingleTopic(), new String(schemaInfoOptional.get().getSchema(), UTF_8)); autoConsumeSchema.setSchema(genericSchema); return doSingleTopicSubscribeAsync(conf, schema, interceptors); } else { return FutureUtil.failedFuture( new PulsarClientException.LookupException("Currently schema detection only works for topics with avro schemas")); } }); } else { return doSingleTopicSubscribeAsync(conf, schema, interceptors); } }
@Override public byte[] encode(GenericRecord message) { ensureSchemaInitialized(); return schema.encode(message); }
@Override public GenericRecord decode(byte[] bytes) { ensureSchemaInitialized(); return schema.decode(bytes); }
@Override public SchemaInfo getSchemaInfo() { ensureSchemaInitialized(); return schema.getSchemaInfo(); } }
@Override public void validate(byte[] message) { ensureSchemaInitialized(); schema.validate(message); }