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

Appearance settings

Commit ba725c2

Browse filesBrowse files
committed
feature #30225 publish message with custom queue options : flags | attributes (fedor.f, insidestyles)
This PR was merged into the 4.3-dev branch. Discussion ---------- publish message with custom queue options : flags | attributes | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> option for publish persistent message: `amqp://localhost/%2f/messages?queue[attributes][delivery_mode]=2&queue[flags]=1` or options: >queue: >>name: '%env(MESSENGER_QUEUE)%' >>routing_key: '%env(MESSENGER_ROUTING_KEY)%' >>attributes: >>>delivery_mode: 2 >>flags: 1 Commits ------- 5e16053 update test case for custom queue options 4532319 publish message with custom queue options : update ConnectionTest 6f9fdaf publish message with custom queue options : flags | attributes
2 parents 2e6d069 + 5e16053 commit ba725c2
Copy full SHA for ba725c2

File tree

2 files changed

+22
-1
lines changed
Filter options

2 files changed

+22
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Tests/Transport/AmqpExt/ConnectionTest.php
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,24 @@ public function testItCanDisableTheSetup()
233233
$connection = Connection::fromDsn('amqp://localhost/%2f/messages?queue[routing_key]=my_key&auto-setup=false', [], true, $factory);
234234
$connection->publish('body');
235235
}
236+
237+
public function testPublishWithQueueOptions()
238+
{
239+
$factory = new TestAmqpFactory(
240+
$amqpConnection = $this->createMock(\AMQPConnection::class),
241+
$amqpChannel = $this->createMock(\AMQPChannel::class),
242+
$amqpQueue = $this->createMock(\AMQPQueue::class),
243+
$amqpExchange = $this->createMock(\AMQPExchange::class)
244+
);
245+
$headers = [
246+
'type' => '*',
247+
];
248+
$amqpExchange->expects($this->once())->method('publish')
249+
->with('body', null, 1, ['delivery_mode' => 2, 'headers' => ['token' => 'uuid', 'type' => '*']]);
250+
251+
$connection = Connection::fromDsn('amqp://localhost/%2f/messages?queue[attributes][delivery_mode]=2&queue[attributes][headers][token]=uuid&queue[flags]=1', [], true, $factory);
252+
$connection->publish('body', $headers);
253+
}
236254
}
237255

238256
class TestAmqpFactory extends AmqpFactory

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Transport/AmqpExt/Connection.php
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ public function publish(string $body, array $headers = []): void
133133
$this->setup();
134134
}
135135

136-
$this->exchange()->publish($body, $this->queueConfiguration['routing_key'] ?? null, AMQP_NOPARAM, ['headers' => $headers]);
136+
$flags = $this->queueConfiguration['flags'] ?? AMQP_NOPARAM;
137+
$attributes = array_merge_recursive($this->queueConfiguration['attributes'] ?? [], ['headers' => $headers]);
138+
139+
$this->exchange()->publish($body, $this->queueConfiguration['routing_key'] ?? null, $flags, $attributes);
137140
}
138141

139142
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.