-
Notifications
You must be signed in to change notification settings - Fork 331
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
Allow sneakers to be run without an exchange #401
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for open this PR! The changes look straightforward and the existing specs passing is a great sign of backwards compatibility.
Can you add some specs to queue_spec.rb
and worker_spec.rb
that explicitly test the nil
exchange case(s)? Do you think we should add an example worker as well?
Hi Gabriel, I have added a bit of test in worker_spec.rb ; however I'm a bit lost in the queue_spec tests and would probably need a bit of a help :-) I'm not sure if an example is really useful, probably a notice in the documentation would be sufficient. But I'm not sure where is the best place for it, the options for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks reasonable except for the test. Thank you.
spec/sneakers/worker_spec.rb
Outdated
@@ -296,6 +308,10 @@ def work(msg) | |||
@dummy_q = DummyWorker.new.queue | |||
@dummy_q.opts[:connection].must_equal(@connection) | |||
end | |||
|
|||
it "should build a queue without an exchange" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this test to be confusing. What does a queue have to do with an exchange? If there is no way to make it clearer, let's drop it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, after re-reading, this is really confusing. Sorry, I'm not familiar at all with the test logic. I've made a correction for this test which, maybe, makes more sense.
thoughts on |
I do think an example would help prove that the consumer behaves the way we expect even when no exchange. |
Ouch, good point. This line is also problematic. Within the current architecture, we cannot have a publisher on a worker if the queue's exchange is not authorized for writing : this case does not really fit sneakers' architecture where a worker deduces its publisher from its queue's parameters. Not sure what we should do here... raise an exception (seems too restrictive to me, the worker will not be able to have a publisher). Or allow a worker to have an exchange for publishing different from the one the queue is bound to? That may lead to complicated refactoring... One solution I can imagine, though, is instead of passing |
yea, it feels like we need to answer this question: what does it mean to publish without an exchange? if publish has no meaning when no exchange, then maybe we have a no-op publisher or even have a separate worker? it does feel like |
I do agree with you, all the more that this looks like repeated code : publisher vs worker.
Indeed. The aim of a worker's publisher is (to my understanding) to have a simple way to answer easily to messages within the worker's handling code ; I've personally never had the use for it since in most cases I use sneakers as an entry point and the "publishing" part is done somewhere else without sneakers. But I understand perfectly the use for it. Within sneakers "convenient" easy-to-use model, an exchange may be needed for replying ; my objection against the current model is, why should it necessarily be the queue's exchange? Probably for keeping the model simple, i.e. sneakers offers a default publisher which is by design bound to the queue's exchange. If one needs another publisher he/she can create it aside and use it for replying. So my proposition is the following :
That way, we should not break anything and keep the compatibility, but be able to create workers on queues without specifying an exchange (with exchange =>nil), and have the possibility to override the default publisher's behavior. What's your on opinion and do you have alternative ideas? :) |
I like the idea of worker "independent of publishing." |
Thank you, @michaelklishin, for your feedback on that matter! @gabrieljoelc are you ok to go for a |
@BenTalagan that's a good idea. However, I think the framework should default to the no-op publisher when |
Sneakers now has a new home under https://github.com/ruby-amqp/kicks. May I ask you to re-submit this PR there? Thank you 🙏 |
This is a basic, minimal draft for implementing this feature : sneakers should (optionally) be able to run on a queue without having to mess at all with the exchange on which the queue is bound. This is important in configurations where the queue already exists and no authorizations are given on the exchange itself. See #399.
Passing explicitly
exchange =>nil
to the sneakers queue configuration will bypass the exchange handling part (until now, sneakers would crash in that configuration). It will not break the compatibility with configurations where a sneakers exchange is not given at all (it will default to the 'sneakers' exchange just as before). I've also run the tests and nothing's reported broken. I'm not familiar with sneakers source, but haven't found other parts of the source that could be impacted by these changes.Example of use :