Skip to content

[Messenger] [AMQP] Support “content encoding” property #47545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 0 commits into from

Conversation

glengemann
Copy link

@glengemann glengemann commented Sep 11, 2022

Q A
Branch? 6.2
Bug fix? no
New feature? yes
Deprecations? no
Tickets
License MIT
Doc PR TODO

When I send a message using the AMQP transport together with the AmqpStamp and the content-encoding property, the message is not compressed.

The AMQP protocol, allow through the content-encoding property, to “indicate what additional content encodings have been applied to the application-data, and thus what decoding mechanisms need to be applied in order to obtain the media-type referenced by the content-type header field”.

The values admitted according to the protocol are: gzip, compress, deflate, identity, etc.

I expect that the body of the message will be compressed and decompressed respectively by the publisher
and the subscriber.

For example, we can send a messages:

$bus->dispatch(new DummyMessage('Foo bar'), [
    new AmqpStamp(attributes: [
        'content_encoding' => 'gzip'
    ]),
]);

and, With the current code the body message (payload) is not compress using gzip:

$ rabbitmqadmin get queue=messages -f pretty_json 
[
  {
    "exchange": "messages",
    "message_count": 0,
    "payload": "{\"name\":\"Foo bar\"}",
    "payload_bytes": 18,
    "payload_encoding": "string",
    "properties": {
      "content_encoding": "gzip",
      "content_type": "application/json",
      "delivery_mode": 2,
      "headers": {
        "X-Message-Stamp-Symfony\\Component\\Messenger\\Stamp\\BusNameStamp": "[{\"busName\":\"messenger.bus.default\"}]",
        "type": "App\\Message\\DummyMessage"
      },
      "timestamp": 1662922329
    },
    "redelivered": true,
    "routing_key": ""
  }
]

but, if we are aware of the value of the content_encoding property we should compress the body message.

$ rabbitmqadmin get queue=messages -f pretty_json 
[
  {
    "exchange": "messages",
    "message_count": 0,
    "payload": "H4sIAAAAAAAAA6tWysxNTE8NyC8u8UxRsrI0qwUAri6HchIAAAA=",
    "payload_bytes": 38,
    "payload_encoding": "base64",
    "properties": {
      "content_encoding": "gzip",
      "content_type": "application/json",
      "delivery_mode": 2,
      "headers": {
        "X-Message-Stamp-App\\Messenger\\UniqueIdStamp": "[{\"uniqueId\":\"631e4bdc3ad3b\"}]",
        "X-Message-Stamp-Symfony\\Component\\Messenger\\Stamp\\BusNameStamp": "[{\"busName\":\"messenger.bus.default\"}]",
        "type": "App\\Message\\AddPonkaToImage"
      },
      "timestamp": 1662929884
    },
    "redelivered": true,
    "routing_key": ""
  }
]

Finally, the subscriber must be able to uncompressed the body message. I made some changes in order to figure out how
this can be accomplished.

Thanks!, I should be grateful for any comments.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.2 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot carsonbot changed the title [Messenger][AMQP] Support **content encoding** property [Messenger] [AMQP] Support **content encoding** property Sep 11, 2022
@glengemann glengemann changed the title [Messenger] [AMQP] Support **content encoding** property [Messenger] [AMQP] Support content encoding property Sep 11, 2022
@glengemann glengemann changed the title [Messenger] [AMQP] Support content encoding property [Messenger] [AMQP] Support “content encoding” property Sep 11, 2022
@@ -18,6 +18,7 @@
"require": {
"php": ">=8.1",
"ext-amqp": "*",
"ext-zlib": "*",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is optional, it should be moved to require-dev instead.


class Gzip implements CompressorInterface
{

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra blank line

@fabpot
Copy link
Member

fabpot commented Sep 13, 2022

You should also rebase to get rid of the merge commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants