resolve comments

Signed-off-by: Sarthak Sharma <sartsharma@microsoft.com>
This commit is contained in:
Sarthak Sharma 2022-10-28 13:13:17 +05:30
parent 03557440ad
commit 991d6bf86c
3 changed files with 16 additions and 13 deletions

View File

@ -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

View File

@ -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, &notification)

View File

@ -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