Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] WatchRemoteConfigOnChannel is not working #28

Closed
hyperjiang opened this issue Dec 29, 2019 · 4 comments
Closed

[BUG] WatchRemoteConfigOnChannel is not working #28

hyperjiang opened this issue Dec 29, 2019 · 4 comments

Comments

@hyperjiang
Copy link

It can not detect the changes, codes:

package main

import (
	"fmt"
	"log"
	"time"

	remote "github.com/shima-park/agollo/viper-remote"
	"github.com/spf13/viper"
)

func main() {
	remote.SetAppID("vip-service")
	namespaces := []string{"application", "database"}

	vipers := make(map[string]*viper.Viper)
	for _, ns := range namespaces {
		v := viper.New()
		v.SetConfigType("prop")
		err := v.AddRemoteProvider("apollo", "localhost:8080", ns)
		if err != nil {
			log.Fatal(err)
		}
		err = v.ReadRemoteConfig()
		if err != nil {
			log.Fatal(err)
		}

		v.WatchRemoteConfigOnChannel() // not working

		vipers[ns] = v
	}

	for {
		for ns, v := range vipers {
			fmt.Println(ns, v.AllSettings()) // every time gets the same configs
		}
		time.Sleep(5 * time.Second)
	}
}

It works if I switch to use WatchRemoteConfig:

for {
	for ns, v := range vipers {
		err := v.WatchRemoteConfig()
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(ns, v.AllSettings())
	}
	time.Sleep(5 * time.Second)
}
@shima-park
Copy link
Owner

shima-park commented Dec 30, 2019

I'll check it later when I have time. Thanks for your feedback

@shima-park
Copy link
Owner

shima-park commented Jan 3, 2020

Hi hyperjiang, Sorry for a long time to fix this. I had fix this issue on latest version. You can try this version.

@hyperjiang
Copy link
Author

hyperjiang commented Jan 3, 2020

It's working now, thank you.
BTW, your tag for 1.1.10 is not correct, should be v1.1.10
You can safely delete the tag 1.1.10 and tag it as v1.1.10

@shima-park
Copy link
Owner

awkward😅,I had tag it as v1.1.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants