一个基于分布式系统的etcd监听者

config-watcher

依赖

  • etcd v3

功能

  • 监听不丢失:
    • 利用etcd revision概念,即使网络不稳定,导致监听器重连,也不会丢失订阅消息
  • 封装了etcd watch模块,用户只需关心:
    • 获取、设置、更改监听对象时,回调函数触发的相关业务逻辑
  • 带有初始值设置功能:
    • 分布式系统环境下,利用etcd事务操作,多个节点只会有一个节点执行初始化,无需担忧重复执行,以及开发额外的代码去做初始化操作

用法

预览

# put callback(初始化成功时触发)
$ etcdctl get /the/key/you/want/to/watch

$ ./etcd_watcher 
put callback: /the/key/you/want/to/watch=/the/value/you/want/to/init

$ etcdctl get /the/key/you/want/to/watch
/the/key/you/want/to/watch
/the/value/you/want/to/init

# get callback(初始化失败时触发,即已经设置过了)
$ etcdctl get /the/key/you/want/to/watch
/the/key/you/want/to/watch
/the/value/you/want/to/init

$ ./etcd_watcher 
get callback: /the/key/you/want/to/watch=/the/value/you/want/to/init

# change callback(监听对象变化时触发)
$ etcdctl put /the/key/you/want/to/watch 123

$ ./etcd_watcher 
...
change callback: /the/key/you/want/to/watch=123
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值