Skip to content

Commit add6a4f

Browse files
committed
remove RABBITMQ_HOST,PORT etc env vars.
1 parent 2991e07 commit add6a4f

13 files changed

Lines changed: 27 additions & 119 deletions

‎docker-compose.yml‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ services:
1919
- './:/mqdev'
2020
environment:
2121
- AMQP_DSN=amqp://guest:guest@rabbitmq:5672/mqdev
22-
- RABITMQ_AMQP_DSN=amqp+rabbitmq://guest:guest@rabbitmq:5672/mqdev
22+
- RABBITMQ_AMQP_DSN=amqp+rabbitmq://guest:guest@rabbitmq:5672/mqdev
2323
- AMQPS_DSN=amqps://guest:guest@rabbitmqssl:5671
2424
- STOMP_DSN=stomp://guest:guest@rabbitmq:61613/mqdev
2525
- RABITMQ_STOMP_DSN=stomp+rabbitmq://guest:guest@rabbitmq:61613/mqdev
@@ -30,12 +30,6 @@ services:
3030
- PHPREDIS_DSN=redis+phpredis://redis
3131
- GPS_DSN=gps:?projectId=mqdev&emulatorHost=http://google-pubsub:8085
3232
- SQS_DSN=sqs:?key=key&secret=secret&region=us-east-1&endpoint=http://localstack:4576&version=latest
33-
- RABBITMQ_HOST=rabbitmq
34-
- RABBITMQ_USER=guest
35-
- RABBITMQ_PASSWORD=guest
36-
- RABBITMQ_VHOST=mqdev
37-
- RABBITMQ_AMQP__PORT=5672
38-
- RABBITMQ_STOMP_PORT=61613
3933
- DOCTRINE_DRIVER=pdo_mysql
4034
- DOCTRINE_HOST=mysql
4135
- DOCTRINE_PORT=3306

‎pkg/amqp-ext/examples/consume.php‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,7 @@
1717

1818
use Enqueue\AmqpExt\AmqpConnectionFactory;
1919

20-
$config = [
21-
'host' => getenv('RABBITMQ_HOST'),
22-
'port' => getenv('RABBITMQ_AMQP__PORT'),
23-
'user' => getenv('RABBITMQ_USER'),
24-
'pass' => getenv('RABBITMQ_PASSWORD'),
25-
'vhost' => getenv('RABBITMQ_VHOST'),
26-
];
27-
28-
$factory = new AmqpConnectionFactory($config);
20+
$factory = new AmqpConnectionFactory(getenv('RABBITMQ_AMQP_DSN'));
2921
$context = $factory->createContext();
3022

3123
$queue = $context->createQueue('foo');

‎pkg/amqp-ext/examples/produce.php‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,7 @@
2020
use Interop\Amqp\AmqpTopic;
2121
use Interop\Amqp\Impl\AmqpBind;
2222

23-
$config = [
24-
'host' => getenv('RABBITMQ_HOST'),
25-
'port' => getenv('RABBITMQ_AMQP__PORT'),
26-
'user' => getenv('RABBITMQ_USER'),
27-
'pass' => getenv('RABBITMQ_PASSWORD'),
28-
'vhost' => getenv('RABBITMQ_VHOST'),
29-
];
30-
31-
$factory = new AmqpConnectionFactory($config);
23+
$factory = new AmqpConnectionFactory(getenv('RABBITMQ_AMQP_DSN'));
3224
$context = $factory->createContext();
3325

3426
$topic = $context->createTopic('test.amqp.ext');

‎pkg/amqp-lib/examples/consume.php‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,7 @@
1717

1818
use Enqueue\AmqpLib\AmqpConnectionFactory;
1919

20-
$config = [
21-
'host' => getenv('RABBITMQ_HOST'),
22-
'port' => getenv('RABBITMQ_AMQP__PORT'),
23-
'user' => getenv('RABBITMQ_USER'),
24-
'pass' => getenv('RABBITMQ_PASSWORD'),
25-
'vhost' => getenv('RABBITMQ_VHOST'),
26-
'receive_method' => 'basic_consume',
27-
];
28-
29-
$factory = new AmqpConnectionFactory($config);
20+
$factory = new AmqpConnectionFactory(getenv('RABBITMQ_AMQP_DSN'));
3021
$context = $factory->createContext();
3122

3223
$queue = $context->createQueue('foo');

‎pkg/amqp-lib/examples/produce.php‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,7 @@
2020
use Interop\Amqp\AmqpTopic;
2121
use Interop\Amqp\Impl\AmqpBind;
2222

23-
$config = [
24-
'host' => getenv('RABBITMQ_HOST'),
25-
'port' => getenv('RABBITMQ_AMQP__PORT'),
26-
'user' => getenv('RABBITMQ_USER'),
27-
'pass' => getenv('RABBITMQ_PASSWORD'),
28-
'vhost' => getenv('RABBITMQ_VHOST'),
29-
];
30-
31-
$factory = new AmqpConnectionFactory($config);
23+
$factory = new AmqpConnectionFactory(getenv('RABBITMQ_AMQP_DSN'));
3224
$context = $factory->createContext();
3325

3426
$topic = $context->createTopic('test.amqp.ext');

‎pkg/stomp/examples/consume.php‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,8 @@
1818
use Enqueue\Stomp\StompConnectionFactory;
1919
use Stomp\Exception\ErrorFrameException;
2020

21-
$config = [
22-
'host' => getenv('RABBITMQ_HOST'),
23-
'port' => getenv('RABBITMQ_STOMP_PORT'),
24-
'login' => getenv('RABBITMQ_USER'),
25-
'password' => getenv('RABBITMQ_PASSWORD'),
26-
'vhost' => getenv('RABBITMQ_VHOST'),
27-
'sync' => true,
28-
];
29-
3021
try {
31-
$factory = new StompConnectionFactory($config);
22+
$factory = new StompConnectionFactory(getenv('RABITMQ_STOMP_DSN'));
3223
$context = $factory->createContext();
3324

3425
$destination = $context->createQueue('destination');

‎pkg/stomp/examples/publish.php‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,8 @@
1818
use Enqueue\Stomp\StompConnectionFactory;
1919
use Stomp\Exception\ErrorFrameException;
2020

21-
$config = [
22-
'host' => getenv('RABBITMQ_HOST'),
23-
'port' => getenv('RABBITMQ_STOMP_PORT'),
24-
'login' => getenv('RABBITMQ_USER'),
25-
'password' => getenv('RABBITMQ_PASSWORD'),
26-
'vhost' => getenv('RABBITMQ_VHOST'),
27-
'sync' => true,
28-
];
29-
3021
try {
31-
$factory = new StompConnectionFactory($config);
22+
$factory = new StompConnectionFactory(getenv('RABITMQ_STOMP_DSN'));
3223
$context = $factory->createContext();
3324

3425
$destination = $context->createQueue('destination');

‎pkg/test/MongodbExtensionTrait.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
namespace Enqueue\Test;
44

55
use Enqueue\Mongodb\MongodbConnectionFactory;
6+
use Enqueue\Mongodb\MongodbContext;
67

78
trait MongodbExtensionTrait
89
{
9-
protected function buildMongodbContext()
10+
protected function buildMongodbContext(): MongodbContext
1011
{
1112
if (false == $env = getenv('MONGO_DSN')) {
1213
$this->markTestSkipped('The MONGO_DSN env is not available. Skip tests');

‎pkg/test/RabbitManagementExtensionTrait.php‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22

33
namespace Enqueue\Test;
44

5+
use Enqueue\Dsn\Dsn;
6+
57
trait RabbitManagementExtensionTrait
68
{
79
/**
810
* @param string $queueName
911
*/
1012
private function removeQueue($queueName)
1113
{
12-
$rabbitmqHost = getenv('RABBITMQ_HOST');
13-
$rabbitmqUser = getenv('RABBITMQ_USER');
14-
$rabbitmqPassword = getenv('RABBITMQ_PASSWORD');
15-
$rabbitmqVhost = getenv('RABBITMQ_VHOST');
14+
$dsn = new Dsn(getenv('RABBITMQ_AMQP_DSN'));
1615

1716
$url = sprintf(
1817
'http://%s:15672/api/queues/%s/%s',
19-
$rabbitmqHost,
20-
urlencode($rabbitmqVhost),
18+
$dsn->getHost(),
19+
urlencode(ltrim($dsn->getPath(), '/')),
2120
$queueName
2221
);
2322

@@ -26,7 +25,7 @@ private function removeQueue($queueName)
2625
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
2726
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
2827
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
29-
curl_setopt($ch, CURLOPT_USERPWD, $rabbitmqUser.':'.$rabbitmqPassword);
28+
curl_setopt($ch, CURLOPT_USERPWD, $dsn->getUser().':'.$dsn->getPassword());
3029
curl_setopt($ch, CURLOPT_HTTPHEADER, [
3130
'Content-Type' => 'application/json',
3231
]);
@@ -46,15 +45,12 @@ private function removeQueue($queueName)
4645
*/
4746
private function removeExchange($exchangeName)
4847
{
49-
$rabbitmqHost = getenv('RABBITMQ_HOST');
50-
$rabbitmqUser = getenv('RABBITMQ_USER');
51-
$rabbitmqPassword = getenv('RABBITMQ_PASSWORD');
52-
$rabbitmqVhost = getenv('RABBITMQ_VHOST');
48+
$dsn = new Dsn(getenv('RABBITMQ_AMQP_DSN'));
5349

5450
$url = sprintf(
5551
'http://%s:15672/api/exchanges/%s/%s',
56-
$rabbitmqHost,
57-
urlencode($rabbitmqVhost),
52+
$dsn->getHost(),
53+
urlencode(ltrim($dsn->getPath(), '/')),
5854
$exchangeName
5955
);
6056

@@ -63,7 +59,7 @@ private function removeExchange($exchangeName)
6359
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
6460
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
6561
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
66-
curl_setopt($ch, CURLOPT_USERPWD, $rabbitmqUser.':'.$rabbitmqPassword);
62+
curl_setopt($ch, CURLOPT_USERPWD, $dsn->getUser().':'.$dsn->getPassword());
6763
curl_setopt($ch, CURLOPT_HTTPHEADER, [
6864
'Content-Type' => 'application/json',
6965
]);

‎pkg/test/RabbitmqAmqpExtension.php‎

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,7 @@ trait RabbitmqAmqpExtension
1212
*/
1313
private function buildAmqpContext()
1414
{
15-
if (false == getenv('RABBITMQ_HOST')) {
16-
throw new \PHPUnit_Framework_SkippedTestError('Functional tests are not allowed in this environment');
17-
}
18-
19-
$config = [
20-
'host' => getenv('RABBITMQ_HOST'),
21-
'port' => getenv('RABBITMQ_AMQP__PORT'),
22-
'user' => getenv('RABBITMQ_USER'),
23-
'pass' => getenv('RABBITMQ_PASSWORD'),
24-
'vhost' => getenv('RABBITMQ_VHOST'),
25-
];
26-
27-
return (new AmqpConnectionFactory($config))->createContext();
28-
}
29-
30-
/**
31-
* @return AmqpContext
32-
*/
33-
private function buildAmqpContextFromDsn()
34-
{
35-
if (false == $dsn = getenv('AMQP_DSN')) {
15+
if (false == $dsn = getenv('RABBITMQ_AMQP_DSN')) {
3616
throw new \PHPUnit_Framework_SkippedTestError('Functional tests are not allowed in this environment');
3717
}
3818

0 commit comments

Comments
 (0)