KAFKA-REST:无法读取回复

时间:2019-09-18 18:42:44

标签: kafka-rest

我试图通过将查询发布到剩余URL来使用存储在KSQL中的NodeJS来获取kafka流。但是无法读取响应,因为它既不是数组也不是json对象。

下面是我正在尝试的一个简单代码段:

    const axios = require('axios');

    exports.retrieveBillingDistributionRequest = async (event, context) => {
      const URL = 'http://=============================/query';
      const head = {
        headers: {
          "Content-Type": "application/vnd.ksql.v1+json",
          "Accept": "application/vnd.ksql.v1+json"
        }
      }
      const payLoad = {
        "ksql": "select * from billing_dist_stream where metaData->eventId ='101' limit 1;",
        "streamsProperties": {
          "ksql.streams.auto.offset.reset": "earliest"
        } 
      }

      return await axios.post(URL, payLoad, head)
        .then((response) => {
          console.log("in success");
          console.log(response.data);
          return {
            statusCode: 200,
            body: response.data
          };
        })
        .catch((error) => {
          console.log("Error=>")
          var response = {
            errors: [
              {
                status: error.code,
                body: error
              }
            ]
          }
          context.fail(JSON.stringify(response));
        });
    };


    Response received :

    {"row":{"columns":[1568457900756,null,{"EVENTID":"101","TRACEID":"101","EVENTTYPE":"UPDATE","CAUSATIONID":"12368990","ORIGINATINGSYSTEM":"ETM","USER":"sumit","CREATEDTIMESTAMP":null}]},"errorMessage":null,"finalMessage":null,"terminal":false}
    {"row":null,"errorMessage":null,"finalMessage":"Limit Reached","terminal":true}

由于它采用某种原始格式,因此我无法读取响应并返回。

需要帮助解决此问题吗?

0 个答案:

没有答案