Comments (6)
Adding a getChannel
method in the FactoryInterface
is not a good idea as this concept is specific to RabbitMQ. If you use Redis for example, this method is not implementable.
Furthermore, your getChannel
won't return the same class in all implementations.
I see 2 solutions here.
Solution 1:
In the PeclFactory
you can use the getQueue
public method to achieve your need.
Changing the visibility of the getChannel
method in the AmqpLibFactory
could be a way to retrieve the number of messages.
This solution is abviously a hack. You won't be able to switch between implementations.
Solution 2:
The cleanest solution is probably to add a getMessageCount
method (or something like this) into the MessageProviderInterface
(directly in swarrot library).
It looks like it's easy to implement for SQS as there is a method to retrieve the approximative number of messages in a queue (see here).
For both Pecl & AmqpLib implementations, it looks like it's possible to retrieve the amount of messages using 2 different ways:
- by declaring the queue (see pecl & amqplib): this isn't a perfect solution as it's probably throw an Exception when you try to create a queue without the same config (when it already exists) or when you don't have enough permissions to create queues.
- as you said: by retrieving a message. Again, that's for from perfect, as it means this message needs to be consumed after (which is far from easy).
None of those implementations are perfect unfortunately.
At the end, I don't have any clean solution for your need... :/
The first solution is definitively the easiest to implement but it means you won't be able to easily switch from an implementation to another if you need to.
The second one is cleaner but way harder to implement... (I'm not even sure it's possible! :o)
WDYT?
from swarrotbundle.
Thanks for all these explanations 👍
I noticed the getQueue
after posting my issue.
But I'm using amqp lib atm (didn't took time to compile the pecl extension).
I agree the second solution looks cleaner but more complex.
I'll go with the first solution.
So should I just open a PR with that?
/**
* getChannel.
*
* @param string $connection
*
* @return AMQPChannel
*/
- protected function getChannel($connection)
+ public function getChannel($connection)
from swarrotbundle.
Yes, it looks fine for me.
from swarrotbundle.
May I ask you what's your need exactly? :)
from swarrotbundle.
I have a command that push thousand messages in a queue every 10 minutes.
I would like that command to check if the queue is empty (or have less than XX messages) before sending again new messages.
See j0k3r/banditore#37 🙂
from swarrotbundle.
Thanks. :)
from swarrotbundle.
Related Issues (20)
- Flex recipes ? HOT 2
- Problem when type hinting method process in PHP7 HOT 5
- dot in messages-types are lost in the command help HOT 1
- Why the message type is not used as the queue name by default HOT 3
- Symfony 4.3 deprecations HOT 3
- Symfony Messenger and Swarrot compatibility HOT 1
- Reset application after each consummed message HOT 1
- Install Fail HOT 2
- Allow users to attach aliases to Swarrot commands HOT 2
- Upgrade to 1.8 on Symfony 3.4 HOT 7
- make queue declare before consume queue HOT 1
- Make Swarrot commands lazy HOT 2
- Consumer on multiple queues HOT 3
- Port cannot be configured by env var HOT 2
- Upgrade Doctrine dependencies HOT 4
- AMQPS configuration
- Multiple hosts support HOT 2
- Symfony 6 compatibility HOT 1
- CI needs to migrate away from Travis
- Non-existed services HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swarrotbundle.