Skip to content

Commit 4b72c9b

Browse files
committed
Merge remote-tracking branch 'origin/master' into pr-452
2 parents efd9543 + 832e88c commit 4b72c9b

32 files changed

+415
-44
lines changed

Diff for: CHANGELOG.md

+33
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
11
# Change Log
22

3+
## [0.8.33](https://github.com/php-enqueue/enqueue-dev/tree/0.8.33) (2018-07-26)
4+
[Full Changelog](https://github.com/php-enqueue/enqueue-dev/compare/0.8.32...0.8.33)
5+
6+
- \[consumption\] process niceness extension [\#449](https://github.com/php-enqueue/enqueue-dev/issues/449)
7+
- \[Symfony\] AsyncListener does not use TraceableProducer [\#392](https://github.com/php-enqueue/enqueue-dev/issues/392)
8+
9+
- Fix call debug method on null [\#480](https://github.com/php-enqueue/enqueue-dev/pull/480) ([makasim](https://github.com/makasim))
10+
11+
- Support MQTT [\#477](https://github.com/php-enqueue/enqueue-dev/issues/477)
12+
- Bugs in RabbitMqDelayPluginDelayStrategy [\#455](https://github.com/php-enqueue/enqueue-dev/issues/455)
13+
- \[sqs\] Support using a pre-configured SqsClient [\#443](https://github.com/php-enqueue/enqueue-dev/issues/443)
14+
- IronMQ \(iron.io\) provider ? [\#415](https://github.com/php-enqueue/enqueue-dev/issues/415)
15+
16+
- Add Localstack Docker container for SQS functional tests [\#473](https://github.com/php-enqueue/enqueue-dev/pull/473) ([elazar](https://github.com/elazar))
17+
- \[consumption\] add process niceness extension [\#467](https://github.com/php-enqueue/enqueue-dev/pull/467) ([ramunasd](https://github.com/ramunasd))
18+
19+
## [0.8.32](https://github.com/php-enqueue/enqueue-dev/tree/0.8.32) (2018-07-10)
20+
[Full Changelog](https://github.com/php-enqueue/enqueue-dev/compare/0.8.31...0.8.32)
21+
22+
- \[Bundle\] auto-tag services [\#409](https://github.com/php-enqueue/enqueue-dev/issues/409)
23+
24+
- Add documentation the processor services need to be public [\#406](https://github.com/php-enqueue/enqueue-dev/issues/406)
25+
26+
- Is it possible to read messages in batch? [\#472](https://github.com/php-enqueue/enqueue-dev/issues/472)
27+
- Batch publishing [\#463](https://github.com/php-enqueue/enqueue-dev/issues/463)
28+
- populating, missing messages and supervisor [\#460](https://github.com/php-enqueue/enqueue-dev/issues/460)
29+
- Processor was not found. processorName: "enqueue.client.router\_processor" [\#451](https://github.com/php-enqueue/enqueue-dev/issues/451)
30+
- \[Bundle\] Enqueue\Symfony\Client\ContainerAwareProcessorRegistry expects processors to be public [\#410](https://github.com/php-enqueue/enqueue-dev/issues/410)
31+
32+
- Update of "back to index" link [\#468](https://github.com/php-enqueue/enqueue-dev/pull/468) ([N-M](https://github.com/N-M))
33+
- PHP\_URL\_SCHEME doesn't support underscores [\#453](https://github.com/php-enqueue/enqueue-dev/pull/453) ([coudenysj](https://github.com/coudenysj))
34+
- WIP: Add support for using a pre-configured client with the SQS driver [\#444](https://github.com/php-enqueue/enqueue-dev/pull/444) ([elazar](https://github.com/elazar))
35+
336
## [0.8.31](https://github.com/php-enqueue/enqueue-dev/tree/0.8.31) (2018-05-24)
437
[Full Changelog](https://github.com/php-enqueue/enqueue-dev/compare/0.8.30...0.8.31)
538

Diff for: bin/run-fun-test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
set -x
44
set -e
55

6-
docker-compose run --workdir="/mqdev" --rm dev ./bin/test "$@"
6+
docker-compose run --workdir="/mqdev" --rm dev ./bin/test "$@"

Diff for: bin/test

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ waitForService beanstalkd 11300 50
3737
waitForService gearmand 4730 50
3838
waitForService kafka 9092 50
3939
waitForService mongo 27017 50
40+
waitForService localstack 4576 50
4041

4142
php pkg/job-queue/Tests/Functional/app/console doctrine:database:create --if-not-exists
4243
php pkg/job-queue/Tests/Functional/app/console doctrine:schema:update --force

Diff for: docker-compose.yml

+14-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ services:
1414
- google-pubsub
1515
- rabbitmqssl
1616
- mongo
17+
- localstack
1718
volumes:
1819
- './:/mqdev'
1920
environment:
@@ -34,9 +35,11 @@ services:
3435
- DOCTRINE_PASSWORD=rootpass
3536
- REDIS_HOST=redis
3637
- REDIS_PORT=6379
37-
- AWS_SQS_KEY=$ENQUEUE_AWS__SQS__KEY
38-
- AWS_SQS_SECRET=$ENQUEUE_AWS__SQS__SECRET
39-
- AWS_SQS_REGION=$ENQUEUE_AWS__SQS__REGION
38+
- AWS_SQS_KEY=key
39+
- AWS_SQS_SECRET=secret
40+
- AWS_SQS_REGION=us-east-1
41+
- AWS_SQS_ENDPOINT=http://localstack:4576
42+
- AWS_SQS_VERSION=latest
4043
- BEANSTALKD_HOST=beanstalkd
4144
- BEANSTALKD_PORT=11300
4245
- BEANSTALKD_DSN=beanstalk://beanstalkd:11300
@@ -109,6 +112,14 @@ services:
109112
ports:
110113
- "27017:27017"
111114

115+
localstack:
116+
image: 'localstack/localstack:latest'
117+
ports:
118+
- '4576:4576'
119+
environment:
120+
HOSTNAME_EXTERNAL: 'localstack'
121+
SERVICES: 'sqs'
122+
112123
volumes:
113124
mysql-data:
114125
driver: local

Diff for: docs/bundle/config_reference.md

+1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ enqueue:
228228
polling_interval: 1000
229229
lazy: true
230230
sqs:
231+
client: null
231232
key: null
232233
secret: null
233234
token: null

Diff for: docs/contribution.md

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Contribution
22

3-
To contribute you have to fork a [enqueue-dev](https://github.com/php-enqueue/enqueue-dev) repository.
4-
Clone it locally.
5-
3+
To contribute you have to send a pull request to [enqueue-dev](https://github.com/php-enqueue/enqueue-dev) repository.
4+
The pull requests to read only subtree split [repositories](https://github.com/php-enqueue/enqueue-dev/blob/master/bin/subtree-split#L46) will be closed.
5+
66
## Setup environment
77

88
```
@@ -15,15 +15,22 @@ Once you did it you can work on a feature or bug fix.
1515

1616
## Testing
1717

18-
To run tests simply run
18+
To run tests
1919

2020
```
2121
./bin/dev -t
2222
```
2323

24+
or for a package only:
25+
26+
27+
```
28+
./bin/dev -t pkg/enqueue
29+
```
30+
2431
## Commit
2532

2633
When you try to commit changes `php-cs-fixer` is run. It fixes all coding style issues. Don't forget to stage them and commit everything.
2734
Once everything is done open a pull request on official repository.
2835

29-
[back to index](index.md)
36+
[back to index](index.md)

Diff for: docs/cookbook/symfony/how-to-change-consume-command-logger.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ services:
2222

2323
The logger extension with the highest priority will set its logger.
2424

25-
[back to index](../index.md)
25+
[back to index](../../index.md)
2626

2727

2828

Diff for: docs/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,4 @@
7575
* [Symfony Async EventDispatcher](https://blog.forma-pro.com/symfony-async-eventdispatcher-d01055a255cf)
7676
* [Spool Swiftmailer emails to real message queue.](https://blog.forma-pro.com/spool-swiftmailer-emails-to-real-message-queue-9ecb8b53b5de)
7777
* [Yii PHP Framework has adopted AMQP Interop.](https://blog.forma-pro.com/yii-php-framework-has-adopted-amqp-interop-85ab47c9869f)
78+
* [(En)queue Symfony console commands](http://tech.yappa.be/enqueue-symfony-console-commands)

Diff for: docs/transport/sqs.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ $factory = new SqsConnectionFactory([
2929
'region' => 'aRegion',
3030
]);
3131

32-
// same as above but given as DSN string
32+
// same as above but given as DSN string. You may need to url encode secret if it contains special char (like +)
3333
$factory = new SqsConnectionFactory('sqs:?key=aKey&secret=aSecret&region=aRegion');
3434

3535
$psrContext = $factory->createContext();
3636

37+
// using a pre-configured client
38+
$client = new Aws\Sqs\SqsClient([ /* ... */ ]);
39+
$factory = new SqsConnectionFactory($client);
40+
3741
// if you have enqueue/enqueue library installed you can use a function from there to create the context
3842
$psrContext = \Enqueue\dsn_to_context('sqs:');
3943
```
@@ -109,4 +113,4 @@ $fooQueue = $psrContext->createQueue('foo');
109113
$psrContext->purge($fooQueue);
110114
```
111115

112-
[back to index](../index.md)
116+
[back to index](../index.md)

Diff for: pkg/amqp-ext/AmqpContext.php

+8-10
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public function subscribe(InteropAmqpConsumer $consumer, callable $callback)
315315

316316
$consumerTag = $extQueue->getConsumerTag();
317317
$consumer->setConsumerTag($consumerTag);
318-
$this->subscribers[$consumerTag] = [$consumer, $callback];
318+
$this->subscribers[$consumerTag] = [$consumer, $callback, $extQueue];
319319
}
320320

321321
/**
@@ -327,15 +327,13 @@ public function unsubscribe(InteropAmqpConsumer $consumer)
327327
return;
328328
}
329329

330-
// seg fault
331-
// $consumerTag = $consumer->getConsumerTag();
332-
// $consumer->setConsumerTag(null);
333-
//
334-
// $extQueue = new \AMQPQueue($this->getExtChannel());
335-
// $extQueue->setName($consumer->getQueue()->getQueueName());
336-
//
337-
// $extQueue->cancel($consumerTag);
338-
// unset($this->subscribers[$consumerTag]);
330+
$consumerTag = $consumer->getConsumerTag();
331+
$consumer->setConsumerTag(null);
332+
333+
list($consumer, $callback, $extQueue) = $this->subscribers[$consumerTag];
334+
335+
$extQueue->cancel($consumerTag);
336+
unset($this->subscribers[$consumerTag]);
339337
}
340338

341339
/**

Diff for: pkg/dbal/DbalConnectionFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ private function parseDsn($dsn)
9898
throw new \LogicException(sprintf('Failed to parse DSN "%s"', $dsn));
9999
}
100100

101-
$schema = parse_url($dsn, PHP_URL_SCHEME);
102-
if (empty($schema)) {
101+
if (!preg_match('/^([0-9a-z_]+):(.+)?$/', $dsn, $matches)) {
103102
throw new \LogicException('Schema is empty');
104103
}
104+
$schema = $matches[1];
105105

106106
$supported = [
107107
'db2' => true,

Diff for: pkg/dbal/Tests/DbalConnectionFactoryConfigTest.php

+20
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ public static function provideConfigs()
7272
],
7373
];
7474

75+
yield [
76+
'pdo_mysql:',
77+
[
78+
'lazy' => true,
79+
'connection' => [
80+
'url' => 'pdo_mysql://root@localhost',
81+
],
82+
],
83+
];
84+
7585
yield [
7686
'pgsql:',
7787
[
@@ -92,6 +102,16 @@ public static function provideConfigs()
92102
],
93103
];
94104

105+
yield [
106+
'pdo_mysql://user:pass@host:10001/db',
107+
[
108+
'lazy' => true,
109+
'connection' => [
110+
'url' => 'pdo_mysql://user:pass@host:10001/db',
111+
],
112+
],
113+
];
114+
95115
yield [
96116
[],
97117
[

Diff for: pkg/enqueue-bundle/Tests/Functional/App/config/custom-config.yml

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
parameters:
22
locale: 'en'
33
secret: 'ThisTokenIsNotSoSecretChangeIt'
4-
4+
env(AWS_SQS_REGION): 'us-east-1'
5+
env(AWS_SQS_VERSION): 'latest'
6+
env(AWS_SQS_KEY): 'key'
7+
env(AWS_SQS_SECRET): 'secret'
8+
env(AWS_SQS_ENDPOINT): 'http://localstack:4576'
59

610
framework:
711
#esi: ~
@@ -33,3 +37,15 @@ services:
3337
public: true
3438
tags:
3539
- { name: 'enqueue.client.processor' }
40+
41+
test.sqs_client:
42+
public: true
43+
class: Aws\Sqs\SqsClient
44+
arguments:
45+
-
46+
endpoint: '%env(AWS_SQS_ENDPOINT)%'
47+
region: '%env(AWS_SQS_REGION)%'
48+
version: '%env(AWS_SQS_VERSION)%'
49+
credentials:
50+
key: '%env(AWS_SQS_KEY)%'
51+
secret: '%env(AWS_SQS_SECRET)%'

Diff for: pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@ public function provideEnqueueConfigs()
201201
'key' => getenv('AWS_SQS_KEY'),
202202
'secret' => getenv('AWS_SQS_SECRET'),
203203
'region' => getenv('AWS_SQS_REGION'),
204+
'endpoint' => getenv('AWS_SQS_ENDPOINT'),
205+
],
206+
],
207+
]];
208+
209+
yield 'sqs_client' => [[
210+
'transport' => [
211+
'default' => 'sqs',
212+
'sqs' => [
213+
'client' => 'test.sqs_client',
204214
],
205215
],
206216
]];
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Enqueue\Consumption\Extension;
4+
5+
use Enqueue\Consumption\Context;
6+
use Enqueue\Consumption\EmptyExtensionTrait;
7+
use Enqueue\Consumption\ExtensionInterface;
8+
9+
class NicenessExtension implements ExtensionInterface
10+
{
11+
use EmptyExtensionTrait;
12+
13+
/**
14+
* @var int
15+
*/
16+
protected $niceness = 0;
17+
18+
/**
19+
* @param int $niceness
20+
*
21+
* @throws \InvalidArgumentException
22+
*/
23+
public function __construct($niceness)
24+
{
25+
if (false === is_int($niceness)) {
26+
throw new \InvalidArgumentException(sprintf(
27+
'Expected niceness value is int but got: "%s"',
28+
is_object($niceness) ? get_class($niceness) : gettype($niceness)
29+
));
30+
}
31+
32+
$this->niceness = $niceness;
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
public function onStart(Context $context)
39+
{
40+
if (0 !== $this->niceness) {
41+
$changed = @proc_nice($this->niceness);
42+
if (!$changed) {
43+
throw new \InvalidArgumentException(sprintf(
44+
'Cannot change process niceness, got warning: "%s"',
45+
error_get_last()['message']
46+
));
47+
}
48+
}
49+
}
50+
}

Diff for: pkg/enqueue/Consumption/QueueConsumer.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,13 @@ public function consume(ExtensionInterface $runtimeExtension = null)
178178
$context = new Context($this->psrContext);
179179
$this->extension->onStart($context);
180180

181-
$this->logger = $context->getLogger() ?: new NullLogger();
181+
if ($context->getLogger()) {
182+
$this->logger = $context->getLogger();
183+
} else {
184+
$this->logger = new NullLogger();
185+
$context->setLogger($this->logger);
186+
}
187+
182188
$this->logger->info('Start consuming');
183189

184190
if ($this->psrContext instanceof AmqpContext) {

Diff for: pkg/enqueue/Symfony/Consumption/LimitsExtensionsCommandTrait.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Enqueue\Consumption\Extension\LimitConsumedMessagesExtension;
66
use Enqueue\Consumption\Extension\LimitConsumerMemoryExtension;
77
use Enqueue\Consumption\Extension\LimitConsumptionTimeExtension;
8+
use Enqueue\Consumption\Extension\NicenessExtension;
89
use Enqueue\Consumption\ExtensionInterface;
910
use Symfony\Component\Console\Input\InputInterface;
1011
use Symfony\Component\Console\Input\InputOption;
@@ -20,7 +21,8 @@ protected function configureLimitsExtensions()
2021
$this
2122
->addOption('message-limit', null, InputOption::VALUE_REQUIRED, 'Consume n messages and exit')
2223
->addOption('time-limit', null, InputOption::VALUE_REQUIRED, 'Consume messages during this time')
23-
->addOption('memory-limit', null, InputOption::VALUE_REQUIRED, 'Consume messages until process reaches this memory limit in MB');
24+
->addOption('memory-limit', null, InputOption::VALUE_REQUIRED, 'Consume messages until process reaches this memory limit in MB')
25+
->addOption('niceness', null, InputOption::VALUE_REQUIRED, 'Set process niceness');
2426
}
2527

2628
/**
@@ -58,6 +60,11 @@ protected function getLimitsExtensions(InputInterface $input, OutputInterface $o
5860
$extensions[] = new LimitConsumerMemoryExtension($memoryLimit);
5961
}
6062

63+
$niceness = $input->getOption('niceness');
64+
if ($niceness) {
65+
$extensions[] = new NicenessExtension($niceness);
66+
}
67+
6168
return $extensions;
6269
}
6370
}

0 commit comments

Comments
 (0)