Rollback an existing transaction. AMQPChannel::startTransaction() must
be called prior to this.
public rollbackTransaction ( ) : boolean | ||
return | boolean | TRUE on success or FALSE on failure. |
/** * @return bool */ public function rollbackTransaction() { if (!$this->isInitialized()) { $this->initialize(); } return $this->channel->rollbackTransaction(); }
/** * @return bool */ public function rollbackTransaction() { try { return $this->rawChannel->rollbackTransaction(); } catch (\Exception $e) { ClientHelper::throwRightException($e); } }
/** * @inheritdoc */ public function rollbackTransaction() { try { return $this->delegate->rollbackTransaction(); } catch (\AMQPChannelException $e) { throw new ChannelException($e->getMessage(), $e->getCode(), $e); } catch (\AMQPConnectionException $e) { throw new ConnectionException($e->getMessage(), $e->getCode(), $e); } }
public function it_should_rollback_if_transaction_failed(\AMQPChannel $channel) { $channel->startTransaction()->shouldBeCalled(); $channel->commitTransaction()->shouldNotBeCalled(); $channel->rollbackTransaction()->shouldBeCalled(); $exception = new \Exception('Whhooops'); $process = function (Channel $channel) use($exception) { throw $exception; }; $this->shouldThrow(new HectorException('Transaction failed', 255, $exception))->during('transaction', [$process]); }
/** * @inheritdoc */ public function rollbackTransaction() { $this->channel->rollbackTransaction(); }
/** * {@inheritDoc} */ public function rollback($key = null) { $this->channel->rollbackTransaction(); }
echo "<pre>"; $conn_args = array("host" => 'localhost', 'port' => 5672, 'login' => 'guest', "password" => 'guest', 'vhost' => '/'); $conn = new AMQPConnection($conn_args); if ($conn->connect()) { echo "Success\r\n"; } else { echo "Fail\r\n"; } $e_name = 'test.fanout'; //交换机名 $q_name = 'q_test5'; //队列名称 $r_key = 'key_test1'; //消息 $message = json_encode(array("HelloWorld")); //创建channel $channel = new AMQPChannel($conn); $ex = new AMQPExchange($channel); $ex->setName($e_name); //创建exchange的名字 echo "\n"; $channel->startTransaction(); //开启事务处理 echo "send: " . $ex->publish($message); //将数据发送 $channel->commitTransaction(); //提交事务 $channel->rollbackTransaction(); //回滚事务 $conn->disconnect();