You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by karan alang <ka...@gmail.com> on 2022/11/11 21:55:26 UTC

Confluent Schema Registry - auto.register.schemas

Hello All,

ref stackoverflow :
https://stackoverflow.com/questions/74396652/confluent-schema-registry-why-is-auto-register-schemas-not-applicable-at-schem

---

I've installed the Schema Registry and want to set the auto.register.schema
set to false - so only avro messages conforming to the registered schema
can be published to Kafka Topic.

From what I understand, the property - auto.register.schemas is a Kafka
Producer property, and not a schema registry property.

Here is the code I use to set the property auto.register.schemas
```

Console Producer:

kafka-avro-console-producer --bootstrap-server localhost:9092
--property schema.registry.url=http://localhost:8081 --topic
srtest-optionalfield --property
value.schema='{"type":"record","name":"myrecord","fields":[{"name":"f2","type":"string"}]}'
--property value.subject.name.strategy=io.confluent.kafka.serializers.subject.RecordNameStrategy
--property auto.register.schemas=false

Java Kafka Avro Producer :

Properties props = new Properties();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "http://localhost:9092");
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
KafkaAvroSerializer.class);
props.put(ProducerConfig.CLIENT_ID_CONFIG, "Kafka Avro  Producer");
props.put("schema.registry.url", "http://localhost:8081");
props.put(AbstractKafkaAvroSerDeConfig.AUTO_REGISTER_SCHEMAS, false);

```

Does this mean that - if a Kafka producer passes the property
auto.register.schemas=true, it will be able to add the schema to the Schema
Registry ?

This does not provide safeguard, since I want to ensure that producer is
allowed to produce only messages that conform to schemas in Schema Registry

How do I do this ? Is there a way for me to set the property -
auto.register.schemas - at the Schema Registry level ?

tia!

Re: Confluent Schema Registry - auto.register.schemas

Posted by karan alang <ka...@gmail.com>.
hello All -
checking to see if anyone has updates on this.

tia!

On Fri, Nov 11, 2022 at 1:55 PM karan alang <ka...@gmail.com> wrote:

> Hello All,
>
> ref stackoverflow :
> https://stackoverflow.com/questions/74396652/confluent-schema-registry-why-is-auto-register-schemas-not-applicable-at-schem
>
> ---
>
> I've installed the Schema Registry and want to set the
> auto.register.schema set to false - so only avro messages conforming to the
> registered schema can be published to Kafka Topic.
>
> From what I understand, the property - auto.register.schemas is a Kafka
> Producer property, and not a schema registry property.
>
> Here is the code I use to set the property auto.register.schemas
> ```
>
> Console Producer:
>
> kafka-avro-console-producer --bootstrap-server localhost:9092 --property schema.registry.url=http://localhost:8081 --topic srtest-optionalfield --property value.schema='{"type":"record","name":"myrecord","fields":[{"name":"f2","type":"string"}]}' --property value.subject.name.strategy=io.confluent.kafka.serializers.subject.RecordNameStrategy --property auto.register.schemas=false
>
> Java Kafka Avro Producer :
>
> Properties props = new Properties();
> props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "http://localhost:9092");
> props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
> props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, KafkaAvroSerializer.class);
> props.put(ProducerConfig.CLIENT_ID_CONFIG, "Kafka Avro  Producer");
> props.put("schema.registry.url", "http://localhost:8081");
> props.put(AbstractKafkaAvroSerDeConfig.AUTO_REGISTER_SCHEMAS, false);
>
> ```
>
> Does this mean that - if a Kafka producer passes the property
> auto.register.schemas=true, it will be able to add the schema to the Schema
> Registry ?
>
> This does not provide safeguard, since I want to ensure that producer is
> allowed to produce only messages that conform to schemas in Schema Registry
>
> How do I do this ? Is there a way for me to set the property -
> auto.register.schemas - at the Schema Registry level ?
>
> tia!
>