-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconn.go
More file actions
46 lines (42 loc) · 1.27 KB
/
conn.go
File metadata and controls
46 lines (42 loc) · 1.27 KB
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
package activemq
import (
"log"
"os"
"time"
"github.com/go-stomp/stomp/v3"
)
func NewConn(userName string, password string, addr string) (*stomp.Conn, error) {
var options []func(*stomp.Conn) error
if len(userName) > 0 && len(password) > 0 {
clientID, err := os.Hostname()
if err != nil {
log.Println("Cannot get hostname", err)
return nil, err
}
options = []func(*stomp.Conn) error{
stomp.ConnOpt.Login(userName, password),
// stomp.ConnOpt.Host("/"),
stomp.ConnOpt.Header("client-id", clientID),
}
}
return stomp.Dial("tcp", addr, options...)
}
func NewConnWithHeartBeat(userName string, password string, addr string, sendTimeout time.Duration, recvTimeout time.Duration) (*stomp.Conn, error) {
var options []func(*stomp.Conn) error
if len(userName) > 0 && len(password) > 0 {
clientID, err := os.Hostname()
if err != nil {
log.Println("Cannot get hostname", err)
return nil, err
}
options = []func(*stomp.Conn) error{
stomp.ConnOpt.Login(userName, password),
// stomp.ConnOpt.Host("/"),
stomp.ConnOpt.Header("client-id", clientID),
stomp.ConnOpt.HeartBeat(sendTimeout, recvTimeout),
}
} else {
options = []func(*stomp.Conn) error{stomp.ConnOpt.HeartBeat(sendTimeout, recvTimeout)}
}
return stomp.Dial("tcp", addr, options...)
}