-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
74 lines (66 loc) · 2.12 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/kubemq-io/kubemq-go"
"github.com/kubemq-io/kubemq-targets/pkg/uuid"
"github.com/kubemq-io/kubemq-targets/types"
)
func main() {
client, err := kubemq.NewClient(context.Background(),
kubemq.WithAddress("kubemq-cluster", 50000),
kubemq.WithClientId(uuid.New().String()),
kubemq.WithTransportType(kubemq.TransportTypeGRPC))
if err != nil {
log.Fatal(err)
}
randomKey := uuid.New().String()
// set request
setRequest := types.NewRequest().
SetMetadataKeyValue("method", "set").
SetMetadataKeyValue("key", randomKey).
SetData([]byte("some-data"))
querySetResponse, err := client.SetQuery(setRequest.ToQuery()).
SetChannel("query.redis").
SetTimeout(10 * time.Second).Send(context.Background())
if err != nil {
log.Fatal(err)
}
setResponse, err := types.ParseResponse(querySetResponse.Body)
if err != nil {
log.Fatal(err)
}
log.Println(fmt.Sprintf("set request for key: %s executed, response: %s", randomKey, setResponse.Metadata.String()))
// get request
getRequest := types.NewRequest().
SetMetadataKeyValue("method", "get").
SetMetadataKeyValue("key", randomKey)
queryGetResponse, err := client.SetQuery(getRequest.ToQuery()).
SetChannel("query.redis").
SetTimeout(10 * time.Second).Send(context.Background())
if err != nil {
log.Fatal(err)
}
getResponse, err := types.ParseResponse(queryGetResponse.Body)
if err != nil {
log.Fatal(err)
}
log.Println(fmt.Sprintf("get request for key: %s executed, response: %s, data: %s", randomKey, getResponse.Metadata.String(), string(getResponse.Data)))
// delete request
delRequest := types.NewRequest().
SetMetadataKeyValue("method", "delete").
SetMetadataKeyValue("key", randomKey)
queryDelResponse, err := client.SetQuery(delRequest.ToQuery()).
SetChannel("query.redis").
SetTimeout(10 * time.Second).Send(context.Background())
if err != nil {
log.Fatal(err)
}
delResponse, err := types.ParseResponse(queryDelResponse.Body)
if err != nil {
log.Fatal(err)
}
log.Println(fmt.Sprintf("delete request for key: %s executed, response: %s", randomKey, delResponse.Metadata.String()))
}