分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

php laravel 消息队列

发布时间:2023-09-06 02:05责任编辑:郭大石关键词:消息队列

* 消息生成

php artisan make:job QueuedTest -queued

  => ./app/Jobs/QueuedTest.php

<?phpnamespace App\Jobs;use Illuminate\Bus\Queueable;use Illuminate\Queue\SerializesModels;use Illuminate\Queue\InteractsWithQueue;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Bus\Dispatchable;class QueuedTest implements ShouldQueue { ???????use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; ???/** ????* Create a new job instance. ????* ????* @return void ????*/ ???public function __construct() { ???????// ???} ???/** ????* Execute the job. ????* ????* @return void ????*/ ???public function handle() { ???????echo "Queue test success"; ???}}
View Code

* 创建数据库消息队列的数据表迁移文件

php artisan queue:table

  => database/migrations/2018_07_21_033228_create_jobs_table.php

<?phpuse Illuminate\Support\Facades\Schema;use Illuminate\Database\Schema\Blueprint;use Illuminate\Database\Migrations\Migration;class CreateJobsTable extends Migration{ ???/** ????* Run the migrations. ????* ????* @return void ????*/ ???public function up() ???{ ???????Schema::create(‘jobs‘, function (Blueprint $table) { ???????????$table->bigIncrements(‘id‘); ???????????$table->string(‘queue‘)->index(); ???????????$table->longText(‘payload‘); ???????????$table->unsignedTinyInteger(‘attempts‘); ???????????$table->unsignedInteger(‘reserved_at‘)->nullable(); ???????????$table->unsignedInteger(‘available_at‘); ???????????$table->unsignedInteger(‘created_at‘); ???????}); ???} ???/** ????* Reverse the migrations. ????* ????* @return void ????*/ ???public function down() ???{ ???????Schema::dropIfExists(‘jobs‘); ???}}迁移文件
View Code
php artisan migrate

  => 数据表结构 jobs表

-- MySQL dump 10.16 ?Distrib 10.1.31-MariaDB, for osx10.6 (i386)---- Host: localhost ???Database: laravel-- -------------------------------------------------------- Server version ???10.1.31-MariaDB/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;/*!40101 SET NAMES utf8 */;/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;/*!40103 SET TIME_ZONE=‘+00:00‘ */;/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=‘NO_AUTO_VALUE_ON_ZERO‘ */;/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;---- Table structure for table `jobs`--DROP TABLE IF EXISTS `jobs`;/*!40101 SET @saved_cs_client ????= @@character_set_client */;/*!40101 SET character_set_client = utf8 */;CREATE TABLE `jobs` ( ?`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, ?`queue` varchar(255) NOT NULL, ?`payload` longtext NOT NULL, ?`attempts` tinyint(3) unsigned NOT NULL, ?`reserved_at` int(10) unsigned DEFAULT NULL, ?`available_at` int(10) unsigned NOT NULL, ?`created_at` int(10) unsigned NOT NULL, ?PRIMARY KEY (`id`), ?KEY `jobs_queue_index` (`queue`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;/*!40101 SET character_set_client = @saved_cs_client */;---- Dumping data for table `jobs`--LOCK TABLES `jobs` WRITE;/*!40000 ALTER TABLE `jobs` DISABLE KEYS */;/*!40000 ALTER TABLE `jobs` ENABLE KEYS */;UNLOCK TABLES;/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;-- Dump completed on 2018-07-21 11:39:29jobs.sql
View Code

 假设数据库名为 laravel, 导出这个表

mysqldump -uroot -hlocalhost -p --databases laravel --tables jobs > jobs.sql

  创建controller

php artisan make:controller WelcomeController

  

php laravel 消息队列

原文地址:https://www.cnblogs.com/mingzhanghui/p/9346144.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved