Python 基于python操纵zookeeper介绍 (2)

                    zk_client.create('/node1/subNode', b'sub nodexxxx', ephemeral=True, sequence=True)

                    zk_client.set('/node1/subNode2', b'new data')

                i += 1

 

 

 

        # 关闭客户端前必须先调用stop,否则会报错

        zk_client.stop()

 

        # 关闭客户端

        zk_client.close()

    except Exception as e:

        print('运行出错:%s' % e)

 

 

monitor.py

#!/usr/bin/env python

#-*- encoding:utf-8 -*-

 

__author__ = 'shouke'

 

import time

 

from kazoo.client import  KazooClient

from kazoo.client import KazooState

 

zk = KazooClient(hosts='10.118.52.26:2181')

zk.start()

 

@zk.add_listener

def my_listener(state):

    if state == KazooState.LOST:

        print('LOST')

        # Register somewhere that the session was lost

    elif state == KazooState.SUSPENDED:

        print('SUSPENDED')

        # Handle being disconnected from Zookeeper

    else:

        pass

        print('CONNECTED')

        # Handle being connected/reconnected to Zookeeper

 

# 监视器

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpjxyd.html