AVRO 模式的 JSON 看起来有效,但从 Kafka 模式注册表返回无效

nul*_*ull 4 schema json avro apache-kafka

我正在尝试将 AVRO 架构注册到架构注册表。该架构包含一条记录和一些字段。我将架构作为 JSON 发布到架构注册表 REST API,虽然 JSON 看起来不错,但服务器返回curl : {"error_code":42201,"message":"Input schema is an invalid Avro schema"}.

有人可以看看吗?

Powershell 用于将架构生成为 JSON。

$type = @{namespace="customer-actions"; name="customer-enrollment"; 
          type="record"; 
          fields=@{name="id"; type="int"},
                 @{name="name"; type="string"}}
$typeJ = ConvertTo-Json $type -Depth 3 -Compress

$schema = @{schema = "$typeJ" }
$schemaJ = ConvertTo-Json $schema -Compress 
Run Code Online (Sandbox Code Playgroud)

这会产生以下...

{"schema":"{\"type\":\"record\",\"namespace\":\"customer-actions\",\"name\":\"customer-enrollment\",\"fields\":[{\"name\":\"id\",\"type\":\"int\
"},{\"name\":\"name\",\"type\":\"string\"}]}"}
Run Code Online (Sandbox Code Playgroud)

这看起来很糟糕;那些转义的引号都是必需的。相同的转义字符与更简单的模式一起使用没有问题。

提前致谢。

[编辑] 调用 Schema Registry API(如果有帮助)

curl -Uri http://server:8081/subjects/customer-enrollment/versions `
     -Method Post `
     -ContentType "application/vnd.schemaregistry.v1+json" `
     -Body $schemaJ
Run Code Online (Sandbox Code Playgroud)

nul*_*ull 5

问题是名称 customer-enrollment 中的 - 字符

$type = @{namespace="customer-actions"; name="enrollment"; 
          type="record"; 
          fields=@{name="id"; type="int"},
                 @{name="name"; type="string"}}
$typeJ = ConvertTo-Json $type -Depth 3 -Compress

$schema = @{schema = "$typeJ" }
$schemaJ = ConvertTo-Json $schema -Compress 
Run Code Online (Sandbox Code Playgroud)

在公共论坛上发布问题后立即自己找到答案是否有术语?

  • 这里的验证器[AVRO Schema Validator](https://json-schema-validator.herokuapp.com/avro.jsp) (4认同)
  • 不确定一个术语,但发生在你身上的事情就像 [Rubber Duck Debugging](https://en.wikipedia.org/wiki/Rubber_duck_debugging) (3认同)