本文整理汇总了PHP中PhpAmqpLib\Connection\AMQPStreamConnection::close方法的典型用法代码示例。如果您正苦于以下问题:PHP AMQPStreamConnection::close方法的具体用法?PHP AMQPStreamConnection::close怎么用?PHP AMQPStreamConnection::close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpAmqpLib\Connection\AMQPStreamConnection
的用法示例。
在下文中一共展示了AMQPStreamConnection::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//
$queue = 'cloudstack';
$conn = new AMQPStreamConnection(Config::get('rabbitmq.host'), Config::get('rabbitmq.port'), Config::get('rabbitmq.user'), Config::get('rabbitmq.pass'), Config::get('rabbitmq.vhost'));
$channel = $conn->channel();
while ($message = $channel->basic_get($queue)) {
$messageData = json_decode($message->body);
// Don't think we care about messages that have no status or event
if (empty($messageData->status) || empty($messageData->event)) {
$channel->basic_ack($message->delivery_info['delivery_tag']);
continue;
}
// For the moment, we don't care about non-Completed messages.
if (!in_array($messageData->status, ['Completed', 'Created'])) {
$channel->basic_ack($message->delivery_info['delivery_tag']);
continue;
}
if (in_array($messageData->event, ['SNAPSHOT.CREATE', 'SNAPSHOT.DELETE', 'VM.CREATE', 'VM.DESTROY'])) {
$messageHandled = $this->parseMessage($messageData);
} else {
$messageHandled = true;
}
if ($messageHandled == true) {
$channel->basic_ack($message->delivery_info['delivery_tag']);
}
}
$channel->close();
$conn->close();
}
示例2: __destruct
/**
*
*/
public function __destruct()
{
if ($this->connection) {
$this->channel->close();
$this->connection->close();
}
}
示例3: tearDown
public function tearDown()
{
if ($this->ch) {
$this->ch->exchange_delete($this->exchange_name);
$this->ch->close();
}
if ($this->conn) {
$this->conn->close();
}
}
示例4: registerAction
/**
* @Route("/register", name="security_register")
* @Method("POST")
*/
public function registerAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$request = Request::createFromGlobals();
$email = $request->request->get('email');
$password = $request->request->get('password');
$ico = trim($request->request->get('ico'));
$user = new User();
$encoder = $this->container->get('security.encoder_factory')->getEncoder($user);
$user->setPassword($encoder->encodePassword($password, $user->getSalt()));
$user->setEmail($email);
$user->setIco($ico);
$backgroundImages = ['animal', 'corn', 'farming', 'chicken'];
shuffle($backgroundImages);
$user->setBackgroundImage($backgroundImages[0]);
$profileImages = ['animal', 'corn', 'farming', 'chicken'];
shuffle($profileImages);
$user->setProfileImage($profileImages[0]);
$em->persist($user);
$em->flush();
$token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
$this->get('security.token_storage')->setToken($token);
//rabbit MQ
$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();
$channel->queue_declare('ico_queue', false, false, false, false);
$json = json_encode(["userId" => $user->getId(), "ico" => $ico]);
$msg = new AMQPMessage($json);
$channel->basic_publish($msg, '', 'ico_queue');
dump(" [x] Sent '{$ico}'\n");
$channel->close();
$connection->close();
return $this->redirect($this->generateUrl('main_overview'));
}
示例5: sendActivityNotice
/**
* Send an activity notice using AMQP
* @param ActivityNotice $notice
* @return bool
*/
public function sendActivityNotice($notice)
{
if (!isset($notice)) {
return false;
}
/** @var array $setting */
$setting = $this->params['amqpSetting'];
try {
if ($this->amqpClientLibrary == "PhpAmqpLib") {
$connection = new AMQPStreamConnection($setting['host'], $setting['port'], $setting['user'], $setting['password']);
$channel = $connection->channel();
$msg = new AMQPMessage(JsonHelper::encode($notice));
$channel->basic_publish($msg, $setting['exchangeName'], $setting['routingKey']);
$channel->close();
$connection->close();
} elseif ($this->amqpClientLibrary == "PECL") {
$connection = new \AMQPConnection(['host' => $setting['host'], 'port' => $setting['port'], 'login' => $setting['user'], 'password' => $setting['password']]);
$connection->connect();
if ($connection->isConnected()) {
$channel = new \AMQPChannel($connection);
$exchange = new \AMQPExchange($channel);
$exchange->setName($setting['exchangeName']);
$exchange->publish(JsonHelper::encode($notice), $setting['routingKey']);
$connection->disconnect();
}
} else {
return false;
}
} catch (\Exception $e) {
return false;
}
return true;
}
示例6: disconnect
/**
* Disconnects from the message broker
*/
public function disconnect()
{
if ($this->connection !== null) {
$this->channel->close();
$this->connection->close();
}
return $this;
}
示例7: close
/**
* Closing connection to the server with possible to delete queue
* @param bool|false $delete Set true for delete queue before closing connection
*/
public function close($delete = false)
{
if ($delete) {
$this->delete();
}
$this->channel->close();
$this->connection->close();
}
示例8: forward_to_router
function forward_to_router($msg, $routing_key)
{
$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();
$channel->queue_declare($routing_key, false, false, false, false);
$channel->basic_publish($msg, '', $routing_key);
$channel->close();
$connection->close();
}
示例9: closeConnections
/**
* Close the channel and connections to AMQP
*
* @return void
*/
public function closeConnections()
{
if ($this->channel) {
$this->channel->close();
}
if ($this->connection) {
$this->connection->close();
}
}
示例10: closeConnection
/**
* @return void
*/
public function closeConnection()
{
$this->closeChannel();
if ($this->connection instanceof AbstractConnection) {
$this->connection->close();
$this->logger->info('Connection clossed!', ['server' => $this->server, 'port' => $this->port, 'vhost' => $this->vhost]);
}
$this->connection = null;
}
示例11: forward_to_translator
function forward_to_translator($msg, $routing_key)
{
$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();
$channel->exchange_declare('bank_translators_exchange', 'direct', false, false, false);
$channel->basic_publish($msg, 'bank_translators_exchange', $routing_key);
$channel->close();
$connection->close();
}
示例12: __destruct
public function __destruct()
{
$this->channel->close();
unset($this->channel);
$this->connection->close();
unset($this->connection);
unset($this->replyQueueName);
unset($this->consumerTag);
unset($this->outputMessages);
}
示例13: sendBuyServiceToRabbit
public function sendBuyServiceToRabbit($taskId, $resourceId)
{
$connection = new AMQPStreamConnection(RABBIT_URL, RABBIT_PORT, RABBIT_USER, RABBIT_PASSWORD);
$channel = $connection->channel();
$channel->queue_declare($taskId, false, false, false, false);
$msg = new AMQPMessage($resourceId);
$channel->basic_publish($msg, '', $taskId);
$channel->close();
$connection->close();
}
示例14: disconnect
/**
* Closes the transient connection with the AMQP broker.
*
* This method will close an open connection with the AMQP broker.
*
* @return boolean true if connection was successfully closed, false otherwise.
*/
public function disconnect()
{
if (!$this->isConnected()) {
return false;
}
try {
$this->connection->close();
} catch (Exception $e) {
return false;
}
return true;
}
示例15: subscribe
public function subscribe()
{
$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();
$channel->queue_declare('aggregator', false, false, false, false);
$channel->basic_consume('aggregator', '', false, true, false, false, array($this, 'on_response'));
echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
while (count($channel->callbacks)) {
$channel->wait();
}
$channel->close();
$connection->close();
}