Skip to content

Commit

Permalink
make routing key dynamic in queue bind (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartłomiej Klimczak authored and roblaszczak committed May 7, 2019
1 parent 6367896 commit 7ee3f6c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
26 changes: 21 additions & 5 deletions message/infrastructure/amqp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ func NewDurablePubSubConfig(amqpURI string, generateQueueName QueueNameGenerator
GenerateName: generateQueueName,
Durable: true,
},
QueueBind: QueueBindConfig{},
QueueBind: QueueBindConfig{
GenerateRoutingKey: func(topic string) string {
return ""
},
},
Publish: PublishConfig{
GenerateRoutingKey: func(topic string) string {
return ""
Expand Down Expand Up @@ -83,7 +87,11 @@ func NewNonDurablePubSubConfig(amqpURI string, generateQueueName QueueNameGenera
Queue: QueueConfig{
GenerateName: generateQueueName,
},
QueueBind: QueueBindConfig{},
QueueBind: QueueBindConfig{
GenerateRoutingKey: func(topic string) string {
return ""
},
},
Publish: PublishConfig{
GenerateRoutingKey: func(topic string) string {
return ""
Expand Down Expand Up @@ -124,7 +132,11 @@ func NewDurableQueueConfig(amqpURI string) Config {
GenerateName: GenerateQueueNameTopicName,
Durable: true,
},
QueueBind: QueueBindConfig{},
QueueBind: QueueBindConfig{
GenerateRoutingKey: func(topic string) string {
return ""
},
},
Publish: PublishConfig{
GenerateRoutingKey: func(topic string) string {
return topic
Expand Down Expand Up @@ -163,7 +175,11 @@ func NewNonDurableQueueConfig(amqpURI string) Config {
Queue: QueueConfig{
GenerateName: GenerateQueueNameTopicName,
},
QueueBind: QueueBindConfig{},
QueueBind: QueueBindConfig{
GenerateRoutingKey: func(topic string) string {
return ""
},
},
Publish: PublishConfig{
GenerateRoutingKey: func(topic string) string {
return topic
Expand Down Expand Up @@ -350,7 +366,7 @@ type QueueConfig struct {
// be routed to the queue when the publishing routing key matches the binding
// routing key.
type QueueBindConfig struct {
RoutingKey string
GenerateRoutingKey func(topic string) string

// When noWait is false and the queue could not be bound, the channel will be
// closed with an error.
Expand Down
2 changes: 1 addition & 1 deletion message/infrastructure/amqp/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (s *Subscriber) prepareConsume(queueName string, exchangeName string, logFi

if err := channel.QueueBind(
queueName,
s.config.QueueBind.RoutingKey,
s.config.QueueBind.GenerateRoutingKey(queueName),
exchangeName,
s.config.QueueBind.NoWait,
s.config.QueueBind.Arguments,
Expand Down

0 comments on commit 7ee3f6c

Please sign in to comment.