[英]PHP AMQP pass headers in request
我正在尝试向AMQP发送请求,坚持如何在请求消息中添加标头,下面是我们正在使用的包装器
$message = ‘{"empId": ‘.$empId.', “empName”:”my name"}’;
$resData = $rpcClient->call($message, self::EXCHANGE, self::ROUTING_KEY);
如何将标头添加到上面的消息
call方法是我们编写的包装器
public function call($requestMessage, $exchange, $routingKey)
{
$this->response = null;
$this->correlationId = uniqid('abcprod', true);
$message = new AMQPMessage(
strval($requestMessage),
array('correlation_id' => $this->correlationId, 'reply_to' => $this->callbackQueue)
);
$this->channel
->basic_publish($message, $exchange, $routingKey);
try {
$this->channel->wait(null, false, self::REQUEST_TIMEOUT);
} catch (AMQPTimeoutException $e) {
return null;
}
return $this->response;
}
创建消息时,应设置application_headers
属性。 这应该是一个Wire\\AMQPTable
,它将构造函数参数作为一个头数组 。
官方amqp_message_headers_snd.php
示例:
$message = new AMQPMessage($data);
$headers = new Wire\AMQPTable(array(
'x-foo'=>'bar',
'table'=>array('figuf', 'ghf'=>5, 5=>675),
'num1' => -4294967295,
'num2' => 5,
'num3' => -2147483648,
'true' => true,
'false' => false,
'void' => null,
'date' => new DateTime(),
'array' => array(null, 'foo', 'bar', 5, 5674625, 'ttt', array(5, 8, 2)),
'arr_with_tbl' => array(
'bar',
5,
array('foo', 57, 'ee', array('foo'=>'bar', 'baz'=>'boo', 'arr'=>array(1,2,3, true, new DateTime()))),
67,
array(
'foo'=>'bar',
5=>7,
8=>'boo',
'baz'=>3
)
),
'64bitint' => 9223372036854775807,
'64bit_uint' => '18446744073709600000',
'64bitint_neg' => -pow(2, 40)
));
$headers->set('shortshort', -5, Wire\AMQPTable::T_INT_SHORTSHORT);
$headers->set('short', -1024, Wire\AMQPTable::T_INT_SHORT);
$message->set('application_headers', $headers);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.