Commit 0d23241f by 杨树贤

队列性能问题

parent df1f8139
......@@ -9,6 +9,7 @@ use App\Http\Services\SyncSupplierService;
use App\Model\SupplierChannelModel;
use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;
use PhpAmqpLib\Connection\AMQPStreamConnection;
//设置供应商是否需要跟进
class SyncAllSupplierToErp extends Command
......@@ -35,10 +36,14 @@ class SyncAllSupplierToErp extends Command
public function handle()
{
$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) {
usleep(100000);
dump($supplierId);
(new SyncSupplierService())->syncSupplierToErp($supplierId);
(new SyncSupplierService())->syncSupplierToErp($supplierId, $conn);
}
}
}
......@@ -22,7 +22,7 @@ use PhpAmqpLib\Message\AMQPMessage;
class SyncSupplierService
{
//同步供应商到erp
public function syncSupplierToErp($supplierId)
public function syncSupplierToErp($supplierId, $conn = null)
{
//先去获取供应商的信息
$supplierModel = new SupplierChannelModel();
......@@ -98,10 +98,15 @@ class SyncSupplierService
}
//dd($message);
$conn = new AMQPStreamConnection(config('database.connections.rabbitmq.host'),
config('database.connections.rabbitmq.port'),
config('database.connections.rabbitmq.login'),
config('database.connections.rabbitmq.password'));
if ($conn) {
} else {
$conn = new AMQPStreamConnection(config('database.connections.rabbitmq.host'),
config('database.connections.rabbitmq.port'),
config('database.connections.rabbitmq.login'),
config('database.connections.rabbitmq.password'));
}
$channel = $conn->channel();
$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