Skip to content

Instantly share code, notes, and snippets.

@makasim
Created January 7, 2018 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makasim/7a9f91a38fe8547f533f398e2a99375e to your computer and use it in GitHub Desktop.
Save makasim/7a9f91a38fe8547f533f398e2a99375e to your computer and use it in GitHub Desktop.
amqp_interop_basic_consume.php
<?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
@Nyholm
Copy link

Nyholm commented Jan 7, 2018

Both subscribe to "foo" queue, is that correct?

@sroze
Copy link

sroze commented Jan 8, 2018

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