-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (48 loc) · 1.53 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
package servicebus
import (
"fmt"
servicebus "github.com/Azure/azure-service-bus-go"
"github.com/cjlapao/common-go/log"
)
var logger = log.Get()
// ServiceBusCli Entity
type ServiceBusCli struct {
ConnectionString string
Namespace *servicebus.Namespace
TopicManager *servicebus.TopicManager
QueueManager *servicebus.QueueManager
ActiveTopic *servicebus.Topic
ActiveSubscription *servicebus.Subscription
ActiveQueue *servicebus.Queue
ActiveQueueListenerHandle *servicebus.ListenerHandle
ActiveTopicListenerHandle *servicebus.ListenerHandle
Peek bool
UseWiretap bool
DeleteWiretap bool
CloseTopicListener chan bool
CloseQueueListener chan bool
}
// NewCli creates a new ServiceBusCli
func NewCli(connectionString string) *ServiceBusCli {
cli := ServiceBusCli{
Peek: false,
UseWiretap: false,
DeleteWiretap: false,
ConnectionString: connectionString,
}
cli.CloseTopicListener = make(chan bool, 1)
cli.CloseQueueListener = make(chan bool, 1)
cli.GetNamespace()
return &cli
}
// GetNamespace gets a new Service Bus connection namespace
func (s *ServiceBusCli) GetNamespace() (*servicebus.Namespace, error) {
logger.Trace("Creating a service bus namespace")
ns, err := servicebus.NewNamespace(servicebus.NamespaceWithConnectionString(s.ConnectionString))
if err != nil {
fmt.Println(err)
return nil, err
}
s.Namespace = ns
return s.Namespace, nil
}