Skip to main content

Using Kazoo to implement specific features of ZooKeeper, such as: program survival monitoring (alive), global configuration, single-point resource lock, and multi-selection resource lock.

Project description

version change

0.0.3 add get_children mapping kazoo

0.0.2 add ensure_path/exists mapping kazoo

0.0.1 fisrt version

ez_zk_client install

pip install ez_zk_client

example connect/disconnect

from ez_zk_client import ZkClient
client = ZkClient(hosts='localhost:2181')
#client.connect(wait_connected=True)
client.connect()
client.disconnect()

example create_path

client.create_node('/pytest','for pytest')

example create_ephemeral & get value/status

client.alive('/pytest/online','create oneline path, offlne auto disapear')
val,stat =  client.get_data('/pytest/online')

example listen node

def node_data_change(node_path, data):
    print('data change:',data) # new data

client.create_node("/testing/test_listener", 'old data')    
client.add_node_listener("/testing/test_listener", node_data_change)
client.set_data("/testing/test_listener", "new data")

example listen children

def children_change(node_path,data):
    # fire twice time
    print(data) # children list: ['child1'] in first time
    print(data) # children list: ['child1','child2'] in second time

client.ensure_path('/testing/listen_children')
client.add_children_listener('/testing/listen_children',children_change)
client.alive(f'/testing/listen_children/child1')
client.alive(f'/testing/listen_children/child2')
    

example lock single resource

client.alive("/testing/single_resource/ALIVE", 'http://localhost:3388')
locker = client.lock_single_resource("/testing/single_resource/ALIVE")
# locker.path=='/testing/single_resource'
with locker: # auto release
    api,stat = client.get_data(locker.path)
    # access api

example lock pool resource

inserted_path = client.insert_pool_resource('/testing/resource_pool', 'http://localhost:10001')
inserted_path = client.insert_pool_resource('/testing/resource_pool', 'http://localhost:10002')
inserted_path = client.insert_pool_resource('/testing/resource_pool', 'http://localhost:10003')
locker1 = client.use_pool_resource('/testing/resource_pool')
api1,stat = client.get_data(locker.path) # http://localhost:10001
locker2 = client.use_pool_resource('/testing/resource_pool')
api2,stat = client.get_data(locker.path) # http://localhost:10002
locker3 = client.use_pool_resource('/testing/resource_pool')
api3,stat = client.get_data(locker.path) # http://localhost:10003

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ez_zk_client-0.0.3-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file ez_zk_client-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: ez_zk_client-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for ez_zk_client-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d3f037b99bba7fa690c332a3940ef01b15b3f884a6b09555bac14ebfcb1ba49a
MD5 e6842e6f19d27cb736f8472dba84a192
BLAKE2b-256 bfac9a63306140a75962d7b52d808160afca669c351ec46476524eca8c6642df

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page