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

Is this really async? #11

Open
enumag opened this issue Nov 5, 2018 · 2 comments
Open

Is this really async? #11

enumag opened this issue Nov 5, 2018 · 2 comments

Comments

@enumag
Copy link
Member

enumag commented Nov 5, 2018

I'm studying the implementation of this package to understand how it works. My assumption was that if I send a multiple queries to the QueryBus, each implementing AsyncMessage, then they would be resolved concurrently (assuming there are multiple consumers to process them). Is this how it is supposed to work?

After studying the EnqueueMessageProducer I don't think this is the case though. When resolving a query the producer calls $reply = $this->producer->sendCommand($this->commandName, $enqueueMessage, (bool) $deferred); but then immediately calls $reply->receive($this->replyTimeout) which is blocking (according to it's docblock).

According to enqueue documentation you should do this:

$promise = $producer->sendCommand(Commands::RUN_COMMAND, new RunCommand('debug:container'), true);

// do other stuff.

if ($replyMessage = $promise->receive(5000)) {

So when running multiple queries concurrently I'm guessing it should go something like this:

$promise1 = $producer->sendCommand(..., true);
$promise2 = $producer->sendCommand(..., true);
$promise3 = $producer->sendCommand(..., true);

$promise1->receive(5000);
$promise2->receive(5000);
$promise3->receive(5000);

But since sendCommand and receive are not separated in the current code, I think multiple queries (as in multiple QueryBus::dispatch() calls) will be resolves sequentially. Is that right? If so, is that intended? Why? Is there any way to resolve the queries concurrently?

@enumag
Copy link
Member Author

enumag commented Nov 6, 2018

this also seems to confirm my suspicion.

@prolic @makasim Any ideas what to do here?

@codeliner
Copy link
Member

@enumag The query bus can only work with async message producers that don't require a blocking call to receive a response, but instead invoke a callback when a response arrives.

Let's say you use artax in a message producer and have a global amp event loop running, then you could make use of the async API of the query bus.

In a standard PHP environment it's not possible, because the message producer has to block until it receives a response and can resolve the deferred passed to it.

I think your only chance is to not use the query bus but only Enqueue so that you can send multiple queries before blocking.

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

No branches or pull requests

2 participants