Skip to content

Commit f1adda6

Browse files
committed
Merge branch 'Yproximite-feature/iron-mq-4'
2 parents eef2d69 + 41cfbe8 commit f1adda6

6 files changed

Lines changed: 123 additions & 27 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"require-dev": {
2929
"phpunit/phpunit": "~3.7",
3030
"aws/aws-sdk-php": "~2.5",
31-
"iron-io/iron_mq": "~2.0",
31+
"iron-io/iron_mq": "^4.0",
3232
"symfony/finder": "~2.3",
3333
"symfony/filesystem": "~2.3"
3434
},

docs/iron-mq-provider.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ and needs to have the library included in your ``composer.json`` file.
1818
1919
{
2020
require: {
21-
"iron-io/iron_mq": "~1.5"
21+
"iron-io/iron_mq": "^4.0"
2222
}
2323
}
2424

src/DependencyInjection/Configuration.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,17 @@ private function getProvidersNode()
7878
->scalarNode('project_id')->end()
7979
->scalarNode('service')->end()
8080
->enumNode('host')
81-
->defaultValue('mq-aws-us-east-1')
81+
->defaultValue('mq-aws-eu-west-1-1')
8282
->values([
83-
'mq-aws-us-east-1',
84-
'mq-aws-eu-west-1',
85-
'mq-rackspace-ord',
86-
'mq-rackspace-lon',
83+
'mq-aws-eu-west-1-1',
84+
'mq-aws-us-east-1-1',
8785
])
8886
->end()
8987
->scalarNode('port')
9088
->defaultValue('443')
9189
->end()
9290
->scalarNode('api_version')
93-
->defaultValue(1)
91+
->defaultValue(3)
9492
->end()
9593
// AWS
9694
->scalarNode('key')->end()
@@ -145,12 +143,17 @@ private function getQueuesNode()
145143
->defaultFalse()
146144
->info('Whether notifications are sent to the subscribers')
147145
->end()
146+
->scalarNode('push_type')
147+
->defaultValue('multicast')
148+
->info('Whether the push queue is multicast or unicast')
149+
->example('unicast')
150+
->end()
148151
->scalarNode('notification_retries')
149152
->defaultValue(3)
150153
->info('How many attempts the Push Notifications are retried if the Subscriber returns an error')
151154
->example(3)
152155
->end()
153-
->scalarNode('notification_retry_delay')
156+
->scalarNode('notification_retries_delay')
154157
->defaultValue(60)
155158
->info('Delay between each Push Notification retry in seconds')
156159
->example(3)
@@ -180,6 +183,11 @@ private function getQueuesNode()
180183
->info('How many seconds to Long Poll when requesting messages - if supported')
181184
->example(3)
182185
->end()
186+
->scalarNode('rate_limit')
187+
->defaultValue(-1)
188+
->info('How many push requests per second will be triggered. -1 for unlimited, 0 disables push')
189+
->example(1)
190+
->end()
183191
->append($this->getSubscribersNode())
184192
->end()
185193
->end()

src/Provider/IronMqProvider.php

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
namespace Uecode\Bundle\QPushBundle\Provider;
2424

25-
use IronMQ;
25+
use IronMQ\IronMQ;
2626
use Doctrine\Common\Cache\Cache;
2727
use Symfony\Bridge\Monolog\Logger;
2828
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -71,10 +71,13 @@ public function create()
7171
{
7272
if ($this->options['push_notifications']) {
7373
$params = [
74-
'push_type' => 'multicast',
75-
'retries' => $this->options['notification_retries'],
76-
'retry_delay' => $this->options['notification_retry_delay'],
77-
'subscribers' => []
74+
'type' => $this->options['push_type'],
75+
'push' => [
76+
'rate_limit' => $this->options['rate_limit'],
77+
'retries' => $this->options['notification_retries'],
78+
'retries_delay' => $this->options['notification_retries_delay'],
79+
'subscribers' => []
80+
]
7881
];
7982

8083
foreach ($this->options['subscribers'] as $subscriber) {
@@ -84,14 +87,14 @@ public function create()
8487
);
8588
}
8689

87-
$params['subscribers'][] = ['url' => $subscriber['endpoint']];
90+
$params['push']['subscribers'][] = ['url' => $subscriber['endpoint']];
8891
}
8992

9093
} else {
9194
$params = ['push_type' => 'pull'];
9295
}
9396

94-
$result = $this->ironmq->updateQueue($this->getNameWithPrefix(), $params);
97+
$result = $this->ironmq->createQueue($this->getNameWithPrefix(), $params);
9598
$this->queue = $result;
9699

97100
$key = $this->getNameWithPrefix();
@@ -301,4 +304,64 @@ public function onMessageReceived(MessageEvent $event)
301304

302305
$event->stopPropagation();
303306
}
307+
308+
/**
309+
* Get queue info
310+
*
311+
* This allows to get queue size. Allowing to know if processing is finished or not
312+
*
313+
* @return stdObject|null
314+
*/
315+
public function queueInfo()
316+
{
317+
if ($this->queueExists()) {
318+
$key = $this->getNameWithPrefix();
319+
$this->queue = $this->ironmq->getQueue($key);
320+
321+
return $this->queue;
322+
}
323+
324+
return null;
325+
}
326+
327+
/**
328+
* Publishes multiple message at once
329+
*
330+
* @param array $messages
331+
* @param array $options
332+
*
333+
* @return array
334+
*/
335+
public function publishMessages(array $messages, array $options = [])
336+
{
337+
$options = $this->mergeOptions($options);
338+
$publishStart = microtime(true);
339+
340+
if (!$this->queueExists()) {
341+
$this->create();
342+
}
343+
344+
$encodedMessages = [];
345+
foreach ($messages as $message) {
346+
$encodedMessages[] = json_encode($message + ['_qpush_queue' => $this->name]);
347+
}
348+
349+
$result = $this->ironmq->postMessages(
350+
$this->getNameWithPrefix(),
351+
$encodedMessages,
352+
[
353+
'timeout' => $options['message_timeout'],
354+
'delay' => $options['message_delay'],
355+
'expires_in' => $options['message_expiration']
356+
]
357+
);
358+
359+
$context = [
360+
'message_ids' => $result->ids,
361+
'publish_time' => microtime(true) - $publishStart
362+
];
363+
$this->log(200, "Messages have been published.", $context);
364+
365+
return $result->ids;
366+
}
304367
}

tests/MockClient/IronMqMockClient.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class IronMqMockClient
3131
{
3232
private $deleteCount = 0;
3333

34-
public function updateQueue($queue, array $params = [])
34+
public function createQueue($queue, array $params = [])
3535
{
3636
$response = new \stdClass;
3737
$response->id = '530295fe3c94fbcf0c79cffe';
@@ -97,4 +97,16 @@ public function deleteMessage($queue, $id)
9797

9898
return $response;
9999
}
100+
101+
public function getQueue($queue)
102+
{
103+
$response = new \stdClass;
104+
$response->id = '530295fe3c94fbcf0c79cffe';
105+
$response->name = 'test';
106+
$response->size = 0;
107+
$response->total_messages = 0;
108+
$response->project_id = '52f67d032001c00005000057';
109+
110+
return $response;
111+
}
100112
}

tests/Provider/IronMqProviderTest.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,18 @@ private function getIronMqProvider(array $options = [])
5858
{
5959
$options = array_merge(
6060
[
61-
'logging_enabled' => false,
62-
'push_notifications' => true,
63-
'notification_retries' => 3,
64-
'notification_retry_delay' => 60,
65-
'message_delay' => 0,
66-
'message_timeout' => 30,
67-
'message_expiration' => 604800,
68-
'messages_to_receive' => 1,
69-
'receive_wait_time' => 3,
70-
'subscribers' => [
61+
'logging_enabled' => false,
62+
'push_notifications' => true,
63+
'push_type' => 'multicast',
64+
'notification_retries' => 3,
65+
'notification_retries_delay' => 60,
66+
'message_delay' => 0,
67+
'message_timeout' => 30,
68+
'message_expiration' => 604800,
69+
'messages_to_receive' => 1,
70+
'rate_limit' => -1,
71+
'receive_wait_time' => 3,
72+
'subscribers' => [
7173
[ 'protocol' => 'http', 'endpoint' => 'http://fake.com' ]
7274
]
7375
],
@@ -195,4 +197,15 @@ public function testOnMessageReceived()
195197
new Message(123, ['foo' => 'bar'], [])
196198
));
197199
}
200+
201+
public function testQueueInfo()
202+
{
203+
$this->assertNull($this->provider->queueInfo());
204+
205+
$this->provider->create();
206+
$queue = $this->provider->queueInfo();
207+
$this->assertEquals('530295fe3c94fbcf0c79cffe', $queue->id);
208+
$this->assertEquals('test', $queue->name);
209+
$this->assertEquals('52f67d032001c00005000057', $queue->project_id);
210+
}
198211
}

0 commit comments

Comments
 (0)