Created
January 7, 2018 21:01
-
-
Save makasim/7a9f91a38fe8547f533f398e2a99375e to your computer and use it in GitHub Desktop.
amqp_interop_basic_consume.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Enqueue\AmqpExt\AmqpConnectionFactory; | |
use Interop\Amqp\AmqpConsumer; | |
use Interop\Amqp\AmqpMessage; | |
include __DIR__.'/vendor/autoload.php'; | |
$context = (new AmqpConnectionFactory())->createContext(); | |
$fooConsumer = $context->createConsumer( | |
$context->createQueue('foo') | |
); | |
$barConsumer = $context->createConsumer( | |
$context->createQueue('foo') | |
); | |
$context->subscribe($fooConsumer, function(AmqpMessage $message, AmqpConsumer $consumer) { | |
// do something when a message from foo queue arrives. | |
$consumer->acknowledge($message); | |
return true; | |
}); | |
$context->subscribe($barConsumer, function(AmqpMessage $message, AmqpConsumer $consumer) { | |
// do something when a message from foo queue arrives. | |
$consumer->acknowledge($message); | |
return true; | |
}); | |
$context->consume(); // blocks here |
I guess it won't be as easy with the example you just gave. But if we can get an iterator instead of attaching the callback when during $context->subscribe()
, then I guess we could use the MultipleIterator
to combine generators as described in this StackOverflow question.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Both subscribe to "foo" queue, is that correct?