Skip to content

Commit 1d51110

Browse files
committed
rename amqp-lib
1 parent 8708592 commit 1d51110

9 files changed

Lines changed: 461 additions & 14 deletions

‎composer.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"enqueue/enqueue": "*@dev",
88
"enqueue/stomp": "*@dev",
99
"enqueue/amqp-ext": "*@dev",
10-
"enqueue/amqplib": "*@dev",
10+
"enqueue/amqp-lib": "*@dev",
1111
"enqueue/redis": "*@dev",
1212
"enqueue/fs": "*@dev",
1313
"enqueue/null": "*@dev",
@@ -71,7 +71,7 @@
7171
},
7272
{
7373
"type": "path",
74-
"url": "pkg/amqplib"
74+
"url": "pkg/amqp-lib"
7575
},
7676
{
7777
"type": "path",
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,42 @@
11
<?php
22

3-
namespace Enqueue\Amqplib;
3+
namespace Enqueue\AmqpLib;
44

55
use Interop\Queue\PsrConnectionFactory;
66
use PhpAmqpLib\Connection\AbstractConnection;
77
use PhpAmqpLib\Connection\AMQPStreamConnection;
88

99
class AmqpConnectionFactory implements PsrConnectionFactory
1010
{
11+
/**
12+
* @var array
13+
*/
1114
private $config;
15+
16+
/**
17+
* @var AbstractConnection
18+
*/
1219
private $connection;
1320

21+
/**
22+
* @param array $config
23+
*/
1424
public function __construct(array $config = [])
1525
{
1626
$this->config = array_replace($this->defaultConfig(), $config);
1727
}
1828

29+
/**
30+
* @return AmqpContext
31+
*/
1932
public function createContext()
2033
{
2134
return new AmqpContext($this->establishConnection());
2235
}
2336

37+
/**
38+
* @return AbstractConnection
39+
*/
2440
private function establishConnection()
2541
{
2642
if (false == $this->connection) {
@@ -36,6 +52,9 @@ private function establishConnection()
3652
return $this->connection;
3753
}
3854

55+
/**
56+
* @return array
57+
*/
3958
private function defaultConfig()
4059
{
4160
return [
Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Enqueue\Amqplib;
3+
namespace Enqueue\AmqpLib;
44

55
use Interop\Queue\InvalidMessageException;
66
use Interop\Queue\PsrConsumer;
@@ -11,20 +11,39 @@
1111

1212
class AmqpConsumer implements PsrConsumer
1313
{
14+
/**
15+
* @var AMQPChannel
16+
*/
1417
private $channel;
18+
19+
/**
20+
* @var AmqpQueue
21+
*/
1522
private $queue;
1623

24+
/**
25+
* @param AMQPChannel $channel
26+
* @param AmqpQueue $queue
27+
*/
1728
public function __construct(AMQPChannel $channel, AmqpQueue $queue)
1829
{
1930
$this->channel = $channel;
2031
$this->queue = $queue;
2132
}
2233

34+
/**
35+
* @return AmqpQueue
36+
*/
2337
public function getQueue()
2438
{
2539
return $this->queue;
2640
}
2741

42+
/**
43+
* @param int $timeout
44+
*
45+
* @return AmqpMessage|null
46+
*/
2847
public function receive($timeout = 0)
2948
{
3049
$end = microtime(true) + ($timeout / 1000);
@@ -38,27 +57,42 @@ public function receive($timeout = 0)
3857
}
3958
}
4059

60+
/**
61+
* @return AmqpMessage|null
62+
*/
4163
public function receiveNoWait()
4264
{
4365
if ($message = $this->channel->basic_get($this->queue->getQueueName())) {
4466
return $this->convertMessage($message);
4567
}
4668
}
4769

70+
/**
71+
* @param AmqpMessage $message
72+
*/
4873
public function acknowledge(PsrMessage $message)
4974
{
5075
InvalidMessageException::assertMessageInstanceOf($message, AmqpMessage::class);
5176

5277
$this->channel->basic_ack($message->getDeliveryTag());
5378
}
5479

80+
/**
81+
* @param AmqpMessage $message
82+
* @param bool $requeue
83+
*/
5584
public function reject(PsrMessage $message, $requeue = false)
5685
{
5786
InvalidMessageException::assertMessageInstanceOf($message, AmqpMessage::class);
5887

5988
$this->channel->basic_reject($message->getDeliveryTag(), $requeue);
6089
}
6190

91+
/**
92+
* @param LibAMQPMessage $amqpMessage
93+
*
94+
* @return AmqpMessage
95+
*/
6296
private function convertMessage(LibAMQPMessage $amqpMessage)
6397
{
6498
$headers = new AMQPTable($amqpMessage->get_properties());
Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,90 @@
11
<?php
22

3-
namespace Enqueue\Amqplib;
3+
namespace Enqueue\AmqpLib;
44

55
use Interop\Queue\Exception;
66
use Interop\Queue\InvalidDestinationException;
77
use Interop\Queue\PsrContext;
88
use Interop\Queue\PsrDestination;
99
use Interop\Queue\PsrTopic;
10+
use PhpAmqpLib\Channel\AMQPChannel;
1011
use PhpAmqpLib\Connection\AbstractConnection;
1112

1213
class AmqpContext implements PsrContext
1314
{
15+
/**
16+
* @var AbstractConnection
17+
*/
1418
private $connection;
19+
20+
/**
21+
* @var AMQPChannel
22+
*/
1523
private $channel;
1624

25+
/**
26+
* @param AbstractConnection $connection
27+
*/
1728
public function __construct(AbstractConnection $connection)
1829
{
1930
$this->connection = $connection;
2031
}
2132

33+
/**
34+
* @param string|null $body
35+
* @param array $properties
36+
* @param array $headers
37+
*
38+
* @return AmqpMessage
39+
*/
2240
public function createMessage($body = null, array $properties = [], array $headers = [])
2341
{
2442
return new AmqpMessage($body, $properties, $headers);
2543
}
2644

45+
/**
46+
* @param string $name
47+
*
48+
* @return AmqpQueue
49+
*/
2750
public function createQueue($name)
2851
{
2952
return new AmqpQueue($name);
3053
}
3154

55+
/**
56+
* @param string $name
57+
*
58+
* @return AmqpTopic
59+
*/
3260
public function createTopic($name)
3361
{
3462
return new AmqpTopic($name);
3563
}
3664

65+
/**
66+
* @param PsrDestination $destination
67+
*
68+
* @return AmqpConsumer
69+
*/
3770
public function createConsumer(PsrDestination $destination)
3871
{
3972
InvalidDestinationException::assertDestinationInstanceOf($destination, AmqpQueue::class);
4073

4174
return new AmqpConsumer($this->getChannel(), $destination);
4275
}
4376

77+
/**
78+
* @return AmqpProducer
79+
*/
4480
public function createProducer()
4581
{
4682
return new AmqpProducer($this->getChannel());
4783
}
4884

85+
/**
86+
* @return AmqpQueue
87+
*/
4988
public function createTemporaryQueue()
5089
{
5190
$queue = $this->createQueue(null);
@@ -56,6 +95,9 @@ public function createTemporaryQueue()
5695
return $queue;
5796
}
5897

98+
/**
99+
* @param AmqpTopic $destination
100+
*/
59101
public function declareTopic(PsrDestination $destination)
60102
{
61103
InvalidDestinationException::assertDestinationInstanceOf($destination, AmqpTopic::class);
@@ -73,6 +115,9 @@ public function declareTopic(PsrDestination $destination)
73115
);
74116
}
75117

118+
/**
119+
* @param AmqpQueue $destination
120+
*/
76121
public function declareQueue(PsrDestination $destination)
77122
{
78123
InvalidDestinationException::assertDestinationInstanceOf($destination, AmqpQueue::class);
@@ -89,6 +134,12 @@ public function declareQueue(PsrDestination $destination)
89134
);
90135
}
91136

137+
/**
138+
* @param AmqpTopic|AmqpQueue $source
139+
* @param AmqpTopic|AmqpQueue $target
140+
*
141+
* @throws Exception
142+
*/
92143
public function bind(PsrDestination $source, PsrDestination $target)
93144
{
94145
$source instanceof PsrTopic
@@ -138,16 +189,16 @@ public function bind(PsrDestination $source, PsrDestination $target)
138189
}
139190
}
140191

141-
/**
142-
* {@inheritdoc}
143-
*/
144192
public function close()
145193
{
146194
if ($this->channel) {
147195
$this->channel->close();
148196
}
149197
}
150198

199+
/**
200+
* @return AMQPChannel
201+
*/
151202
private function getChannel()
152203
{
153204
if (null === $this->channel) {

0 commit comments

Comments
 (0)