Git Product home page Git Product logo

nacos-sdk-nodejs's People

Contributors

aladdin-add avatar bobjiang1988 avatar cevio avatar chen-gaoyuan avatar chenhao26-nineteen avatar czy88840616 avatar darcyda1 avatar evanhahaha avatar gxcsoccer avatar hujingkang avatar isnolan avatar netfoxor avatar perttyzhan avatar silverera avatar sun2008mt avatar ugrg avatar vinlic avatar yanlinly avatar zhangchen915 avatar zhanghengyao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nacos-sdk-nodejs's Issues

本地node服务有一个warn警告,这是啥问题

报错日志为:

2021-09-08 13:46:39,790 WARN 12508 [ClusterClient:DiamondClient@undefined] follower closed, and try to init it again
2021-09-08 13:46:40,275 WARN 12508 [ClusterClient:DiamondClient@undefined] follower closed, and try to init it again

报错截图
webwxgetmsgimg

[直连模式]NacosConfigClient在ssl为true的时候无法连接到https服务

nacos-config/src/http_agent.ts里面有下列代码
// 获取请求 url
getRequestUrl(currentServer) {
let url;
if (/:/.test(currentServer)) {
url = http://${currentServer};
if (this.ssl) {
url = https://${this.currentServer}; <- 走到这里的时候this.currentServer为undefined,应该采用参数的currentServer。另外this.currentServer一直没有找到设值的地方
}
} else {
url = http://${currentServer}:${this.serverPort};
if (this.ssl) {
url = https://${this.currentServer}:${this.serverPort}; <- 这里有同样问题
}
}
return ${url}/${this.contextPath};
}

无法送nacos上获取配置

我使用nodejs测试从远处获取配置,但是获取到的是空的数据

const NacosConfigClient = require('nacos').NacosConfigClient; // js
const configClient = new NacosConfigClient({
  serverAddr: '8.130.234.99:8848',
  namespace: 'user_src',
});

(async () => {
  const result = await configClient.getConfig('test3', 'DEFAULT_GROUP');
  console.log(result, '结果');
 // 结果是null
})();

image
我不知道是哪里出了问题

为什么拿不到指定namespace的配置,总是拿到的public的

版本:nacos 2.0.0
const client = new NacosConfigClient({ serverAddr: NACOS_SERVICE_ADDR, namespace: 'test' }) const content = await configClient.getConfig(DATA_ID, GROUP);
期望:拿到test namespece中dataId=DATA_ID, group = GROUP的nacos配置
image

结果:null。而且如果dataId跟group来自public就会读取到,即使不写namespace,所以默认namespace是public?

in nodejs, pm2 start ./bin/www, use nacos discovery

Failed to register with Nacos service in nodejs

  1. In the bin / www file, use the registration method of Nacos official website
    image
  2. In the development mode, you can directly use npm run start to start
  3. Once started, the service can be found in the Nacos registry
  4. However, when pm2 mode is used, the above registration code remains unchanged. The startup mode is changed to pm2 run pm2. json. The JSON file contents are as follows
{
  "script": "./bin/www",
  "instances": "1",
  "env": {
    "NODE_ENV": "development"
  },
  "env_production": {
    "NODE_ENV": "production"
  }
}
  1. pm2 start result iserrored
    View progress info,The error path is bin/www
    image
    Error log
    image
  2. If the service registration code is removed, pm2 starts normally

Nodejs中使用nacos服务注册失败

  1. bin/www文件下,使用nacos官网注册方式
    image
  2. 开发模式下,直接使用npm run start 启动
  3. 启动后,在nacos注册中心可以找到该服务
  4. 但是使用pm2方式时,上述注册代码不变。启动方式变为pm2 run pm2.json,其中json文件内容如下
{
  "script": "./bin/www",
  "instances": "1",
  "env": {
    "NODE_ENV": "development"
  },
  "env_production": {
    "NODE_ENV": "production"
  }
}
  1. pm2启动结果为errored
    查看进程内容,提示错误路径为bin/www
    image
    错误日志
    image
  2. 去掉服务注册代码则pm2启动正常

期望行为
希望能够像dev启动中一样正常注册服务

Expected behavior
I hope to be able to register the service as normal as in dev startup

v1.1.3版的nacos,默认的namespace是public

v1.1.3版的nacos,服务器默认的namespace是public,目前这个nodejs这个是defalut,是注册不上的,花了一天功夫才调试出问题在这,把下面这两个文件的namespace值改成default才行:
nacos-naming\lib\naming\client.js
nacos-naming\lib\naming\proxy.js


const defaultOptions = {
namespace: 'default',
....
};

正确
const defaultOptions = {
namespace: 'public',
....
};

服务注册程序Ctrl+C终止后,服务发现程序不能立即感知下线?

注册:

'use strict';

const NacosNamingClient = require('nacos').NacosNamingClient;
const logger = console;

const client = new NacosNamingClient({
  logger,
  serverList: '127.0.0.1:8848', // replace to real nacos serverList
  namespace: 'public',
});
(async () => {
  await client.ready();

  const serviceName = 'controller';

  await client.registerInstance(serviceName, {
    ip: '2.2.2.2',
    port: 8080,
    enabled: true,
    metadata: {room: '1231231'},
  });

})();

发现:

'use strict';

const NacosNamingClient = require('nacos').NacosNamingClient;
const logger = console;

const client = new NacosNamingClient({
  logger,
  serverList: '127.0.0.1:8848', // replace to real nacos serverList
  namespace: 'public',
});

(async () => {
  await client.ready();

  const serviceName = 'controller';

  // subscribe instance
  await client.subscribe(serviceName, hosts => {
    console.log(hosts);
  });
})();

npm 安装插件启动的时候报错host_reactor.js 有误

index.js?bed3:161 [WDS] Errors while compiling. Reload prevented.
errors @ index.js?bed3:161
onmessage @ socket.js?57b2:41
EventTarget.dispatchEvent @ sockjs.js?3600:170
eval @ sockjs.js?3600:887
SockJS._transportMessage @ sockjs.js?3600:885
EventEmitter.emit @ sockjs.js?3600:86
WebSocketTransport.ws.onmessage @ sockjs.js?3600:2961
index.js?bed3:167 ./node_modules/nacos-naming/lib/naming/host_reactor.js
Module parse failed: Can not use 'await' as identifier inside an async function (191:17)
You may need an appropriate loader to handle this file type.
| } else if (this._updatingSet.has(key)) {
| // await updating
| await this.await(${key}_changed);
| }
| this._scheduleUpdateIfAbsent(serviceName, clusters);
@ ./node_modules/nacos-naming/lib/naming/client.js 26:20-45
@ ./node_modules/nacos-naming/index.js
@ ./node_modules/nacos/dist/index.js
@ ./src/common/nacos/config_service.js
@ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/pages/system/main/music.vue
@ ./src/pages/system/main/music.vue
@ ./src/router/index.js
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js

Fuzzy query for dataId

Hi there,

Is there any API in sdk supporting fuzzy query for dataId?

Just Like dataId=*app_id in HTTP request.

Thanks.

如何通过帐号密码去连接自己本地的nacos服务呢?

配置里面只写了如何连接阿里云的acm服务,我本地搭建的nacos如何连接呢?看官方的接口里面也没有类似参数呢.

  accessKey: '***************',
  secretKey: '***************',

另外k8s部署的nacos开启了鉴权之后,我的web使用帐号密码登录不上了,提示帐号密码错误,关闭NACOS_AUTH_ENABLE=false之后可以正常登录了,这是为啥呢?

Initialization of NacosNamingClient, injection instance is problematic

I created a NamingService class in midway and initialized NacosNamingClient. Then when I injected this NamingService class into other classes, I threw an exception when accessing the request. I suspected initially that it was await this. nacosClient. ready () code problem. Please check it.
image
image
异常信息:
image

getConfig需要提供tenant入参支持

getConfig方法无法获取非public空间下的配置

正确的获取请求

curl http://some.nacos.instance/nacos/v1/cs/configs?dataId=TEST_CONFIG_ITEM&group=LOCAL&tenant=1243f842-fa03-4ef8-b226-5ba55a79052c

文档
追踪了一下源码没有地方提供这个参数的支持

NacosConfigClient TCP timeout

Nacos version: 1.1.4
nacos-nodejs-sdk version: 2.0.0
Nodejs version: 14.15.5
npm version: 6.14.11
OS version: centos 7.6

logger.info('Connecting Nacos config client...')
const configClient = new NacosConfigClient({
    serverAddr: config.nacos.serverAddr,
    namespace: config.nacos.namespace
});
const content = await configClient.getConfig('-', '-');

// let doc = yaml.load(content)
let doc = JSON.parse(content)
appConfig.set(doc)

output:

2021-02-23 18:28:39,119 WARN 2197 nodejs.ResponseTimeoutError: register to channel: DiamondClient@undefined failed, will retry after 3s, Server no response in 3000ms, address#127.0.0.1:7777
    at Timeout._onTimeout (/app/data/${project}/node_modules/tcp-base/lib/base.js:225:21)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)
socketMeta: {"id":2,"dataLength":91,"bufferSize1":0,"bufferSize2":0,"startTime":1614076116118,"endTime":1614076116118,"writeSuccess":true}
name: "ResponseTimeoutError"
pid: 2197

I tried curl command on server

curl -G -d 'tenant=${namespace}' -d 'dataId=${dataid}' -d 'group=${group}' http:/${host}/nacos/v1/cs/configs

which returns the correct configuration stored in nacos.

In addition, the same code works in win10 and Java client with same configuration can get nacos config successfully.

连接standalone模式启动的nacos时候,serverlist报404

standalone模式启动的,应该没有serverlist的接口。
log如下

cluster-client [ClusterClient:[email protected]:8848] init cluster client, try to seize the leader on port:7777 +0ms
cluster-client:server listen 7777 success +0ms
diamond-client:snapshot 0.7743671956236662 +0ms
cluster-client [ClusterClient:[email protected]:8848] has seized port 7777, and serves as leader client. +8ms
nacos:9342:ins-496:client_worker client worker start +0ms
nacos:9342:ins-496:client_worker calling getConfig, dataId: test, group: DEFAULT_GROUP +1ms
urllib Request#1 GET http://127.0.0.1:8848/nacos/serverlist with headers {"User-Agent":"node-urllib/2.31.3 Node.js/10.13.0 (Linux 4.19; x64)"}, options.path: /nacos/serverlist +0ms
urllib ConnectTimeout: 6000, ResponseTimeout: 6000 +1ms
urllib Connect timer ticking, timeout: 6000 +2ms
urllib Response timer ticking, timeout: 6000 +3ms
urllib Request#1 http://127.0.0.1:8848/nacos/serverlist new socket connected +0ms
urllib Request#1 http://127.0.0.1:8848/nacos/serverlist req response event emit: status 404, headers: {"content-type":"application/json;charset=UTF-8","transfer-encoding":"chunked","date":"Tue, 11 Dec 2018 20:54:41 GMT"} +109ms
urllib Request#1 http://127.0.0.1:8848/nacos/serverlist: res data event emit, size 137 +1ms
urllib Request#1 http://127.0.0.1:8848/nacos/serverlist: res end event emit, total size 137, _dumped: false +0ms
urllib [118ms] done, 137 bytes HTTP 404 GET 127.0.0.1 /nacos/serverlist, keepAliveSocket: false, timing: null, socketHandledRequests: 1, socketHandledResponses: 1 +1ms

[Wed Dec 12 2018 04:54:41 GMT+0800 (China Standard Time)][pid: 9342][NacosConfigClient] NacosServerResponseError: [Nacos#ServerListManager] request url: http://127.0.0.1:8848/nacos/serverlist failed with statusCode: 404
Error Stack:
NacosServerResponseError: [Nacos#ServerListManager] request url: http://127.0.0.1:8848/nacos/serverlist failed with statusCode: 404
at ServerListManager.request (/home/jiangzhuo/Desktop/test-client/node_modules/nacos-config/src/server_list_mgr.ts:126:35)
at process._tickCallback (internal/process/next_tick.js:68:7)
Error Additions:
url: "http://127.0.0.1:8848/nacos/serverlist"
params: {"timeout":6000,"dataType":"text","requestUrls":["http://127.0.0.1:8848/nacos/serverlist"],"maxRedirects":10}
body: "{"timestamp":"2018-12-11T20:54:41.199+0000","status":404,"error":"Not Found","message":"No message available","path":"/nacos/serverlist"}"

Too many 'TIME_WAIT'

nacos nodejs client start for a while, there are may "TIME_WAIT" to nacos servier connections.

RAM 相关

发现缺少更加安全的通过RAM访问的接口。根据我所知道的情况,通过RAM访问应该比硬编码AK安全。请问一下,您近期是否有相关计划?

支持namespace的方式

无法支持namespace,namespaceId为实际注册导致无法。尝试修改注册也无效。

async registerService(serviceName, instance) {
this.logger.info('[NameProxy][REGISTER-SERVICE] registering service: %s with instance:%j', serviceName, instance);

const params = {
  namespaceId: '3c239366-d993-489a-afbe-89e53160117f', //自定义命名空间
  ip: instance.ip,
  port: instance.port + '',
  weight: instance.weight + '',
  enable: instance.enabled ? 'true' : 'false',
  healthy: instance.healthy ? 'true' : 'false',
  metadata: JSON.stringify(instance.metadata),
  clusterName: instance.clusterName,
  serviceName,
};
console.log('registerService:',params);
return await this.reqAPI(Constants.NACOS_URL_INSTANCE, params, 'PUT');

}

同时创建两个客户端,传入不同的namespace, 其中一个拿不到值

你好,我在使用这个nacos库,但是发现了一些问题

const configClient = new NacosConfigClient({
      serverAddr: '127.0.0.1:50010',
      // serverAddr: BR_NACOS_SERVER,
      // serverAddr,
      namespace: DATAVIEW_NAMESPACE
    })
    const configGlobalClient = new NacosConfigClient({
      // serverAddr: '127.0.0.1:50011',
      // serverAddr: BR_NACOS_SERVER,
      serverAddr,
      namespace: GLOBAL_NAMESPACE
    })
    // const content = await configClient.getConfig(CONFIG_DATAVIEW_ID, CONFIG_DATAVIEW_GROUP)
    // logger.info('======== GET dataview nacos config once  =====', content)
    configClient.subscribe({
      dataId: CONFIG_DATAVIEW_ID,
      group: CONFIG_DATAVIEW_GROUP
    }, content => {
      logger.info('======== GET dataview nacos config  =====', content)
    })
    configGlobalClient.subscribe({
      dataId: CONFIG_GLOBAL_ID,
      group: CONFIG_GLOBAL_GROUP
    }, content => {
      logger.info('======== GET global nacos config  =====', content)
    })

期待结果:

'======== GET dataview nacos config once  ====='
xxx
'======== GET global nacos config  ====='
xxx

实际输出

'======== GET dataview nacos config once  ====='
xxx
'======== GET global nacos config  ====='
null

使用中发现,只有前面的对面会输出结果,后面的数据结果是null,有时间请大神帮忙看下这个问题

启动报错了,,本地可以运行,部署到linux服务器就出错了

(node:15631) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token C in JSON at position 2 (address: 127.0.0.1:7777)
at JSON.parse ()
at Function.decode (/root/works/eryipay/node_modules/nacos-config/node_modules/cluster-client/lib/protocol/packet.js:86:26)
at Follower.decode (/root/works/eryipay/node_modules/nacos-config/node_modules/cluster-client/lib/follower.js:68:27)
at Follower._readPacket (/root/works/eryipay/node_modules/tcp-base/lib/base.js:308:25)
at Follower.handleReadable (/root/works/eryipay/node_modules/tcp-base/lib/base.js:374:26)
at Socket.socket.on (/root/works/eryipay/node_modules/tcp-base/lib/base.js:392:40)
at Socket.emit (events.js:182:13)
at emitReadable
(_stream_readable.js:534:12)
at onEofChunk (_stream_readable.js:512:7)
at readableAddChunk (_stream_readable.js:232:5)
(node:15631) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:15631) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
^C

How to create NacosConfigClient with username and password?

My nacos server has username and password, but I can't find the username and password fields in the ClientOptions interface.

const configClient = new NacosConfigClient({
    serverAddr: 'ip',
    namespace: 'namesapce',
    username: 'username',
    password: 'password'
});

Nacos nodejs sdk version: 2.0.0.

Direct Mode not works / 直连模式无法使用

复制 Readme里面的代码,

// index.js

const {NacosConfigClient} = require('nacos'); // js

// for direct mode
const configClient = new NacosConfigClient({
  serverAddr: '127.0.0.1:8848',
});

// listen data changed
configClient.subscribe({
  dataId: 'test',
  group: 'DEFAULT_GROUP',
}, content => {
  console.log(content);
});

执行 node index.js 然后报错

[Sun Mar 31 2019 00:20:06 GMT+0800 (GMT+08:00)][pid: 56608][NacosConfigClient] AssertionError [ERR_ASSERTION]: [Client] options.endpoint is required
Error Stack:
  AssertionError [ERR_ASSERTION]: [Client] options.endpoint is required
    at new DataClient (/Users/xxx/code/demo/node_modules/nacos-config/dist/client.js:31:9)
    at Object.createRealClient (/Users/xxx/code/demo/node_modules/cluster-client/lib/index.js:102:22)
    at new Leader (/Users/xxx/code/demo/node_modules/cluster-client/lib/leader.js:38:37)
    at ClusterClient.[ClusterClient#init] (/Users/xxx/code/demo/node_modules/cluster-client/lib/client.js:88:27)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:744:11)
    at startup (internal/bootstrap/node.js:285:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
Error Additions:
  generatedMessage: false
  code: "ERR_ASSERTION"
  actual: undefined
  expected: true
  operator: "=="

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.