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;
}
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());
}
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));
}
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());
}
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());
}
Aggregations