|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + |
| 7 | + "google.golang.org/grpc" |
| 8 | + |
| 9 | + runtimev1pb "mosn.io/layotto/spec/proto/runtime/v1" |
| 10 | +) |
| 11 | + |
| 12 | +func main() { |
| 13 | + conn, err := grpc.Dial("127.0.0.1:34904", grpc.WithInsecure()) |
| 14 | + if err != nil { |
| 15 | + panic(err) |
| 16 | + } |
| 17 | + // 1. invoke sayHello API |
| 18 | + client := runtimev1pb.NewRuntimeClient(conn) |
| 19 | + hello, err := client.SayHello(context.Background(), &runtimev1pb.SayHelloRequest{ |
| 20 | + ServiceName: "quick_start_demo", |
| 21 | + Name: "eva", |
| 22 | + }) |
| 23 | + if err != nil { |
| 24 | + panic(err) |
| 25 | + } |
| 26 | + // validate the response value |
| 27 | + if hello.Hello != "greeting, eva" { |
| 28 | + panic(fmt.Errorf("Assertion failed! Result is %v", hello.Hello)) |
| 29 | + } |
| 30 | + fmt.Println(hello.Hello) |
| 31 | + |
| 32 | + // 2. invoke lifecycle API to modify the `sayHello` component configuration |
| 33 | + c := runtimev1pb.NewLifecycleClient(conn) |
| 34 | + metaData := make(map[string]string) |
| 35 | + // change the configuration from "greeting" to "goodbye" |
| 36 | + metaData["hello"] = "goodbye" |
| 37 | + req := &runtimev1pb.DynamicConfiguration{ComponentConfig: &runtimev1pb.ComponentConfig{ |
| 38 | + Kind: "hellos", |
| 39 | + Name: "quick_start_demo", |
| 40 | + Metadata: metaData, |
| 41 | + }} |
| 42 | + _, err = c.ApplyConfiguration(context.Background(), req) |
| 43 | + if err != nil { |
| 44 | + panic(err) |
| 45 | + } |
| 46 | + // 3. invoke sayHello API again |
| 47 | + client = runtimev1pb.NewRuntimeClient(conn) |
| 48 | + hello, err = client.SayHello(context.Background(), &runtimev1pb.SayHelloRequest{ |
| 49 | + ServiceName: "quick_start_demo", |
| 50 | + Name: "eva", |
| 51 | + }) |
| 52 | + if err != nil { |
| 53 | + panic(err) |
| 54 | + } |
| 55 | + // validate the response value. It should be different this time. |
| 56 | + if hello.Hello != "goodbye, eva" { |
| 57 | + panic(fmt.Errorf("Assertion failed! Result is %v", hello.Hello)) |
| 58 | + } |
| 59 | + fmt.Println(hello.Hello) |
| 60 | +} |
0 commit comments