-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
43 lines (40 loc) · 1.07 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
package main
import (
"context"
"encoding/json"
"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)
}
body, err := json.Marshal("test")
if err != nil {
panic(err)
}
// send
sendRequest := types.NewRequest().
SetMetadataKeyValue("method", "send").
SetMetadataKeyValue("label", `test`).
SetData(body)
sendUploadResponse, err := client.SetQuery(sendRequest.ToQuery()).
SetChannel("azure.servicebus").
SetTimeout(10 * time.Second).Send(context.Background())
if err != nil {
log.Fatal(err)
}
sendResponse, err := types.ParseResponse(sendUploadResponse.Body)
if err != nil {
log.Fatal(err)
}
log.Println(fmt.Sprintf("send request executed, error: %v , response:%s", sendResponse.Error, sendResponse.Metadata["result"]))
}