Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[Messenger] [AMQP] Add routing key to data passed to serializer decode.#47975

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
jenkoian wants to merge1 commit intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromjenkoian:issue-43039

Conversation

jenkoian
Copy link
Contributor

@jenkoianjenkoian commentedOct 24, 2022
edited
Loading

QA
Branch?6.2
Bug fix?no
New feature?no
Deprecations?no
TicketsFix#43039
LicenseMIT
Doc PRN/A

It's often useful to have the routing key available when decoding messages from AMQP. For example, sometimes the routing key contains meta information required for the processing of the message.

This introduces anextra element which currently only contains the routing key, but there is scope to add other meta information from \AMQPEnvelope such as the exchange name for example.

Fixes#43039

jkatruska and davidkoberan reacted with thumbs up emoji
@carsonbotcarsonbot added this to the6.2 milestoneOct 24, 2022
@carsonbotcarsonbot changed the title[Messenger][AMQP] Add routing key to data passed to serializer decode.[Messenger] [AMQP] Add routing key to data passed to serializer decode.Oct 24, 2022
It's often useful to have the routing key available when decodingmessages from AMQP. For example, sometimes the routing key contains metainformation required for the processing of the message.This introduces an `extra` element which currently only contains therouting key, but there is scope to add other meta information from\AMQPEnvelope such as the exchange name for example.Fixessymfony#43039
@glengemann
Copy link

Hi! It is possible that you can solve the problem or at least have a workaround using aMiddleware in conjunction with theHandlerArgumentsStamp.

For example, I have a message with some AMQP properties attached:

$message =newDetectFacesMessage($file->getContent());$this->bus->dispatch($message, [newAmqpStamp('detect-faces', attributes: ['content_type' =>'text/plain','correlation_id' =>$uniqid,'reply_to' =>'response-queue',            ]),        ]);

And I need thecontent_type,correlation_id andreply_to AMQP properties in theconsumer in order to perform some logic. Then, my consumer look this way:

publicfunction__invoke(DetectFacesMessage$message,string$replyTo,string$correlationId,string$contentType,string$timestamp,    ) {    }

I have theAMPQ properties as a method parameters because I am using aMiddleware. It reads/gets theAMPQ properties from theAMPQ Envelope. TheMiddleware look like this:

publicfunctionhandle(Envelope$envelope,StackInterface$stack):Envelope    {$amqpStamp =$envelope->last(AmqpReceivedStamp::class);if ($amqpStamp) {$replyTo =$amqpStamp->getAmqpEnvelope()->getReplyTo();$correlationId =$amqpStamp->getAmqpEnvelope()->getCorrelationId();$contentType =$amqpStamp->getAmqpEnvelope()->getContentType();$timestamp =$amqpStamp->getAmqpEnvelope()->getTimestamp();$routingKey =$amqpStamp->getAmqpEnvelope()->getRoutingKey();// Here!$arguments = [$replyTo,$correlationId,$contentType,$timestamp,            ];$envelope =$envelope->with(newHandlerArgumentsStamp($arguments));        }return$stack->next()->handle($envelope,$stack);    }

I think you can get therouting key in this way. Sounds good to you?

@jenkoian
Copy link
ContributorAuthor

Thanks@glengemann, I'm looking to have the routing key available in the serializer as part of decoding (I need it to work out which message to create based from the routing key). If I've understood correctly, serializer decoding (deserializing) is done before it enter into the bus and thus the middlewares.

@nicolas-grekasnicolas-grekas modified the milestones:6.3,6.4May 23, 2023
@nicolas-grekasnicolas-grekas modified the milestones:6.4,7.1Nov 15, 2023
@xabbuhxabbuh modified the milestones:7.1,7.2May 15, 2024
@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

Add routing key to header for amqp custom serializer
6 participants
@jenkoian@glengemann@fabpot@nicolas-grekas@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp