1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Xervice\RabbitMQ; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
|
8
|
|
|
use DataProvider\RabbitMqConnectionConfigDataProvider; |
9
|
|
|
use DataProvider\RabbitMqConsumerConfigDataProvider; |
10
|
|
|
use Xervice\Core\Business\Model\Config\AbstractConfig; |
11
|
|
|
|
12
|
|
|
class RabbitMQConfig extends AbstractConfig |
13
|
|
|
{ |
14
|
|
|
public const CONNECTION_HOST = 'rabbitmq.connection.host'; |
15
|
|
|
public const CONNECTION_PORT = 'rabbitmq.connection.port'; |
16
|
|
|
public const CONNECTION_USERNAME = 'rabbitmq.connection.username'; |
17
|
|
|
public const CONNECTION_PASSWORD = 'rabbitmq.connection.password'; |
18
|
|
|
public const CONNECTION_VIRTUALHOST = 'rabbitmq.connection.virtualhost'; |
19
|
|
|
public const CONNECTION_INSIST = 'rabbitmq.connection.insist'; |
20
|
|
|
public const CONNECTION_LOGIN_METHOD = 'rabbitmq.connection.login.method'; |
21
|
|
|
public const CONNECTION_LOCALE = 'rabbitmq.connection.locale'; |
22
|
|
|
public const CONNECTION_CONNECTION_TIMEOUT = 'rabbitmq.connection.connection.timeout'; |
23
|
|
|
public const CONNECTION_READWRITE_TIMEOUT = 'rabbitmq.connection.rewrite.timeout'; |
24
|
|
|
public const CONNECTION_CONTEXT = 'rabbitmq.connection.context'; |
25
|
|
|
public const CONNECTION_KEEPALIVE = 'rabbitmq.connection.keepalive'; |
26
|
|
|
public const CONNECTION_HEARTBEAT = 'rabbitmq.connection.hearthbeat'; |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
public const CONSUMER_TAG = 'rabbitmq.consumer.tag'; |
30
|
|
|
public const CONSUMER_NOLOCAL = 'rabbitmq.consumer.nolocal'; |
31
|
|
|
public const CONSUMER_NOACK = 'rabbitmq.consumer.noack'; |
32
|
|
|
public const CONSUMER_EXCLUSIVE = 'rabbitmq.consumer.exclusive'; |
33
|
|
|
public const CONSUMER_NOWAIT = 'rabbitmq.consumer.nowait'; |
34
|
|
|
public const CONSUMER_TICKET = 'rabbitmq.consumer.ticket'; |
35
|
|
|
public const CONSUMER_ARGUMENTS = 'rabbitmq.consumer.arguments'; |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return \DataProvider\RabbitMqConnectionConfigDataProvider |
40
|
|
|
*/ |
41
|
1 |
|
public function getConnectionConfig(): RabbitMqConnectionConfigDataProvider |
42
|
|
|
{ |
43
|
1 |
|
$connectionConfig = new RabbitMqConnectionConfigDataProvider(); |
44
|
|
|
$connectionConfig |
45
|
1 |
|
->setHost($this->get(self::CONNECTION_HOST, '127.0.0.1')) |
46
|
1 |
|
->setPort($this->get(self::CONNECTION_PORT, '5672')) |
47
|
1 |
|
->setUsername($this->get(self::CONNECTION_USERNAME)) |
48
|
1 |
|
->setPassword($this->get(self::CONNECTION_PASSWORD)) |
49
|
1 |
|
->setVirtualHost($this->get(self::CONNECTION_VIRTUALHOST, '/')) |
50
|
1 |
|
->setInsist($this->get(self::CONNECTION_INSIST, 'false')) |
51
|
1 |
|
->setLoginMethod($this->get(self::CONNECTION_LOGIN_METHOD, 'AMQPLAIN')) |
52
|
1 |
|
->setLocale($this->get(self::CONNECTION_LOCALE, 'de_DE')) |
53
|
1 |
|
->setConnectionTimeout($this->get(self::CONNECTION_CONNECTION_TIMEOUT, 3.0)) |
54
|
1 |
|
->setReadWriteTimeout($this->get(self::CONNECTION_READWRITE_TIMEOUT, 3.0)) |
55
|
1 |
|
->setContext($this->get(self::CONNECTION_CONTEXT)) |
56
|
1 |
|
->setKeepAlive($this->get(self::CONNECTION_KEEPALIVE, false)) |
57
|
1 |
|
->setHeartbeat($this->get(self::CONNECTION_HEARTBEAT, 0)) |
58
|
|
|
; |
59
|
|
|
|
60
|
1 |
|
return $connectionConfig; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return \DataProvider\RabbitMqConsumerConfigDataProvider |
65
|
|
|
*/ |
66
|
2 |
|
public function getConsumerConfig(): RabbitMqConsumerConfigDataProvider |
67
|
|
|
{ |
68
|
2 |
|
$consumerConfig = new RabbitMqConsumerConfigDataProvider(); |
69
|
|
|
$consumerConfig |
70
|
2 |
|
->setTag($this->get(self::CONSUMER_TAG, '')) |
71
|
2 |
|
->setNoLocal($this->get(self::CONSUMER_NOLOCAL, false)) |
72
|
2 |
|
->setNoAck($this->get(self::CONSUMER_NOACK, false)) |
73
|
2 |
|
->setExclusive($this->get(self::CONSUMER_EXCLUSIVE, false)) |
74
|
2 |
|
->setNoWait($this->get(self::CONSUMER_NOWAIT, false)) |
75
|
2 |
|
->setTicket($this->get(self::CONSUMER_TICKET)) |
76
|
2 |
|
->setArguments($this->get(self::CONSUMER_ARGUMENTS, [])); |
77
|
|
|
|
78
|
2 |
|
return $consumerConfig; |
79
|
|
|
} |
80
|
|
|
} |