GithubHelp home page GithubHelp logo

Comments (6)

odolbeau avatar odolbeau commented on September 7, 2024

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.

j0k3r avatar j0k3r commented on September 7, 2024

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.

odolbeau avatar odolbeau commented on September 7, 2024

Yes, it looks fine for me.

from swarrotbundle.

odolbeau avatar odolbeau commented on September 7, 2024

May I ask you what's your need exactly? :)

from swarrotbundle.

j0k3r avatar j0k3r commented on September 7, 2024

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.

odolbeau avatar odolbeau commented on September 7, 2024

Thanks. :)

from swarrotbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.