plc4x v0.8.0 kafka连接器在按下新连接器时返回“null”

xqkwcwgp  于 2021-06-05  发布在  Kafka
关注(0)|答案(1)|浏览(774)

我最近更新了plc4xkafkaconnect插件,从版本0.5.0到版本0.8.0,方法是从plc4x的github页面的源代码进行克隆,并使用maven构建它,完全符合自述文件中的规定。在构建源代码之后,我收到了一个uberjar,其中包含了kafkaconnect插件所需的所有库和依赖项。然后,我创建一个连接器配置文件,该文件类似于plc4x的github页面中的示例:

{
 "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/connectors

rest接口现在响应:

{"error_code":500,"message":null}

这就是我被困的地方。我相信这个错误与config.json文件中的以下行有关:

"connector.class":"org.apache.plc4x.kafka.Plc4xSourceConnector"

因为当我使用不同的连接器类时,例如:

"connector.class":"FileStreamSinkConnector"

一切正常,我可以成功地将连接器配置推送到rest接口。这个问题在plc4x的0.5.0版本中也没有出现。我已经解压了包含所有依赖项的uberjar,并验证了plc4xsourceconnector类确实存在。我不知道我做错了什么,因为我按照他们github页面中概述的步骤来构建和配置一切。还有其他人遇到过这个问题吗?

ql3eal8s

ql3eal8s1#

我设法找到了问题的解决办法。我使用的连接器配置文件是为plc4xv.0.4.0设计的,在v.0.8.0发布之前已经更新过。我在plc4xgithub repo中找到了一个示例配置文件,并将其用作布局。从他们的网站上我发现:

"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时,必须指定所需的key:values in 连接器配置:

"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的源代码,特别是这个类,来找出需要哪些字段。

相关问题