Skip to content

Commit

Permalink
Merge branch '4.3' into 4.4
Browse files Browse the repository at this point in the history
* 4.3: (26 commits)
  [Console] Fix #33915, Detect dimensions using mode CON if vt100 is supported
  [HttpKernel][DataCollectorInterface] Ease compatibility
  Add tests to ensure defaultLocale is properly passed to the URL generator
  [DependencyInjection] Fix broken references in tests
  [HttpClient] Retry safe requests when then fail before the body arrives
  Avoid using of kernel after shutdown
  Simplify PHP CS Fixer configuration
  [PropertyInfo] Fixed type extraction for nullable collections of non-nullable elements
  [FrameworkBundle] [HttpKernel] fixed correct EOL and EOM month
  [Serializer] Fix property name usage for denormalization
  Name test accordingly to the tested class
  Fix MockFileSessionStorageTest::sessionDir being used after it's unset
  bumped Symfony version to 4.3.7
  updated VERSION for 4.3.6
  updated CHANGELOG for 4.3.6
  bumped Symfony version to 3.4.34
  updated VERSION for 3.4.33
  update CONTRIBUTORS for 3.4.33
  updated CHANGELOG for 3.4.33
  [HttpClient] Fix perf issue when doing thousands of requests with curl
  ...
  • Loading branch information
nicolas-grekas committed Nov 5, 2019
2 parents b7b034c + 2433101 commit 4e0cae3
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 7 deletions.
36 changes: 36 additions & 0 deletions Tests/Transport/AmqpExt/AmqpStampTest.php
Expand Up @@ -34,4 +34,40 @@ public function testFlagsAndAttributes()
$this->assertSame(AMQP_DURABLE, $stamp->getFlags());
$this->assertSame(['delivery_mode' => 'unknown'], $stamp->getAttributes());
}

public function testCreateFromAmqpEnvelope()
{
$amqpEnvelope = $this->createMock(\AMQPEnvelope::class);
$amqpEnvelope->method('getRoutingKey')->willReturn('routingkey');
$amqpEnvelope->method('getDeliveryMode')->willReturn(2);
$amqpEnvelope->method('getPriority')->willReturn(5);
$amqpEnvelope->method('getAppId')->willReturn('appid');

$stamp = AmqpStamp::createFromAmqpEnvelope($amqpEnvelope);

$this->assertSame($amqpEnvelope->getRoutingKey(), $stamp->getRoutingKey());
$this->assertSame($amqpEnvelope->getDeliveryMode(), $stamp->getAttributes()['delivery_mode']);
$this->assertSame($amqpEnvelope->getPriority(), $stamp->getAttributes()['priority']);
$this->assertSame($amqpEnvelope->getAppId(), $stamp->getAttributes()['app_id']);
$this->assertSame(AMQP_NOPARAM, $stamp->getFlags());
}

public function testCreateFromAmqpEnvelopeWithPreviousStamp()
{
$amqpEnvelope = $this->createMock(\AMQPEnvelope::class);
$amqpEnvelope->method('getRoutingKey')->willReturn('routingkey');
$amqpEnvelope->method('getDeliveryMode')->willReturn(2);
$amqpEnvelope->method('getPriority')->willReturn(5);
$amqpEnvelope->method('getAppId')->willReturn('appid');

$previousStamp = new AmqpStamp('otherroutingkey', AMQP_MANDATORY, ['priority' => 8]);

$stamp = AmqpStamp::createFromAmqpEnvelope($amqpEnvelope, $previousStamp);

$this->assertSame('otherroutingkey', $stamp->getRoutingKey());
$this->assertSame($amqpEnvelope->getDeliveryMode(), $stamp->getAttributes()['delivery_mode']);
$this->assertSame(8, $stamp->getAttributes()['priority']);
$this->assertSame($amqpEnvelope->getAppId(), $stamp->getAttributes()['app_id']);
$this->assertSame(AMQP_MANDATORY, $stamp->getFlags());
}
}
14 changes: 8 additions & 6 deletions Transport/AmqpExt/AmqpSender.php
Expand Up @@ -45,20 +45,22 @@ public function send(Envelope $envelope): Envelope
$delayStamp = $envelope->last(DelayStamp::class);
$delay = $delayStamp ? $delayStamp->getDelay() : 0;

/** @var AmqpStamp|null $amqpStamp */
$amqpStamp = $envelope->last(AmqpStamp::class);
if (isset($encodedMessage['headers']['Content-Type'])) {
$contentType = $encodedMessage['headers']['Content-Type'];
unset($encodedMessage['headers']['Content-Type']);

$attributes = $amqpStamp ? $amqpStamp->getAttributes() : [];

if (!isset($attributes['content_type'])) {
$attributes['content_type'] = $contentType;

$amqpStamp = new AmqpStamp($amqpStamp ? $amqpStamp->getRoutingKey() : null, $amqpStamp ? $amqpStamp->getFlags() : AMQP_NOPARAM, $attributes);
if (!$amqpStamp || !isset($amqpStamp->getAttributes()['content_type'])) {
$amqpStamp = AmqpStamp::createWithAttributes(['content_type' => $contentType], $amqpStamp);
}
}

$amqpReceivedStamp = $envelope->last(AmqpReceivedStamp::class);
if ($amqpReceivedStamp instanceof AmqpReceivedStamp) {
$amqpStamp = AmqpStamp::createFromAmqpEnvelope($amqpReceivedStamp->getAmqpEnvelope(), $amqpStamp);
}

try {
$this->connection->publish(
$encodedMessage['body'],
Expand Down
29 changes: 29 additions & 0 deletions Transport/AmqpExt/AmqpStamp.php
Expand Up @@ -44,4 +44,33 @@ public function getAttributes(): array
{
return $this->attributes;
}

public static function createFromAmqpEnvelope(\AMQPEnvelope $amqpEnvelope, self $previousStamp = null): self
{
$attr = $previousStamp->attributes ?? [];

$attr['headers'] = $attr['headers'] ?? $amqpEnvelope->getHeaders();
$attr['content_type'] = $attr['content_type'] ?? $amqpEnvelope->getContentType();
$attr['content_encoding'] = $attr['content_encoding'] ?? $amqpEnvelope->getContentEncoding();
$attr['delivery_mode'] = $attr['delivery_mode'] ?? $amqpEnvelope->getDeliveryMode();
$attr['priority'] = $attr['priority'] ?? $amqpEnvelope->getPriority();
$attr['timestamp'] = $attr['timestamp'] ?? $amqpEnvelope->getTimestamp();
$attr['app_id'] = $attr['app_id'] ?? $amqpEnvelope->getAppId();
$attr['message_id'] = $attr['message_id'] ?? $amqpEnvelope->getMessageId();
$attr['user_id'] = $attr['user_id'] ?? $amqpEnvelope->getUserId();
$attr['expiration'] = $attr['expiration'] ?? $amqpEnvelope->getExpiration();
$attr['type'] = $attr['type'] ?? $amqpEnvelope->getType();
$attr['reply_to'] = $attr['reply_to'] ?? $amqpEnvelope->getReplyTo();

return new self($previousStamp->routingKey ?? $amqpEnvelope->getRoutingKey(), $previousStamp->flags ?? AMQP_NOPARAM, $attr);
}

public static function createWithAttributes(array $attributes, self $previousStamp = null): self
{
return new self(
$previousStamp->routingKey ?? null,
$previousStamp->flags ?? AMQP_NOPARAM,
array_merge($previousStamp->attributes ?? [], $attributes)
);
}
}
2 changes: 1 addition & 1 deletion Transport/AmqpExt/Connection.php
Expand Up @@ -224,7 +224,7 @@ private function publishWithDelay(string $body, array $headers, int $delay, Amqp
private function publishOnExchange(\AMQPExchange $exchange, string $body, string $routingKey = null, array $headers = [], AmqpStamp $amqpStamp = null)
{
$attributes = $amqpStamp ? $amqpStamp->getAttributes() : [];
$attributes['headers'] = array_merge($headers, $attributes['headers'] ?? []);
$attributes['headers'] = array_merge($attributes['headers'] ?? [], $headers);

$exchange->publish(
$body,
Expand Down

0 comments on commit 4e0cae3

Please sign in to comment.