Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement normal queue and delay queue with think-queue in thinkphp6

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article Xiaobian introduces in detail for you "thinkphp6 uses think-queue to achieve ordinary queues and delay queues", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "thinkphp6 uses think-queue to achieve ordinary queues and delay queues" can help you solve your doubts.

# TP6 queue

Normal queues and delay queues can be implemented by using think-queue in TP6.

Think-queue is a message queuing service officially provided by thinkphp, which supports some basic features of message queuing:

Message release, acquisition, execution, deletion, retransmission, failure handling, delayed execution, timeout control, etc.

Multiple queues for queues, memory limits, start, stop, daemon, etc.

Message queuing can be degraded to synchronous execution

Message queue implementation process

1. Push messages to the message queuing service through the producer

2. The message queuing service stores the received messages in the redis queue (zset)

3. Consumers listen to the queue and get the first item of the queue when they hear a new message.

4. Process the obtained message and call the business class to process the related business.

5. After business processing, you need to delete the message from the queue.

Composer installation think-queuecomposer require topthink/think-queue configuration file

After installing think-queue, queue.php is generated in the config directory, which is the configuration file for the queue.

There are many ways to implement message queues in tp6. Sync is used by default, and I choose to use Redis here.

Return ['default' = >' redis', 'connections' = > [' sync' = > ['type' = >' sync',], 'database' = > [' type' = > 'database',' queue' = > 'default',' table' = > 'jobs',' connection' = > null,] 'redis' = > [' type' = > 'redis',' queue' = > 'default',' host' = > env ('redis.host',' 127.0.0.1'), 'port' = > env (' redis.port', '6379'),' password' = > env ('redis.password','123456') 'select' = > 0,' timeout' = > 0, 'persistent' = > false,],' failed' = > ['type' = >' none', 'table' = >' failed_jobs',],] Create directory and queue consumer files

Create a queue directory under the app directory, and then create a new abstract class Queue.php file under that directory as the base class

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report