Skip to content

Commit 3ebf9ec

Browse files
committed
Fix: Exclusive queue when using worker style
1 parent d1ef69e commit 3ebf9ec

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pkg/eventsourcing/messaging/bus_rabbitmq.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,22 @@ func (b *rabbitEventBus) addHandler(ctx context.Context, handler evs.EventHandle
172172
routingKeys = append(routingKeys, rabbitMatcher.generateRoutingKey())
173173
}
174174

175+
options := []func(*rabbitmq.ConsumeOptions){
176+
rabbitmq.WithConsumeOptionsBindingExchangeName(b.conf.exchangeName),
177+
rabbitmq.WithConsumeOptionsBindingExchangeKind(amqp.ExchangeTopic),
178+
rabbitmq.WithConsumeOptionsBindingExchangeDurable,
179+
}
180+
if workQueueName == "" {
181+
options = append(options, rabbitmq.WithConsumeOptionsQueueExclusive)
182+
}
183+
175184
err := b.consumer.StartConsuming(
176185
func(d amqp.Delivery) bool {
177186
return b.handleIncomingMessages(ctx, d, handler)
178187
},
179188
workQueueName,
180189
routingKeys,
181-
rabbitmq.WithConsumeOptionsBindingExchangeName(b.conf.exchangeName),
182-
rabbitmq.WithConsumeOptionsBindingExchangeKind(amqp.ExchangeTopic),
183-
rabbitmq.WithConsumeOptionsBindingExchangeDurable,
184-
rabbitmq.WithConsumeOptionsQueueExclusive,
190+
options...,
185191
)
186192
if err != nil {
187193
return errors.ErrMessageBusConnection

0 commit comments

Comments
 (0)