Skip to content
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

Writing a Custom Provider #97

Open
talisman-innovations opened this issue May 12, 2016 · 8 comments
Open

Writing a Custom Provider #97

talisman-innovations opened this issue May 12, 2016 · 8 comments

Comments

@talisman-innovations
Copy link

talisman-innovations commented May 12, 2016

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
Copy link
Author

talisman-innovations commented May 13, 2016

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
Copy link

odinns commented Jun 6, 2016

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

@talisman-innovations
Copy link
Author

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
Copy link

odinns commented Jun 7, 2016

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
Copy link

odinns commented Jun 30, 2016

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
Copy link
Author

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 #97 (comment), or mute the thread https://github.com/notifications/unsubscribe/AO7HJ3vbvCANSyI-raF68tMYjUTwBGLUks5qQ3oJgaJpZM4IdPxG.

@odinns
Copy link

odinns commented Jun 30, 2016

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant