dyjh/laravel-mns

This package aggregate the message queue of laravel and aliyun IOT MNS.

Downloads

10

Stars

4

Version

Aliyun MNS Queue Driver For Laravel 6.0

Latest Version on Packagist Software License Total Downloads

The Laravel adaptation of aliyun messaging service (MNS) is essentially the addition of MNS drivers to Laravel's queues. Includes aliyun MNS SDK, which is necessary for Laravel to use MNS transparently.

Changes from lokielse/laravel-mns to modify some of the content added manually call news release, added the laravel 6.0 support.

Install

Via Composer

$ composer require dyjh/laravel-mns

Config

Add following service providers into your providers array in config/app.php

Dyjh\LaravelMNS\LaravelMNSServiceProvider::class

Edit your config/queue.php, add mns connection

'mns'        => [
	'driver'       => 'mns',
	'key'          => env('QUEUE_MNS_ACCESS_KEY'),
	'secret'       => env('QUEUE_MNS_SECRET_KEY'),
	'endpoint'     => env('QUEUE_MNS_ENDPOINT'),
	'queue'        => env('QUEUE_NAME'),
	'wait_seconds' => 30,
    'receiveController' => ReceiveController::class,
]

About wait_seconds

Edit your .env file

QUEUE_DRIVER=mns
QUEUE_NAME=foobar-local
QUEUE_MNS_ACCESS_KEY=your_acccess_key
QUEUE_MNS_SECRET_KEY=your_secret_key
QUEUE_MNS_ENDPOINT=http://12345678910.mns.cn-hangzhou.aliyuncs.com/

You should update QUEUE_MNS_ENDPOINT to internal endpoint in production mode

MessageReceiver Example

About [ReceiveController], please look at Example

Usage

First create a queue and get queue endpoint at Aliyun MNS Console

Then update MNS_ENDPOINT in .env

Push a test message to queue

Queue::push(function($job){
	/**
	 * Your statments go here
	 */
	$job->delete();
});

Create queue listener, run command in terminal

$ php artisan queue:listen

or only create the receiver queue

$ php artisan queue:work mns

Commands

Flush MNS messages on Aliyun

$ php artisan queue:mns:flush

Manually publish message

Send The Message to Aliyun MNS

$sender = new MNSSender("test");
$res = $sender->push("testMessage");

Security

Create RAM access control at Aliyun RAM Console

  1. Create a custom policy such as AliyunMNSFullAccessFoobar

    {
      "Version": "1",
      "Statement": [
    	{
    	  "Action": "mns:*",
    	  "Resource": [
    		"acs:mns:*:*:*/foobar-local",
    		"acs:mns:*:*:*/foobar-sandbox",
    		"acs:mns:*:*:*/foobar-production"
    	  ],
    	  "Effect": "Allow"
    	}
      ]
    }
    
  2. Create a user for you app such as foobar

  3. Assign the policy AliyunMNSFullAccessFoobar to the user foobar

  4. Create and get the AccessKeyId and AccessKeySecret for user foorbar

  5. update QUEUE_MNS_ACCESS_KEY and QUEUE_MNS_ACCESS_SECRET in .env

Testing

$ composer test

License

The MIT License (MIT). Please see License File for more information.