This is a creation in Article, where the information may have evolved or changed.
Previous article: Go language nsq Source code interpretation of the three NSQLOOKUPD source Nsqlookupd.go mainly read Nsqlookupd.go This file, this section will interpret the Nsqlookupd.go files involved in the three files: Options.go, Context.go and Wait_group_wrapper.go.
Options.go
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21st 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
Package NSQLOOKUPD
Import( "Log" "OS" "Time" )
Type Nsqlookupdoptionsstruct { Verbose BOOL ' flag:"Verbose"`//Whether to open the long-winded mode, after opening, will hit a lot of log, generally in debugging or positioning problems when used.
Tcpaddress string ' flag:"Tcp-address"`//tcp Listening Address Httpaddress string ' flag:"Http-address"`//http Listening Address BroadcastAddress string ' flag:"Broadcast-address"`//External address of this lookup node
//producer The interaction timeout, which is 5 minutes by default. That is, if the NSQLOOKUPD does not receive a producer Ping (like a heartbeat packet) within 5 minutes, the producer is considered to be off-line. Inactiveproducertimeout Time.Duration' Flag:"Inactive-producer-timeout"` //literal translation is tombstone time //When accessing the/tombstone_topic_producer URL in the HTTP interface of Nsqadmin, NSQLOOKUPD will give producer tombstonelifetime length of time to log off //default is 45 seconds, in this 45 seconds, producer no longer be found by any consumer through Nsqadmin/lookup operation, while producer will also delete topic and other operations. ///45 seconds later, the producer is disconnected from the NSQLOOKUPD, and the producer is removed from the data record by unregister operations in the NSQLOOKUPD TCP connection. TombstoneLifetime Time.Duration' Flag:"Tombstone-lifetime"` }
// //A pointer to a variable of the new nsqlookupdoptions type // Func newnsqlookupdoptions() *Nsqlookupdoptions{ //Get host name Hostname,Err:=Os.Hostname() ifErr!=Nil{ Log.Fatal(Err) }
//Returns a variable of type nsqlookupdoptions and specifies the default parameter. return &Nsqlookupdoptions{ //tcp Monitor the 4160 port of this machine Tcpaddress:"0.0.0.0:4160",
//http Monitor the 4161 port of this machine
Httpaddress:"0.0.0.0:4161",
//Host name BroadcastAddress:Hostname,
//5 minutes Timeout Inactiveproducertimeout: - * Time.Second,
//45 sec TombstoneLifetime: $ * Time.Second, } } |
Context.go
1 2 3 4 5 6 7 8 9
|
Package NSQLOOKUPD
// According to the context of the naming, refers to the environment, context meaning. In layman's terms, it is the information that keeps some of the running environment As you can see from the definition below, the context is just a pointer to the NSQLOOKUPD // Type Context struct { NSQLOOKUPD *nsqlookupd } |
Wait_group_wrapper.go
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21st 22 23
|
Package util
Import( "Sync" )
// //This file is the encapsulation of Waitgroup, about Waitgroup, according to the meaning, wait is the mean of waiting, group is the meaning of groups, groups, together means waiting for a group. //means that when all the operations in a group have been completed, the execution will continue. //can refer to http://www.baiyuxiong.com/?p=913 to understand Waitgroup usage //
Type Waitgroupwrapperstruct { Sync.Waitgroup }
Func(W*Waitgroupwrapper)Wrap(CB Func()) { W.ADD(1) Go func() { Cb() W. Done() }() } |