普通发送:
$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…
发表回复