1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* This file is part of the daikon-cqrs/rabbitmq3-adapter project. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Daikon\RabbitMq3\Connector; |
10
|
|
|
|
11
|
|
|
use Daikon\Dbal\Connector\ConnectorInterface; |
12
|
|
|
use Daikon\Dbal\Connector\ProvidesConnector; |
13
|
|
|
use PhpAmqpLib\Connection\AMQPLazyConnection; |
14
|
|
|
|
15
|
|
|
class RabbitMq3Connector implements ConnectorInterface |
16
|
|
|
{ |
17
|
|
|
use ProvidesConnector; |
18
|
|
|
|
19
|
|
|
protected function connect(): AMQPLazyConnection |
20
|
|
|
{ |
21
|
|
|
$settings = $this->getSettings(); |
22
|
|
|
|
23
|
|
|
// https://github.com/videlalvaro/php-amqplib/blob/master/PhpAmqpLib/Connection/AMQPStreamConnection.php#L8-L39 |
24
|
|
|
return new AMQPLazyConnection( |
25
|
|
|
$settings['host'] ?? 'localhost', |
26
|
|
|
$settings['port'] ?? '5672', |
27
|
|
|
$settings['user'] ?? '', |
28
|
|
|
$settings['password'] ?? '', |
29
|
|
|
$settings['vhost'] ?? '/', |
30
|
|
|
$settings['insist'] ?? false, |
31
|
|
|
$settings['login_method'] ?? 'AMQPLAIN', |
32
|
|
|
null, |
33
|
|
|
$settings['locale'] ?? 'en_US', |
34
|
|
|
$settings['connection_timeout'] ?? 3.0, |
35
|
|
|
$settings['read_write_timeout'] ?? 3.0, |
36
|
|
|
null, |
37
|
|
|
$settings['keepalive'] ?? true, |
38
|
|
|
// setting this to NULL may lead to using the server proposed value? |
39
|
|
|
$settings['heartbeat'] ?? 0 |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function disconnect(): void |
44
|
|
|
{ |
45
|
|
|
if ($this->isConnected()) { |
46
|
|
|
$this->connection->close(); |
47
|
|
|
$this->connection = null; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|