In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces how to encapsulate the DynamicBrokerReader class in Storm-kafka, which is very detailed and has certain reference value. Friends who are interested must finish it!
Grasp the encapsulation class of DynamicBrokerReder-ZkBrokerReader in detail
Package com.mixbox.storm.kafka.trident;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import com.mixbox.storm.kafka.DynamicBrokersReader;import com.mixbox.storm.kafka.ZkHosts;import java.util.Map / * 2014-07-22 * getting GlobalPartitionInformation * * ZkBrokerReader in ZK is a simple package for DynamicBrokersReader * @ author Yin Shuai * / public class ZkBrokerReader implements IBrokerReader {public static final Logger LOG = LoggerFactory .getLogger (ZkBrokerReader.class); GlobalPartitionInformation cachedBrokers; DynamicBrokersReader reader; long lastRefreshTimeMs; long refreshMillis / * * @ param conf * @ param topic * specify the zkBrokerReader * @ param hosts * / public ZkBrokerReader of topic (Map conf, String topic, ZkHosts hosts) {reader = new DynamicBrokersReader (conf, hosts.brokerZkStr, hosts.brokerZkPath, topic) CachedBrokers = reader.getBrokerInfo (); lastRefreshTimeMs = System.currentTimeMillis (); refreshMillis = hosts.refreshFreqSecs * 1000L;} @ Override public GlobalPartitionInformation getCurrentBrokers () {long currTime = System.currentTimeMillis () / / simply specify how long you need to start refreshing Brokerlibiao if (currTime > lastRefreshTimeMs + refreshMillis) {LOG.info ("brokers need refreshing because" + refreshMillis + "ms have expired"); cachedBrokers = reader.getBrokerInfo () LastRefreshTimeMs = currTime;} return cachedBrokers;} @ Override public void close () {reader.close ();}}
An overview of our Code:
ZkBrokerReader is a simple encapsulation of DynamicBrokersReader, which holds two main Class in ZkBrokerReader
1 GlobalPartitionInformatio cachedBroker
2 DynamicBrokersReader reader
3 the latest refresh time of long lastRefreshTimeMs;
LastRefreshTimeMs = System.currentTimeMillis (); the latest refresh time is the current time of the system
4 long refreshMillis
RefreshMillis = host.refreshFreqSecs * 1000L sets the number of milliseconds to refresh
five
Public GlobalPartitionInformation getCurrentBrokers () {long currTime = System.currentTimeMillis (); / / it simply specifies how long you start refreshing Brokerlibiao if (currTime > lastRefreshTimeMs + refreshMillis) {LOG.info ("brokers need refreshing because" + refreshMillis + "ms have expired") CachedBrokers = reader.getBrokerInfo (); lastRefreshTimeMs = currTime;} return cachedBrokers;}
Every time getCurrentBrokers is called, System.currentTimeMillis will be fetched first when the current system time exceeds the earliest refresh time + refresh
The interval will go with the new again:
CachedBrokers = reader.getBrokerInfo (); every time the getBrokerInfo () method is called, it will be re-fetched in the zk
Once.
ZkBrokerReader is an encapsulation of DynamicBrokerReader, the Dynamic nature of DynamicBrokerReader is not a program dynamic factor, but simply in the process of reading ZK data, Zk data has changed dynamically?
The above is all the content of the article "how to encapsulate DynamicBrokerReader classes in Storm-kafka". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.