-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
always declare a queue in factory, even with auto_setup_fabric disabled #61
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.
Maybe add a purge command for rabbitmq before each test to test every branch separated. Random queue/exchange names could also work therefor.
src/Container/QueueFactory.php
Outdated
@@ -163,8 +163,6 @@ public function __invoke(ContainerInterface $container): Queue | |||
$exchangeObjects[$exchange] = ExchangeFactory::$exchange($container, $this->channel, true); | |||
} | |||
|
|||
$queue->declareQueue(); |
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 would potentially fail, if auto_setup_fabric is true, since you would bind a queue to an exchange which is not declared.
How? When auto setup fabric is used, the exchange gets created first.
…On Dec 15, 2017 6:10 PM, "Eric Braun" ***@***.***> wrote:
***@***.**** requested changes on this pull request.
Maybe add a purge command for rabbitmq before each test to test every
branch separated. Random queue/exchange names could also work therefor.
------------------------------
In src/Container/QueueFactory.php
<#61 (comment)>:
> @@ -163,8 +163,6 @@ public function __invoke(ContainerInterface $container): Queue
$exchangeObjects[$exchange] = ExchangeFactory::$exchange($container, $this->channel, true);
}
- $queue->declareQueue();
This would potentially fail, if auto_setup_fabric is true, since you would
bind a queue to an exchange which is not declared.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#61 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAYEvN_tK-ms9dlAZ3sYr47g5ZKu7HHyks5tAkV7gaJpZM4QqZvU>
.
|
Sorry, I expressed it badly. You create an exchange and bind the queue to the exchange. And than you create the queue. Currently, the tests doesn't fail, while you create the queue in another test. So every test should purge the whole rabbitmq queues/exchanges before run. |
Ah I see. Will try to fix this tomorrow unless you provide a PR first.
…On Dec 17, 2017 12:05 AM, "Eric Braun" ***@***.***> wrote:
Sorry, I expressed it badly.
You create a exchange and bind the queue to the exchange. And than you
create the queue.
This would fail, since the queue would be bound to the exchange before the
queue exists.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#61 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAYEvJADhvmtLA1MoRuTHTKyvnmUPYiHks5tA-pDgaJpZM4QqZvU>
.
|
@oqq good to release now? |
That seems not to be enough to fix the issue. So given for an exclusive rpc queue, the queue would be created but never be bind to an exchange. I still have to set auto_setup_fabric, but this would also create the exchange, which already exists on the broker with a configuration I am not always aware about. |
ping @oqq - wanna check this? |
src/Container/QueueFactory.php
Outdated
$exchanges = iterator_to_array($exchanges); | ||
} | ||
|
||
if (! is_array($exchanges) || empty($exchanges)) { |
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.
It should not be necessary for this library to bind a queue to an exchange.
E.g. a service which purges queues (or handles other tasks) needs only to know the queue name, but not the name of the exchange.
src/Container/QueueFactory.php
Outdated
$bindArguments = $exchangeOption['bind_arguments'] ?? []; | ||
$this->bindQueue($queue, $exchangeName, $routingKeys, $bindArguments); | ||
} | ||
$exchangeObjects[$exchange] = ExchangeFactory::$exchange($container, $this->channel, false); |
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.
Here my advice for a code cleanup:
$autoSetupFabric = $this->autoSetupFabric || $options['auto_setup_fabric'];
if ($autoSetupFabric && isset($options['arguments']['x-dead-letter-exchange'])) {
$exchangeName = $options['arguments']['x-dead-letter-exchange'];
ExchangeFactory::$exchangeName($container, $this->channel, true);
}
foreach ($exchanges as $exchange => $exchangeOptions) {
$exchangeObjects[$exchange] = ExchangeFactory::$exchange($container, $this->channel, $autoSetupFabric);
}
An anonymous queue (without name) needs exchange binding upfront, so it can
consume messages.
…On Dec 31, 2017 19:06, "Eric Braun" ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/Container/QueueFactory.php
<#61 (comment)>:
> @@ -139,6 +139,19 @@ public function __invoke(ContainerInterface $container): Queue
$queue->setFlags($this->getFlags($options));
$queue->setArguments($options['arguments']);
+ $exchanges = $options['exchanges'];
+
+ if ($exchanges instanceof \Traversable) {
+ $exchanges = iterator_to_array($exchanges);
+ }
+
+ if (! is_array($exchanges) || empty($exchanges)) {
It should not be necessary for this library to bind a queue to an exchange.
E.g. a service which purges queues (or handles other tasks) needs only to
know the queue name, but not the name of the exchange.
------------------------------
In src/Container/QueueFactory.php
<#61 (comment)>:
> foreach ($exchanges as $exchange => $exchangeOptions) {
- $exchangeObject = $exchangeObjects[$exchange];
- $exchangeName = $exchangeObject->getName();
- if (empty($exchangeOptions)) {
- $this->bindQueue($queue, $exchangeName, [], []);
- } else {
- foreach ($exchangeOptions as $exchangeOption) {
- $routingKeys = $exchangeOption['routing_keys'] ?? [];
- $bindArguments = $exchangeOption['bind_arguments'] ?? [];
- $this->bindQueue($queue, $exchangeName, $routingKeys, $bindArguments);
- }
+ $exchangeObjects[$exchange] = ExchangeFactory::$exchange($container, $this->channel, false);
Here my advice for a code cleanup:
$autoSetupFabric = $this->autoSetupFabric || $options['auto_setup_fabric'];if ($autoSetupFabric && isset($options['arguments']['x-dead-letter-exchange'])) { $exchangeName = $options['arguments']['x-dead-letter-exchange']; ExchangeFactory::$exchangeName($container, $this->channel, true);}foreach ($exchanges as $exchange => $exchangeOptions) { $exchangeObjects[$exchange] = ExchangeFactory::$exchange($container, $this->channel, $autoSetupFabric);}
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#61 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAYEvIUT14NnlaEvEgEBtU8LnxBhcwsEks5tF2rJgaJpZM4QqZvU>
.
|
This factory is not used only for anonymous queues, or is it? But I see also a service wich simply calls some amqp methods on an anonymous queue which already exists, without knowing her exchange bindings. This would be impossible to implemented with this library if I always need to define exchanges. This would be a BC break by the way. ;) |
@oqq I'm thinking about this solution:
Additional I have another thought on auto_setup_fabric considering queues... current behaviour is, that the exchanges are also getting created. Maybe we remove this feature and add another option auto_setup_exchanges => true/false additionally to the queue factory. As this is a bigger problem here which leads to unexpected errors, I'm ok with slightly breaking BC and will update docs/ release notes accordingly. |
@oqq Sorry for taking so much time, I think the new behaviour here is good, I also updated the readme. Can you check please? |
ping @oqq |
@prolic this would still produce errors, if you try to bind a queue to an exchange before declaring it.
|
@oqq updated |
I have an application with a complex infrastructure and all tests run successfully with this patch. So I assume this would fix the issue. Thanks! |
alternative solution to #57
ping @oqq