PHP AMQP在请求中传递标头

时间:2015-07-09 10:18:18

标签: php amqp php-amqplib

我正在尝试向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;
}

2 个答案:

答案 0 :(得分:4)

创建消息时,应设置public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => 'AppBundle\Entity\Workflow', 'workflow' => '' )); } 属性。 这应该是Wire\AMQPTable,它将构造函数参数作为array标题。

官方amqp_message_headers_snd.php示例:

application_headers

答案 1 :(得分:1)