Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: multi client in direct mode #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

HuJingKang
Copy link
Contributor

@HuJingKang HuJingKang commented Sep 29, 2022

问题: 直连模式下如果有多个客户端的话,所有客户端都会订阅第一个客户端的数据,导致数据错乱

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

const dataId = 'dataId';
const group = 'group';

const client1 = new NacosConfigClient({
  serverAddr: '127.0.0.1:8848',
  namespace: 'local',
});
client1.subscribe({ dataId, group }, data => {
  console.log('client1', data);
});

const client2 = new NacosConfigClient({
  serverAddr: '127.0.0.1:8848',
  namespace: 'test',
});
client2.subscribe({ dataId, group }, data => {
  console.log('client2', data);
});

const client3 = new NacosConfigClient({
  serverAddr: '127.0.0.1:8849',
  namespace: 'test',
});
client3.subscribe({ dataId, group }, data => {
  console.log('client3', data);
});

经排查,NacosConfigClient 中的 clusterOptions.name 是由 endpoint 构成的,如果没有传 endpoint 的话,name 都会是 DiamondClient@undefined。所以直连模式下,所有的name都相同, 第一个client是Leader,后面所有的client都是第一个client的Follower,所以订阅的都是第一个client的数据

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


hujingkang seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

ugrg

This comment was marked as outdated.

@ugrg
Copy link
Contributor

ugrg commented Apr 7, 2024

这个问题我查下来,像是client使用默认的端口是7777,同建立多个client时,这个7777端口会被占用导致失效。
不过好在我们可以使用NODE_CLUSTER_CLIENT_PORT这个环境变量来设置默认端口,这样就可以避免多个服务使用同一个接口而链接失败。实践下来,将这个值设置成0,即可实现随机端口。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants