Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Support default exchange in consumer and publisher modules #213

Merged
merged 7 commits into from Oct 22, 2020

Conversation

mkorszun
Copy link
Collaborator

@mkorszun mkorszun commented Oct 9, 2020

As requested in https://github.com/meltwater/gen_rmq/issues/206, this PR introduces support for the default exchange in the publisher and consumer module.

Default Exchange

The default exchange is a direct exchange with no name (empty string) pre-declared by the broker. It has one special property that makes it very useful for simple applications: every queue that is created is automatically bound to it with a routing key which is the same as the queue name.

Implementation:
Whenever a publisher is configured with the default exchange, we need to ensure that such an exchange is not redeclared otherwise broker will return an error.

Whenever a consumer is configured with the default exchange, we need ensure that exchange is not redeclared and binding is not created (it already exists).

The default exchange is configured by providing :default atom as an exchange:

def init() do
  [
    exchange: :default
  ]
end

Description

Checklist

  • I have added unit tests to cover my changes.
  • I have improved the code quality of this repo. (refactoring, or reduced number of static analyser issues)
  • I have updated the documentation accordingly

@coveralls
Copy link

Coverage Status

Coverage remained the same at 89.967% when pulling d62e8eb on support-default-exchanges into e67a6ee on master.

@coveralls
Copy link

coveralls commented Oct 9, 2020

Coverage Status

Coverage remained the same at 89.369% when pulling 98a7757 on support-default-exchanges into 28f98d5 on master.

Copy link
Collaborator

@vorce vorce left a comment

Choose a reason for hiding this comment

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

Looks really nice @mkorszun 👍

@@ -4,11 +4,13 @@ defmodule GenRMQ.Binding do
declaring consumer bindings and exchanges.
"""

@type exchange :: String.t() | {exchange_kind(), String.t()}
@type exchange :: String.t() | {exchange_kind(), String.t()} | :default
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add something that explains :default in the documentation here as well? I think it would be the first place I would look.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@vorce good point. Will update / extend the documentation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@vorce added some docs. Let me know if this is smth you had in mind.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@mkorszun yes, perfect 👍

Copy link
Collaborator

@akoutmos akoutmos left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@mkorszun mkorszun merged commit dd341e7 into master Oct 22, 2020
@mkorszun mkorszun deleted the support-default-exchanges branch October 22, 2020 18:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants