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

连接多个zookeeper #45

Closed
SmartKarven opened this issue Aug 10, 2018 · 0 comments
Closed

连接多个zookeeper #45

SmartKarven opened this issue Aug 10, 2018 · 0 comments

Comments

@SmartKarven
Copy link

你好:
我一个服务注册在两个不同的zookeeper,想通过dubbo2.js 调用这两个不同注册中心上的服务,发现只能调用同一个注册中心上的服务。

以下为实现:
const {Dubbo, java, TDubboCallResult} = require('dubbo2.js');
const {dubboInvoke,invoker} = require('dubbo-invoker');
const app = require('http');

//创建dubbo对象
var dubbo = new Dubbo({
application: {name: 'dubbo-node-consumer'},
//zookeeper address
register: '127.0.0.1:2182',
dubboVersion: '2.0.10',
interfaces: ['com.sitech.hsf.Interface.ServerA'],
});

const demoProvider = dubbo.proxyService({
dubboInterface: 'com.sitech.hsf.Interface.ServerA',
version: '2.0.0',
timeout:10,
group:'',
methods: {
sayHello(name) {
return [java.String(name)];
},
},
});

var dubbo2 = new Dubbo({
application: {name: 'dubbo-node-consumer1'},
//zookeeper address
register: '127.0.0.1:2181',
dubboVersion: '2.0.10',
interfaces: ['com.sitech.hsf.Interface.ServerA'],
});

const demoProvider2 = dubbo2.proxyService({
dubboInterface: 'com.sitech.hsf.Interface.ServerA',
version: '2.0.0',
timeout:10,
group:'',
methods: {
sayHello(name) {
return [java.String(name)];
},
},
});

(async () => {
await dubbo.ready();
await dubbo2.ready();
console.log('dubbo ready over...');
})();
(async () => {
await dubbo.ready();
await dubbo2.ready();
console.log('dubbo ready over...');
})();
app.createServer(async (req, res) => {
const result1 = await demoProvider.sayHello("node");
const result2 = await demoProvider2.sayHello("node");
const result3 = await demoProvider2.sayHello("node");
const result4 = await demoProvider.sayHello("node");
console.log('end->',result1,result2,result3,result4);
res.end(result.res);
}).listen(8080);

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

No branches or pull requests

1 participant