当前位置:网站首页>laravel 消息队列
laravel 消息队列
2022-06-24 19:41:00 【王道长的编程之路】
@[topic]
一、配置
配置主要分两部分,databasel和queue两个配置文件,database主要配置的是消息队列的中间件redis,而queue才是真正的队列配置
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'),//驱动设置,sync是同步操作,如果需要异步,需要把sync设置成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',
],
];
二、创建工作任务
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(){
//写耗时操作的逻辑
}
}
三、调用
# webroute.php
Route::get("/", function(){
dispatch(new QueueJob($res, $this->invite_code));
})
边栏推荐
- Combine pod identity in aks and secret in CSI driver mount key vault
- 非单文件组件
- [Wuhan University] information sharing of the first and second postgraduate entrance examinations
- Dynamic menu, auto align
- 详细了解Redis的八种数据类型及应用场景分析
- Push markdown format information to the nailing robot
- vulnhub DC: 2
- Beijiafu (p+f) R2000 modified radar IP
- See how sparksql supports enterprise level data warehouse
- Database transaction Transanction
猜你喜欢

How to submit the shopee opening and settlement flow?

JMM 最最最核心的概念:Happens-before 原则

EPICS记录参考2--EPICS过程数据库概念

Some updates about a hand slider (6-18, JS reverse)

Win10 or win11 printer cannot print

Memory alignment of structures

The difference between interceptor and filter

Getting started with the go Cobra command line tool

Learn more about redis' eight data types and application scenario analysis

Development specification - parameter verification exception, exception return prompt section
随机推荐
倍加福(P+F)R2000修改雷达IP
【Laravel系列7.9】测试
2022 safety officer-a certificate examination questions and answers
【武汉大学】考研初试复试资料分享
Some updates about a hand slider (6-18, JS reverse)
Attackg: constructing technical knowledge graph from cyber thread intelligence reports
别再乱用了,这才是 @Validated 和 @Valid 的真正区别!!!
vulnhub Vegeta: 1
Leetcode algorithm refers to offer II 027 Palindrome linked list
Research Report on solar battery charger industry - market status analysis and development prospect forecast
Design and implementation of spark offline development framework
LeetCode Algorithm 剑指 Offer II 027. 回文链表
动态菜单,自动对齐
剑指 Offer 42. 连续子数组的最大和
vulnhub DC: 2
LeetCode Algorithm 剑指 Offer 52. 两个链表的第一个公共节点
EPICS记录参考4--所有输入记录都有的字段和所有输出记录都有的字段
Programmers become gods by digging holes in one year, carrying flags in five years and becoming gods in ten years
vulnhub Vegeta: 1
Servlet