当前位置:网站首页>Laravel message queue
Laravel message queue
2022-06-24 23:12:00 【Wang Daochang's way of programming】
@[topic]
One 、 To configure
The configuration is mainly divided into two parts ,databasel and queue Two configuration files ,database The main configuration is the message queue middleware redis, and queue Is the real queue configuration
database.php
...
'redis' => [
'client' => env('REDIS_CLIENT', 'phpredis'),
'options' => [
'cluster' => env('REDIS_CLUSTER', 'redis'),
'prefix' => env('REDIS_PREFIX', ''),
],
'default' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_DB', '2'),
],
...
queue.php
return [
'default' => env('QUEUE_CONNECTION', 'sync'),// Drive settings ,sync It's a synchronous operation , If asynchronous is required , Need to put sync Set to redis
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
],
'beanstalkd' => [
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
'retry_after' => 90,
'block_for' => 0,
],
'sqs' => [
'driver' => 'sqs',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'),
'queue' => env('SQS_QUEUE', 'your-queue-name'),
'suffix' => env('SQS_SUFFIX'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => env('REDIS_QUEUE', 'default'),
'retry_after' => 90,
'block_for' => 5,
],
],
'failed' => [
'driver' => env('QUEUE_FAILED_DRIVER', 'database'),
'database' => env('DB_CONNECTION', 'mysql'),
'table' => 'failed_jobs',
],
];
Two 、 Create work tasks
php artisan make:job QueueJob;
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class QueueJob implements ShouldQueue{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(){
}
public function handle(){
// Write logic for time-consuming operations
}
}
3、 ... and 、 call
# webroute.php
Route::get("/", function(){
dispatch(new QueueJob($res, $this->invite_code));
})
边栏推荐
- laravel 宝塔安全配置
- Cases of addition, deletion, modification and search of C # learning for two years and C # import and export (de duplication)
- Cat write multiline content to file
- vulnhub DC: 2
- vulnhub DC: 2
- Non single file component
- laravel 添加helper文件
- 03_ Spingboot core profile
- 对抗训练理论分析:自适应步长快速对抗训练
- How to add Google maps to a project
猜你喜欢

Cases of addition, deletion, modification and search of C # learning for two years and C # import and export (de duplication)

vulnhub Vegeta: 1

对抗训练理论分析:自适应步长快速对抗训练

【Laravel系列7.9】测试

Simulated 100 questions and online simulated examination of high voltage electrician examination in 2022
Mycms we media CMS V3.0, resource push optimization, new free template

shopee开店入驻流水如何提交?

Solution to the login error of tangdou people

Blogs personal blog project details (servlet implementation)

Epics record reference 4 -- fields for all input records and fields for all output records
随机推荐
How to add Google maps to a project
Sword finger offer 13 Range of motion of robot
監聽 Markdown 文件並熱更新 Next.js 頁面
Sword finger offer 42 Maximum sum of successive subarrays
Selection (026) - what is the output of the following code?
[ROS play with turtle turtle]
Epics record reference 2 -- epics process database concept
倍加福(P+F)R2000修改雷达IP
JD 618 conference tablet ranking list announced that the new dark horse brand staff will compete for the top three, learning from Huawei, the leader of domestic products
2022 safety officer-b certificate examination question bank and answers
Canvas to add watermark to pictures
Epics record reference 4 -- fields for all input records and fields for all output records
F29oc analysis
laravel 添加helper文件
是否需要提高代码阅读能力?这有技巧
2022安全员-B证考试题库及答案
Construction equipment [5]
Attention, postgraduate candidates! They are the easiest scams to get caught during the preparation period?!
Getting started with the go Cobra command line tool
Selection (027) - what is the output of the following code?