log and port

This commit is contained in:
Mark Chmarny 2020-05-02 05:06:58 -07:00
parent c0c9f0166b
commit f184c9c943
2 changed files with 9 additions and 7 deletions

View File

@ -2,6 +2,7 @@ package client
import (
"context"
"fmt"
"net"
"os"
@ -33,6 +34,7 @@ func NewClientWithPort(port string) (client *Client, err error) {
// NewClientWithAddress instantiates dapr client configured for the specific address
func NewClientWithAddress(address string) (client *Client, err error) {
fmt.Printf("dapr client initializing for: %s", address)
conn, err := grpc.Dial(address, grpc.WithInsecure())
if err != nil {
return nil, errors.Wrapf(err, "error creating connection to '%s': %v", address, err)

View File

@ -26,37 +26,37 @@ func main() {
}
fmt.Println(string(resp))
// publish a message to the topic example-topic
err = client.PublishEvent(ctx, "example-topic", data)
// publish a message to the topic messagebus
err = client.PublishEvent(ctx, "messagebus", data)
if err != nil {
panic(err)
}
fmt.Println("data published")
// save state with the key key1
err = client.SaveState(ctx, "example-store", "key1", data)
err = client.SaveState(ctx, "statestore", "key1", data)
if err != nil {
panic(err)
}
fmt.Println("data saved")
// get state for key key1
dataOut, err := client.GetState(ctx, "example-store", "key1")
dataOut, err := client.GetState(ctx, "statestore", "key1")
if err != nil {
panic(err)
}
fmt.Println(string(dataOut))
// delete state for key key1
err = client.DeleteState(ctx, "example-store", "key1")
err = client.DeleteState(ctx, "statestore", "key1")
if err != nil {
panic(err)
}
fmt.Println("data deleted")
// invoke output binding named 'kafka-topic'.
// invoke output binding named 'example-binding'.
// make sure you set up a dapr binding, otherwise this will fail
err = client.InvokeBinding(ctx, "kafka-topic", data)
err = client.InvokeBinding(ctx, "example-binding", data)
if err != nil {
panic(err)
}