Skip to content

Commit

Permalink
废弃 AMQP Connection 注解
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft committed Oct 18, 2023
1 parent 39e7f3d commit f0db452
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 278 deletions.
8 changes: 4 additions & 4 deletions doc/base/version/2.1-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

[toc]

imi v3.0 是一个全新版本,与 imi v2.1 差异较大,以下是更新内容。

## 不兼容的更改

### 框架核心
Expand All @@ -12,6 +10,8 @@ imi v3.0 是一个全新版本,与 imi v2.1 差异较大,以下是更新内

### imi-amqp

* 废弃 `Imi\AMQP\Swoole\AMQPSwooleConnection`

* 连接配置项有所增改,参考 [连接配置项](https://doc.imiphp.com/v3.0/components/mq/amqp.html#%E8%BF%9E%E6%8E%A5%E9%85%8D%E7%BD%AE%E9%A1%B9)

* 废弃 `Imi\AMQP\Swoole\AMQPSwooleConnection` 客户端类

* 废弃 `Imi\AMQP\Annotation\Connection` 注解类
7 changes: 2 additions & 5 deletions src/Components/amqp/example/AMQP/Test/TestConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace AMQPApp\AMQP\Test;

use Imi\AMQP\Annotation\Connection;
use Imi\AMQP\Annotation\Consumer;
use Imi\AMQP\Annotation\Queue;
use Imi\AMQP\Base\BaseConsumer;
Expand All @@ -14,13 +13,11 @@
use Imi\Redis\Redis;

/**
* 启动一个新连接消费.
* 使用连接池中的连接消费.
*
* @Bean("TestConsumer")
*
* @Connection(host=AMQP_SERVER_HOST, port=5672, user="guest", password="guest")
*
* @Consumer(tag="tag-imi", queue="queue-imi-1", message=\AMQPApp\AMQP\Test\TestMessage::class)
* @Consumer(tag="tag-imi", queue="queue-imi-2", message=\AMQPApp\AMQP\Test\TestMessage::class)
*/
class TestConsumer extends BaseConsumer
{
Expand Down
34 changes: 33 additions & 1 deletion src/Components/amqp/example/AMQP/Test/TestMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ class TestMessage extends Message
*/
private $memberId;

/**
* 内容.
*
* @var string
*/
private $content;

public function __construct()
{
parent::__construct();
$this->routingKey = 'imi-1';
$this->routingKey = 'imi-2';
$this->format = \Imi\Util\Format\Json::class;
}

Expand All @@ -42,6 +49,7 @@ public function getBodyData()
{
return [
'memberId' => $this->memberId,
'content' => $this->content,
];
}

Expand All @@ -68,4 +76,28 @@ public function setMemberId(int $memberId)

return $this;
}

/**
* Get 内容.
*
* @return string
*/
public function getContent()
{
return $this->content;
}

/**
* Set 内容.
*
* @param string $content 内容
*
* @return self
*/
public function setContent(string $content)
{
$this->content = $content;

return $this;
}
}
7 changes: 2 additions & 5 deletions src/Components/amqp/example/AMQP/Test/TestPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace AMQPApp\AMQP\Test;

use Imi\AMQP\Annotation\Connection;
use Imi\AMQP\Annotation\Exchange;
use Imi\AMQP\Annotation\Publisher;
use Imi\AMQP\Annotation\Queue;
Expand All @@ -14,11 +13,9 @@
/**
* @Bean("TestPublisher")
*
* @Connection(host=AMQP_SERVER_HOST, port=5672, user="guest", password="guest")
* @Publisher(tag="tag-imi", queue="queue-imi-2", exchange="exchange-imi", routingKey="imi-2")
*
* @Publisher(tag="tag-imi", queue="queue-imi-1", exchange="exchange-imi", routingKey="imi-1")
*
* @Queue(name="queue-imi-1", routingKey="imi-1")
* @Queue(name="queue-imi-2", routingKey="imi-2")
*
* @Exchange(name="exchange-imi")
*/
Expand Down
38 changes: 0 additions & 38 deletions src/Components/amqp/example/AMQP/Test2/TestConsumer2.php

This file was deleted.

103 changes: 0 additions & 103 deletions src/Components/amqp/example/AMQP/Test2/TestMessage2.php

This file was deleted.

24 changes: 0 additions & 24 deletions src/Components/amqp/example/AMQP/Test2/TestPublisher2.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use AMQPApp\AMQP\QueueTest\QueueTestMessage;
use AMQPApp\AMQP\Test\TestMessage;
use AMQPApp\AMQP\Test2\TestMessage2;
use Imi\Controller\HttpController;
use Imi\Queue\Facade\Queue;
use Imi\Queue\Model\Message;
Expand Down Expand Up @@ -44,15 +43,10 @@ public function publish(int $memberId = 19260817)
{
$message = new TestMessage();
$message->setMemberId($memberId);
$message->setContent('memberId:' . $memberId);
// @phpstan-ignore-next-line
$r1 = RequestContext::getBean('TestPublisher')->publish($message);

$message2 = new TestMessage2();
$message2->setMemberId($memberId);
$message2->setContent('memberId:' . $memberId);
// @phpstan-ignore-next-line
$r2 = RequestContext::getBean('TestPublisher2')->publish($message2);

$queueTestMessage = new QueueTestMessage();
$queueTestMessage->setMemberId($memberId);
$message = new Message();
Expand All @@ -61,7 +55,6 @@ public function publish(int $memberId = 19260817)

return [
'r1' => $r1,
'r2' => $r2,
];
}

Expand All @@ -75,17 +68,15 @@ public function publish(int $memberId = 19260817)
public function consume($memberId)
{
$r1 = Redis::get($key1 = 'imi-amqp:consume:1:' . $memberId);
$r2 = Redis::get($key2 = 'imi-amqp:consume:2:' . $memberId);
$r3 = Redis::get($key3 = 'imi-amqp:consume:QueueTest:' . $memberId);
if (false !== $r1 && false !== $r2 && false !== $r3)
$r2 = Redis::get($key2 = 'imi-amqp:consume:QueueTest:' . $memberId);
if (false !== $r1 && false !== $r2)
{
Redis::del($key1, $key2, $key3);
Redis::del($key1, $key2);
}

return [
'r1' => $r1,
'r2' => $r2,
'r3' => $r3,
];
}
}
14 changes: 2 additions & 12 deletions src/Components/amqp/example/Process/SwooleTestProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace AMQPApp\Process;

use AMQPApp\AMQP\Test\TestConsumer;
use Imi\AMQP\Contract\IConsumer;
use Imi\Aop\Annotation\Inject;
use Imi\Event\Event;
Expand All @@ -20,30 +21,19 @@ class SwooleTestProcess extends BaseProcess
{
/**
* @Inject("TestConsumer")
*
* @var \AMQPApp\AMQP\Test\TestConsumer
*/
protected $testConsumer;

/**
* @Inject("TestConsumer2")
*
* @var \AMQPApp\AMQP\Test2\TestConsumer2
*/
protected $testConsumer2;
protected TestConsumer $testConsumer;

private bool $running = false;

public function run(\Swoole\Process $process): void
{
$this->running = true;
$this->runConsumer($this->testConsumer);
$this->runConsumer($this->testConsumer2);
$channel = new \Swoole\Coroutine\Channel();
Event::on('IMI.PROCESS.END', function () use ($channel) {
$this->running = false;
$this->testConsumer->close();
$this->testConsumer2->close();
$channel->push(1);
}, ImiPriority::IMI_MAX);
$channel->pop();
Expand Down
Loading

0 comments on commit f0db452

Please sign in to comment.