Skip to content

Commit

Permalink
队列实现优化
Browse files Browse the repository at this point in the history
  • Loading branch information
kiss291323003 committed Feb 22, 2023
1 parent 5ea2e23 commit 865295f
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class Queue
private $driver;
private $nodeId;

private $consumer;
private $producer;

function __construct(QueueDriverInterface $driver)
{
$this->driver = $driver;
Expand All @@ -22,14 +25,26 @@ function queueDriver():QueueDriverInterface
return $this->driver;
}

function consumer():Consumer
function consumer(bool $renew = false):Consumer
{
return new Consumer($this->driver);
if(!$renew){
$this->consumer = new Consumer($this->driver);
}
if($this->consumer == null){
$this->consumer = new Consumer($this->driver);
}
return $this->consumer;
}

function producer():Producer
function producer(bool $renew = false):Producer
{
return new Producer($this->driver, $this->nodeId);
if(!$renew){
$this->producer = new Producer($this->driver, $this->nodeId);
}
if($this->producer == null){
$this->producer = new Producer($this->driver, $this->nodeId);
}
return $this->producer;
}

function info():?array
Expand Down

0 comments on commit 865295f

Please sign in to comment.