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

changeEvent.ChangeType 定義為何 #24

Closed
JimChung0403 opened this issue May 31, 2018 · 8 comments
Closed

changeEvent.ChangeType 定義為何 #24

JimChung0403 opened this issue May 31, 2018 · 8 comments
Assignees

Comments

@JimChung0403
Copy link

作者你好, 我使用下列方式 取得更換事件

event := agollo.ListenChangeEvent()
changeEvent := <-event

有時後我更該一個存在的key時, ChangeType有時取得1, 有時取得0

似乎長時間不操作後, 就會取得0
之後短時間內有一更新value, 就會取得1

@zouyx zouyx self-assigned this Jun 1, 2018
@zouyx
Copy link
Member

zouyx commented Jun 1, 2018

@JimChung0403 该方法为监听值变更的阻塞方法用于自定义值变更后操作。

取得的changeEvent应该是个结构体如下:

···
//config change event
type ChangeEvent struct {
Namespace string
Changes map[string]*ConfigChange
}
···

请问问题中提到的0和1,是获取什么值的时候出现呢?如果是获取changeEvent应该不会出现0和1。

@JimChung0403
Copy link
Author

@zouyx 抱歉, 是我沒說清楚
changeEvent.Changes["nameSpace"].ChangeType

type ConfigChange struct {
OldValue string
NewValue string
ChangeType ConfigChangeType
}

@zouyx
Copy link
Member

zouyx commented Jun 4, 2018

@JimChung0403 关于ConfigChangeType定义如下

0=ADDED是代表该值是新增的
1=MODIFIED是代表该值是被修改过的

···
const(
ADDED ConfigChangeType=iota
MODIFIED
DELETED
)
···

你的意思是ChangeType=0的状态是不正确的?

@JimChung0403
Copy link
Author

@zouyx
我有時候 修改apollo上面的value (key為舊的)
但 ConfigChangeType 取得是0

不常發生, 但大多發生在一段時間沒使用的“第一次”
第二次以後 都會取得1

@zouyx
Copy link
Member

zouyx commented Jun 4, 2018

@JimChung0403 我想我知道是什么原因,估计是和#23 引起的

@zouyx
Copy link
Member

zouyx commented Jun 5, 2018

@JimChung0403 这个问题你也验证一下。

@zouyx zouyx added bug and removed wip labels Jun 5, 2018
@JimChung0403
Copy link
Author

@zouyx 驗證沒問題了, 謝謝

@zouyx
Copy link
Member

zouyx commented Jun 6, 2018

好的,我关闭一下,谢谢你的反馈。

@zouyx zouyx closed this as completed Jun 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants