ShannonDing commented on a change in pull request #315: [ISSUE #314] support
name server domain
URL: https://github.com/apache/rocketmq-client-go/pull/315#discussion_r359199487
##########
File path: internal/namesrv.go
##########
@@ -125,3 +138,103 @@ func (s *namesrvs) SetCredentials(credentials
primitive.Credentials) {
func (s *namesrvs) AddrList() []string {
return s.srvs
}
+
+// UpdateNameServerAddress will update srvs.
+// docs: https://rocketmq.apache.org/docs/best-practice-namesvr/
+func (s *namesrvs) UpdateNameServerAddress(nameServerDomain, instanceName
string) {
+ s.lock.Lock()
+ defer s.lock.Unlock()
+
+ nameServers := []string{}
+ if nameServerDomain == "" {
+ // try to get from environment variable
+ if v := os.Getenv("NAMESRV_ADDR"); v != "" {
+ nameServers = strings.Split(v, ";")
+ s.srvs = nameServers
+ return
+ }
+ // use default domain
+ nameServerDomain = DEFAULT_NAMESRV_ADDR
+ }
+
+ //load snapshot
+ homeDir := ""
+ if usr, err := user.Current(); err == nil {
+ homeDir = usr.HomeDir
+ } else {
+ rlog.Error("name server domain, can't get user home directory",
map[string]interface{}{
+ "err": err,
+ })
+ }
+ storePath := path.Join(homeDir, "/logs/rocketmq-go/snapshot")
Review comment:
For snapshot,it is not necessary to open and write it every time. it would
be better to load it once when client is start. and update it if nameserver
changed and domain server is OK.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services