@@ -111,6 +111,7 @@ public function __construct(
111111 public function run ()
112112 {
113113 $ runByCron = $ this ->deploymentConfig ->get ('cron_consumers_runner/cron_run ' , true );
114+ $ multipleProcesses = $ this ->deploymentConfig ->get ('cron_consumers_runner/multiple_processes ' , []);
114115
115116 if (!$ runByCron ) {
116117 return ;
@@ -125,19 +126,47 @@ public function run()
125126 continue ;
126127 }
127128
128- $ arguments = [
129- $ consumer ->getName (),
130- '--single-thread '
131- ];
132-
133- if ($ maxMessages ) {
134- $ arguments [] = '--max-messages= ' . min ($ consumer ->getMaxMessages () ?? $ maxMessages , $ maxMessages );
129+ if (array_key_exists ($ consumer ->getName (), $ multipleProcesses )) {
130+ $ numberOfProcesses = $ multipleProcesses [$ consumer ->getName ()];
131+
132+ for ($ i = 1 ; $ i <= $ numberOfProcesses ; $ i ++) {
133+ if ($ this ->lockManager ->isLocked (md5 ($ consumer ->getName ()))) { //phpcs:ignore
134+ continue ;
135+ }
136+ $ arguments = [
137+ $ consumer ->getName (),
138+ '--multi-process= ' . $ i
139+ ];
140+
141+ if ($ maxMessages ) {
142+ $ arguments [] = '--max-messages= ' . min ($ consumer ->getMaxMessages () ?? $ maxMessages , $ maxMessages );
143+ }
144+
145+ $ command = $ php . ' ' . BP . '/bin/magento queue:consumers:start %s %s '
146+ . ($ maxMessages ? ' %s ' : '' );
147+
148+ $ this ->shellBackground ->execute ($ command , $ arguments );
149+ }
150+ $ this ->lockManager ->lock (md5 ($ consumer ->getName ()));
151+ } else {
152+ if ($ this ->lockManager ->isLocked (md5 ($ consumer ->getName ()))) { //phpcs:ignore
153+ return false ;
154+ }
155+
156+ $ arguments = [
157+ $ consumer ->getName (),
158+ '--single-thread '
159+ ];
160+
161+ if ($ maxMessages ) {
162+ $ arguments [] = '--max-messages= ' . min ($ consumer ->getMaxMessages () ?? $ maxMessages , $ maxMessages );
163+ }
164+
165+ $ command = $ php . ' ' . BP . '/bin/magento queue:consumers:start %s %s '
166+ . ($ maxMessages ? ' %s ' : '' );
167+
168+ $ this ->shellBackground ->execute ($ command , $ arguments );
135169 }
136-
137- $ command = $ php . ' ' . BP . '/bin/magento queue:consumers:start %s %s '
138- . ($ maxMessages ? ' %s ' : '' );
139-
140- $ this ->shellBackground ->execute ($ command , $ arguments );
141170 }
142171 }
143172
@@ -157,10 +186,6 @@ private function canBeRun(ConsumerConfigItemInterface $consumerConfig, array $al
157186 return false ;
158187 }
159188
160- if ($ this ->lockManager ->isLocked (md5 ($ consumerName ))) { //phpcs:ignore
161- return false ;
162- }
163-
164189 $ connectionName = $ consumerConfig ->getConnection ();
165190 try {
166191 $ this ->mqConnectionTypeResolver ->getConnectionType ($ connectionName );
0 commit comments