Giter VIP home page Giter VIP logo

laravel-mns-driver's Introduction

Aliyun MNS Queue Driver For Laravel

Latest Version on Packagist Software License Total Downloads

Install

Via Composer

$ composer require chenzi/laravel-mns-driver

Config

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

Chenzi\LaravelMNS\LaravelMNSServiceProvider::class

Edit your config/queue.php, add mns connection

'mns'        => [
    'sms'=> [
        'driver'       => 'sms',
        'key'          => env('QUEUE_MNS_ACCESS_KEY'),
        'secret'       => env('QUEUE_MNS_SECRET_KEY'),
        'endpoint'     => env('QUEUE_MNS_ENDPOINT'),
        'queue'        => env('QUEUE_NAME'),
        'wait_seconds' => 30,
    ],
    'email'=> [
        'driver'       => 'email',
        'key'          => env('QUEUE_MNS_ACCESS_KEY'),
        'secret'       => env('QUEUE_MNS_SECRET_KEY'),
        'endpoint'     => env('QUEUE_MNS_ENDPOINT'),
        'queue'        => env('QUEUE_NAME'),
        'wait_seconds' => 30,
    ]
]

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

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();
});

You also can custom request data format add mns queue with other program

return json_encode( [
    'displayName' => 'App\Jobs\SendSms',
    'job'         => 'App\Jobs\SendSms',
    'maxTries'    => null,
    'timeout'     => null,
    'data'        => [],
] );

Create queue work, run command in terminal

$ php artisan queue:mns:work sms

Commands

Flush MNS messages on Aliyun

$ php artisan queue:mns:flush

Job handle

class SendSms implements ShouldQueue
{
    ...
    
    public function handle(ReceiveMessageResponse $job){
        $messageId = $job->getMessageId();
        $messageBody = $job->getMessageBody();
        
        //TODO do some thing...
    }
    
    ...
}   

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

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Credits

License

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

laravel-mns-driver's People

Contributors

chenzi avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.