@@ -183,11 +183,19 @@ public function laterRaw($delay, string $payload, $queue = null, int $attempts =
183
183
*/
184
184
public function bulk ($ jobs , $ data = '' , $ queue = null ): void
185
185
{
186
- foreach ((array ) $ jobs as $ job ) {
186
+ $ this ->publishBatch ($ jobs , $ queue , $ data );
187
+ }
188
+
189
+ /**
190
+ * @throws AMQPProtocolChannelException
191
+ */
192
+ protected function publishBatch ($ jobs , $ data = '' , $ queue = null ): void
193
+ {
194
+ foreach ($ jobs as $ job ) {
187
195
$ this ->bulkRaw ($ this ->createPayload ($ job , $ queue , $ data ), $ queue , ['job ' => $ job ]);
188
196
}
189
197
190
- $ this ->publishBatch ();
198
+ $ this ->batchPublish ();
191
199
}
192
200
193
201
/**
@@ -274,21 +282,6 @@ public function setConnection(AbstractConnection $connection): RabbitMQQueue
274
282
return $ this ;
275
283
}
276
284
277
- public function getChannel ($ forceNew = false ): AMQPChannel
278
- {
279
- if (! $ this ->channel || $ forceNew ) {
280
- $ this ->channel = $ this ->createChannel ();
281
- }
282
-
283
- return $ this ->channel ;
284
- }
285
-
286
- protected function reconnect ()
287
- {
288
- $ this ->getConnection ()->reconnect ();
289
- $ this ->getChannel (true );
290
- }
291
-
292
285
/**
293
286
* Job class to use.
294
287
*
@@ -746,13 +739,33 @@ protected function publishBasic($msg, $exchange = '', $destination = '', $mandat
746
739
$ this ->getChannel ()->basic_publish ($ msg , $ exchange , $ destination , $ mandatory , $ immediate , $ ticket );
747
740
}
748
741
749
- protected function publishBatch (): void
742
+ protected function batchPublish (): void
750
743
{
751
744
$ this ->getChannel ()->publish_batch ();
752
745
}
753
746
747
+ public function getChannel ($ forceNew = false ): AMQPChannel
748
+ {
749
+ if (! $ this ->channel || $ forceNew ) {
750
+ $ this ->channel = $ this ->createChannel ();
751
+ }
752
+
753
+ return $ this ->channel ;
754
+ }
755
+
754
756
protected function createChannel (): AMQPChannel
755
757
{
756
758
return $ this ->getConnection ()->channel ();
757
759
}
760
+
761
+ /**
762
+ * @throws Exception
763
+ */
764
+ protected function reconnect (): void
765
+ {
766
+ // Reconnects using the original connection settings.
767
+ $ this ->getConnection ()->reconnect ();
768
+ // Create a new main channel because all old channels are removed.
769
+ $ this ->getChannel (true );
770
+ }
758
771
}
0 commit comments