如何将apache kafka连接到eclipse ditto?

How to connect apache kafka to eclipse ditto?

我正在尝试使用默认配置将 apache kafka 2.x 连接到本地的 eclipse ditto。

我正在关注这个 https://www.eclipse.org/ditto/connectivity-protocol-bindings-kafka2.html,所以我尝试使用 POST 请求创建一个新连接,如下所示:

curl -X POST -i -u devops:foobar  -H 'Content-Type: application/json' -d '{
   "targetActorSelection":"/system/sharding/connection",
   "headers":{
      "aggregate":false
   },
   "piggybackCommand":{
      "type":"connectivity.commands:createConnection",
      "connection":{
         "id":"kafka123",
         "connectionType":"kafka",
         "connectionStatus":"open",
         "failoverEnabled":true,
         "uri":"tcp://localhost:9092",
         "specificConfig":{
            "bootstrapServers":"localhost:9092"
         },
         "sources":[
            {
               "addresses":["topic01"],
               "consumerCount":1,
               "qos":0,
               "authorizationContext":["nginx:ditto"],
               "enforcement":{
                  "input":"{{ header:device_id }}",
                  "filters":["{{ entity:id }}"]
               },
               "headerMapping":{
                  "topic01":"{{ header:topic01 }}",
                  "the-key":"{{ header:kafka.key }}"
               },
               "payloadMapping":["Ditto"],
               "replyTarget":{
                  "enabled":true,
                  "address":"topic01",
                  "headerMapping":{
                     
                  },
                  "expectedResponseTypes":[
                     "response",
                     "error",
                     "nack"
                  ]
               },
               "acknowledgementRequests":{
                  "includes":[]
               },
               "declaredAcks":[]
            }
         ]
      }
   }
}' 'http://localhost:8080/devops/piggyback/connectivity?timeout=10'

这是结果:

HTTP/1.1 408 Request Timeout
Server: nginx/1.21.6
Date: Wed, 18 May 2022 14:11:33 GMT
Content-Type: application/json
Content-Length: 4
Connection: keep-alive
correlation-id: 16231ebe-3cd1-4ec1-9f42-ad58b9b82d14
timeout: 10
response-required: false
Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: *

null%        

我不明白我做错了什么。我该如何解决?

似乎 nginx 无法将您的请求发送到同上服务。也许某些同上服务不是 运行 或者您正在尝试使用错误的端口 8080(如果您按照同上设置的说明进行操作,它应该是 30080)。 请检查是否所有同上 pods 都是 运行(使用 'kubectl get pods')以及您的同上侦听的端口(使用 'kubectl get svc')

我解决了:检查 ditto-connectivity 日志(在 docker 上),我发现一个关于 java 库的错误。为了解决这个问题,我再次安装了 ditto (https://github.com/eclipse/ditto#getting-started)。

在那之后,我的问题中写的命令起作用了,我得到了 200 的响应。