Skip to content

Commit 0315b10

Browse files
committed
fix: adjust consumer tags
1 parent 90a6fce commit 0315b10

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

pubsub/consumer.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,24 @@ type Consumer struct {
88
exchange string
99
queue string
1010
exchangeType string
11+
tag string
12+
}
13+
14+
type Config struct {
15+
ExchangeType ExchangeType
16+
ConsumerTag string
1117
}
1218

1319
// Create a new consumer instance
14-
func NewConsumer(rabbitURL, exchange, queue string, exchangeType ExchangeType) *Consumer {
15-
return &Consumer{rabbitURL, exchange, queue, string(exchangeType)}
20+
func NewConsumer(rabbitURL, exchange, queue string, config ...Config) *Consumer {
21+
c := Consumer{url: rabbitURL, exchange: exchange, queue: queue, exchangeType: string(Direct)}
22+
23+
if len(config) > 0 {
24+
c.exchangeType = string(config[0].ExchangeType)
25+
c.tag = config[0].ConsumerTag
26+
}
27+
28+
return &c
1629
}
1730

1831
// Consume consume messages from the channels
@@ -30,7 +43,7 @@ func (c *Consumer) Consume(workerFunc func([]byte)) error {
3043

3144
deliveries, err := ch.Consume(
3245
c.queue, // queue
33-
"", // consumer
46+
c.tag, // consumerTag
3447
true, // auto-ack
3548
false, // exclusive
3649
false, // no-local

0 commit comments

Comments
 (0)