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 40 forks source link

Job Queue #2

Closed MrAwanishKumar closed 9 years ago

MrAwanishKumar commented 9 years ago

HI!!

I want to use yii2-amqp for sending 1000+ Mail & SMS. I gone through this link https://github.com/webtoucher/yii2-amqp step by step & installed but I'm unable to understand where (which location of Yii2 directory structure) create RabbitInterpreter file & call

Add messages interpreter class @app/components/RabbitInterpreter with your handlers for different routing keys:

<?php

namespace app\components;

use webtoucher\amqp\components\AmqpInterpreter;

class RabbitInterpreter extends AmqpInterpreter { /* * Interprets AMQP message with routing key 'hello_world'. * @param array $message */ public function readHelloWorld($message) { // todo: write message handler $this->log(print_r($message, true)); } }

Thanks

webtoucher commented 9 years ago

Anywhere you want. If you use namespace 'app\components' file path will be 'application/components/RabbitInterpreter.php'

MrAwanishKumar commented 9 years ago

Yes got it

MrAwanishKumar commented 9 years ago

Now another problem arises -- reference link https://github.com/webtoucher/yii2-amqp

Usage Just run command $ php yii rabbit

While running the command getting connection refused exception Exception 'PhpAmqpLib\Exception\AMQPRuntimeException' with message 'Error Connecting to server(111): Connection refused ' in /home/awanish_k/http/queue/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:48

What is the connection username and password? I am using guest as username & password see my console/config/main.php file

<?php $params = array_merge( require(DIR . '/../../common/config/params.php'), require(DIR . '/../../common/config/params-local.php'), require(DIR . '/params.php'), require(DIR . '/params-local.php') );

return [ 'id' => 'app-console', 'basePath' => dirname(DIR), 'bootstrap' => ['log', 'gii'], 'controllerNamespace' => 'console\controllers', 'modules' => [ 'gii' => 'yii\gii\Module', ], 'components' => [ 'log' => [ 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning'], ], ], ], 'amqp' => [ 'class' => 'webtoucher\amqp\components\Amqp', 'host' => '127.0.0.1', 'port' => 5672, 'user' => 'guest', 'password' => 'guest', 'vhost' => '/', ], ], 'controllerMap' => [ 'rabbit' => [ 'class' => 'webtoucher\amqp\controllers\AmqpListenerController', 'interpreters' => [ 'my-exchange' => 'app\components\RabbitInterpreter', // interpreters for each exchange ], 'exchange' => 'my-exchange', // default exchange ], ], 'params' => $params, ];

also there are three file missing on composer update yii2-ampq Thanks

webtoucher commented 9 years ago

This is just a wrapper for php-amqplib If you wanna use it you should read manuals http://www.rabbitmq.com/tutorials/tutorial-one-php.html

MrAwanishKumar commented 9 years ago

Thanks. Going through the above link and trying to implement....