Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use zkconfigutil

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to use zkconfigutil". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use zkconfigutil.

Zkconfigutil introduction

It is just a tool for managing configuration items among distributed clusters. It is small, but very easy to use, easy play

Code example

/ * * just test * @ author JERRY * * / @ TypeZkConfigurable (path= "/ test/jerry", server= "localhost:2181", useOwnZkServer=false) public final class Demo {@ FieldZkConfigurable (resove=DemoF1Resolve.class, dynamicUpdate=true) public static String F1 = "F1"; @ FieldZkConfigurable (resove=DemoF2Resolve.class, dynamicUpdate=true) public static String F2 = "F2"; @ FieldZkConfigurable (resove=DemoF3Resolve.class, dynamicUpdate=true) public static Boolean F3 = false } public final class DemoF1Resolve extends AbstractResolve {@ Override public String resolve () {/ / TODO Auto-generated method stub return Demo.F1 } @ Override public void dResolve (String src) {/ / TODO Auto-generated method stub Demo.F1 = src;}}

Detailed explanation

The Demo simulates the cluster environment and is pretended to be Demo for project public configuration management. Generally, there are more fields. The current zkconfigutil version only considers that the values of configurable fields can be expressed through string, so that we can easily realize visual modification through the eclipse zookeeer plug-in.

As you can see, there are two main types of annotations in Demo, one for class and one for fields

@ TypeZkConfigurable (path= "/ test/jerry", server= "localhost:2181", useOwnZkServer=false)

This annotation has three main parameters for class. Path represents the root directory of the configuration on zookeeper. The path of a configuration item actually saved on zookeeper is / path/ClassSimpleName/FieldName,server represents the zookeeper address used. The standard zookeeper address format. UseOwnZkServer indicates whether to use the private zookeeper specified by yourself. You will see a totalzookeeper below. Read on patiently.

@ FieldZkConfigurable (resove=DemoF1Resolve.class, dynamicUpdate=true)

This annotation has two main parameters for field. Resove mainly implements the assignment operation of the field. DynamicUpdate sets whether the field needs to be dynamically updated. When true, zookeeper will add dataListener to the path. When the value on zookeeper changes, update the field through reslove.

As you may see, the main work is the development of reslove, but there are only two ways, easy play

ZkConfigUtil app = new ZkConfigUtil ("localhost:2181"); app.register (Demo.class, true)

So easy, two lines of code to achieve the zookeeperization of Demo.

Thank you for your reading, the above is the content of "how to use zkconfigutil", after the study of this article, I believe you have a deeper understanding of how to use zkconfigutil, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report