Kafka架构注册表

时间:2018-02-17 17:18:14

标签: avro confluent confluent-schema-registry

我知道我有任何消息来找你,但是我解决了一个可能是我的错的问题,实际上我无法意识到解决方案是什么。 我使用Confluent平台的独立安装(4.0.0开源版本)来演示如何为特定用例采用该平台。 试图证明使用模式注册表的价值我面临以下问题,使用Postman发布新模式。

请求是:http://host:8081/subjects/test/versions
,方法POST ,标题:接受:application / vnd.schemaregistry.v1 + json,application / vnd.schemaregistry + json,application / json 内容类型:应用程序/ JSON , 身体: {"模式":" {{\"命名空间\":\" com.testlab \" \"名称\& #34;:\"测试\" \"类型\":\"记录\" \"字段\&#34 ;:[{\"名称\":\" resourcepath \" \"类型\":\"串\&#34 ;},{\"名称\":\"资源\" \"类型\":\"串\&#34 ;}]}}" }

响应是:{" error_code":42201," message":"输入架构是无效的Avro架构"}

观看文档并经过Google搜索后,我没有选择。 有什么建议吗? 谢谢你的时间 R上。

1 个答案:

答案 0 :(得分:0)

模式字段周围有多余的{}

一种测试方法是使用jq

之前

$ echo '{"schema":"{{\"namespace\":\"com.testlab\",\"name\":\"test\",\"type\":\"record\",\"fields\":[{\"name\":\"resourcepath\",\"type\":\"string\"},{\"name\":\"resource\",\"type\":\"string\"}]}}" }' | jq '.schema|fromjson'
jq: error (at <stdin>:1): Objects must consist of key:value pairs at line 1, column 146 (while parsing '{{"namespace":"com.testlab","name":"test","type":"record","fields":[{"name":"resourcepath","type":"string"},{"name":"resource","type":"string"}]}}')

之后

$ echo '{"schema":"{\"namespace\":\"com.testlab\",\"name\":\"test\",\"type\":\"record\",\"fields\":[{\"name\":\"resourcepath\",\"type\":\"string\"},{\"name\":\"resource\",\"type\":\"string\"}]}" }' | jq  '.schema|fromjson'
{
  "namespace": "com.testlab",
  "name": "test",
  "type": "record",
  "fields": [
    {
      "name": "resourcepath",
      "type": "string"
    },
    {
      "name": "resource",
      "type": "string"
    }
  ]
}

有关导入AVSC文件的信息,请参见{{3}},这样您就无需在CLI上键入JSON