RabbitMQ笔记

普通发送:

$ex->publish($message, $this->_queue->getName(), AMQP_MANDATORY, $params);

事务模式:
单个发送:

$ch->startTransaction();
try {
    $ex->publish($message, $this->_queue->getName(), AMQP_MANDATORY, $params);
    $ch->commitTransaction();
}
catch(AMQPConnectionException $e) {
    $ch->rollbackTransaction();
}

批量发送:

$loop_times = 10;
$ch->startTransaction();
for($i=0;$i<$loop_times;$i++) {
    try {
        $ex->publish($message, $this->_queue->getName(), AMQP_MANDATORY, $params);
        $ch->commitTransaction();
    }
    catch(AMQPConnectionException $e) {
        $ch->rollbackTransaction();
    }
}

// to be continued

Refer:
RabbitMQ专栏:https://blog.csdn.net/u013256…
php-amqp测试用例:https://github.com/pdezwart/p…

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理