Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 309b111

Browse files
magento enqueue
1 parent 42a3f76 commit 309b111

File tree

3 files changed

+185
-45
lines changed

3 files changed

+185
-45
lines changed

‎src/Enqueue/Enqueue/Helper/Data.php

Lines changed: 165 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use Enqueue\Client\Message;
4+
use Enqueue\Client\SimpleClient;
45
use Enqueue\Psr\PsrProcessor;
56

67
class Enqueue_Enqueue_Helper_Data extends Mage_Core_Helper_Data
@@ -10,11 +11,6 @@ class Enqueue_Enqueue_Helper_Data extends Mage_Core_Helper_Data
1011
*/
1112
private $client;
1213

13-
/**
14-
* @var \Enqueue\Client\ProducerInterface
15-
*/
16-
private $producer;
17-
1814
public function bindProcessors()
1915
{
2016
if (false == $processors = Mage::getStoreConfig('enqueue/processors')) {
@@ -56,11 +52,7 @@ public function send($topic, $message)
5652
*/
5753
public function getProducer()
5854
{
59-
if (null === $this->producer) {
60-
$this->producer = $this->getClient()->getProducer();
61-
}
62-
63-
return $this->producer;
55+
return $this->getClient()->getProducer();
6456
}
6557

6658
/**
@@ -69,53 +61,181 @@ public function getProducer()
6961
public function getClient()
7062
{
7163
if (null === $this->client) {
72-
$name = Mage::getStoreConfig('enqueue/transport/default');
73-
74-
switch ($name) {
75-
case 'rabbitmq-amqp':
76-
$this->client = $this->buildRabbitMqAmqp();
77-
break;
78-
default:
79-
throw new \LogicException(sprintf('Unknown transport: "%s"', $name));
80-
}
64+
$this->client = new SimpleClient($this->buildConfig());
8165
}
8266

8367
return $this->client;
8468
}
8569

8670
/**
87-
* @return \Enqueue\Client\SimpleClient
71+
* @return array
8872
*/
89-
public function buildRabbitMqAmqp()
73+
public function buildConfig()
9074
{
91-
$config = [
92-
'host' => Mage::getStoreConfig('enqueue/rabbitmq/host'),
93-
'port' => Mage::getStoreConfig('enqueue/rabbitmq/port'),
94-
'login' => Mage::getStoreConfig('enqueue/rabbitmq/login'),
95-
'password' => Mage::getStoreConfig('enqueue/rabbitmq/password'),
96-
'vhost' => Mage::getStoreConfig('enqueue/rabbitmq/vhost'),
97-
];
98-
99-
$connectionFactory = new \Enqueue\AmqpExt\AmqpConnectionFactory($config);
100-
101-
return new \Enqueue\Client\SimpleClient(
102-
$connectionFactory->createContext(),
103-
$this->buildConfig()
104-
);
75+
$config = $this->getClientConfig();
76+
$config['transport'] = [];
77+
78+
switch ($name = Mage::getStoreConfig('enqueue/transport/default')) {
79+
case 'rabbitmq_amqp':
80+
$config['transport'] = $this->getRabbitMqAmqpConfig();
81+
break;
82+
case 'amqp':
83+
$config['transport'] = $this->getAmqpConfig();
84+
break;
85+
case 'stomp':
86+
$config['transport'] = $this->getStompConfig();
87+
break;
88+
case 'rabbitmq_stomp':
89+
$config['transport'] = $this->getRabbitMqStompConfig();
90+
break;
91+
case 'fs':
92+
$config['transport'] = $this->getFsConfig();
93+
break;
94+
case 'sqs':
95+
$config['transport'] = $this->getSqsConfig();
96+
break;
97+
case 'redis':
98+
$config['transport'] = $this->getRedisConfig();
99+
break;
100+
case 'dbal':
101+
$config['transport'] = $this->getDbalConfig();
102+
break;
103+
default:
104+
throw new \LogicException(sprintf('Unknown transport: "%s"', $name));
105+
}
106+
107+
return $config;
105108
}
106109

107110
/**
108-
* @return \Enqueue\Client\Config
111+
* @return array
109112
*/
110-
public function buildConfig()
113+
public function getClientConfig()
114+
{
115+
return ['client' => [
116+
'prefix' => Mage::getStoreConfig('enqueue/client/prefix'),
117+
'app_name' => Mage::getStoreConfig('enqueue/client/app_name'),
118+
'router_topic' => Mage::getStoreConfig('enqueue/client/router_topic'),
119+
'router_queue' => Mage::getStoreConfig('enqueue/client/router_queue'),
120+
'default_processor_queue' => Mage::getStoreConfig('enqueue/client/default_processor_queue'),
121+
'redelivered_delay_time' => (int) Mage::getStoreConfig('enqueue/client/redelivered_delay_time'),
122+
]];
123+
}
124+
125+
/**
126+
* @return array
127+
*/
128+
public function getRabbitMqAmqpConfig()
129+
{
130+
return ['rabbitmq_amqp' => [
131+
'host' => Mage::getStoreConfig('enqueue/rabbitmq_amqp/host'),
132+
'port' => (int) Mage::getStoreConfig('enqueue/rabbitmq_amqp/port'),
133+
'login' => Mage::getStoreConfig('enqueue/rabbitmq_amqp/login'),
134+
'password' => Mage::getStoreConfig('enqueue/rabbitmq_amqp/password'),
135+
'vhost' => Mage::getStoreConfig('enqueue/rabbitmq_amqp/vhost'),
136+
'lazy' => (bool) Mage::getStoreConfig('enqueue/rabbitmq_amqp/lazy'),
137+
'delay_plugin_installed' => (bool) Mage::getStoreConfig('enqueue/rabbitmq_amqp/delay_plugin_installed'),
138+
]];
139+
}
140+
141+
/**
142+
* @return array
143+
*/
144+
public function getAmqpConfig()
145+
{
146+
return ['amqp' => [
147+
'host' => Mage::getStoreConfig('enqueue/amqp/host'),
148+
'port' => (int) Mage::getStoreConfig('enqueue/amqp/port'),
149+
'login' => Mage::getStoreConfig('enqueue/amqp/login'),
150+
'password' => Mage::getStoreConfig('enqueue/amqp/password'),
151+
'vhost' => Mage::getStoreConfig('enqueue/amqp/vhost'),
152+
'lazy' => (bool) Mage::getStoreConfig('enqueue/amqp/lazy'),
153+
]];
154+
}
155+
156+
/**
157+
* @return array
158+
*/
159+
public function getStompConfig()
160+
{
161+
return ['stomp' => [
162+
'host' => Mage::getStoreConfig('enqueue/stomp/host'),
163+
'port' => (int) Mage::getStoreConfig('enqueue/stomp/port'),
164+
'login' => Mage::getStoreConfig('enqueue/stomp/login'),
165+
'password' => Mage::getStoreConfig('enqueue/stomp/password'),
166+
'vhost' => Mage::getStoreConfig('enqueue/stomp/vhost'),
167+
'lazy' => (bool) Mage::getStoreConfig('enqueue/stomp/lazy'),
168+
]];
169+
}
170+
171+
/**
172+
* @return array
173+
*/
174+
public function getRabbitMqStompConfig()
175+
{
176+
return ['rabbitmq_stomp' => [
177+
'host' => Mage::getStoreConfig('enqueue/rabbitmq_stomp/host'),
178+
'port' => (int) Mage::getStoreConfig('enqueue/rabbitmq_stomp/port'),
179+
'login' => Mage::getStoreConfig('enqueue/rabbitmq_stomp/login'),
180+
'password' => Mage::getStoreConfig('enqueue/rabbitmq_stomp/password'),
181+
'vhost' => Mage::getStoreConfig('enqueue/rabbitmq_stomp/vhost'),
182+
'lazy' => (bool) Mage::getStoreConfig('enqueue/rabbitmq_stomp/lazy'),
183+
'delay_plugin_installed' => (bool) Mage::getStoreConfig('enqueue/rabbitmq_stomp/delay_plugin_installed'),
184+
'management_plugin_installed' => (bool) Mage::getStoreConfig('enqueue/rabbitmq_stomp/management_plugin_installed'),
185+
'management_plugin_port' => (int) Mage::getStoreConfig('enqueue/rabbitmq_stomp/management_plugin_port'),
186+
]];
187+
}
188+
189+
/**
190+
* @return array
191+
*/
192+
public function getFsConfig()
193+
{
194+
return ['fs' => [
195+
'store_dir' => Mage::getStoreConfig('enqueue/fs/store_dir'),
196+
'pre_fetch_count' => (int) Mage::getStoreConfig('enqueue/fs/pre_fetch_count'),
197+
'chmod' => intval(Mage::getStoreConfig('enqueue/fs/chmod'), 8),
198+
]];
199+
}
200+
201+
/**
202+
* @return array
203+
*/
204+
public function getSqsConfig()
205+
{
206+
return ['sqs' => [
207+
'key' => Mage::getStoreConfig('enqueue/sqs/key'),
208+
'secret' => Mage::getStoreConfig('enqueue/sqs/secret'),
209+
'token' => Mage::getStoreConfig('enqueue/sqs/token'),
210+
'region' => Mage::getStoreConfig('enqueue/sqs/region'),
211+
'retries' => (int) Mage::getStoreConfig('enqueue/sqs/retries'),
212+
'lazy' => (bool) Mage::getStoreConfig('enqueue/sqs/lazy'),
213+
]];
214+
}
215+
216+
/**
217+
* @return array
218+
*/
219+
public function getRedisConfig()
220+
{
221+
return ['redis' => [
222+
'host' => Mage::getStoreConfig('enqueue/redis/host'),
223+
'port' => (int) Mage::getStoreConfig('enqueue/redis/port'),
224+
'vendor' => Mage::getStoreConfig('enqueue/redis/vendor'),
225+
'lazy' => (bool) Mage::getStoreConfig('enqueue/redis/lazy'),
226+
]];
227+
}
228+
229+
/**
230+
* @return array
231+
*/
232+
public function getDbalConfig()
111233
{
112-
return new \Enqueue\Client\Config(
113-
Mage::getStoreConfig('enqueue/client/prefix'),
114-
Mage::getStoreConfig('enqueue/client/app_name'),
115-
Mage::getStoreConfig('enqueue/client/router_topic'),
116-
Mage::getStoreConfig('enqueue/client/router_queue'),
117-
Mage::getStoreConfig('enqueue/client/default_processor_queue'),
118-
'enqueue-router-processor'
119-
);
234+
return ['dbal' => [
235+
'url' => Mage::getStoreConfig('enqueue/redis/url'),
236+
'table_name' => Mage::getStoreConfig('enqueue/redis/table_name'),
237+
'polling_interval' => (int) Mage::getStoreConfig('enqueue/redis/polling_interval'),
238+
'lazy' => (bool) Mage::getStoreConfig('enqueue/redis/lazy'),
239+
]];
120240
}
121241
}

‎src/Enqueue/Enqueue/etc/config.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@
3939
<lazy>1</lazy>
4040
<delay_plugin_installed>0</delay_plugin_installed>
4141
</rabbitmq_amqp>
42+
<amqp>
43+
<lazy>1</lazy>
44+
</amqp>
45+
<rabbitmq_stomp>
46+
<lazy>1</lazy>
47+
</rabbitmq_stomp>
48+
<stomp>
49+
<lazy>1</lazy>
50+
</stomp>
4251
<fs>
4352
<pre_fetch_count>1</pre_fetch_count>
4453
<chmod>0600</chmod>

‎src/Enqueue/Enqueue/etc/system.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
<show_in_default>1</show_in_default>
9393
<show_in_website>0</show_in_website>
9494
<show_in_store>-</show_in_store>
95+
<validate>validate-number</validate>
9596
</redelivered_delay_time>
9697
</fields>
9798
</client>
@@ -119,6 +120,7 @@
119120
<show_in_default>1</show_in_default>
120121
<show_in_website>0</show_in_website>
121122
<show_in_store>-</show_in_store>
123+
<validate>validate-number</validate>
122124
</port>
123125
<login translate="label">
124126
<label>Login</label>
@@ -189,6 +191,7 @@
189191
<show_in_default>1</show_in_default>
190192
<show_in_website>0</show_in_website>
191193
<show_in_store>-</show_in_store>
194+
<validate>validate-number</validate>
192195
</port>
193196
<login translate="label">
194197
<label>Login</label>
@@ -250,6 +253,7 @@
250253
<show_in_default>1</show_in_default>
251254
<show_in_website>0</show_in_website>
252255
<show_in_store>-</show_in_store>
256+
<validate>validate-number</validate>
253257
</port>
254258
<login translate="label">
255259
<label>Login</label>
@@ -311,6 +315,7 @@
311315
<show_in_default>1</show_in_default>
312316
<show_in_website>0</show_in_website>
313317
<show_in_store>-</show_in_store>
318+
<validate>validate-number</validate>
314319
</port>
315320
<login translate="label">
316321
<label>Login</label>
@@ -371,6 +376,7 @@
371376
<show_in_default>1</show_in_default>
372377
<show_in_website>0</show_in_website>
373378
<show_in_store>-</show_in_store>
379+
<validate>validate-number</validate>
374380
</management_plugin_port>
375381
</fields>
376382
</rabbitmq_stomp>
@@ -400,6 +406,7 @@
400406
<show_in_website>0</show_in_website>
401407
<show_in_store>-</show_in_store>
402408
<comment>The option tells how many messages should be read from file at once. The feature saves resources but could lead to bigger messages lose.</comment>
409+
<validate>validate-number</validate>
403410
</pre_fetch_count>
404411
<chmod translate="label">
405412
<label>Filesystem permissions</label>
@@ -409,6 +416,7 @@
409416
<show_in_website>0</show_in_website>
410417
<show_in_store>-</show_in_store>
411418
<comment>The queue files are created with this given permissions if not exist.</comment>
419+
<validate>validate-number</validate>
412420
</chmod>
413421
</fields>
414422
</fs>
@@ -461,6 +469,7 @@
461469
<show_in_website>0</show_in_website>
462470
<show_in_store>-</show_in_store>
463471
<comment>Configures the maximum number of allowed retries for a client (pass 0 to disable retries)</comment>
472+
<validate>validate-number</validate>
464473
</retries>
465474
<lazy translate="label">
466475
<label>Lazy Connection</label>
@@ -498,6 +507,7 @@
498507
<show_in_default>1</show_in_default>
499508
<show_in_website>0</show_in_website>
500509
<show_in_store>-</show_in_store>
510+
<validate>validate-number</validate>
501511
</port>
502512
<vendor translate="label">
503513
<label>Default</label>
@@ -553,6 +563,7 @@
553563
<show_in_default>1</show_in_default>
554564
<show_in_website>0</show_in_website>
555565
<show_in_store>-</show_in_store>
566+
<validate>validate-number</validate>
556567
</polling_interval>
557568
<lazy translate="label">
558569
<label>Lazy Connection</label>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /