首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使工具管理器插件API动作工作?

如何使工具管理器插件API动作工作?
EN

Stack Overflow用户
提问于 2022-03-25 09:09:46
回答 1查看 28关注 0票数 0

我成功地在后端文件中安装并加载了kuzzle-device-manager

代码语言:javascript
复制
import { Backend } from 'kuzzle';
import { DeviceManagerPlugin } from 'kuzzle-device-manager';

const app = new Backend('playground');

console.log(app.config);

const deviceManager = new DeviceManagerPlugin();

const mappings = {
  updatedAt: { type: 'date' },
  payloadUuid: { type: 'keyword' },
  value: { type: 'float' }
} 

deviceManager.devices.registerMeasure('humidity', mappings)

app.plugin.use(deviceManager)

app.start()
  .then(async () => {
    // Interact with Kuzzle API to create a new index if it does not already exist
    console.log(' started!');
  })
  .catch(console.error);

但是,当我尝试使用该插件中的控制器时,例如带有device-manager/device操作的create,我会得到一个错误输出。以下是js中的“客户端”代码:

代码语言:javascript
复制
const { Kuzzle, WebSocket } = require("kuzzle-sdk")

const kuzzle = new Kuzzle(
  new WebSocket('KUZZLE_IP')
)

kuzzle.on('networkError', error => {
  console.error('Network Error: ', error);
})

const run = async () => {
  try {
    // Connects to the Kuzzle server
    await kuzzle.connect();
    // Creates an index
    const result = await kuzzle.query({
      index: "nyc-open-data",
      controller: "device-manager/device",
      action: "create",
      body: {
        model: "model-1234",
        reference: "reference-1234"
      }
    }, {
      queuable: false
    })
    console.log(result)

  } catch (error) {
    console.error(error.message);
  } finally {
    kuzzle.disconnect();
  }
};
run();

结果日志:

代码语言:javascript
复制
API action "device-manager/device":"create" not found

注意:nyc-open-data索引存在并且是空的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-28 05:44:57

我们对文档中的这个错误表示歉意,device-manager/device:create方法不可用,因为插件在v2之前一直在使用自动配置。

您应该向您的解码器发送有效负载,如果不存在https://docs.kuzzle.io/official-plugins/device-manager/1/guides/decoders/#receive-payloads,插件将自动提供设备。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71614469

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档