In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 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 zk-etcd-config". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use zk-etcd-config.
Zk-etcd-config is a lightweight dynamic property configuration interface that supports both etcd v3 and zookeeper middleware.
Github address
With zk-etcd-config, you can flexibly switch and use etcd or zookeeper as dynamic attribute configuration middleware, and use a simple interface to listen for the dynamic change of attribute values.
Sample code
(1) use: suppose our system has two parameters that need to be configured dynamically, and when the micro-service cluster of the system starts, we need to dynamically capture the changes of these two parameter values. If we use zookeeper as the middleware to store, all the parameters are assembled into a file similar to properties.application in the following format:
Param1=value1param2=value2
Then we can write the above configuration content to the data of the / config node of zookeeper. When the value of param1 or param2 in / config changes, the change notification is received in real time through the IWatcher interface. Sample code
String kind= "zookeeper"; String hosts= "localhost:2181,localhost:2183"; String path= "/ config"; IConfiger config = ConfigerFactory.createFactory (kind, hosts, path); config.start (); String value= config.get ("param1"); LOG.error ("# # key= {}, value= {}", "param1", value); IWatcher w = new TestWatcher (); config.addWatcher ("param1", w)
TestWatcher is a custom class that implements the IWatcher interface:
Import org.slf4j.Logger;import org.slf4j.LoggerFactory;import houyijun.dynamic.config.IWatcher;public class TestWatcher implements IWatcher {private static final Logger LOG = LoggerFactory.getLogger (TestWatcher.class); public void onChanged (String key, String oldValue, String newValue) {LOG.error ("# changed,old= {}, new= {}", oldValue,newValue);}}
Kind indicates what kind of middleware to use. Currently, the supported values are: "etcd-v3" indicates the interface with the V3 version of etcd. "zookeeper" indicates the interface that uses zookeeper. Hosts represents the address of etcd or zookeeper, separated by "," and in ip:port format. Path represents the node path where dynamic attributes are stored on etcd or zookeeper. IWatcher is a listening event interface, which is defined as:
Public interface IWatcher {/ * watcher event happened * @ param key * node path * @ param oldValue * old value * @ param newValue * new value * / void onChanged (String key,String oldValue,String newValue);}
(2) close config when you exit:
Config.close (); maven pom dependency package
Dependency packages in addition to zk-etcd-config, you must add dependency packages for etcd and zookeeper.
Houyijun.dynamic zk-etcd-config 0.2.0 io.etcd jetcd-core 0.4.1 org.apache.curator curator-recipes 4.0.1 Org.apache.zookeeper zookeeper 3.4.8 to this I believe you have a deeper understanding of "how to use zk-etcd-config". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.