xutl/yii2-broadcast

The broadcast queue extension for the Yii framework

Installs: 7

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:yii2-extension

1.0.4 2017-08-21 10:36 UTC

This package is not auto-updated.

Last update: 2024-11-02 01:31:46 UTC


README

Latest Stable Version Total Downloads Reference Status Build Status Dependency Status License

Installation

Next steps will guide you through the process of installing yii2-broadcast using composer. Installation is a quick and easy three-step process.

Install component via composer

Either run

composer require --prefer-dist xutl/yii2-broadcast

or add

"yuncms/yii2-broadcast": "~1.0.0"

to the require section of your composer.json.

Configuring your application

Add following lines to your main configuration file:

'components' => [
    'broadcast' => [
        'class' => 'xutl\broadcast\Broadcast',
        'endPoint' => 'http://abcdefg.mns.cn-hangzhou.aliyuncs.com/',
        'accessId' => '1234567890',
        'accessKey' => '1234567890',
    ],
    //etc
],

Use broadcast

/** @var \xutl\broadcast\Broadcast $broadcast */
$broadcast = Yii::$app->broadcast;

$topicName = 'CreateTopicAndPublishMessageExample';
$broadcast->create($topicName);

$topic = $broadcast->getTopicRef($topicName);
$subscriptionName = "SubscriptionExample";

try{
    $res = $topic->subscribe($subscriptionName,'https://www.baidu.com','test.test');
    echo "SubscriptionCreated! \n";
}catch (MnsException $e){
    echo "CreateSubscriptionFailed: " . $e;
    return;
}

$messageBody = "test";
$res = $topic->publishMessage($messageBody, 'test.test');
var_dump($res);
class ApiController extends \yii\web\Controller
{
    public function actions()
    {
        return [
            /**
             * Returns an access token.
             */
            'callback' => [
                'class' => \xutl\broadcast\TopicAction::classname(),
                'callback'=>[$this, 'callback'],
            ],
        ];
    }
    
    /**
     * 
     */
    public function callback($params)
    {
        print_r($params);
    }
}

License

This is released under the MIT License. See the bundled LICENSE.md for details.