当前位置:网站首页>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));
})
边栏推荐
- Development specification - parameter verification exception, exception return prompt section
- See how sparksql supports enterprise data warehouse
- The core concept of JMM: happens before principle
- vulnhub DC: 2
- docker安装mysql-简单无坑
- Do you need to improve your code reading ability? It's a trick
- Attention, postgraduate candidates! They are the easiest scams to get caught during the preparation period?!
- 糖豆人登录报错解决方案
- Cat write multiline content to file
- 详细了解Redis的八种数据类型及应用场景分析
猜你喜欢

Attention, postgraduate candidates! They are the easiest scams to get caught during the preparation period?!

07_SpingBoot 实现 RESTful 风格

Leetcode: calculate the number of elements less than the current element on the right (sortedlist+bisect\u left)

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

【武汉大学】考研初试复试资料分享

A big factory interview must ask: how to solve the problem of TCP reliable transmission? 8 pictures for you to learn in detail

【nvm】

Introduction to machine learning compilation course learning notes lesson 1 overview of machine learning compilation

2022 safety officer-b certificate examination question bank and answers

Stop using it indiscriminately. This is the real difference between @validated and @valid!!!
随机推荐
[text data mining] Chinese named entity recognition: HMM model +bilstm_ CRF model (pytoch) [research and experimental analysis]
How to integrate Huawei cloud function services in fluent
Recommended movies: Northeast tiger, licorice pizza
加分利器 不负所托 | 知道创宇获攻防演练防守方感谢信!
23研考生注意啦!备考期间最容易中招的骗局,居然是它们?!
vulnhub Vegeta: 1
LeetCode Algorithm 剑指 Offer II 027. 回文链表
EPICS记录参考4--所有输入记录都有的字段和所有输出记录都有的字段
Memory alignment of structures
Push markdown format information to the nailing robot
STP spanning tree protocol Foundation
Spark 离线开发框架设计与实现
Simulated 100 questions and online simulated examination of high voltage electrician examination in 2022
Database transaction Transanction
China solar window market trend report, technical dynamic innovation and market forecast
Some updates about a hand slider (6-18, JS reverse)
双亲委派机制
[QT] QT event handling
China solar thermal market trend report, technical dynamic innovation and market forecast
Learn more about the practical application of sentinel