1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
<?php
namespace PhpAmqpLib\Tests\Functional\Channel;
use PhpAmqpLib\Message\AMQPMessage;
use PhpAmqpLib\Wire\AMQPTable;
use PHPUnit\Framework\Attributes\Test;
/**
* @group connection
*/
class HeadersExchangeTest extends ChannelTestCase
{
protected function setUpCompat()
{
parent::setUpCompat();
$this->exchange->name = 'amq.headers';
}
/**
* @small
* @covers \PhpAmqpLib\Channel\AMQPChannel::queue_bind()
* @covers \PhpAmqpLib\Exchange\AMQPExchangeType
*/
#[Test]
public function consume_specific_headers()
{
list($queue1) = $this->channel->queue_declare();
$this->channel->queue_bind($queue1, $this->exchange->name);
$bindArguments = [
'foo' => 'bar',
];
list($queue2) = $this->channel->queue_declare();
$this->channel->queue_bind($queue2, $this->exchange->name, '', false, new AMQPTable($bindArguments));
// publish message without headers - should appear in 1st queue without filters
$message = new AMQPMessage('test');
$this->channel->basic_publish($message, $this->exchange->name);
$received1 = $this->channel->basic_get($queue1, true);
$received2 = $this->channel->basic_get($queue2, true);
$this->assertInstanceOf(AMQPMessage::class, $received1);
$this->assertNull($received2);
// publish message with matching headers
$message->set('application_headers', new AMQPTable($bindArguments));
$this->channel->basic_publish($message, $this->exchange->name);
$received1 = $this->channel->basic_get($queue1, true);
$received2 = $this->channel->basic_get($queue2, true);
// should appear in both queues
$this->assertInstanceOf(AMQPMessage::class, $received1);
$this->assertInstanceOf(AMQPMessage::class, $received2);
// publish with not matching headers
$message->set('application_headers', new AMQPTable(array('foo' => false)));
$this->channel->basic_publish($message, $this->exchange->name);
$received1 = $this->channel->basic_get($queue1, true);
$received2 = $this->channel->basic_get($queue2, true);
// should appear in non filtered queue only
$this->assertInstanceOf(AMQPMessage::class, $received1);
$this->assertNull($received2);
}
}
|