本文整理汇总了PHP中AMQPConnection::channel方法的典型用法代码示例。如果您正苦于以下问题:PHP AMQPConnection::channel方法的具体用法?PHP AMQPConnection::channel怎么用?PHP AMQPConnection::channel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AMQPConnection
的用法示例。
在下文中一共展示了AMQPConnection::channel方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
$this->conn = new AMQPSocketConnection(HOST, PORT, USER, PASS, VHOST);
$this->ch = $this->conn->channel();
$this->ch->exchange_declare($this->exchange_name, 'direct', false, true, false);
$this->conn2 = new AMQPStreamConnection(HOST, PORT, USER, PASS, VHOST);
$this->ch2 = $this->conn->channel();
list($this->queue_name, , ) = $this->ch2->queue_declare();
$this->ch2->queue_bind($this->queue_name, $this->exchange_name, $this->queue_name);
}
示例2: activateOptions
/**
* Build a rabbitmq connection.
*
* @return boolean true if all ok.
* @throws an Exception if the attempt to connect to the requested rabbitmq server fails.
*/
public function activateOptions()
{
try {
$this->connection = new AMQPConnection($this->host, $this->port, $this->user, $this->password);
$this->channel = $this->connection->channel();
// $this->channel->exchange_declare($this->exchange, $this->routing_type, false, false, false);
// $this->channel->queue_declare($this->queue, false, false, false, false);
// $this->channel->queue_bind($this->queue, $this->exchange, $this->routing_key);
} catch (AMQPConnectionException $ce) {
$this->append = false;
} catch (AMQPChannelException $che) {
$this->append = false;
}
$this->append = true;
return true;
}
示例3: initializeConnection
/**
* Initialize connection
*
* @return void
*/
protected function initializeConnection()
{
$this->channel = null;
$this->connection = null;
if (function_exists('bcmod')) {
$config = \XLite::getInstance()->getOptions(array('amqp'));
$this->connection = new \AMQPConnection($config['host'], $config['port'], $config['user'], $config['password'], $config['vhost']);
$this->channel = $this->connection->channel();
}
}
示例4: sendMessage
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();
}
示例5: sendMessage
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();
}
示例6: send
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();
}
}
示例7: SendMessageToShowRecorder
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();
}
示例8: AMQPConnection
<?php
$source = $_GET['source'];
$title = $_GET['title'];
$url = $_GET['url'];
$shorturl = $_GET['shorturl'];
require_once __DIR__ . '/amqp.inc';
include __DIR__ . '/config.php';
$exchange = 'tweet_queue';
$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.
示例9: process_message
#!/usr/bin/php
<?php
require_once 'amqp.inc';
include 'config.php';
$in_exchange = 'soundcloud_music';
$in_queue = 'music';
$consumer_tag = 'consumer';
$response = "";
$conn = new AMQPConnection($rmq_HOST, $rmq_PORT, $rmq_USER, $rmq_PASS, $rmq_VHOST);
$in_ch = $conn->channel();
$in_ch->queue_declare($in_queue, false, true, false, false);
$in_ch->exchange_declare($in_exchange, 'direct', false, true, false);
$in_ch->queue_bind($in_queue, $in_exchange);
function process_message($msg)
{
global $debug;
global $useragent;
$json = $msg->body;
$ob = json_decode($json);
$id = $ob->id;
$url = $ob->url;
$aurl = $ob->avatar_url;
print "*** FETCHING id: {$id}, {$url}\n";
mkdir("data/{$id}");
mkdir("data/{$id}/uploads");
file_put_contents("data/{$id}/profile.json", "{$json}\n");
get_meta($id, $aurl);
crawl($id, $url);
system("nice tar -cjvf data/{$id}.tar.bz2 data/{$id}");
system("rm -rf data/{$id}");
system("scp data/{$id}.tar.bz2 steve@10.0.0.77:/temp/soundcloud");
示例10: AMQPConnection
<?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();
示例11: process_message
#!/usr/bin/php
<?php
$debug = 0;
require_once 'amqp.inc';
include 'config.php';
include '../website/common.php';
$in_exchange = 'feeds_queue';
$in_queue = 'feeds';
$out_exchange = 'articles_queue';
$out_queue = 'articles';
$consumer_tag = 'consumer';
$response = "";
$conn = new AMQPConnection($rmq_HOST, $rmq_PORT, $rmq_USER, $rmq_PASS, $rmq_VHOST);
$in_ch = $conn->channel();
$in_ch->queue_declare($in_queue, false, true, false, false);
$in_ch->exchange_declare($in_exchange, 'direct', false, true, false);
$in_ch->queue_bind($in_queue, $in_exchange);
$out_ch = $conn->channel();
$out_ch->queue_declare($out_queue, false, true, false, false);
$out_ch->exchange_declare($out_exchange, 'direct', false, true, false);
$out_ch->queue_bind($out_queue, $out_exchange);
$my_conn = mysql_connect($mysql_host, $mysql_user, $mysql_passwd);
if (!mysql_select_db("rsshose", $my_conn)) {
$error_string = "ERROR: can't connect to the DB\n";
print "{$error_string}";
exit(1);
}
function process_message($msg)
{
global $debug;
global $out_ch;
示例12: channel
/**
* {@inheritdoc}
*/
public function channel($channel_id = null)
{
$this->connect();
return parent::channel($channel_id);
}
示例13: queue
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();
}
示例14: channel
/**
* @inheritdoc
*/
public function channel($channel_id = null)
{
$this->initLazyConnection();
return parent::channel($channel_id);
}