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

Passing state to handle_setup #67

Merged
merged 6 commits into from
Mar 11, 2021
Merged

Conversation

Odaeus
Copy link
Contributor

@Odaeus Odaeus commented Jan 13, 2021

Resolves issue #64.

Please review and let me know if the code fits to how you want it to work!

- If the Consumer defines handle_setup/1 (instead of /2) then it will
  receive the entire current state and can update it by returning `{:ok,
  state}`.
- Make `queue` an optional argument to avoid providing an empty value if
  RabbitMQ is expected to generate the queue name in `handle_setup/1`.
- Add test coverage for a Consumer without `handle_setup`.
- Pass the full state if `handle_setup/2` is provided as a callback.
- Allow the result of `handle_setup` to modify the state.
- Add `setup_opts` as an init argument to store in the state.
@nsweeting
Copy link
Owner

Thanks @Odaeus! I will try and review this today.

The queue name might be set dynamically in `handle_setup` instead of
supplying the value on start. If there is no queue name by the time we
start consuming then stop the server.
@Odaeus Odaeus force-pushed the handle_setup_state branch from 3341fb9 to 26c3d69 Compare January 14, 2021 13:56
@Odaeus
Copy link
Contributor Author

Odaeus commented Jan 14, 2021

@nsweeting I've pulled out the "optional queue opt" to a separate commit and added something to return a clear error if there's no queue name by the time it reaches consume. In theory it could automatically declare if there's no queue but that might be confusing behaviour. Obviously this commit can be discarded if you really want to keep the option as required.

@Odaeus Odaeus mentioned this pull request Jan 14, 2021
@Odaeus
Copy link
Contributor Author

Odaeus commented Feb 10, 2021

Hey @nsweeting, just wanted to let you know that I'm planning to merge this and related changes into the master branch of my fork this week. Still happy to make any changes when requested, with the aim that we will eventually be using your official version.

Copy link
Owner

@nsweeting nsweeting left a comment

Choose a reason for hiding this comment

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

Since we are still a pre-1.0 release - I would be fine with making this a "breaking" change in order to maintain this as a cleaner implementation. As long as we make sure to note the change in the release notes.

Based on the above - I think we can drop support for handle_setup/2 and only deal with handle_setup/1 with the state being passed. The expected return value should be {:ok, state} .

I don' t think we need to support a :skip return value. Unless you have a requirement I don't see right now?

Odaeus added 2 commits March 10, 2021 17:18
This backwards-incompatible change simplifies the
`Consumer.handle_setup` usage and implementation.
This backwards-incompatible change simplifies the usage and
implementation of `Producer.handle_setup` while keeping the flexibility
of providing the entire state rather than just the channel.

Also makes it consistent with the equivalent function in `Consumer`.
@Odaeus
Copy link
Contributor Author

Odaeus commented Mar 10, 2021

Sorry for the delay on this! I've removed .handle_setup/2 support. I've done it for both Consumer and Producer, but if you wanted the latter kept feel free to drop the commit.

Hopefully I've updated all the documentation in the right places.

@nsweeting
Copy link
Owner

Sorry for the delay on this! I've removed .handle_setup/2 support. I've done it for both Consumer and Producer, but if you wanted the latter kept feel free to drop the commit.

Hopefully I've updated all the documentation in the right places.

Looks great @Odaeus! Will merge and cut a new release. Thanks.

@nsweeting nsweeting merged commit a931b87 into nsweeting:master Mar 11, 2021
@nsweeting
Copy link
Owner

@Odaeus Had to submit PR #73 to support Rabbit.ConsumerSupervisor.handle_setup/1 which I missed within this PR. No big deal though. Version 0.13.0 should be available now - https://hex.pm/packages/rabbit/0.13.0.

@Odaeus
Copy link
Contributor Author

Odaeus commented Mar 12, 2021

Thanks so much!

@Odaeus Odaeus mentioned this pull request Mar 12, 2021
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.

2 participants