Skip to content
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

[Messenger] Add reply functionality #34337

Open
wants to merge 1 commit into
base: 4.4
from

Conversation

@webnet-fr
Copy link
Contributor

webnet-fr commented Nov 12, 2019

Q A
Branch? 4.4
Bug fix? no
New feature? yes
Deprecations? no
License MIT
Doc PR coming

It would be nice to provide developers with possibility to retrieve the result from a handler (with some sort of RPC):

// Get the result from sync transport
$envelope = $messageBus->dispatch($message, [new ReplyStamp()]);
$replyStamp = $envelope->last(ReplyStamp::class);
$result = $replyStamp->getResponse();
// Get the result from amqp transport
$envelope = $messageBus->dispatch($message, [new ReplyStamp()]);
// do something while messange is being treated
$replyStamp = $envelope->last(AmqpReplyStamp::class);
$result = $replyStamp->getResponse(); // wait for reponse, blocking call

Let's consider this PR as a discussion to find out:

  • whether we need this functionality at all,
  • whether this solution is on the right way.

I will add necssary tests/documentation if community is interested in this implementation.

Thanks for giving your opinion.

@webnet-fr webnet-fr requested a review from sroze as a code owner Nov 12, 2019
@nicolas-grekas nicolas-grekas added this to the next milestone Nov 12, 2019
@Nyholm

This comment has been minimized.

Copy link
Member

Nyholm commented Jan 19, 2020

Interesting suggestion.
Looking at the PR and and your example code I think you are both right and wrong.

The "sync" transport. Is the same as what CQRS would call a QueryBus. That is already implemented, see docs: https://symfony.com/doc/current/messenger/handler_results.html

Your async example is not really RPC, since RPC is blocking if I recall correctly. And, of course, why would we like to write blocking code if we can do unblocking =)
Your PR description shows an unblocking example, but that is the same as you have to applications which are both senders and receivers, right? Or am I mistaken?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.