Skip to content

Commit 405c292

Browse files
committed
fix: generic pubsub
1 parent a47e2f2 commit 405c292

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

pubsub/publisher.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package pubsub
22

33
import (
4+
"fmt"
45
"time"
56

67
"github.com/streadway/amqp"
@@ -22,14 +23,13 @@ func NewPublisher(rabbitURL, exchange, queue string) *publisher {
2223
func (p *publisher) publish(body []byte, delay time.Duration) error {
2324
conn, ch, err := initQ(p.url)
2425
if err != nil {
25-
return err
26+
return fmt.Errorf("failed to initialize a connection: %s", err.Error())
2627
}
27-
2828
defer ch.Close()
2929
defer conn.Close()
3030

3131
if err := initPubSub(ch, p.exchange, p.queue); err != nil {
32-
return err
32+
return fmt.Errorf("failed to initialize a pubsub: %s", err.Error())
3333
}
3434

3535
// publish message to exchange

pubsub/pubsub.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ import (
99
func initQ(url string) (*amqp.Connection, *amqp.Channel, error) {
1010
conn, err := amqp.Dial(url)
1111
if err != nil {
12-
return nil, nil, err
12+
return nil, nil, fmt.Errorf("failed to connect to RabbitMQ: %s", err.Error())
1313
}
1414

1515
ch, err := conn.Channel()
1616
if err != nil {
17-
return nil, nil, err
17+
return nil, nil, fmt.Errorf("failed to open a channel: %s", err.Error())
1818
}
1919

2020
err = ch.Qos(1, 0, false) // fair dispatch
2121
if err != nil {
22-
return nil, nil, err
22+
return nil, nil, fmt.Errorf("failed to set QoS: %s", err.Error())
2323
}
2424

2525
return conn, ch, nil

0 commit comments

Comments
 (0)