-
Notifications
You must be signed in to change notification settings - Fork 13
/
default.go
57 lines (45 loc) · 1.8 KB
/
default.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
package producer
import (
"github.com/nsqio/go-nsq"
)
// DefaultProducer - Default nsq producer.
var DefaultProducer *Producer
func init() {
DefaultProducer = New()
}
// Publish - sends message to nsq topic
func Publish(topic string, body []byte) error {
return DefaultProducer.Publish(topic, body)
}
// PublishJSONAsync - sends message to nsq topic in json format asynchronously
func PublishJSONAsync(topic string, v interface{}, doneChan chan *nsq.ProducerTransaction, args ...interface{}) error {
return DefaultProducer.PublishJSONAsync(topic, v, doneChan, args...)
}
// PublishJSON - sends message to nsq topic in json format
func PublishJSON(topic string, v interface{}) error {
return DefaultProducer.PublishJSON(topic, v)
}
// PublishAsync - sends a message to nsq topic asynchronously
func PublishAsync(topic string, body []byte, doneChan chan *nsq.ProducerTransaction, args ...interface{}) error {
return DefaultProducer.PublishAsync(topic, body, doneChan, args...)
}
// MultiPublish - sends multiple message to to nsq topic
func MultiPublish(topic string, body [][]byte) error {
return DefaultProducer.MultiPublish(topic, body)
}
// MultiPublishAsync - sends multiple message to nsq topic asynchronously
func MultiPublishAsync(topic string, body [][]byte, doneChan chan *nsq.ProducerTransaction, args ...interface{}) error {
return DefaultProducer.MultiPublishAsync(topic, body, doneChan, args...)
}
// Connect method initialize the connection to nsq
func Connect(addr string) error {
return DefaultProducer.Connect(addr)
}
// ConnectConfig method initialize the connection to nsq with config
func ConnectConfig(addr string, config *nsq.Config) error {
return DefaultProducer.ConnectConfig(addr, config)
}
// Stop initiates a graceful stop of the Producer (permanent)
func Stop() {
DefaultProducer.Stop()
}