-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
36 lines (33 loc) · 940 Bytes
/
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
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("localhost", 50000),
kubemq.WithClientId(uuid.New().String()),
kubemq.WithTransportType(kubemq.TransportTypeGRPC))
if err != nil {
log.Fatal(err)
}
publishRequest := types.NewRequest().
SetMetadataKeyValue("Key", "S2V5").
SetData([]byte("new-data"))
queryPublishResponse, err := client.SetQuery(publishRequest.ToQuery()).
SetChannel("query.msk").
SetTimeout(10 * time.Second).Send(context.Background())
if err != nil {
log.Fatal(err)
}
publishResponse, err := types.ParseResponse(queryPublishResponse.Body)
if err != nil {
log.Fatal(err)
}
log.Println(fmt.Sprintf("publish message, response: %s", publishResponse.Metadata.String()))
}