0

使用kazoo连接zookeeper服务器,简单的leader选择。当重新启动zookeper领导服务器,并触发监听但没有工作,那么连接连接时如何添加监听?

def create_path():
    # create child ephemeral sequence node of path

def select():
   nodes = zk.get_children(path, watch=my_watch)
   # use ephemeral sequence node to select leader

def my_watch(event: WatchedEvent)
    if event_state == KeeperState.CONNECTED or event_type in [EventType.CHILD, 
           EventType.CHANGED,  EventType.DELETED, EventType.CREATED]:
        select()

def my_listener(state):
    if state == KazooState.LOST:
         create_path()
         select() 
    if state == KazooState.CONNECTED
        select()   # not work 
4

0 回答 0