我最近将Plc4xKafka Connect插件从0.5.0版本更新到0.8.0版本,方法是从Plc4x的Github page中克隆源代码,并使用Plc4x构建它,完全按照自述文件中的说明进行。在构建源代码之后,我收到了一个超级JAR,其中包含了Kafka Connect插件的所有必需库和依赖项。然后,我创建了一个连接器配置文件,与plc4x的Github page中的示例类似
{
"name":"plc-source-test",
"config": {
"connector.class":"org.apache.plc4x.kafka.Plc4xSourceConnector",
"tasks.max":"1",
"file":"test.sink.txt",
"topics":"connect-test"
}
}然后我将配置推送到REST接口:
curl -X POST -H "Content-Type: application/json" --data config.json http://localhost:8083/connectorsREST接口现在响应为:
{"error_code":500,"message":null}这就是我被卡住的地方。我认为这个错误与config.json文件中的以下行有关:
"connector.class":"org.apache.plc4x.kafka.Plc4xSourceConnector"因为当我使用不同的连接器类时,例如:
"connector.class":"FileStreamSinkConnector"一切正常,我可以成功地将连接器配置推送到REST接口。在0.5.0版本的Plc4x中也不会出现此问题。我已经解压了包含所有依赖项的超级JAR,并验证了Plc4xSourceConnector类确实存在。我不知道我做错了什么,因为我正在遵循他们的Github页面中概述的步骤来构建和配置所有内容。还有没有人遇到过这个问题?
发布于 2020-07-06 18:36:21
我设法找到了我的问题的答案。我使用的连接器配置文件是为PLC4x v.0.4.0设计的,并且在v.0.8.0发布之前已经更新过。我在PLC4X Github repo中找到了一个示例配置文件,并将其用作布局。从他们的website中我发现这个字段:
"sources.machineX.connectionString"必须以特殊方式格式化。我将我的连接器配置文件更新为:
{"name": "plc-source-test",
"config": {
"connector.class": "org.apache.plc4x.kafka.Plc4xSourceConnector",
"default-topic": "test-topic",
"tasks.max": "1",
"sources": "machineA",
"sources.machineA.connectionString": "s7:<PLC_IP>?remote-rack=0&remote-slot=0",
"sources.machineA.jobReferences": "jobA",
"sources.machineA.jobReferences.jobA": "job-topic",
"jobs": "jobA",
"jobs.jobA.interval": "500",
"jobs.jobA.fields": "fieldA",
"jobs.jobA.fields.fieldA": "%DB1.DBD1:REAL"
}让一切都运转起来!
使用Plc4xSourceConnector时,必须在连接器配置中指定所需的键:值:
"default-topic" //Required. The default name for the Kafka topic
"tasks.max" //Not quite sure what this does, but it is in the example config so lets use it
"sources" //Required. It must be a comma separated list of your source
"sources.machineA.connectionString" //Required. The connection string to the machine/PLC that you want to talk to
"sources.machineA.jobReferences" //Required. A comma separated list of all the jobs that you wish to create for this machine
"sources.machineA.jobReferences.jobA" //Required. The Kafka topic name for data produced by jobA
"jobs" //Required. A comma separated list of all jobs you wish to create
"jobs.jobA.interval" //Not sure if this is required. Determines the polling rate of your created job
"jobs.jobA.fields" //Required. A comma separated list of the fields belonging to this job. A field is a machine/PLC register containing a value
"jobs.jobA.fields.fieldA" //Required. The address to the resource on your machine/PLC发布错误连接器配置时显示的错误消息非常模糊,通常只是一些NullPointerException。因此,我花了一些时间分析PLC4X的源代码,特别是this class,以找出哪些字段是必需的。
https://stackoverflow.com/questions/62383670
复制相似问题