Commit 0d23241f by 杨树贤

队列性能问题

parent df1f8139
...@@ -9,6 +9,7 @@ use App\Http\Services\SyncSupplierService; ...@@ -9,6 +9,7 @@ use App\Http\Services\SyncSupplierService;
use App\Model\SupplierChannelModel; use App\Model\SupplierChannelModel;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring; use Illuminate\Foundation\Inspiring;
use PhpAmqpLib\Connection\AMQPStreamConnection;
//设置供应商是否需要跟进 //设置供应商是否需要跟进
class SyncAllSupplierToErp extends Command class SyncAllSupplierToErp extends Command
...@@ -35,10 +36,14 @@ class SyncAllSupplierToErp extends Command ...@@ -35,10 +36,14 @@ class SyncAllSupplierToErp extends Command
public function handle() public function handle()
{ {
$supplierIds = SupplierChannelModel::where('is_type', 0)->pluck('supplier_id')->toArray(); $supplierIds = SupplierChannelModel::where('is_type', 0)->pluck('supplier_id')->toArray();
$conn = new AMQPStreamConnection(config('database.connections.rabbitmq.host'),
config('database.connections.rabbitmq.port'),
config('database.connections.rabbitmq.login'),
config('database.connections.rabbitmq.password'));
foreach ($supplierIds as $supplierId) { foreach ($supplierIds as $supplierId) {
usleep(100000); usleep(100000);
dump($supplierId); dump($supplierId);
(new SyncSupplierService())->syncSupplierToErp($supplierId); (new SyncSupplierService())->syncSupplierToErp($supplierId, $conn);
} }
} }
} }
...@@ -22,7 +22,7 @@ use PhpAmqpLib\Message\AMQPMessage; ...@@ -22,7 +22,7 @@ use PhpAmqpLib\Message\AMQPMessage;
class SyncSupplierService class SyncSupplierService
{ {
//同步供应商到erp //同步供应商到erp
public function syncSupplierToErp($supplierId) public function syncSupplierToErp($supplierId, $conn = null)
{ {
//先去获取供应商的信息 //先去获取供应商的信息
$supplierModel = new SupplierChannelModel(); $supplierModel = new SupplierChannelModel();
...@@ -98,10 +98,15 @@ class SyncSupplierService ...@@ -98,10 +98,15 @@ class SyncSupplierService
} }
//dd($message); //dd($message);
if ($conn) {
} else {
$conn = new AMQPStreamConnection(config('database.connections.rabbitmq.host'), $conn = new AMQPStreamConnection(config('database.connections.rabbitmq.host'),
config('database.connections.rabbitmq.port'), config('database.connections.rabbitmq.port'),
config('database.connections.rabbitmq.login'), config('database.connections.rabbitmq.login'),
config('database.connections.rabbitmq.password')); config('database.connections.rabbitmq.password'));
}
$channel = $conn->channel(); $channel = $conn->channel();
$channel->queue_declare('supplier_sync', false, true, false, false); $channel->queue_declare('supplier_sync', false, true, false, false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment