GithubHelp home page GithubHelp logo

midway-nacos's Introduction

midway-nacos

use nacos in midwayjs。

这是基于 midway 3.0 的 nacos 组件模块,基于 nacos模块 封装

引入组件

首先,引入 组件,在 src/configuration.ts 中导入

import { Configuration } from '@midwayjs/decorator';
import * as nacos from 'midway-nacos';
import { join } from 'path';

@Configuration({
  imports: [
    // ...
    nacos, // 导入 nacos 组件
  ],
  importConfigs: [join(__dirname, 'config')],
})
export class ContainerLifeCycle {}

配置

单客户端配置

// src/config/config.default.ts
export default {
  // ...
  nacos: {
    'registry': {     //注册中心
      client: {     //单实例 https://midwayjs.org/en/docs/service_factory#%E5%8D%95%E4%B8%AA%E5%AE%9E%E4%BE%8B
        serverList: '127.0.0.1:8848', // replace to real nacos serverList
        namespace: 'public',
      }
    },
    'config': {     //配置中心
      client: {
        serverAddr: '127.0.0.1:8848',
      }
    }
  }
};

使用

import { NacosNamingFactoryService } from 'midway-nacos';
import { join } from 'path';

@Provide()
export class UserService {
  
  @Inject()
  nacosNamingFactoryService: NacosNamingFactoryService;
  
  async invoke() {
    
    const namingIns = this.nacosNamingFactoryService.get();
    
    let status = await namingIns.getServerStatus();     //namingIns 就是 https://github.com/nacos-group/nacos-sdk-nodejs NacosNamingClient实例

  }
}

midway-nacos's People

Contributors

larryzhuo avatar

Stargazers

Roman avatar Mr Torn avatar

Watchers

 avatar

Forkers

torns

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.