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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
--TEST--
AMQPExchange publish with properties
--SKIPIF--
<?php
if (!extension_loaded("amqp")) print "skip AMQP extension is not loaded";
elseif (!getenv("PHP_AMQP_HOST")) print "skip PHP_AMQP_HOST environment variable is not set";
?>
--FILE--
<?php
require '_test_helpers.php.inc';
$cnn = new AMQPConnection();
$cnn->setHost(getenv('PHP_AMQP_HOST'));
$cnn->connect();
$ch = new AMQPChannel($cnn);
$ex = new AMQPExchange($ch);
$ex->setName("exchange-" . bin2hex(random_bytes(32)));
$ex->setType(AMQP_EX_TYPE_FANOUT);
$ex->declareExchange();
$q = new AMQPQueue($ch);
$q->declareQueue();
$q->bind($ex->getName());
$attrs = array(
'content_type' => 1, // should be string
'content_encoding' => 2, // should be string
'message_id' => 3, // should be string
//'user_id' => 4, // should be string // NOTE: fail due to Validated User-ID https://www.rabbitmq.com/validated-user-id.html, @see tests/amqpexchange_publish_with_properties_user_id_failure.phpt test
'app_id' => 5, // should be string
'delivery_mode' => '1-non-persistent', // should be long
'priority' => '2high', // should be long
'timestamp' => '123now', // should be long
'expiration' => 100000000, // should be string // NOTE: in fact it is milliseconds for how long to stay in queue, see https://www.rabbitmq.com/ttl.html#per-message-ttl for details
'type' => 7, // should be string
'reply_to' => 8, // should be string
'correlation_id' => 9, // should be string
//'headers' => 'not array', // should be array // NOTE: covered in tests/amqpexchange_publish_with_properties_ignore_num_header.phpt
);
$attrs_control = array(
'content_type' => 1, // should be string
'content_encoding' => 2, // should be string
'message_id' => 3, // should be string
//'user_id' => 4, // should be string // NOTE: fail due to Validated User-ID https://www.rabbitmq.com/validated-user-id.html, @see tests/amqpexchange_publish_with_properties_user_id_failure.phpt test
'app_id' => 5, // should be string
'delivery_mode' => '1-non-persistent', // should be long
'priority' => '2high', // should be long
'timestamp' => '123now', // should be long
'expiration' => 100000000, // should be string // NOTE: in fact it is milliseconds for how long to stay in queue, see https://www.rabbitmq.com/ttl.html#per-message-ttl for details
'type' => 7, // should be string
'reply_to' => 8, // should be string
'correlation_id' => 9, // should be string
//'headers' => 'not array', // should be array // NOTE: covered in tests/amqpexchange_publish_with_properties_ignore_num_header.phpt
);
var_dump($ex->publish('message', 'routing.key', AMQP_NOPARAM, $attrs));
//var_dump($attrs, $attrs_control);
echo 'Message attributes are ', $attrs === $attrs_control ? 'the same' : 'not the same', PHP_EOL;
$msg = $q->get(AMQP_AUTOACK);
dump_message($msg);
$ex->delete();
$q->delete();
?>
--EXPECTF--
NULL
Message attributes are the same
AMQPEnvelope
getBody:
string(7) "message"
getContentType:
string(1) "1"
getRoutingKey:
string(11) "routing.key"
getConsumerTag:
string(0) ""
getDeliveryTag:
int(1)
getDeliveryMode:
int(1)
getExchangeName:
string(%d) "exchange-%s"
isRedelivery:
bool(false)
getContentEncoding:
string(1) "2"
getType:
string(1) "7"
getTimeStamp:
int(123)
getPriority:
int(2)
getExpiration:
string(9) "100000000"
getUserId:
NULL
getAppId:
string(1) "5"
getMessageId:
string(1) "3"
getReplyTo:
string(1) "8"
getCorrelationId:
string(1) "9"
getHeaders:
array(0) {
}
|