mirror of https://github.com/dapr/go-sdk.git
log and port
This commit is contained in:
parent
c0c9f0166b
commit
f184c9c943
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue