1
1
package pubsub
2
2
3
3
import (
4
- "fmt"
5
4
"time"
6
5
7
6
"github.com/streadway/amqp"
@@ -14,10 +13,9 @@ type publisher struct {
14
13
queue string
15
14
}
16
15
17
- // newPublisher ...
18
- func newPublisher (queueName string ) * publisher {
19
- exchange := fmt .Sprintf ("%s-exchange" , queueName )
20
- return & publisher {rabbitURL , exchange , queueName }
16
+ // NewPublisher creates a new publisher to rabbit
17
+ func NewPublisher (rabbitURL , exchange , queue string ) * publisher {
18
+ return & publisher {rabbitURL , exchange , queue }
21
19
}
22
20
23
21
// publish ...
@@ -54,13 +52,11 @@ func (p *publisher) publish(body []byte, delay time.Duration) error {
54
52
}
55
53
56
54
// PublishWithDelay ...
57
- func PublishWithDelay (queueName string , body []byte , delay time.Duration ) error {
58
- p := newPublisher (fmt .Sprintf ("%s-%s" , queuePrefix , queueName ))
55
+ func (p * publisher ) PublishWithDelay (queueName string , body []byte , delay time.Duration ) error {
59
56
return p .publish (body , delay )
60
57
}
61
58
62
59
// Publish ...
63
- func Publish (queueName string , body []byte ) error {
64
- p := newPublisher (fmt .Sprintf ("%s-%s" , queuePrefix , queueName ))
60
+ func (p * publisher ) Publish (queueName string , body []byte ) error {
65
61
return p .publish (body , 0 )
66
62
}
0 commit comments