From 5d6a9aec0f89ac349ca545a95255c8b1d9eed661 Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 2 Aug 2020 19:06:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90amqp=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Amqp/Consumer/DevicOrderConsumer.php | 34 ++++++++++++++++++++++++ composer.json | 3 ++- config/autoload/amqp.php | 33 +++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 app/Amqp/Consumer/DevicOrderConsumer.php create mode 100644 config/autoload/amqp.php diff --git a/app/Amqp/Consumer/DevicOrderConsumer.php b/app/Amqp/Consumer/DevicOrderConsumer.php new file mode 100644 index 0000000..ea4cc7d --- /dev/null +++ b/app/Amqp/Consumer/DevicOrderConsumer.php @@ -0,0 +1,34 @@ +getBody()); + if($this->msgCount< 10){ + $this->msgCount += 1; + return Result::REQUEUE; + } + return Result::ACK; + } + + public function isEnable(): bool + { + //if(env('APP_ENV')!='prod') return false; + return parent::isEnable(); + } +} diff --git a/composer.json b/composer.json index f15665e..e089108 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,8 @@ "hyperf/filesystem": "^2.0", "xxtime/flysystem-aliyun-oss": "^1.5", "hyperf/task": "^2.0", - "alibabacloud/iot": "^1.8" + "alibabacloud/iot": "^1.8", + "hyperf/amqp": "^2.0" }, "require-dev": { "swoole/ide-helper": "^4.5", diff --git a/config/autoload/amqp.php b/config/autoload/amqp.php new file mode 100644 index 0000000..e14780a --- /dev/null +++ b/config/autoload/amqp.php @@ -0,0 +1,33 @@ + [ + 'host' => env('RQM_HOST', 'localhost'), + 'port' => 5672, + 'user' => env('RQM_USER','guest'), + 'password' => env('RQM_PASSWORD','guest'), + 'vhost' => '/', + 'concurrent' => [ + 'limit' => 1, + ], + 'pool' => [ + 'min_connections' => 1, + 'max_connections' => 10, + 'connect_timeout' => 10.0, + 'wait_timeout' => 3.0, + 'heartbeat' => -1, + ], + 'params' => [ + 'insist' => false, + 'login_method' => 'AMQPLAIN', + 'login_response' => null, + 'locale' => 'en_US', + 'connection_timeout' => 3.0, + 'read_write_timeout' => 6.0, + 'context' => null, + 'keepalive' => false, + 'heartbeat' => 3, + 'close_on_destruct' => false, + ], + ] +];