Vinelab / minion

A Simplified Client for WAMP v2 (Web Application Messaging Protocol) with command line support - PHP WebSocket Made Easy
MIT License
126 stars 16 forks source link

Getting Invalid Provider Exception #2

Closed arjundas closed 8 years ago

arjundas commented 9 years ago

I use this plugin to get notification in my client app ( angularjs ) from server ( Laravel 4.2 ), I implement autobahn.js at client side, but when i implement Vinelab/minion library in Laravel and trying to run minion by calling php artisan minion:run it give me error like

 [Vinelab\Minion\InvalidProviderException]
 Provider Vinelab\Minion\ChatProvider must be an instance of \Vinelab\Minion
 \Provider

directory structure

and in app/config/packages/vinelab/minion/minion.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Router Realm
    |--------------------------------------------------------------------------
    |
    | The realm that the router should use.
    |
    */
    'realm' => 'minion',

    /*
    |--------------------------------------------------------------------------
    | Router Host
    |--------------------------------------------------------------------------
    |
    | The IP or hostname that the router should run under.
    |
    */
    'host' => '127.0.0.1',

    /*
    |--------------------------------------------------------------------------
    | Router Port
    |--------------------------------------------------------------------------
    |
    | The port that should be used by the router.
    |
    */
    'port' => 9090,

    /*
    |--------------------------------------------------------------------------
    | Auto-registered Providers
    |--------------------------------------------------------------------------
    |
    | The providers listed here will be automatically registered on the
    | session start of the router, in return their role is to register RPCs,
    | subscribe and publish to topics and pretty much whatever an Internal Client does.
    |
    */
    'providers' => [

        'ChatProvider'

    ],

    'debug' => true,

];

and in providers/ChatProvider.php

<?php

use Vinelab\Minion\Provider;

class ChatProvider extends Provider {

    protected $prefix = 'order.';

    public function boot()
    {
        // will be registered to topic: chat.send
        $this->register('send', 'sendMessage');
    }

    public function sendMessage($args, $data)
    {
        $message = $data->message;

        // store message in the database

        // tell everyone about it
        $this->publish('message', compact('message'));

        // response with the status
        return true;
    }
    }
}

I check for various name space and lot of things but i can not solve this.

Please tell where i am wrong.

Thanks...

Mulkave commented 9 years ago

What version of Laravel are you using ?

Mulkave commented 9 years ago

Ah, I see from your structure it seems to be Laravel 4. can you please use the following in your composer.json:

{
   "vinelab/minion": "1.2"
}

then perform a composer update and try again.

arjundas commented 9 years ago

NO, its not work, :(,

I am using modular structure in Laravel, Can it affect this?

I am using creolab/laravel-modules for Modularization in laravel.

Mulkave commented 9 years ago

It shouldn't matter what structure you use, as long as your provider is extending Vinelab\Minion\Provider it should work.

If you are running minion using artisan make sure you tell minion about your ChatProvider class with the register option:

php artisan minion:run --register="ChatProvider"
arjundas commented 9 years ago

I tried this also but it still not working.

Mulkave commented 9 years ago

seems like Minion is detecting the wrong ChatProvider class

ChaosPower commented 9 years ago

@arjundas I replied to your stackoverflow. @Mulkave is right, it is detecting a different ChatProvider class. Make sure Laravel is loading providers folder or you can't just use ChatProvider directly. You need to specify proper namespacing. PSR-0 standard.

namespace Providers\ChatProvider;

then you register ChatProvider like this --register"Providers\ChatProvider" you need to specify composer what to autoload.

Minion and Laravel are loading differently. That's why you need to specify a namespace.

prbaron commented 9 years ago

Just got the same error. I am using Laravel 4. Here is my folder configuration :

app
    + Arato
        + push
            - AlertProvider.php
    + commands
    + config
    + controllers

in my composer.json :

"autoload": {
    "classmap": [
        ...
        "app/Arato"
    ]
}

the minion.php :

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Router Realm
    |--------------------------------------------------------------------------
    |
    | The realm that the router should use.
    |
    */
    'realm'     => 'minion',

    /*
    |--------------------------------------------------------------------------
    | Router Host
    |--------------------------------------------------------------------------
    |
    | The IP or hostname that the router should run under.
    |
    */
    'host'      => '127.0.0.1',

    /*
    |--------------------------------------------------------------------------
    | Router Port
    |--------------------------------------------------------------------------
    |
    | The port that should be used by the router.
    |
    */
    'port'      => 9090,

    /*
    |--------------------------------------------------------------------------
    | Auto-registered Providers
    |--------------------------------------------------------------------------
    |
    | The providers listed here will be automatically registered on the
    | session start of the router, in return their role is to register RPCs,
    | subscribe and publish to topics and pretty much whatever an Internal Client does.
    |
    */
    'providers' => [
        "Arato\push\AlertProvider"
    ],

    'debug'     => true,

];

the AlertProvider.php file :

<?php
namespace Arato\push;

use Vinelab\Minion\Provider;

class AlertProvider extends Provider
{
    public function boot()
    {
        $this->publish('i.am.here', ['name' => 'mr.minion']);
    }
}

I do not know why the namespace is incorrect.

Best regards.

Mulkave commented 9 years ago

The problem is a namespace problem, you are classmapping in composer instead of autoloading with PSR, try:

"autoload": {
   " ...",
   "psr-0": {
       "Arato": "app/"
    }
}

And as a standard convention, try uppercasing the push folder, namespace and provider such as:

namespace Arato\Push;
prbaron commented 9 years ago

Thank you, I think it should be fixed now.

However I still have a problem, when I run php artisan minion:run with debug to true, I get the following :

2015-03-16T21:16:44.3259470 info       [Thruway\Transport\PawlTransportProvider 7393] Starting Transport
2015-03-16T21:16:44.3288680 info       [Thruway\Transport\PawlTransportProvider 7393] Pawl has connected
2015-03-16T21:16:44.3311980 debug      [Thruway\Transport\PawlTransportProvider 7393] Received: [2,356050420,{"roles":{"broker":{"features":{"publisher_exclusion":true,"subscriber_blackwhite_listing":true,"subscription_meta_api":true,"pattern_based_subscription":true,"publisher_identification":true}},"dealer":{"features":{"progressive_call_results":true,"shared_registration":true,"registration_meta_api":true,"pattern_based_registration":true,"caller_identification":true}}},"authid":"oJp4lmZNL5TWfnh2ADMzOO7K","authrole":"anonymous","authmethod":"anonymous"}]
2015-03-16T21:16:44.3313030 debug      [Vinelab\Minion\Client 7393] Client onMessage: [Thruway\Message\WelcomeMessage]
2015-03-16T21:16:44.3313290 info       [Vinelab\Minion\Client 7393] We have been welcomed...
2015-03-16T21:16:44.3327700 info       [Thruway\Transport\PawlTransportProvider 7393] Pawl has closed
2015-03-16T21:16:45.8362700 info       [Thruway\Transport\PawlTransportProvider 7393] Starting Transport
2015-03-16T21:16:45.8389650 info       [Thruway\Transport\PawlTransportProvider 7393] Pawl has connected
2015-03-16T21:16:45.8412010 debug      [Thruway\Transport\PawlTransportProvider 7393] Received: [2,1628429246,{"roles":{"broker":{"features":{"publisher_exclusion":true,"subscriber_blackwhite_listing":true,"subscription_meta_api":true,"pattern_based_subscription":true,"publisher_identification":true}},"dealer":{"features":{"progressive_call_results":true,"shared_registration":true,"registration_meta_api":true,"pattern_based_registration":true,"caller_identification":true}}},"authid":"o67hOrx3oruFbO62ecd1o567","authrole":"anonymous","authmethod":"anonymous"}]
2015-03-16T21:16:45.8413230 debug      [Vinelab\Minion\Client 7393] Client onMessage: [Thruway\Message\WelcomeMessage]
2015-03-16T21:16:45.8413510 info       [Vinelab\Minion\Client 7393] We have been welcomed...
2015-03-16T21:16:45.8430050 info       [Thruway\Transport\PawlTransportProvider 7393] Pawl has closed

and it is looping.

EDIT : seems this behavior comes from $this->publish('i.am.here', ['name' => 'mr.minion']); EDIT 2 :

it should be

$this->publish('i.am.here', [], ['name' => 'mr.minion']);
Mulkave commented 9 years ago

@prbaron exactly! It is publish($topic, $args, $kwArgs) where $args is an array of arguments and $kwArgs is the key-value array. Glad you had it resolved.