本文整理汇总了PHP中PhpAmqpLib\Connection\AMQPStreamConnection::channel方法的典型用法代码示例。如果您正苦于以下问题:PHP AMQPStreamConnection::channel方法的具体用法?PHP AMQPStreamConnection::channel怎么用?PHP AMQPStreamConnection::channel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpAmqpLib\Connection\AMQPStreamConnection
的用法示例。
在下文中一共展示了AMQPStreamConnection::channel方法的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: getChannel
protected function getChannel()
{
if (null === $this->channel) {
$this->channel = $this->connection->channel();
}
return $this->channel;
}
示例3: getChannel
/**
* @return ChannelInterface
*/
public function getChannel()
{
if (is_null($this->channel)) {
$this->channel = new Channel($this, $this->connection->channel());
}
return $this->channel;
}
示例4: __construct
/**
* @param AMQPStreamConnection $connection
* @param string $queueName
*/
public function __construct(AMQPStreamConnection $connection, $queueName)
{
$this->connection = $connection;
$this->channel = $this->connection->channel();
$this->queueName = $queueName;
$this->channel->queue_declare($this->queueName, false, true, false, false);
}
示例5: connect
/**
*
*/
private function connect()
{
if (!$this->connection) {
$this->connection = new AMQPStreamConnection($this->host, $this->port, 'guest', 'guest');
$this->channel = $this->connection->channel();
$this->channel->exchange_declare($this->channel_name, 'fanout', false, false, false);
}
}
示例6: reconnect
/**
* Reconnect amqp connection
*/
public function reconnect()
{
if (!$this->amqpConnection->isConnected()) {
$this->amqpConnection->reconnect();
$this->channel = $this->amqpConnection->channel();
$this->declaredQueues = [];
}
}
示例7: setUp
public function setUp()
{
$this->conn = $this->createConnection();
$this->ch = $this->conn->channel();
$this->ch->exchange_declare($this->exchange_name, 'direct', false, false, false);
list($this->queue_name, , ) = $this->ch->queue_declare();
$this->ch->queue_bind($this->queue_name, $this->exchange_name, $this->queue_name);
}
示例8: open
/**
* @param string $exchangeName
*/
public function open($exchangeName)
{
if (null !== $this->channel) {
return;
}
$channel = $this->connection->channel();
$channel->queue_declare($exchangeName, false, true, false, false);
$this->channel = $channel;
}
示例9: __construct
/**
* Create a new RabbitMQ queue instance.
*
* @param \PhpAmqpLib\Connection\AMQPStreamConnection $amqpConnection
* @param array $config
*/
public function __construct(AMQPStreamConnection $amqpConnection, $config)
{
$this->connection = $amqpConnection;
$this->default = $config['queue'];
$this->configQueue = $config['queue_params'];
$this->configExchange = $config['exchange_params'];
$this->declareExchange = $config['exchange_declare'];
$this->declareBindQueue = $config['queue_declare_bind'];
$this->channel = $this->connection->channel();
}
示例10: connect
/**
* @param $exchange_name
*/
private function connect($exchange_name)
{
if (null !== $this->channel) {
return;
}
$this->channel = $this->connection->channel();
$this->channel->exchange_declare($exchange_name, 'fanout', false, true, false);
$this->channel->queue_declare($exchange_name, false, true, false, false);
$this->channel->queue_bind($exchange_name, $exchange_name);
}
示例11: __construct
/**
* @param AMQPStreamConnection $amqpConnection
* @param string $queue Queue name
* @param string $exchange Exchange name
* @param null $key Routing key
*/
public function __construct(AMQPStreamConnection $amqpConnection, $queue, $exchange = 'jsonbus', $key = null)
{
$this->connection = $amqpConnection;
$this->channel = $this->connection->channel();
$this->channel->exchange_declare($exchange, 'direct', false, true);
$this->channel->queue_declare($queue, false, true);
if (!$key) {
$key = $queue;
}
$this->channel->queue_bind($queue, $exchange, $key);
$this->exchange = $exchange;
$this->queue = $queue;
}
示例12: declareExchange
/**
* First tries to create exchange using passive flag.
* If exchange does not exist, creates new with provided settings.
*
* @param \PhpAmqpLib\Connection\AMQPStreamConnection $connection AMQP connection
* @param string $name Exchange name
* @param string $type Exchange type
* @param array $params optional declare exchange parameters
* @see self::$defaultDeclareExchangeParams
*/
public static function declareExchange($connection, $name, $type, $params = [])
{
$params = array_replace(self::$defaultDeclareExchangeParams, $params);
$ch = $connection->channel();
try {
$ch->exchange_declare($name, $type, true);
} catch (AMQPProtocolChannelException $e) {
$ch = $connection->channel();
if ($params['arguments'] and is_array($params['arguments'])) {
$params['arguments'] = new AMQPTable($params['arguments']);
}
$ch->exchange_declare($name, $type, false, $params['durable'], $params['auto_delete'], $params['internal'], $params['nowait'], $params['arguments']);
}
}
示例13: __construct
/**
* @param AMQPStreamConnection $conn
*/
public function __construct(AMQPStreamConnection $conn)
{
$this->conn = $conn;
$this->channel = $conn->channel();
list($this->queueName) = $this->channel->queue_declare('', false, true, true, false);
$this->channel->exchange_declare(self::TOPIC_NAME, self::MESSAGE_TYPE, false, true, true, false);
}
示例14: openChannel
/**
* @param bool $forceNewChannell
*
* @return void
*/
protected function openChannel($forceNewChannell = false)
{
if (true == $forceNewChannell || false == $this->channel instanceof AMQPChannel) {
$this->channel = $this->connection->channel();
$this->logger->info('New channel opened!', [$this->channel->getChannelId()]);
}
}
示例15: 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;
}