Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make routing key dynamic in queue bind #70

Merged
merged 1 commit into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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