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

Basic use of zookeeper curator

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Below, we'll demonstrate curator's most basic crud functionality with a simple example:

maven dependency:

org.apache.zookeeper zookeeper 3.4.12 org.apache.curator curator-recipes 2.12.0 junit junit 4.12 test

Test Category:

package per.ym.zookeeper;import java.util.List;import org.apache.curator.RetryPolicy;import org.apache.curator.framework.CuratorFramework;import org.apache.curator.framework.CuratorFrameworkFactory;import org.apache.curator.retry.BoundedExponentialBackoffRetry;import org.apache.curator.retry.ExponentialBackoffRetry;import org.apache.curator.retry.RetryForever;import org.apache.curator.retry.RetryNTimes;import org.apache.curator.retry.RetryOneTime;import org.apache.curator.retry.RetryUntilElapsed;import org.apache.zookeeper.data.Stat;import org.junit.After;import org.junit.Before;import org.junit.Test;public class CuratorBasicAPI { private CuratorFramework client; private String connectString = "192.168.61.131:2184"; private int sessionTimeoutMs = 60000; private int connectionTimeoutMs = 60000; private String path = "/test"; private String rootPath = "/"; private byte[] data = "data".getBytes(); private byte[] newData = "newData".getBytes(); private int baseSleepTimeMs = 1000; private int maxRetries = 3; @Before public void connect() { //baseSleepTimeMs: basal sleep time;maxRetries: maximum number of retries;maxSleepMs: maximum sleep time between retries //The formula for calculating sleep time is: sleepMs = baseSleepTimeMs * Math.max(1, random.nextInt(1

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

Internet Technology

Wechat

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

12
Report