Skip to content

Commit 5cfa081

Browse files
author
Keith Kirk
committed
fixing merge conflict
2 parents 2ca0c19 + 9f70222 commit 5cfa081

12 files changed

Lines changed: 193 additions & 94 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The bundle should be installed through composer.
2222
```json
2323
{
2424
"require": {
25-
"uecode/qpush-bundle": "~1.4.0",
25+
"uecode/qpush-bundle": "~2.0.0",
2626
}
2727
}
2828
```

docs/aws-provider.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ credentials in your configuration.
2828
2929
uecode_qpush:
3030
providers:
31-
aws:
31+
my_provider:
32+
driver: aws
3233
key: <aws key>
3334
secret: <aws secret>
3435
region: us-east-1
3536
queues:
3637
my_queue_name:
37-
provider: aws
38+
provider: my_provider
3839
options:
3940
push_notifications: true
4041
subscribers:

docs/configuration.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,24 @@ A working configuration would look like the following
107107
logging_enabled: true
108108
providers:
109109
aws:
110+
driver: aws #optional for providers named 'aws' or 'ironmq'
111+
key: YOUR_AWS_KEY_HERE
112+
secret: YOUR_AWS_SECRET_HERE
113+
region: YOUR_AWS_REGION_HERE
114+
another_aws_provider:
115+
driver: aws #required for named providers
110116
key: YOUR_AWS_KEY_HERE
111117
secret: YOUR_AWS_SECRET_HERE
112118
region: YOUR_AWS_REGION_HERE
113119
ironmq:
120+
driver: aws #optional for providers named 'aws' or 'ironmq'
114121
token: YOUR_IRONMQ_TOKEN_HERE
115122
project_id: YOUR_IRONMQ_PROJECT_ID_HERE
123+
in_band:
124+
driver: sync
116125
queues:
117126
my_queue_key:
118-
provider: ironmq #or aws or sync
127+
provider: ironmq #or aws or in_band or another_aws_provider
119128
options:
120129
queue_name: my_actual_queue_name
121130
push_notifications: true

docs/installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The bundle should be installed through composer.
99
1010
{
1111
"require": {
12-
"uecode/qpush-bundle": "~1.1",
12+
"uecode/qpush-bundle": "~2.0.0",
1313
}
1414
}
1515

docs/iron-mq-provider.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,24 @@ an account and have a project id.
3030
testing and using this service extremely easy.
3131

3232
Just include your OAuth `token` and `project_id` in the configuration and set your
33-
queue to use the `ironmq` provider.
33+
queue to use a provider using the `ironmq` driver.
3434

3535
.. code-block:: yaml
3636
3737
#app/config.yml
3838
3939
uecode_qpush:
4040
providers:
41-
ironmq:
41+
my_provider:
42+
driver: ironmq
4243
token: YOUR_TOKEN_HERE
4344
project_id: YOUR_PROJECT_ID_HERE
4445
host: YOUR_OPTIONAL_HOST_HERE
4546
port: YOUR_OPTIONAL_PORT_HERE
4647
version_id: YOUR_OPTIONAL_VERSION_HERE
4748
queues:
4849
my_queue_name:
49-
provider: ironmq
50+
provider: my_provider
5051
options:
5152
push_notifications: true
5253
subscribers:

docs/sync-provider.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ of queue-based code paths.
88
Configuration
99
^^^^^^^^^^^^^
1010

11-
To use the sync queue, set the ``provider`` of a given queue to ``sync``. No further
11+
To designate a queue as synchronous, set the ``driver`` of its provider to ``sync``. No further
1212
configuration is necessary.
1313

1414
.. code-block:: yaml
1515
1616
#app/config_dev.yml
1717
1818
uecode_qpush:
19+
providers:
20+
in_band:
21+
driver: sync
1922
queues:
2023
my_queue_name:
21-
provider: sync
24+
provider: in_band

src/DependencyInjection/Configuration.php

Lines changed: 86 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -54,41 +54,62 @@ public function getConfigTreeBuilder()
5454

5555
private function getProvidersNode()
5656
{
57-
$treeBuilder = new TreeBuilder();
58-
$node = $treeBuilder->root('providers');
57+
$treeBuilder = new TreeBuilder();
58+
$node = $treeBuilder->root('providers');
59+
$requirements = [
60+
'aws' => ['key', 'secret'],
61+
'ironmq' => ['token', 'project_id'],
62+
'sync' => [],
63+
];
5964

6065
$node
61-
->children()
62-
->arrayNode('aws')
63-
->children()
64-
->scalarNode('key')->end()
65-
->scalarNode('secret')->end()
66-
->scalarNode('region')
67-
->defaultValue('us-east-1')
68-
->end()
66+
->useAttributeAsKey('name')
67+
->prototype('array')
68+
->treatNullLike([])
69+
->children()
70+
->enumNode('driver')
71+
->isRequired()
72+
->values(array_keys($requirements))
6973
->end()
70-
->end()
71-
->arrayNode('ironmq')
72-
->children()
73-
->scalarNode('token')->end()
74-
->scalarNode('project_id')->end()
75-
->enumNode('host')
76-
->defaultValue('mq-aws-us-east-1')
77-
->values([
78-
'mq-aws-us-east-1',
79-
'mq-aws-eu-west-1',
80-
'mq-rackspace-ord',
81-
'mq-rackspace-lon'
82-
])
83-
->end()
84-
->scalarNode('port')
85-
->defaultValue('443')
86-
->end()
87-
->scalarNode('api_version')
88-
->defaultValue(1)
89-
->end()
74+
// IronMQ
75+
->scalarNode('token')->end()
76+
->scalarNode('project_id')->end()
77+
->enumNode('host')
78+
->defaultValue('mq-aws-us-east-1')
79+
->values([
80+
'mq-aws-us-east-1',
81+
'mq-aws-eu-west-1',
82+
'mq-rackspace-ord',
83+
'mq-rackspace-lon',
84+
])
85+
->end()
86+
->scalarNode('port')
87+
->defaultValue('443')
88+
->end()
89+
->scalarNode('api_version')
90+
->defaultValue(1)
91+
->end()
92+
// AWS
93+
->scalarNode('key')->end()
94+
->scalarNode('secret')->end()
95+
->scalarNode('region')
96+
->defaultValue('us-east-1')
9097
->end()
9198
->end()
99+
100+
->validate()
101+
->always()
102+
->then(function (array $provider) use ($node, $requirements) {
103+
foreach ($requirements[$provider['driver']] as $requirement) {
104+
if (empty($provider[$requirement])) {
105+
throw new \InvalidArgumentException(
106+
sprintf('%s queue providers must have a %s; none provided', $provider['driver'], $requirement)
107+
);
108+
}
109+
}
110+
111+
return $provider;
112+
})
92113
->end()
93114
;
94115

@@ -119,36 +140,41 @@ private function getQueuesNode()
119140
->defaultFalse()
120141
->info('Whether notifications are sent to the subscribers')
121142
->end()
122-
->scalarNode('notification_retries')
123-
->defaultValue(3)
124-
->info('How many attempts the Push Notifications are retried if the Subscriber returns an error')
125-
->example(3)
126-
->end()
127-
->scalarNode('message_delay')
128-
->defaultValue(0)
129-
->info('How many seconds before messages are inititally visible in the Queue')
130-
->example(0)
131-
->end()
132-
->scalarNode('message_timeout')
133-
->defaultValue(30)
134-
->info('How many seconds the Queue hides a message while its being processed')
135-
->example(30)
136-
->end()
137-
->scalarNode('message_expiration')
138-
->defaultValue(604800)
139-
->info('How many seconds a message is kept in Queue, the default is 7 days (604800 seconds)')
140-
->example(604800)
141-
->end()
142-
->scalarNode('messages_to_receive')
143-
->defaultValue(1)
144-
->info('Max amount of messages to receive at once - an event will be fired for each individually')
145-
->example(1)
146-
->end()
147-
->scalarNode('receive_wait_time')
148-
->defaultValue(3)
149-
->info('How many seconds to Long Poll when requesting messages - if supported')
150-
->example(3)
151-
->end()
143+
->scalarNode('notification_retries')
144+
->defaultValue(3)
145+
->info('How many attempts the Push Notifications are retried if the Subscriber returns an error')
146+
->example(3)
147+
->end()
148+
->scalarNode('notification_retry_delay')
149+
->defaultValue(60)
150+
->info('Delay between each Push Notification retry in seconds')
151+
->example(3)
152+
->end()
153+
->scalarNode('message_delay')
154+
->defaultValue(0)
155+
->info('How many seconds before messages are inititally visible in the Queue')
156+
->example(0)
157+
->end()
158+
->scalarNode('message_timeout')
159+
->defaultValue(30)
160+
->info('How many seconds the Queue hides a message while its being processed')
161+
->example(30)
162+
->end()
163+
->scalarNode('message_expiration')
164+
->defaultValue(604800)
165+
->info('How many seconds a message is kept in Queue, the default is 7 days (604800 seconds)')
166+
->example(604800)
167+
->end()
168+
->scalarNode('messages_to_receive')
169+
->defaultValue(1)
170+
->info('Max amount of messages to receive at once - an event will be fired for each individually')
171+
->example(1)
172+
->end()
173+
->scalarNode('receive_wait_time')
174+
->defaultValue(3)
175+
->info('How many seconds to Long Poll when requesting messages - if supported')
176+
->example(3)
177+
->end()
152178
->append($this->getSubscribersNode())
153179
->end()
154180
->end()

src/DependencyInjection/UecodeQPushExtension.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,21 @@ public function load(array $configs, ContainerBuilder $container)
6060
$class = null;
6161
$client = null;
6262

63-
switch ($provider) {
63+
switch ($config['providers'][$provider]['driver']) {
6464
case 'aws':
6565
$class = $container->getParameter('uecode_qpush.provider.aws');
6666
$client = $this->createAwsClient(
6767
$config['providers'][$provider],
68-
$container
68+
$container,
69+
$provider
6970
);
7071
break;
7172
case 'ironmq':
7273
$class = $container->getParameter('uecode_qpush.provider.ironmq');
7374
$client = $this->createIronMQClient(
7475
$config['providers'][$provider],
75-
$container
76+
$container,
77+
$provider
7678
);
7779
break;
7880
case 'sync':
@@ -116,12 +118,15 @@ public function load(array $configs, ContainerBuilder $container)
116118
*
117119
* @param array $config A Configuration array for the client
118120
* @param ContainerBuilder $container The container
121+
* @param string $name The provider key
119122
*
120-
* return Reference
123+
* @return Reference
121124
*/
122-
private function createAwsClient($config, ContainerBuilder $container)
125+
private function createAwsClient($config, ContainerBuilder $container, $name)
123126
{
124-
if (!$container->hasDefinition('uecode_qpush.provider.aws')) {
127+
$service = sprintf('uecode_qpush.provider.%s', $name);
128+
129+
if (!$container->hasDefinition($service)) {
125130

126131
if (!class_exists('Aws\Common\Aws')) {
127132
throw new \RuntimeException(
@@ -140,24 +145,27 @@ private function createAwsClient($config, ContainerBuilder $container)
140145
]
141146
]);
142147

143-
$container->setDefinition('uecode_qpush.provider.aws', $aws)
148+
$container->setDefinition($service, $aws)
144149
->setPublic(false);
145150
}
146151

147-
return new Reference('uecode_qpush.provider.aws');
152+
return new Reference($service);
148153
}
149154

150155
/**
151156
* Creates a definition for the IronMQ provider
152157
*
153158
* @param array $config A Configuration array for the provider
154159
* @param ContainerBuilder $container The container
160+
* @param string $name The provider key
155161
*
156-
* return Reference
162+
* @return Reference
157163
*/
158-
private function createIronMQClient($config, ContainerBuilder $container)
164+
private function createIronMQClient($config, ContainerBuilder $container, $name)
159165
{
160-
if (!$container->hasDefinition('uecode_qpush.provider.ironmq')) {
166+
$service = sprintf('uecode_qpush.provider.%s', $name);
167+
168+
if (!$container->hasDefinition($service)) {
161169

162170
if (!class_exists('IronMQ')) {
163171
throw new \RuntimeException(
@@ -176,11 +184,11 @@ private function createIronMQClient($config, ContainerBuilder $container)
176184
]
177185
]);
178186

179-
$container->setDefinition('uecode_qpush.provider.ironmq', $ironmq)
187+
$container->setDefinition($service, $ironmq)
180188
->setPublic(false);
181189
}
182190

183-
return new Reference('uecode_qpush.provider.ironmq');
191+
return new Reference($service);
184192
}
185193

186194
private function createSyncClient()

src/Provider/IronMqProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function create()
7272
$params = [
7373
'push_type' => 'multicast',
7474
'retries' => $this->options['notification_retries'],
75+
'retry_delay' => $this->options['notification_retry_delay'],
7576
'subscribers' => []
7677
];
7778

tests/DependencyInjection/UecodeQPushExtensionTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,19 @@ public function testConfiguration()
6565
$this->container->compile();
6666

6767
$this->assertTrue($this->container->has('uecode_qpush'));
68+
6869
$this->assertTrue($this->container->has('uecode_qpush.test_aws'));
70+
$this->assertTrue($this->container->has('uecode_qpush.test_secondary_aws'));
71+
$this->assertNotSame(
72+
$this->container->get('uecode_qpush.test_aws'),
73+
$this->container->get('uecode_qpush.test_secondary_aws')
74+
);
75+
6976
$this->assertTrue($this->container->has('uecode_qpush.test_ironmq'));
77+
$this->assertTrue($this->container->has('uecode_qpush.test_secondary_ironmq'));
78+
$this->assertNotSame(
79+
$this->container->get('uecode_qpush.test_ironmq'),
80+
$this->container->get('uecode_qpush.test_secondary_ironmq')
81+
);
7082
}
7183
}

0 commit comments

Comments
 (0)