-
Notifications
You must be signed in to change notification settings - Fork 2
自定义服务发现实现
zōng yǔ edited this page Nov 23, 2018
·
2 revisions
自定义 Registry 需要实现下面一些接口
// simple_registry.js
'use strict';
const Base = require('sdk-base');
class SimpleRegistry extends Base {
constructor(options) {
super(options);
this.ready(true);
}
async register(config) { ... }
async unRegister(config) { ... }
subscribe(config, listener) { ... }
unSubscribe(config, listener) { ... }
close() { ... }
}
module.exports = SimpleRegistry;
然后用 cluster-client
封装起来
'use strict';
const RegistryBase = require('sofa-rpc-node/lib/registry/base');
const DataClient = require('./simple_registry');
class ClusterRegistry extends RegistryBase {
get DataClient() {
return DataClient;
}
}
module.exports = ClusterRegistry
exports.sofaRpc = {
registryClass: require('your-registry'),
registry: {
// 这里可以配置自定义的配置,这个节点不能为 null
},
};