Search in sources :

Example 1 with ProtobufSchemaProvider

use of io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider 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 ProtobufSchemaProvider

use of io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider in project schema-registry by confluentinc.

the class SchemaValuesTest method testSchemaValueCanonicalize.

@Test
public void testSchemaValueCanonicalize() {
    String oldSchema = "syntax = \"proto3\";\npackage com.mycorp.mynamespace;\n\n// Test Comment.\r\nmessage value {\n  int32 myField1 = 1;\n}\n";
    String newSchema = "syntax = \"proto3\";\npackage com.mycorp.mynamespace;\n\nmessage value {\n  int32 myField1 = 1;\n}\n";
    SchemaValue schemaValue = new SchemaValue("sub", 1, 0, ProtobufSchema.TYPE, null, oldSchema, false);
    KafkaStoreMessageHandler.canonicalize(new ProtobufSchemaProvider(), schemaValue);
    assertEquals(newSchema, schemaValue.getSchema());
}
Also used : ProtobufSchemaProvider(io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider) Test(org.junit.Test)

Example 3 with ProtobufSchemaProvider

use of io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider in project schema-registry by confluentinc.

the class ProtobufConverter method configure.

@Override
public void configure(Map<String, ?> configs, boolean isKey) {
    this.isKey = isKey;
    ProtobufConverterConfig protobufConverterConfig = new ProtobufConverterConfig(configs);
    if (schemaRegistry == null) {
        schemaRegistry = new CachedSchemaRegistryClient(protobufConverterConfig.getSchemaRegistryUrls(), protobufConverterConfig.getMaxSchemasPerSubject(), Collections.singletonList(new ProtobufSchemaProvider()), configs, protobufConverterConfig.requestHeaders());
    }
    serializer = new Serializer(configs, schemaRegistry);
    deserializer = new Deserializer(configs, schemaRegistry);
    protobufData = new ProtobufData(new ProtobufDataConfig(configs));
}
Also used : AbstractKafkaProtobufDeserializer(io.confluent.kafka.serializers.protobuf.AbstractKafkaProtobufDeserializer) CachedSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient) ProtobufSchemaProvider(io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider) AbstractKafkaProtobufSerializer(io.confluent.kafka.serializers.protobuf.AbstractKafkaProtobufSerializer)

Example 4 with ProtobufSchemaProvider

use of io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider in project schema-registry by confluentinc.

the class RestApiSerializerTest method testDependency2.

@Test
public void testDependency2() throws Exception {
    Properties serializerConfig = new Properties();
    serializerConfig.put(KafkaProtobufSerializerConfig.AUTO_REGISTER_SCHEMAS, true);
    serializerConfig.put(KafkaProtobufSerializerConfig.SCHEMA_REGISTRY_URL_CONFIG, "bogus");
    serializerConfig.put(KafkaProtobufSerializerConfig.SKIP_KNOWN_TYPES_CONFIG, false);
    SchemaRegistryClient schemaRegistry = new CachedSchemaRegistryClient(restApp.restClient, 10, Collections.singletonList(new ProtobufSchemaProvider()), Collections.emptyMap(), Collections.emptyMap());
    KafkaProtobufSerializer protobufSerializer = new KafkaProtobufSerializer(schemaRegistry, new HashMap(serializerConfig));
    KafkaProtobufDeserializer protobufDeserializer = new KafkaProtobufDeserializer(schemaRegistry);
    Properties clickCasDeserializerConfig = new Properties();
    clickCasDeserializerConfig.put(KafkaProtobufDeserializerConfig.SCHEMA_REGISTRY_URL_CONFIG, "bogus");
    KafkaProtobufDeserializer clickCasDeserializer = new KafkaProtobufDeserializer(schemaRegistry, new HashMap(clickCasDeserializerConfig), ExampleProtoAcme.ClickCas.class);
    byte[] bytes;
    // specific -> specific
    bytes = protobufSerializer.serialize(topic, CLICK_CAS_MESSAGE);
    assertEquals(CLICK_CAS_MESSAGE, clickCasDeserializer.deserialize(topic, bytes));
    // specific -> dynamic
    bytes = protobufSerializer.serialize(topic, CLICK_CAS_MESSAGE);
    DynamicMessage message = (DynamicMessage) protobufDeserializer.deserialize(topic, bytes);
    assertEquals(CLICK_CAS_MESSAGE.getGlupOrigin().getHostname(), getField((DynamicMessage) getField(message, "glup_origin"), "hostname"));
    ParsedSchema schema = schemaRegistry.getSchemaBySubjectAndId("test-value", 4);
    assertEquals(ProtobufSchemaUtils.getSchema(CLICK_CAS_MESSAGE).canonicalString(), schema.canonicalString());
}
Also used : HashMap(java.util.HashMap) KafkaProtobufDeserializer(io.confluent.kafka.serializers.protobuf.KafkaProtobufDeserializer) DynamicMessage(com.google.protobuf.DynamicMessage) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) Properties(java.util.Properties) CachedSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient) ProtobufSchemaProvider(io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider) KafkaProtobufSerializer(io.confluent.kafka.serializers.protobuf.KafkaProtobufSerializer) ExampleProtoAcme(com.acme.glup.ExampleProtoAcme) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) CachedSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient) Test(org.junit.Test)

Example 5 with ProtobufSchemaProvider

use of io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider in project schema-registry by confluentinc.

the class RestApiSerializerTest method testDependency.

@Test
public void testDependency() throws Exception {
    Properties serializerConfig = new Properties();
    serializerConfig.put(KafkaProtobufSerializerConfig.AUTO_REGISTER_SCHEMAS, true);
    serializerConfig.put(KafkaProtobufSerializerConfig.SCHEMA_REGISTRY_URL_CONFIG, "bogus");
    serializerConfig.put(KafkaProtobufSerializerConfig.SKIP_KNOWN_TYPES_CONFIG, false);
    SchemaRegistryClient schemaRegistry = new CachedSchemaRegistryClient(restApp.restClient, 10, Collections.singletonList(new ProtobufSchemaProvider()), Collections.emptyMap(), Collections.emptyMap());
    KafkaProtobufSerializer protobufSerializer = new KafkaProtobufSerializer(schemaRegistry, new HashMap(serializerConfig));
    KafkaProtobufDeserializer protobufDeserializer = new KafkaProtobufDeserializer(schemaRegistry);
    Properties dependencyMessageDeserializerConfig = new Properties();
    dependencyMessageDeserializerConfig.put(KafkaProtobufDeserializerConfig.SCHEMA_REGISTRY_URL_CONFIG, "bogus");
    KafkaProtobufDeserializer dependencyMessageDeserializer = new KafkaProtobufDeserializer(schemaRegistry, new HashMap(dependencyMessageDeserializerConfig), DependencyMessage.class);
    byte[] bytes;
    // specific -> specific
    bytes = protobufSerializer.serialize(topic, DEPENDENCY_MESSAGE);
    assertEquals(DEPENDENCY_MESSAGE, dependencyMessageDeserializer.deserialize(topic, bytes));
    // specific -> dynamic
    bytes = protobufSerializer.serialize(topic, DEPENDENCY_MESSAGE);
    DynamicMessage message = (DynamicMessage) protobufDeserializer.deserialize(topic, bytes);
    assertEquals(DEPENDENCY_MESSAGE.getNestedMessage().getUserId().getKafkaUserId(), getField((DynamicMessage) getField((DynamicMessage) getField(message, "nested_message"), "user_id"), "kafka_user_id"));
    ParsedSchema schema = schemaRegistry.getSchemaBySubjectAndId("test-value", 6);
    assertEquals(ProtobufSchemaUtils.getSchema(DEPENDENCY_MESSAGE).canonicalString(), schema.canonicalString());
}
Also used : HashMap(java.util.HashMap) KafkaProtobufDeserializer(io.confluent.kafka.serializers.protobuf.KafkaProtobufDeserializer) DynamicMessage(com.google.protobuf.DynamicMessage) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) Properties(java.util.Properties) CachedSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient) ProtobufSchemaProvider(io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider) KafkaProtobufSerializer(io.confluent.kafka.serializers.protobuf.KafkaProtobufSerializer) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) CachedSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient) Test(org.junit.Test)

Aggregations

ProtobufSchemaProvider (io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider)14 CachedSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient)10 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)7 HashMap (java.util.HashMap)6 Test (org.junit.Test)6 KafkaProtobufDeserializer (io.confluent.kafka.serializers.protobuf.KafkaProtobufDeserializer)5 KafkaProtobufSerializer (io.confluent.kafka.serializers.protobuf.KafkaProtobufSerializer)5 Properties (java.util.Properties)5 DynamicMessage (com.google.protobuf.DynamicMessage)4 ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)4 AvroSchemaProvider (io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider)4 JsonSchemaProvider (io.confluent.kafka.schemaregistry.json.JsonSchemaProvider)4 SchemaProvider (io.confluent.kafka.schemaregistry.SchemaProvider)2 ProtobufSchema (io.confluent.kafka.schemaregistry.protobuf.ProtobufSchema)2 ExampleProtoAcme (com.acme.glup.ExampleProtoAcme)1 ByteString (com.google.protobuf.ByteString)1 DescriptorRef (io.confluent.connect.protobuf.test.DescriptorRef)1 RestService (io.confluent.kafka.schemaregistry.client.rest.RestService)1 SchemaString (io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString)1 RestClientException (io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException)1