Search in sources :

Example 1 with AvroSchemaProvider

use of io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider in project ksql by confluentinc.

the class KsqlSchemaRegistryClientFactory method get.

public SchemaRegistryClient get() {
    if (schemaRegistryUrl.equals("")) {
        return new DefaultSchemaRegistryClient();
    }
    final RestService restService = serviceSupplier.get();
    // This call sets a default sslSocketFactory.
    final SchemaRegistryClient client = schemaRegistryClientFactory.create(restService, 1000, ImmutableList.of(new AvroSchemaProvider(), new ProtobufSchemaProvider(), new JsonSchemaProvider()), schemaRegistryClientConfigs, httpHeaders);
    // above.
    if (sslContext != null) {
        restService.setSslSocketFactory(sslContext.getSocketFactory());
    }
    return client;
}
Also used : JsonSchemaProvider(io.confluent.kafka.schemaregistry.json.JsonSchemaProvider) RestService(io.confluent.kafka.schemaregistry.client.rest.RestService) ProtobufSchemaProvider(io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider) AvroSchemaProvider(io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) CachedSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient)

Example 2 with AvroSchemaProvider

use of io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider in project schema-registry by confluentinc.

the class AvroConverter method configure.

@Override
public void configure(Map<String, ?> configs, boolean isKey) {
    this.isKey = isKey;
    AvroConverterConfig avroConverterConfig = new AvroConverterConfig(configs);
    if (schemaRegistry == null) {
        schemaRegistry = new CachedSchemaRegistryClient(avroConverterConfig.getSchemaRegistryUrls(), avroConverterConfig.getMaxSchemasPerSubject(), Collections.singletonList(new AvroSchemaProvider()), configs, avroConverterConfig.requestHeaders());
    }
    serializer = new Serializer(configs, schemaRegistry);
    deserializer = new Deserializer(configs, schemaRegistry);
    avroData = new AvroData(new AvroDataConfig(configs));
}
Also used : AbstractKafkaAvroDeserializer(io.confluent.kafka.serializers.AbstractKafkaAvroDeserializer) CachedSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient) AvroSchemaProvider(io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider) AbstractKafkaAvroSerializer(io.confluent.kafka.serializers.AbstractKafkaAvroSerializer)

Example 3 with AvroSchemaProvider

use of io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider in project schema-registry by confluentinc.

the class AvroSchemaTest method testInvalidDefault.

@Test
public void testInvalidDefault() throws Exception {
    AvroSchemaProvider provider = new AvroSchemaProvider();
    Map<String, String> configs = Collections.singletonMap(AvroSchemaProvider.AVRO_VALIDATE_DEFAULTS, "false");
    provider.configure(configs);
    Optional<ParsedSchema> schema = provider.parseSchema(recordInvalidDefaultSchema, Collections.emptyList(), true);
    assertTrue(schema.isPresent());
    configs = Collections.singletonMap(AvroSchemaProvider.AVRO_VALIDATE_DEFAULTS, "true");
    provider.configure(configs);
    schema = provider.parseSchema(recordInvalidDefaultSchema, Collections.emptyList(), true);
    assertFalse(schema.isPresent());
}
Also used : ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) AvroSchemaProvider(io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider) Test(org.junit.Test)

Example 4 with AvroSchemaProvider

use of io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider in project schema-registry by confluentinc.

the class AbstractKafkaAvroDeserializer method configure.

/**
 * Sets properties for this deserializer without overriding the schema registry client itself.
 * Useful for testing, where a mock client is injected.
 */
protected void configure(KafkaAvroDeserializerConfig config) {
    configureClientProperties(config, new AvroSchemaProvider());
    useSpecificAvroReader = config.getBoolean(KafkaAvroDeserializerConfig.SPECIFIC_AVRO_READER_CONFIG);
    avroReflectionAllowNull = config.getBoolean(KafkaAvroDeserializerConfig.AVRO_REFLECTION_ALLOW_NULL_CONFIG);
    avroUseLogicalTypeConverters = config.getBoolean(KafkaAvroSerializerConfig.AVRO_USE_LOGICAL_TYPE_CONVERTERS_CONFIG);
}
Also used : AvroSchemaProvider(io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider)

Example 5 with AvroSchemaProvider

use of io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider in project schema-registry by confluentinc.

the class AbstractKafkaAvroSerializer method configure.

protected void configure(KafkaAvroSerializerConfig config) {
    configureClientProperties(config, new AvroSchemaProvider());
    normalizeSchema = config.normalizeSchema();
    autoRegisterSchema = config.autoRegisterSchema();
    removeJavaProperties = config.getBoolean(KafkaAvroSerializerConfig.AVRO_REMOVE_JAVA_PROPS_CONFIG);
    useSchemaId = config.useSchemaId();
    idCompatStrict = config.getIdCompatibilityStrict();
    useLatestVersion = config.useLatestVersion();
    latestCompatStrict = config.getLatestCompatibilityStrict();
    avroReflectionAllowNull = config.getBoolean(KafkaAvroSerializerConfig.AVRO_REFLECTION_ALLOW_NULL_CONFIG);
    avroUseLogicalTypeConverters = config.getBoolean(KafkaAvroSerializerConfig.AVRO_USE_LOGICAL_TYPE_CONVERTERS_CONFIG);
}
Also used : AvroSchemaProvider(io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider)

Aggregations

AvroSchemaProvider (io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider)9 CachedSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient)5 JsonSchemaProvider (io.confluent.kafka.schemaregistry.json.JsonSchemaProvider)4 ProtobufSchemaProvider (io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider)4 SchemaProvider (io.confluent.kafka.schemaregistry.SchemaProvider)2 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)2 ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)1 RestService (io.confluent.kafka.schemaregistry.client.rest.RestService)1 SchemaString (io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString)1 SchemaRegistryRestApplication (io.confluent.kafka.schemaregistry.rest.SchemaRegistryRestApplication)1 AbstractKafkaAvroDeserializer (io.confluent.kafka.serializers.AbstractKafkaAvroDeserializer)1 AbstractKafkaAvroSerializer (io.confluent.kafka.serializers.AbstractKafkaAvroSerializer)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Connection (org.akhq.configs.Connection)1 Test (org.junit.Test)1