forked from kubemq-io/kubemq-sources
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
61 lines (53 loc) · 1.27 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
package main
import (
"context"
"log"
"time"
"github.com/go-stomp/stomp"
"github.com/kubemq-io/kubemq-go"
"github.com/nats-io/nuid"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
client, err := kubemq.NewClient(context.Background(),
kubemq.WithAddress("localhost", 50000),
kubemq.WithClientId(nuid.Next()),
kubemq.WithCheckConnection(true),
kubemq.WithTransportType(kubemq.TransportTypeGRPC))
if err != nil {
log.Fatal(err)
}
go func() {
errCh := make(chan error)
eventsCh, err := client.SubscribeToEvents(ctx, "event.messaging.activemq", "", errCh)
if err != nil {
log.Fatal(err)
}
for {
select {
case err := <-errCh:
log.Fatal(err)
return
case event, more := <-eventsCh:
if !more {
log.Println("client done")
return
}
log.Printf("client: Channel: %s, Data: %s", event.Channel, string(event.Body))
case <-ctx.Done():
return
}
}
}()
var options []func(*stomp.Conn) error = []func(*stomp.Conn) error{
stomp.ConnOpt.Login("admin", "admin"),
stomp.ConnOpt.Host("/"),
}
conn, err := stomp.Dial("tcp", "localhost:61613", options...)
if err != nil {
log.Fatal(err)
}
conn.Send("my-dest", "text/plain", []byte("test-send-activemq"))
time.Sleep(3 * time.Second)
}