Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[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
base:7.4
Are you sure you want to change the base?
Conversation
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 commentedDec 3, 2022
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? |
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. |
Uh oh!
There was an error while loading.Please reload this page.
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 an
extra
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