如何将自定义连接器配置文件解析为 java 属性格式?
How to have a custom connector config file be parsed as java properties format?
我有一个自定义连接器,可以将文件中的 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
所以我用 brew 安装了 jq,现在又出现了之前的错误。
我希望此文件被解析为 java 属性格式,我认为由于 .properties 而隐含,但我是否需要在某处的设置中明确显示?
更新:
我按照@Konstantine Karantasis 的建议将 .properties 转换为 JSON,但我得到了与以前相同的错误,但没有第一行:
parse error: Invalid numeric literal at line 2, column 0
我对我的格式进行了三次检查,并对错误进行了一些搜索,但都没有找到答案。如果我的格式有误,或者在将 JSON 文件与我不关心的 Kafka Connect 一起使用时出现细微差别,请告诉我。
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"
}]
您用来启动连接器的 Confluent CLI 会尝试智能地确定属性文件的类型。它不依赖于扩展名 (.properties),而是在输入文件上调用 file
并将结果与 ASCII
字符串匹配。
这符合 java 属性文件 (https://en.wikipedia.org/wiki/.properties) 的当前定义,但它应该被扩展以匹配以 UTF-8 编码的文件或包含转义 unicode 字符的文件。
你有两个选择。
- 将您的属性转换为 JSON 格式。
- 编辑 CLI 以匹配 运行
file <yourconf.properties>
时返回的文件类型
查看 https://www.confluent.io/blog/simplest-useful-kafka-connect-data-pipeline-world-thereabouts-part-1/ 以获取使用 confluent
CLI
加载的有效 json
文件的示例
在你的例子中,试试这个:
{
"name": "neo4k-file-source",
"config": {
"connector.class": "neo4k.filestream.source.Neo4jFileStreamSourceConnector",
"tasks.max": 1,
"file": "Neo4jCommands.txt",
"topic": "neo4j-commands"
}
}
我有一个自定义连接器,可以将文件中的 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
所以我用 brew 安装了 jq,现在又出现了之前的错误。
我希望此文件被解析为 java 属性格式,我认为由于 .properties 而隐含,但我是否需要在某处的设置中明确显示?
更新:
我按照@Konstantine Karantasis 的建议将 .properties 转换为 JSON,但我得到了与以前相同的错误,但没有第一行:
parse error: Invalid numeric literal at line 2, column 0
我对我的格式进行了三次检查,并对错误进行了一些搜索,但都没有找到答案。如果我的格式有误,或者在将 JSON 文件与我不关心的 Kafka Connect 一起使用时出现细微差别,请告诉我。
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"
}]
您用来启动连接器的 Confluent CLI 会尝试智能地确定属性文件的类型。它不依赖于扩展名 (.properties),而是在输入文件上调用 file
并将结果与 ASCII
字符串匹配。
这符合 java 属性文件 (https://en.wikipedia.org/wiki/.properties) 的当前定义,但它应该被扩展以匹配以 UTF-8 编码的文件或包含转义 unicode 字符的文件。
你有两个选择。
- 将您的属性转换为 JSON 格式。
- 编辑 CLI 以匹配 运行
file <yourconf.properties>
时返回的文件类型
查看 https://www.confluent.io/blog/simplest-useful-kafka-connect-data-pipeline-world-thereabouts-part-1/ 以获取使用 confluent
CLI
json
文件的示例
在你的例子中,试试这个:
{
"name": "neo4k-file-source",
"config": {
"connector.class": "neo4k.filestream.source.Neo4jFileStreamSourceConnector",
"tasks.max": 1,
"file": "Neo4jCommands.txt",
"topic": "neo4j-commands"
}
}