uecode / qpush-bundle

Asynchronous processing for Symfony using Push Queues
qpush-bundle.readthedocs.org
Apache License 2.0
168 stars 54 forks source link

Writing a Custom Provider #97

Open talisman-innovations opened 8 years ago

talisman-innovations commented 8 years ago

Hi

I'm trying to write a custom provider which uses a DB via Doctrine to queue and persist the messages. I've run some tests using the sync driver which works fine. I've now implemented the beginning of the custom provider by implementing ProviderInterface. However when I try to use the new custom queue I get the following message

Warning: Missing argument 1 for AppBundle\QPush\DoctrineProvider::__construct(), called in /Users/sbrookes/Development/symfony/app/cache/dev/appDevDebugProjectContainer.php on line 1839 and defined

As if the customer provider isn't calling the constructor with any arguments. Any ideas or some working code that implements a custom provider I can work from?

Thanks

Steve

Section from config.yml

uecode_qpush:

providers:
    in_band:
        driver: sync
    file_based:
        driver: file
        path: %kernel.root_dir%/tmp
    custom_provider:
        driver: custom
        service: qpush.doctrine

queues:
    tide_queue:
        provider: file_based
        options:
          message_delay:          0
          push_notifications:     true
          messages_to_receive:    100
    tide_queue1:
        provider: custom_provider

Services.yml

services:

qpush.doctrine:
    class: AppBundle\QPush\DoctrineProvider

DoctrineProvider.php

namespace AppBundle\QPush;

use Doctrine\Common\Cache\Cache; use Symfony\Bridge\Monolog\Logger; use AppBundle\Entity\DoctrineMessage; use Uecode\Bundle\QPushBundle\Event\MessageEvent; use Uecode\Bundle\QPushBundle\Message\Message; use Uecode\Bundle\QPushBundle\Provider\ProviderInterface;

class DoctrineProvider implements ProviderInterface { protected $em;

/**
 * Constructor for Provider classes
 *
 * @param string $name    Name of the Queue the provider is for
 * @param array  $options An array of configuration options for the Queue
 * @param mixed  $client  A Queue Client for the provider
 * @param Cache  $cache   An instance of Doctrine\Common\Cache\Cache
 * @param Logger $logger  An instance of Symfony\Bridge\Mongolog\Logger
 */
public function __construct($name, array $options, $client, Cache $cache, Logger $logger)
{
    $this->name     = $name;
    $this->options  = $options;
    $this->cache    = $cache;
    $this->logger   = $logger;
    $this->em       = $this->getDoctrine()->getManager();
}

Other functions still in development

talisman-innovations commented 8 years ago

So I managed to get this to work by injecting the missing information in via the service definition. This works OK, but seems a but convoluted

qpush.doctrine:
    class: AppBundle\QPush\DoctrineProvider
    arguments: [ "tide_queue1", {}, 'AppBundle\QPush\DoctrineProvider', '@uecode_qpush.file_cache', '@logger']
    calls:
        - [setEntityManager, ['@doctrine.orm.entity_manager']]`
odinns commented 8 years ago

Hi there! I am interested in your solution for this. Have you completed the provider in the mean time?

talisman-innovations commented 8 years ago

Hi - yes we a have a working prototype, but not deployed it in anger yet. Would be good to hear if this is the right way to extend the providers though.

odinns commented 8 years ago

Alright. Well I am still adjusting to Symfony after a some time on Laravel, so I can't really tell if it's the right way :-)

odinns commented 8 years ago

Any progress on this? We could use this for a project here, and I'd like to help finishing the DoctrineProvider if you'll allow me :-)

talisman-innovations commented 8 years ago

Hi

Yes we have it all working here. I was thinking of submitting it to the project as a new native provider as the custom provider solution is a pain to work with when you want multiple queues etc. Not had a chance to do that yet though as the code needs a bit of a rework for that. I’ll ask the developer if it would be welcome as an addition

Steve

On 30 Jun 2016, at 09:10, Odinn Adalsteinsson notifications@github.com wrote:

Any progress on this? We could use this for a project here, and I'd like to help finishing the DoctrineProvider if you'll allow me :-)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/uecode/qpush-bundle/issues/97#issuecomment-229591541, or mute the thread https://github.com/notifications/unsubscribe/AO7HJ3vbvCANSyI-raF68tMYjUTwBGLUks5qQ3oJgaJpZM4IdPxG.

odinns commented 8 years ago

I'd be very happy with your working solution as is and rework it as needed, since we're in a situation using the file provider and it backfiring on us due to filesystem rights. So I'd have to implement it myself anyway if I can't use yours.

talisman-innovations commented 8 years ago

Check out pull request #110 for a native implementation of a doctrine provider.