File tree Expand file tree Collapse file tree 2 files changed +22
-13
lines changed Expand file tree Collapse file tree 2 files changed +22
-13
lines changed Original file line number Diff line number Diff line change @@ -15,16 +15,24 @@ type options struct {
15
15
logger queue.Logger
16
16
addr string
17
17
subj string
18
+ tag string
18
19
}
19
20
20
- // WithAddr setup the addr of NATS
21
+ // WithAddr setup the URI
21
22
func WithAddr (addr string ) Option {
22
23
return func (w * options ) {
23
24
w .addr = "nats://" + addr
24
25
}
25
26
}
26
27
27
- // WithSubj setup the subject of NATS
28
+ // WithAddr setup the tag
29
+ func WithTag (tag string ) Option {
30
+ return func (w * options ) {
31
+ w .tag = tag
32
+ }
33
+ }
34
+
35
+ // WithSubj setup the topic
28
36
func WithSubj (subj string ) Option {
29
37
return func (w * options ) {
30
38
w .subj = subj
@@ -49,6 +57,7 @@ func newOptions(opts ...Option) options {
49
57
defaultOpts := options {
50
58
addr : "amqp://guest:guest@localhost:5672/" ,
51
59
subj : "queue" ,
60
+ tag : "golang-queue" ,
52
61
logger : queue .NewLogger (),
53
62
runFunc : func (context.Context , core.QueuedMessage ) error {
54
63
return nil
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ var _ core.Worker = (*Worker)(nil)
17
17
18
18
// Worker for NSQ
19
19
type Worker struct {
20
- client * amqp.Connection
20
+ conn * amqp.Connection
21
21
channel * amqp.Channel
22
22
stop chan struct {}
23
23
stopFlag int32
@@ -36,12 +36,12 @@ func NewWorker(opts ...Option) *Worker {
36
36
tasks : make (chan amqp.Delivery ),
37
37
}
38
38
39
- w .client , err = amqp .Dial (w .opts .addr )
39
+ w .conn , err = amqp .Dial (w .opts .addr )
40
40
if err != nil {
41
41
panic (err )
42
42
}
43
43
44
- w .channel , err = w .client .Channel ()
44
+ w .channel , err = w .conn .Channel ()
45
45
if err != nil {
46
46
panic (err )
47
47
}
@@ -66,13 +66,13 @@ func (w *Worker) startConsumer() (err error) {
66
66
}
67
67
68
68
w .tasks , err = w .channel .Consume (
69
- q .Name , // queue
70
- "" , // consumer
71
- true , // auto-ack
72
- false , // exclusive
73
- false , // no-local
74
- false , // no-wait
75
- nil , // args
69
+ q .Name , // queue
70
+ w . opts . tag , // consumer
71
+ true , // auto-ack
72
+ false , // exclusive
73
+ false , // no-local
74
+ false , // no-wait
75
+ nil , // args
76
76
)
77
77
78
78
if err != nil {
@@ -152,7 +152,7 @@ func (w *Worker) Shutdown() error {
152
152
if err := w .channel .Cancel ("" , true ); err != nil {
153
153
w .opts .logger .Error (err )
154
154
}
155
- if err := w .client .Close (); err != nil {
155
+ if err := w .conn .Close (); err != nil {
156
156
w .opts .logger .Error (err )
157
157
}
158
158
})
You can’t perform that action at this time.
0 commit comments