I'm looking at the library for now, trying to figure out the possibility of using schema references. Is this supported in the library?
For example I have 2 files:
com.myapp.Children.avsc:
{
"namespace": "com.myapp",
"type": "record",
"name": "Children",
"fields": [
{"name": "first_name", "type": "string"},
{"name": "last_name", "type": "string"}
]
}
com.myapp.People.avsc:
{
"namespace": "com.myapp",
"type": "record",
"name": "People",
"fields": [
{"name": "id", "type": "string"},
{"name": "first_name", "type": "string"},
{"name": "last_name", "type": "string"},
{
"name": "children",
"type": ["null",
{
"type": "array",
"items": "Children"
}],
"doc": ""
}
]
}
And I want to get a schema, that matches People.avsc.
My test code:
$schemaRegistryClient = new CachedRegistry(
new PromisingRegistry(
new Client(['base_uri' => 'http://****:8081'])
),
new AvroObjectCacheAdapter()
);
$recordSerializer = new RecordSerializer(
$schemaRegistryClient,
[
// If you want to auto-register missing schemas set this to true
RecordSerializer::OPTION_REGISTER_MISSING_SCHEMAS => false,
// If you want to auto-register missing subjects set this to true
RecordSerializer::OPTION_REGISTER_MISSING_SUBJECTS => false,
]
);
$baseDir = "./avro";
$inflector = static function ($record, bool $isKey) {
echo "Searching for:".get_class($record);
$ext = $isKey ? '.key.avsc' : '.avsc';
$fileName = is_object($record)
? str_replace('\\', '.', get_class($record))
: 'default';
return $fileName . $ext;
};
$resolver = new FileResolver($baseDir, $inflector);
$normalizer = new GetSetMethodNormalizer();
$encoder = new AvroSerDeEncoder($recordSerializer);
$symfonySerializer = new Serializer([$normalizer], [$encoder]);
$children=new Children("Nikolai","Lubiagov");
$people=new People("Nikolai","Lubiagov", [$children]);
$schemac= $resolver->valueSchemaFor($children);
$schemap= $resolver->valueSchemaFor($people);
I don't see any code at all to resolve the link. Or how to transfer the already obtained Children scheme to People, is this supported?
I also can't get already registread schema, with refernces over:
$sc=$schemaRegistryClient->schemaForSubjectAndVersion("phptopic-value",1)->wait();
{
"subject":"phptopic-value",
"version":1,
"id":70,
"references":[
{
"name":"Children",
"subject":"Children",
"version":1
}
],
"schema":"{"type":"record","name":"People","namespace":"com.myapp","fields":[{"name":"id","type":"string"},{"name":"first_name","type":"string"},{"name":"last_name","type":"string"},{"name":"children","type":["null",{"type":"array","items":"Children"}],"doc":""}]}"
}
I found this 322fcd6 for previously defined types, but if type defined in another subject, it is not fit...?
I'm looking at the library for now, trying to figure out the possibility of using schema references. Is this supported in the library?
For example I have 2 files:
com.myapp.Children.avsc:
com.myapp.People.avsc:
And I want to get a schema, that matches People.avsc.
My test code:
I don't see any code at all to resolve the link. Or how to transfer the already obtained Children scheme to People, is this supported?
I also can't get already registread schema, with refernces over:
$sc=$schemaRegistryClient->schemaForSubjectAndVersion("phptopic-value",1)->wait();{
"subject":"phptopic-value",
"version":1,
"id":70,
"references":[
{
"name":"Children",
"subject":"Children",
"version":1
}
],
"schema":"{"type":"record","name":"People","namespace":"com.myapp","fields":[{"name":"id","type":"string"},{"name":"first_name","type":"string"},{"name":"last_name","type":"string"},{"name":"children","type":["null",{"type":"array","items":"Children"}],"doc":""}]}"
}
I found this 322fcd6 for previously defined types, but if type defined in another subject, it is not fit...?