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 configuring topology more flexible #72

Merged
merged 11 commits into from
May 10, 2019
Merged

Make configuring topology more flexible #72

merged 11 commits into from
May 10, 2019

Conversation

bkielbasa
Copy link
Contributor

Ou our RabbitMQ, we have topologies with 2 exchanges and we use routing keys to route the messages between exchanges/queues.

The problem we are facing is that we cannot configure 2 topologies currently. The fix adds a builder which can be easily replaced with a custom one.

There are no breaking changes.

)

type topologyBuilder interface {
buildTopology(channel *amqp.Channel, queueName string, logFields watermill.LogFields, exchangeName string, exchangeDeclarer exchangeDeclarer) error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about adding exchangeDeclarer DeclareExchange(channel *amqp.Channel, exchangeName string) error) ? to the interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, definitely good idea

"github.com/streadway/amqp"
)

type topologyBuilder interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it will be a good idea to make it public (may be useful for example for Dependency Injection)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildTopology can be also public :)

@@ -91,6 +94,10 @@ func (s *Subscriber) Subscribe(ctx context.Context, topic string) (<-chan *messa
return out, nil
}

func (s *Subscriber) SetTopologyBuilder(builder topologyBuilder) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe using Config to pass builder (with defaultBuilder default value) may be a cleaner way? and it will be also backward compatible and more consistent with the rest of the code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in that case probably it will be a better idea to pass Config to buildTopology method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem with this solution is that:

  • while creating the topologyBuilder I don't have the config yet
func NewDurablePubSubConfig(amqpURI string, generateQueueName QueueNameGenerator) Config {
	config := Config{
		Connection: ConnectionConfig{
			AmqpURI: amqpURI,
		},

		Marshaler: DefaultMarshaler{},

		Exchange: ExchangeConfig{
			GenerateName: func(topic string) string {
				return topic
			},
			Type:    "fanout",
			Durable: true,
		},
		Queue: QueueConfig{
			GenerateName: generateQueueName,
			Durable:      true,
		},
		QueueBind: QueueBindConfig{
			GenerateRoutingKey: func(topic string) string {
				return ""
			},
		},
		Publish: PublishConfig{
			GenerateRoutingKey: func(topic string) string {
				return ""
			},
		},
		Consume: ConsumeConfig{
			Qos: QosConfig{
				PrefetchCount: 1,
			},
		},
	}
	
	config.TopologyBuilder = DefaultTopologyBuilder{
		config:config,
	}
	
	return config
}

I'm not sure if it's a clearer way :) you decide

and the second is that I don't have the logger there so we have two options:

  • add the logger separately (everyone who uses ex NewDurablePubSubConfig will have to add the logger)
  • remove the logger from buildTopology but we'll lose some logs
  • add logger to method NewDurablePubSubConfig

if we choose the last option, maybe it's a good idea (in next step) to have separate configuration for every topology?

WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we can pass config and logger as the argument to DeclareExchange function, it will become pretty long but I think that here it will be not a problem because it will be not often used and all params types are different so it will be no problem with confused

@roblaszczak roblaszczak merged commit 2972718 into ThreeDotsLabs:master May 10, 2019
@bkielbasa
Copy link
Contributor Author

@roblaszczak thanks for merging! Can you create the tag as before? :P

@roblaszczak
Copy link
Member

done, thanks again! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants