-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
include(__DIR__ . '/../config.php'); | ||
|
||
// define('HOST', getenv('TEST_RABBITMQ_HOST') ? getenv('TEST_RABBITMQ_HOST') : '127.0.0.1'); | ||
// define('PORT', getenv('TEST_RABBITMQ_PORT') ? getenv('TEST_RABBITMQ_PORT') : 5672); | ||
// define('USER', getenv('TEST_RABBITMQ_USER') ? getenv('TEST_RABBITMQ_USER') : 'guest'); | ||
// define('PASS', getenv('TEST_RABBITMQ_PASS') ? getenv('TEST_RABBITMQ_PASS') : 'guest'); | ||
// define('VHOST', '/'); | ||
//define('AMQP_DEBUG', getenv('TEST_AMQP_DEBUG') !== false ? (bool)getenv('TEST_AMQP_DEBUG') : false); | ||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
use PhpAmqpLib\Connection\AMQPStreamConnection; | ||
|
||
$connection = new AMQPStreamConnection(HOST, PORT, USER, PASS, VHOST); | ||
|
||
$channel = $connection->channel(); | ||
|
||
$channel->queue_declare('qos_queue', false, true, false, false); | ||
|
||
//第二个参数代表:每次只消费1条 | ||
$channel->basic_qos(null, 1, null); | ||
|
||
function process_message($message) | ||
{ | ||
//消费完消息之后进行应答,告诉rabbit我已经消费了,可以发送下一组了 | ||
$message->delivery_info['channel']->basic_ack($message->delivery_info['delivery_tag']); | ||
echo "finish\n"; | ||
} | ||
|
||
$channel->basic_consume('qos_queue', '', false, false, false, false, 'process_message'); | ||
|
||
while ($channel->is_consuming()) { | ||
// After 10 seconds there will be a timeout exception. | ||
$channel->wait(null, false, 30000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# 限流 | ||
|
||
高并发 | ||
|
||
basic_qos($prefetchSize, $prefetchCount, $global) | ||
|
||
## QOS | ||
|
||
当不给$message->delivery_info['channel']->basic_ack($message->delivery_info['delivery_tag'])回执,就无法知道是否完成,就不会发送下一批消息。 | ||
|