AVRO模式的JSON看起来有效但从Kafka Schema Registry返回无效

时间:2017-10-21 16:30:11

标签: json apache-kafka schema avro

我正在尝试将AVRO架构注册到Schema Registry。架构包含记录和一些字段。我将架构作为JSON发布到Schema Registry 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 

这会产生以下内容......

{"schema":"{\"type\":\"record\",\"namespace\":\"customer-actions\",\"name\":\"customer-enrollment\",\"fields\":[{\"name\":\"id\",\"type\":\"int\
"},{\"name\":\"name\",\"type\":\"string\"}]}"}

哪个看起来很糟糕;那些逃脱的报价都是必需的。相同的转义字符使用更简单的架构而没有问题。

提前致谢。

[编辑] 如果有帮助的话,调用Schema Registry API

curl -Uri http://server:8081/subjects/customer-enrollment/versions `
     -Method Post `
     -ContentType "application/vnd.schemaregistry.v1+json" `
     -Body $schemaJ

1 个答案:

答案 0 :(得分:4)

问题是名称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 

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