-
Notifications
You must be signed in to change notification settings - Fork 161
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
Add zookeeper auth supports #132
Conversation
感谢你的pr ^_^ const dubbo = new Dubbo<typeof service>({
application: {name: 'node-dubbo'},
// 这个作为一个兼容模式存在默认为zk作为注册中心,未来我们可能支持redis,naccos
register: 'localhost:2181',
service,
}); 所以通过这样设计就比较单薄了不方便扩展,而且会让dubbo的初始化参数爆表。 所以做了重构之后,我们现在是这样的设计: import {Dubbo, setting, Zk} from 'dubbo2.js';
const dubbo = new Dubbo<typeof service>({
application: {name: 'dubbo-node-consumer'},
service,
dubboSetting,
register: Zk({
url: 'localhost:2181,localhost:2182,localhost:2183',
// others arguments, for example authInfo
}),
}); 这样注册中心的扩展性就不会影响到Dubbo的入口参数,Keep it simple. 所以希望authInfo不要挂在this.props.authInfo, 而是作为Zk的入口参数。 |
packages/dubbo/src/dubbo.ts
Outdated
@@ -98,9 +98,12 @@ export default class Dubbo<TService = Object> | |||
|
|||
//if dubbo register is string, create a zookeeper instance | |||
let register = this._props.register; | |||
const zkAuthInfo = this._props.zkAuthInfo; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个参数的设置直接放入Zk({url: '', authInfo: {}})这个函数的参数内部,这样不会再在Dubbo的构造方法中添加更多的属性参数,为后续的多注册中心打下基础。
packages/dubbo/src/dubbo.ts
Outdated
if (isString(register)) { | ||
register = Zk({ | ||
url: this._props.register as string, | ||
zkAuthInfo: zkAuthInfo, | ||
zkRoot: this._props.zkRoot as string, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
url为string的注册中心地址,默认是zk的注册中心,这个只作为兼容方案,后续希望收入到Zk函数,保证更好的扩展性
所以这个地方 不需要加入zkRoot和zkAuthInfo属性的设置
@@ -111,7 +113,13 @@ export interface IDubboProvider { | |||
methods: {[methodName: string]: Function}; | |||
} | |||
|
|||
export interface IZKAuthInfo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes!
//debug log | ||
log(`connecting zkserver ${register}`); | ||
//connect | ||
this._client = zookeeper.createClient(register, { | ||
retries: 10, | ||
}); | ||
|
||
if (zkAuthInfo && zkAuthInfo.scheme && zkAuthInfo.auth) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes!
@@ -145,14 +145,18 @@ export class ZkRegistry extends Registry<IZkClientProps & IDubboRegistryProps> { | |||
* connect zookeeper | |||
*/ | |||
private _connect = (callback: (err: Error) => void) => { | |||
const {url: register} = this._props; | |||
const {url: register, zkAuthInfo} = this._props; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
@hufeng 感谢回复和review。 重构的设计的确具有更好的抽象,我稍后在这个思路下重新提交一次,烦请您再查阅,十分感谢! |
@hufeng 更新了pr, 自测功能正常,辛苦您再查看一下。 |
@xusd320 好的,我来review下 辛苦了 |
For Issue:130.
Add zookeeper authInfo supports.
Detail is here:
node-zookeeper-client#addAuthInfo