webtoucher / yii2-amqp

Yii 2 extension wrapper to communicate with RabbitMQ server via AMQP.
https://packagist.org/packages/webtoucher/yii2-amqp
BSD 3-Clause "New" or "Revised" License
60 stars 41 forks source link

Basic guide for consumer #11

Open thiagotalma opened 9 years ago

thiagotalma commented 9 years ago

@webtoucher Hello!

It would be useful if it were written a basic guide to run the consumer.

What do you use? Supervisord? I've never used anything like this, aid would be very helpful! I'm using a cron 1 minute, but I am sure that is not the best solution.

(PS: The project is abandoned? I hope not. It's a good code.)

Cheers!

unclead commented 9 years ago

the project has been for a long time without support, but I plan to soon revive it

thiagotalma commented 9 years ago

:+1:

unclead commented 9 years ago

If you need an example asup i can give you some code snippets. This is how i use AmqpListenerController for processing incoming message during DIRECT exchange

in config file

'controllerMap' => [
        'rabbit'    => [
            'class'         =>  'webtoucher\amqp\controllers\AmqpListenerController',
            'exchange'      => 'backend-inform',
            'interpreters'  => [
                  'backend-inform' => 'app\components\rabbit\BackendInformInterpreter',
            ], 
        ],
    ],

BackendInformInterpreter.php

/**
 * Class BackendInformInterpreter
 * @package app\components\rabbit
 */
class BackendInformInterpreter extends AmqpInterpreter
{
    /**
     * @param $message
     * @throws \yii\base\Exception
     */
    public function readRenewCache($message)
    {
        // your business logic
    }

Also i prefer to use supervisord for control daemons. You can configure supervisord as in the example below

[program:backend-inform]

command                 = bash -c "/usr/bin/php /path/to/yii rabbit"
process_name            = Backend inform intepreter
numprocs                = 1
autostart               = true
autorestart             = true
user                    = root
stdout_logfile          = /path/to/logs/rabbit.info.log
stdout_logfile_maxbytes = 10MB
stderr_logfile          = /path/to/logs/rabbit.error.log
stderr_logfile_maxbytes = 10MB

But i want to notice that current version of extension a bit outdated. I'm gonna relase version 2.0 with structural changes and improvements. New version will based on our private repo which based on this one but has been developing in parallel

thiagotalma commented 9 years ago

@unclead Great news!

You already have a timeline for this upgrade?