In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
In this issue, Xiaobian will bring you about how to realize nsqlookupd entry file analysis. The article is rich in content and analyzes and narrates from a professional perspective. After reading this article, I hope you can gain something.
The nsqlookupd role in nsq is relatively simple and suitable as an entry point for analyzing nsq
apps/nsqlookupd/nsqlookupd.go
nsqlookupd is a stand-alone program, so put it in the apps directory, relying on the internal package nsqlookupd, util, and the external package:
github.com/BurntSushi/toml # TOML is a profile specification, this package is a parse package for golang
github.com/mreiferson/go-options #Toolkit for injecting command line and profile parameters into struct, only one file
Key Code Parsing
1. Definition of global variables
The command line parameter in go becomes flag, and the flag collection becomes FlagSet. Before parsing the command line parameter, you need to create FlagSet first, define each flag, as shown in the global variable below, and provide important default values.
var (
flagSet = flag.NewFlagSet("nsqlookupd", flag.ExitOnError)
config = flagSet.String("config", "", "path to config file")
///////////////
)
2. Command line parameter analysis
flagSet.Parse(os.Args[1:])
os.Args is all command-line arguments;os.Args[0] is the full pathname of the executable program;
flagSet.Parse parses command-line parameters, overriding flag default definition in flagSet
3. How to exit the nsqlookupd process
Two chan are defined, signalChan receives the exit signal sent by OS, anonymous coroutine receives data, sends a 1 to exitChan, and waits for the main coroutine on exitChan to call nsqlookupd Exit method.
signalChan := make(chan os.Signal, 1)
exitChan := make(chan int)
go func() {
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.