-
Notifications
You must be signed in to change notification settings - Fork 63
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
集成 dubbo 时,直连服务是可以的,但是通过注册中心就不成功了 #15
Comments
服务端代码用的是官方的 demo,然后将 registry 配置成 zookeeper https://github.com/apache/incubator-dubbo/tree/master/dubbo-demo/dubbo-demo-provider 'use strict';
const { RpcClient } = require('sofa-node-rpc').client;
const { ZookeeperRegistry } = require('sofa-node-rpc').registry;
const protocol = require('dubbo-remoting');
const logger = console;
const registry = new ZookeeperRegistry({
logger,
address: '127.0.0.1:2181/dubbo/', // 注意:这里需要以 /dubbo/ 结尾
});
async function invoke() {
const client = new RpcClient({
logger,
registry,
protocol,
group: 'dubbo', // 这个根据实际情况填
version: null, // 这个根据实际情况填
});
const consumer = client.createConsumer({
interfaceName: 'org.apache.dubbo.demo.DemoService',
});
await consumer.ready();
const result = await consumer.invoke('sayHello', [{
$class: 'java.lang.String',
$: 'zongyu',
}], { responseTimeout: 3000 });
console.log(result);
}
invoke().catch(console.error); |
我按照 demo 试了一下,注册中心连接成功了,但是 group 的设置貌似依然不对 'use strict'
const { RpcClient } = require('sofa-rpc-node').client
const { ZookeeperRegistry } = require('sofa-rpc-node').registry
const { RpcServer } = require('sofa-rpc-node').server
const protocol = require('dubbo-remoting')
const logger = console
const registry = new ZookeeperRegistry({
logger,
address: '127.0.0.1:2181/dubbo/'
})
async function call() {
const client = new RpcClient({
logger: app.logger,
protocol,
registry,
group: 'HSF'
})
const consumer = client.createConsumer({
interfaceName: 'com.demo.provider.UserBaseQueryProvider',
version: '1.0.0.dev' //指定版本
})
await consumer.ready()
const result = await consumer.invoke('getUserInfo',
[{
$class: ' com.demo.provider.param.UserInfoQueryDTO',
$: {
mobilePhoneLike: {
$class: 'java.lang.String',
$: '157'
}
}
}], {
responseTimeout: 3000
})
console.log('==============result======================')
console.log(result)
console.log('====================================')
return result
} 结果运行报错:
并且程序还尝试了去连接这个接口的另外两个版本(1.0.0.daily 和 1.0.0.test)(我并没有去指定连接它们),抛出警告:
|
我大概知道了,稍等 |
@JimmyDaddy 重新安装一下,再试试 |
问题还是存在的 no provider of *** found! 直连是可以成功的, async getConnection(req) {
const meta = req.meta;
meta.connectionGroup = this.key;
const address = this._loadbalancer.select(req); // address 为 null
if (!address) return null;
const { connectionOpts, connectionClass } = this.options;
return await this.connectionManager.createAndGet(address, connectionOpts, connectionClass);
} 测试代码和上面的 demo 一样 |
@JimmyDaddy 把完整的日志给我 |
要具体看下订阅到的 url,之前都可以访问到机器,只是 group 没有匹配上,现在找不到,说明是新加的逻辑把它过滤掉了 |
日志并不多,仅仅抛出了一个我上面提到的错误;
subscribe(config, listener) {
assert(config && config.interfaceName, '[ZookeeperRegistry] subscribe(config, listener) config.interfaceName is required');
const interfaceName = config.interfaceName;
if (!this._subscribeMap.has(interfaceName)) {
this._subscribeMap.set(interfaceName, null);
const providerPath = this._buildProviderPath(config); // /dubbo/com.sxc.jothuheim.userbaseclient.provider.UserBaseQueryProvider/providers
this._zkClient.mkdirp(providerPath)
.then(() => {
this._zkClient.watchChildren(providerPath, (err, children) => {
if (err) {
this.emit('error', err);
return;
}
console.log('=============children=======================');
console.log( children); // 这里的 children 返回了四个版本的接口,是我们服务器上已有的
console.log('====================================');
const originAddressList = children.map(url => urlencode.decode(url));
const addressList = originAddressList.filter(url => this._isMatch(config, url));
this.logger.info('[ZookeeperRegistry] receive interface:%s:%s@%s address list (%d):\n%s\nvalid providers (%d):\n%s',
config.interfaceName, config.version || '', config.group || '',
originAddressList.length, formatAddrs(originAddressList), addressList.length, formatAddrs(addressList));
this._subscribeMap.set(interfaceName, addressList);
this.emit(interfaceName, addressList);
});
})
.catch(err => { this.emit('error', err); });
const consumerPath = this._buildConsumerPath(config);
const consumerUrl = fmt('%s://%s?uniqueId=%s&version=%s&pid=%s&timeout=%s&appName=%s&serialization=%s&startTime=',
config.protocol, localIp, config.uniqueId || '', '1.0', process.pid, config.timeout, config.appName || '', Date.now());
const path = consumerPath + '/' + urlencode.encode(consumerUrl);
this._zkClient.mkdirp(consumerPath)
.then(() => {
return this._zkClient.create(path, EMPTY, CreateMode.EPHEMERAL);
})
.catch(err => {
this.logger.warn('[ZookeeperRegistry] create consumerPath: %s failed, caused by %s', path, err.message);
});
} else {
const addressList = this._subscribeMap.get(interfaceName);
if (addressList) {
setImmediate(() => { listener(addressList); });
}
}
this.on(interfaceName, listener);
} 其中
providerInfo 为 :
前两个是直接注册到 zk 上的,后两个则是通过 edas 注册到 zk 上的,并且前两个的 dubbo 版本 为 2.0.1 ,后两个版本为 2.6.1 我发现问题出在 _isMatch(consumer, urlStr) {
const url = new URL(urlStr);
const providerInfo = url.searchParams || {};
const interfaceName = providerInfo.get('interface') || url.pathname.slice(1);
if (interfaceName && consumer.interfaceName !== interfaceName) {
return false;
}
const category = providerInfo.get('category');
if (category && category !== 'providers') {
return false;
}
const enabled = providerInfo.get('enabled');
if (enabled && enabled !== 'true') {
return false;
}
const consumerGroup = consumer.group;
const consumerVersion = consumer.version;
const providerGroup = providerInfo.get('group'); // group 有可能为 default.group
const providerVersion = providerInfo.get('version'); // version 有可能为 default.version
return (!consumerGroup || consumerGroup === providerGroup) &&
(!consumerVersion || consumerVersion === providerVersion);
} 我将 const providerGroup = providerInfo.get('group');
const providerVersion = providerInfo.get('version'); 改为 const providerGroup = providerInfo.get('group') || providerInfo.get('default.group');
const providerVersion = providerInfo.get('version') || providerInfo.get('default.version'); 就能访问成功了 |
@JimmyDaddy ok,我改下 |
@JimmyDaddy 再试试 |
好了,没问题了@gxcsoccer 谢谢 |
时返回 null
想知道为什么 addressList 是空的?
集成 dubbo 时,直连服务是可以的,但是通过注册中心就不成功了
还有 group 的设置貌似不成功,直连的时候我需要将 group 名字写在 interfaceName 里面才行,单独配置 group 或者在初始化 client 时设置 group 都不成功
The text was updated successfully, but these errors were encountered: