diff --git a/configuration/config-updater/README.md b/configuration/config-updater/README.md index 08893beb..5bbb7773 100644 --- a/configuration/config-updater/README.md +++ b/configuration/config-updater/README.md @@ -2,7 +2,7 @@ > **Note:** Run this app in the background before running any configuration quickstart. -This golang app is used for `configuration` quickstarts to simulate updating value of configuration items in the configuration store. +This is a supplementary app, written in Go, to simulate changes to configuration items. It is required to demonstrate the notification to subscribing app, when a configuration item changes. ## Prerequisite diff --git a/configuration/go/http/config-subscriber/app.go b/configuration/go/http/config-subscriber/app.go index 92a10291..4c457a7a 100644 --- a/configuration/go/http/config-subscriber/app.go +++ b/configuration/go/http/config-subscriber/app.go @@ -55,7 +55,7 @@ func subscribeToConfigUpdates() { subscription, err := http.Get(DAPR_HOST + ":" + DAPR_HTTP_PORT + "/v1.0-alpha1/configuration/" + DAPR_CONFIGURATION_STORE + "/subscribe") if err != nil { - fmt.Print(err.Error()) + fmt.Println("Error subscribing to config updates, err:" + err.Error()) os.Exit(1) } sub, err := ioutil.ReadAll(subscription.Body) @@ -85,7 +85,7 @@ func startServerToListen() { func configUpdateHandler(w http.ResponseWriter, r *http.Request) { body, err := ioutil.ReadAll(r.Body) if err != nil { - panic(err) + log.Panic(err) } var notification map[string]interface{} json.Unmarshal(body, ¬ification) diff --git a/configuration/go/sdk/config-subscriber/app.go b/configuration/go/sdk/config-subscriber/app.go index 31749443..998176d1 100644 --- a/configuration/go/sdk/config-subscriber/app.go +++ b/configuration/go/sdk/config-subscriber/app.go @@ -4,34 +4,37 @@ import ( "context" "encoding/json" "fmt" + "log" "os" "time" dapr "github.com/dapr/go-sdk/client" ) +var DAPR_CONFIGURATION_STORE = "configstore" +var CONFIGURATION_ITEMS = []string{"appID1", "appID2"} + func main() { client, err := dapr.NewClient() if err != nil { - panic(err) + log.Panic(err) } - CONFIGURATION_STORE := "configstore" - CONFIGURATION_ITEMS := []string{"appID1", "appID2"} - ctx, cancel := context.WithTimeout(context.Background(), 15 * time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) defer cancel() - // Get configuration from config store + // Get config items from config store for _, item := range CONFIGURATION_ITEMS { - config, err := client.GetConfigurationItem(ctx, CONFIGURATION_STORE, item) + config, err := client.GetConfigurationItem(ctx, DAPR_CONFIGURATION_STORE, item) if err != nil { - fmt.Printf("Error getting configuration for : %s", item) + fmt.Printf("Could not get config item, err:" + err.Error()) + os.Exit(1) } c, _ := json.Marshal(config) fmt.Println("Configuration for " + item + ": " + string(c)) } // Subscribe for config changes - err = client.SubscribeConfigurationItems(ctx, CONFIGURATION_STORE, CONFIGURATION_ITEMS, func(id string, config map[string]*dapr.ConfigurationItem) { + err = client.SubscribeConfigurationItems(ctx, DAPR_CONFIGURATION_STORE, CONFIGURATION_ITEMS, func(id string, config map[string]*dapr.ConfigurationItem) { // First invocation when app subscribes to config changes only returns subscription id if len(config) == 0 { fmt.Println("App subscribed to config changes with subscription id: " + id) @@ -42,8 +45,8 @@ func main() { fmt.Println("Configuration update " + string(c)) }) if err != nil { - fmt.Println("Error subscribing to config changes") - panic(err) + fmt.Println("Error subscribing to config updates, err:" + err.Error()) + os.Exit(1) } // Exit app after 15 seconds