|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TreeHouse\Queue\Amqp\Driver\Amqp; |
|
4
|
|
|
|
|
5
|
|
|
use TreeHouse\Queue\Amqp\ChannelInterface; |
|
6
|
|
|
use TreeHouse\Queue\Amqp\ConnectionInterface; |
|
7
|
|
|
use TreeHouse\Queue\Amqp\ExchangeInterface; |
|
8
|
|
|
use TreeHouse\Queue\Factory\FactoryInterface; |
|
9
|
|
|
|
|
10
|
|
|
class AmqpFactory implements FactoryInterface |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @inheritdoc |
|
14
|
|
|
*/ |
|
15
|
42 |
|
public function createConnection($host, $port = 5672, $user = 'guest', $pass = 'guest', $vhost = '/', array $connectionParams = []) |
|
16
|
|
|
{ |
|
17
|
42 |
|
$delegate = new \AMQPConnection(array_merge( |
|
18
|
|
|
[ |
|
19
|
42 |
|
'host' => $host, |
|
20
|
42 |
|
'port' => $port, |
|
21
|
42 |
|
'login' => $user, |
|
22
|
42 |
|
'password' => $pass, |
|
23
|
42 |
|
'vhost' => $vhost, |
|
24
|
|
|
], |
|
25
|
|
|
$connectionParams |
|
26
|
|
|
)); |
|
27
|
|
|
|
|
28
|
42 |
|
return new Connection($delegate); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @inheritdoc |
|
33
|
|
|
*/ |
|
34
|
27 |
|
public function createChannel(ConnectionInterface $connection) |
|
35
|
|
|
{ |
|
36
|
|
|
// we have to be connected before instantiating a channel |
|
37
|
27 |
|
if (!$connection->isConnected()) { |
|
38
|
27 |
|
$connection->connect(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
27 |
|
$delegate = new \AMQPChannel($connection->getDelegate()); |
|
42
|
|
|
|
|
43
|
27 |
|
return new Channel($delegate, $connection); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @inheritdoc |
|
48
|
|
|
*/ |
|
49
|
11 |
|
public function createExchange( |
|
50
|
|
|
ChannelInterface $channel, |
|
51
|
|
|
$name, |
|
52
|
|
|
$type = ExchangeInterface::TYPE_DIRECT, |
|
53
|
|
|
$flags = null, |
|
54
|
|
|
array $args = [] |
|
55
|
|
|
) { |
|
56
|
11 |
|
$delegate = new \AMQPExchange($channel->getDelegate()); |
|
57
|
11 |
|
$delegate->setName($name); |
|
58
|
11 |
|
$delegate->setType($type); |
|
59
|
11 |
|
$delegate->setFlags(Exchange::convertToDelegateFlags($flags)); |
|
60
|
11 |
|
$delegate->setArguments($args); |
|
61
|
|
|
|
|
62
|
11 |
|
return new Exchange($delegate, $channel); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @inheritdoc |
|
67
|
|
|
*/ |
|
68
|
3 |
|
public function createQueue(ChannelInterface $channel, $name = null, $flags = null, array $args = []) |
|
69
|
|
|
{ |
|
70
|
3 |
|
$delegate = new \AMQPQueue($channel->getDelegate()); |
|
71
|
3 |
|
$delegate->setFlags(Queue::convertToDelegateFlags($flags)); |
|
72
|
3 |
|
$delegate->setArguments($args); |
|
73
|
|
|
|
|
74
|
3 |
|
if (null !== $name) { |
|
75
|
1 |
|
$delegate->setName($name); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
3 |
|
return new Queue($delegate, $channel); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|