如何将自定义连接器配置文件解析为java属性格式?

时间:2017-08-23 14:23:16

标签: neo4j apache-kafka apache-kafka-connect

我有一个自定义连接器,可以将Neo4j命令从文件写入Kafka,我想调试它。所以,我下载了Confluent v3.3.0并花时间熟悉它;但是,我发现自己一直试图加载连接器。当我尝试使用.properties文件加载连接器时,出现以下错误:

parse error: Invalid string: control characters from U+0000 through U+001F must be escaped at line 1, column 124
parse error: Invalid numeric literal at line 2, column 0

我有一个暗示,它试图将文件解析为JSON文件,因为此错误在尝试加载连接器时出现以下错误:

Warning: Install 'jq' to add support for parsing JSON

所以我酿造了安装的jq,现在已经得到了前一个错误。

我希望将此文件解析为java属性格式,由于.properties,我认为这种格式是隐式的,但我是否需要在某个设置中显式?

更新

我按照@Konstantine Karantasis的建议将.properties转换为JSON,但是我得到了和以前一样的错误,但没有第一行:

parse error: Invalid numeric literal at line 2, column 0

我三重检查了我的格式并对错误进行了一些搜索,但是已经很短了。如果我在格式化方面出错或者在使用Kafka Connect时使用JSON文件时存在细微差别,请告诉我。

Java属性:

name=neo4k-file-source
connector.class=neo4k.filestream.source.Neo4jFileStreamSourceConnector
tasks.max=1
file=Neo4jCommands.txt
topic=neo4j-commands

转换为JSON:

[{
  "name": "neo4k-file-source",
  "connector": {
    "class": "neo4k.filestream.source.Neo4jFileStreamSourceConnector"
  },
  "tasks": {
    "max": 1
  },
  "file": "Neo4jCommands.txt",
  "topic": "neo4j-commands"
}]

2 个答案:

答案 0 :(得分:1)

查看https://www.confluent.io/blog/simplest-useful-kafka-connect-data-pipeline-world-thereabouts-part-1/以获取使用json CLI加载的有效confluent文件的示例

在您的示例中,请尝试以下操作:

{
    "name": "neo4k-file-source",
    "config": {
        "connector.class": "neo4k.filestream.source.Neo4jFileStreamSourceConnector",
        "tasks.max": 1,
        "file": "Neo4jCommands.txt",
        "topic": "neo4j-commands"
    }
}

答案 1 :(得分:0)

用于启动连接器的Confluent CLI尝试巧妙地确定属性文件的类型。它不依赖于扩展名(.properties),而是在输入文件上调用file并将结果与​​ASCII字符串进行匹配。

这符合java属性文件(https://en.wikipedia.org/wiki/.properties)的当前定义,但应扩展为匹配以UTF-8编码的文件或包含转义的unicode字符的文件。

您有两种选择。

  1. 将您的属性转换为JSON格式。
  2. 编辑CLI以匹配运行file <yourconf.properties>
  3. 时返回的文件类型