Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c30f462

Browse files
committed
feature #30671 Add optional parameter prefetching for AMQP connection (fbouchery)
This PR was merged into the 4.3-dev branch. Discussion ---------- Add optional parameter `prefetching` for AMQP connection Add prefetching connection parameter to setup channel prefetch count. | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | When setting up AMQP transport connection, it can be interesting to configure prefetching on a channel, which is not currently possible. Commits ------- 47777ee Add optional parameter `prefetching` in connection configuration, to setup channel prefetch count
2 parents 4184cc6 + 47777ee commit c30f462

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/Symfony/Component/Messenger/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ CHANGELOG
44
4.3.0
55
-----
66

7+
* Added optional parameter `prefetch_count` in connection configuration,
8+
to setup channel prefetch count
79
* New classes: `RoutableMessageBus`, `AddBusNameStampMiddleware`
810
and `BusNameStamp` were added, which allow you to add a bus identifier
911
to the `Envelope` then find the correct bus when receiving from

src/Symfony/Component/Messenger/Tests/Transport/AmqpExt/ConnectionTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,25 @@ public function testPublishWithQueueOptions()
256256
$connection->publish('body', $headers);
257257
}
258258

259+
public function testSetChannelPrefetchWhenSetup()
260+
{
261+
$factory = new TestAmqpFactory(
262+
$amqpConnection = $this->createMock(\AMQPConnection::class),
263+
$amqpChannel = $this->createMock(\AMQPChannel::class),
264+
$amqpQueue = $this->createMock(\AMQPQueue::class),
265+
$amqpExchange = $this->createMock(\AMQPExchange::class)
266+
);
267+
268+
// makes sure the channel looks connected, so it's not re-created
269+
$amqpChannel->expects($this->exactly(2))->method('isConnected')->willReturn(true);
270+
271+
$amqpChannel->expects($this->exactly(2))->method('setPrefetchCount')->with(2);
272+
$connection = Connection::fromDsn('amqp://localhost/%2f/messages?prefetch_count=2', [], $factory);
273+
$connection->setup();
274+
$connection = Connection::fromDsn('amqp://localhost/%2f/messages', ['prefetch_count' => 2], $factory);
275+
$connection->setup();
276+
}
277+
259278
public function testItDelaysTheMessage()
260279
{
261280
$amqpConnection = $this->getMockBuilder(\AMQPConnection::class)->disableOriginalConstructor()->getMock();

src/Symfony/Component/Messenger/Transport/AmqpExt/Connection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class Connection
8484
* * exchange_name: Name of the exchange to be used for the retried messages (Default: "retry")
8585
* * auto_setup: Enable or not the auto-setup of queues and exchanges (Default: true)
8686
* * loop_sleep: Amount of micro-seconds to wait if no message are available (Default: 200000)
87+
* * prefetch_count: set channel prefetch count
8788
*/
8889
public function __construct(array $connectionConfiguration, array $exchangeConfiguration, array $queueConfiguration, AmqpFactory $amqpFactory = null)
8990
{
@@ -323,6 +324,10 @@ public function channel(): \AMQPChannel
323324
throw new \AMQPException(sprintf('Could not connect to the AMQP server. Please verify the provided DSN. (%s)', json_encode($credentials)), 0, $e);
324325
}
325326
$this->amqpChannel = $this->amqpFactory->createChannel($connection);
327+
328+
if (isset($this->connectionConfiguration['prefetch_count'])) {
329+
$this->amqpChannel->setPrefetchCount($this->connectionConfiguration['prefetch_count']);
330+
}
326331
}
327332

328333
return $this->amqpChannel;

0 commit comments

Comments
 (0)