0.0.4 • Published 1 year ago

@iot9x.com/nestjs-emqx-http v0.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

NestJS EMQX http 集成插件

注意:仍在开发中,目前仅在内部使用

使用说明

外部人员仅供参考,请不要用于生产环境,因此导致的事故后果请自行承担。

支持环境

  • node >=16.x
  • nest == 8.x
  • EMQX == 4.x

安装

$ npm i @iot9x.com/nestjs-emqx
or
$ yarn add @iot9x.com/nestjs-emqx
or
$ pnpm add @iot9x.com/nestjs-emqx  # 推荐使用pnpm

配置

同步方式

import { Module } from '@nestjs/common';
import { EmqxHttpModule } from '@iot9x.com/nestjs-emqx-http';

@Module({
  imports: [
    EmqxHttpModule.forRoot({
      url: 'EMQX http api地址',
      appid: 'AppID',
      appSecret: 'AppSecret'
    })
  ]
})
export class AppModule {}

异步方式

import { Module } from '@nestjs/common';
import { ConfigModule, ConfigType } from '@nestjs/config';
import { EmqxHttpModule } from '@iot9x.com/nestjs-emqx-http';
import { EmqxConfigRegister } from './modules/config/registers/emqx.register';
import { ConfigValidation } from './modules/config/validations/config.validation';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      validationSchema: ConfigValidation,
      validationOptions: {
        allowUnknown: true,
        abortEarly: true
      },
      load: [EmqxConfigRegister]
    }),
    EmqxHttpModule.forRootAsync({
      useFactory: (emqxConfig: ConfigType<typeof EmqxConfigRegister>) => ({
        url: emqxConfig.url,
        appid: emqxConfig.appid,
        appSecret: emqxConfig.appSecret
      }),
      inject: [EmqxConfigRegister.KEY]
    })
  ]
})
export class AppModule {}
0.0.4

1 year ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago