public function tearDown() { if ($this->ch) { $this->ch->exchange_delete($this->exchange_name); $this->ch->close(); } if ($this->conn) { $this->conn->close(); } if ($this->ch2) { $this->ch2->close(); } if ($this->conn2) { $this->conn2->close(); } }
public function tearDown() { if ($this->channel) { $this->channel->queue_delete($this->queueName . '1'); $this->channel->close(); } if ($this->connection) { $this->connection->close(); } }
private static function sendMessage($exchange, $data) { global $CC_CONFIG; $conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"], $CC_CONFIG["rabbitmq"]["port"], $CC_CONFIG["rabbitmq"]["user"], $CC_CONFIG["rabbitmq"]["password"], $CC_CONFIG["rabbitmq"]["vhost"]); $channel = $conn->channel(); $channel->access_request($CC_CONFIG["rabbitmq"]["vhost"], false, false, true, true); $channel->exchange_declare($exchange, 'direct', false, true); $msg = new AMQPMessage($data, array('content_type' => 'text/plain')); $channel->basic_publish($msg, $exchange); $channel->close(); $conn->close(); }
public function close() { if ($this->closed != true) { if ($this->channel != null) { $this->channel->close(); $this->channel = null; } if ($this->connection != null) { $this->connection->close(); $this->connection = null; } $this->closed = true; } }
private static function sendMessage($exchange, $data) { $CC_CONFIG = Config::getConfig(); $conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"], $CC_CONFIG["rabbitmq"]["port"], $CC_CONFIG["rabbitmq"]["user"], $CC_CONFIG["rabbitmq"]["password"], $CC_CONFIG["rabbitmq"]["vhost"]); if (!isset($conn)) { throw new Exception("Cannot connect to RabbitMQ server"); } $channel = $conn->channel(); $channel->access_request($CC_CONFIG["rabbitmq"]["vhost"], false, false, true, true); $channel->exchange_declare($exchange, 'direct', false, true); $msg = new AMQPMessage($data, array('content_type' => 'text/plain')); $channel->basic_publish($msg, $exchange); $channel->close(); $conn->close(); }
function send($to, $subject, $text) { try { $conn = new AMQPConnection($this->rabbitMQConf['host'], $this->rabbitMQConf['port'], $this->rabbitMQConf['user'], $this->rabbitMQConf['pass']); $channel = $conn->channel(); $channel->access_request($this->rabbitMQConf['virtualHost'], false, false, true, true); $mailData = array("to" => $to, "subject" => $subject, "text" => $text); $mailDataToJson = json_encode($mailData); $msg = new AMQPMessage($mailDataToJson, array('content_type' => 'text/plain')); $channel->basic_publish($msg, $this->queueConf['exchange']); $channel->close(); $conn->close(); return true; } catch (Exception $e) { echo "Something went wrong " . $e->getMessage(); } }
public static function SendMessageToShowRecorder($event_type) { global $CC_CONFIG; $conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"], $CC_CONFIG["rabbitmq"]["port"], $CC_CONFIG["rabbitmq"]["user"], $CC_CONFIG["rabbitmq"]["password"]); $channel = $conn->channel(); $channel->access_request($CC_CONFIG["rabbitmq"]["vhost"], false, false, true, true); $EXCHANGE = 'airtime-show-recorder'; $channel->exchange_declare($EXCHANGE, 'direct', false, true); $today_timestamp = date("Y-m-d H:i:s"); $now = new DateTime($today_timestamp); $end_timestamp = $now->add(new DateInterval("PT2H")); $end_timestamp = $end_timestamp->format("Y-m-d H:i:s"); $temp['event_type'] = $event_type; if ($event_type = "update_schedule") { $temp['shows'] = Show::getShows($today_timestamp, $end_timestamp, $excludeInstance = NULL, $onlyRecord = TRUE); } $data = json_encode($temp); $msg = new AMQPMessage($data, array('content_type' => 'text/plain')); $channel->basic_publish($msg, $EXCHANGE); $channel->close(); $conn->close(); }
$queue = 'tweets'; $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST); $ch = $conn->channel(); /* The following code is the same both in the consumer and the producer. In this way we are sure we always have a queue to consume from and an exchange where to publish messages. */ /* name: $queue passive: false durable: true // the queue will survive server restarts exclusive: false // the queue can be accessed in other channels auto_delete: false //the queue won't be deleted once the channel is closed. */ $ch->queue_declare($queue, false, true, false, false); /* name: $exchange type: direct passive: false durable: true // the exchange will survive server restarts auto_delete: false //the exchange won't be deleted once the channel is closed. */ $ch->exchange_declare($exchange, 'direct', false, true, false); $ch->queue_bind($queue, $exchange); $msg_body = implode(' ', array_slice($argv, 1)); $msg = new AMQPMessage($msg_body, array('content_type' => 'text/plain')); $ch->basic_publish($msg, $exchange); $ch->close(); $conn->close();
<?php require_once __DIR__ . '/lib/php-amqplib/amqp.inc'; $connection = new AMQPConnection('localhost', 5672, 'guest', 'guest'); $channel = $connection->channel(); $channel->exchange_declare('logs', 'fanout', false, false, false); $data = implode(' ', array_slice($argv, 1)); if (empty($data)) { $data = "info: Hello World!"; } $msg = new AMQPMessage($data); $channel->basic_publish($msg, 'logs'); echo " [x] Sent ", $data, "\n"; $channel->close(); $connection->close();
public function queue($queue) { $connection = new AMQPConnection('localhost', 5672, 'guest', 'guest'); $channel = $connection->channel(); $channel->queue_declare('rockola', false, false, false, false); $msg = new AMQPMessage($queue); $channel->basic_publish($msg, '', 'rockola'); $channel->close(); $connection->close(); }