在mqtt souce连接器上设置Kafka主题

时间:2019-12-04 11:04:51

标签: apache-kafka mqtt apache-kafka-connect confluent-platform

我正在使用融合平台5.3.1,并使用以下方式在分布式模式下定义了两个不同的mqtt源连接器:

curl -s -X POST -H 'Content-Type: application/json' http://localhost:8083/connectors -d '{
"name" : "mqtt-source1",
"config" : {
"connector.class" : "io.confluent.connect.mqtt.MqttSourceConnector",
"tasks.max" : "1",
"mqtt.server.uri" : "<IP-ADDRESS 1>",
"mqtt.topics" : "<TOPIC MQTT 1>",
"kafka.topics" : "mqtt1",
"value.converter":"org.apache.kafka.connect.converters.ByteArrayConverter",
"key.converter":"org.apache.kafka.connect.storage.StringConverter",
"key.converter.schemas.enable" : "false",
"value.converter.schemas.enable" : "false",
"confluent.topic.bootstrap.servers": "localhost:9092",
"confluent.topic.replication.factor": "1",
"confluent.license":""
}
}'

curl -s -X POST -H 'Content-Type: application/json' http://localhost:8083/connectors -d '{
"name" : "mqtt-source2",
"config" : {
"connector.class" : "io.confluent.connect.mqtt.MqttSourceConnector",
"tasks.max" : "1",
"mqtt.server.uri" : "<IP-ADDRESS 2>",
"mqtt.topics" : "<TOPIC MQTT 2>",
"kafka.topics" : "mqtt2",
"value.converter":"org.apache.kafka.connect.converters.ByteArrayConverter",
"key.converter":"org.apache.kafka.connect.storage.StringConverter",
"key.converter.schemas.enable" : "false",
"value.converter.schemas.enable" : "false",
"confluent.topic.bootstrap.servers": "localhost:9092",
"confluent.topic.replication.factor": "1",
"confluent.license":""
}
}'

我有一些问题:

1)查看连接器的状态,我对两个连接器都得到相同的结果(以下是我发布的响应示例):

{
"name": "mqtt-source1",
"connector": {
  "state": "RUNNING",
  "worker_id": "127.0.0.1:8083"
},
"tasks": [
  {
   "id": 0,
   "state": "RUNNING",
   "worker_id": "127.0.0.1:8083"
 }
],
  "type": "source"
}

2)创建第一个连接器时,将在kafka上自动创建主题“ mqtt”。 就个人而言,我将在两个连接器上设置的kafka上创建两个不同的主题(即“ mqtt1”和“ mqtt2”),但是我无法从创建的主题中读取任何数据。为什么?两个连接器中的IP和mqtt主题不同。

谢谢。

1 个答案:

答案 0 :(得分:0)

配置属性是kafka.topic而不是kafka.topics

由于您已指定kafka.topics,所以连接器将采用默认值mqtt

参考:Configuration Properties