本文整理汇总了PHP中AMQPExchange::setType方法的典型用法代码示例。如果您正苦于以下问题:PHP AMQPExchange::setType方法的具体用法?PHP AMQPExchange::setType怎么用?PHP AMQPExchange::setType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AMQPExchange
的用法示例。
在下文中一共展示了AMQPExchange::setType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialize
/**
* @param \AMQPExchange|null $exchange
*
* @throws HectorException
*/
public function initialize(\AMQPExchange $exchange = null)
{
if (null == $exchange) {
$exchange = new \AMQPExchange($this->channel->getWrappedChannel());
}
$this->exchange = $exchange;
$this->exchange->setName($this->getName());
$this->exchange->setType($this->context->getType());
$this->exchange->setArguments($this->context->getArguments());
$this->exchange->setFlags((int) $this->context->getFlags());
$this->exchange->declareExchange();
$this->initialized = true;
}
示例2:
function __construct()
{
$connection = new \AMQPConnection();
$connection->connect();
if (!$connection->isConnected()) {
throw new \AMQPConnectionException('Rabbit is not connected');
}
$this->channel = new \AMQPChannel($connection);
$this->exchange = new \AMQPExchange($this->channel);
//$this->exchange->delete('Celium');
$this->exchange->setName('Celium');
$this->exchange->setType('direct');
//$this->exchange->setFlags(\AMQP_DURABLE);
$this->exchange->declare();
}
示例3: declareExchange
public function declareExchange($name, $type = AMQP_EX_TYPE_TOPIC, $flags = AMQP_DURABLE)
{
$exchange = new \AMQPExchange($this->channel);
$exchange->setName($name);
$exchange->setType($type);
$exchange->setFlags($flags);
$exchange->declareExchange();
return $exchange;
}
示例4: createExchange
/**
* @inheritdoc
*/
public function createExchange(ChannelInterface $channel, $name, $type = ExchangeInterface::TYPE_DIRECT, $flags = null, array $args = [])
{
$delegate = new \AMQPExchange($channel->getDelegate());
$delegate->setName($name);
$delegate->setType($type);
$delegate->setFlags(Exchange::convertToDelegateFlags($flags));
$delegate->setArguments($args);
return new Exchange($delegate, $channel);
}
示例5: _getExchange
/**
* Get transport exchange for current channel.
* @return AMQPExchange
*/
protected function _getExchange()
{
if (!$this->_exchange) {
$this->_exchange = new \AMQPExchange($this->_getChannel());
//设置exchange名称
$this->_exchange->setName($this->_params['exchange']);
//设置exchange类型
$this->_exchange->setType(AMQP_EX_TYPE_DIRECT);
//设置exchange参数
$this->_exchange->setFlags(AMQP_DURABLE | AMQP_AUTODELETE);
}
return $this->_exchange;
}
示例6: getExchange
/**
* @return \AMQPExchange
* @throws \Exception
*/
protected function getExchange()
{
if (!$this->exchange) {
$this->exchange = new \AMQPExchange($this->getChannel());
$this->exchange->setName($this->exchangeConfig['name']);
$this->exchange->setType($this->exchangeConfig['type']);
$this->exchange->setArguments($this->exchangeConfig['arguments']);
$this->exchange->setFlags($this->exchangeConfig['flags']);
if (!$this->exchange->declareExchange()) {
throw new \Exception('Can not declare exchange ' . $this->exchange->getName());
}
}
return $this->exchange;
}
示例7: setupConnection
public static function setupConnection(\AMQPConnection $connection, $config)
{
$channel = new \AMQPChannel($connection);
$exchange = new \AMQPExchange($channel);
$exchange->setName($config['exchange_name']);
$exchange->setType(AMQP_EX_TYPE_DIRECT);
$exchange->setFlags(AMQP_DURABLE);
$exchange->declareExchange();
$queue = new \AMQPQueue($channel);
$queue->setName($config['queue_name']);
$queue->setFlags(AMQP_DURABLE);
$queue->declareQueue();
// $exchange->bind($config['queue_name'], 'gos.websocket.pusher');
return [$channel, $exchange, $queue];
}
示例8: exchangeDeclare
protected function exchangeDeclare()
{
if ($this->exchange === null) {
$this->exchange = new AMQPExchange($this->channel);
}
$this->exchange->setName($this->exchangeOptions['name']);
$this->exchange->setType($this->exchangeOptions['type']);
$this->exchange->setFlags($this->getFlagsFromOptions());
$this->exchange->setArguments($this->exchangeOptions['arguments']);
$this->exchange->declareExchange();
foreach ($this->exchangeOptions['binding'] as $bindOpt) {
$this->exchange->bind($bindOpt['name'], $bindOpt['routing-keys']);
}
$this->exchangeDeclared = true;
}
示例9: setUpAmqp
/**
* {@inheritDoc}
*/
protected function setUpAmqp()
{
$this->conn = new \AMQPConnection(['host' => $_SERVER['AMQP_HOST'], 'port' => $_SERVER['AMQP_PORT'], 'login' => $_SERVER['AMQP_USER'], 'password' => $_SERVER['AMQP_PASS'], 'vhost' => $_SERVER['AMQP_VHOST']]);
$this->conn->connect();
$channel = new \AMQPChannel($this->conn);
$exchange = new \AMQPExchange($channel);
$exchange->setName('event_band.test.exchange');
$exchange->setFlags(AMQP_AUTODELETE);
$exchange->setType(AMQP_EX_TYPE_TOPIC);
$exchange->declareExchange();
$queue = new \AMQPQueue($channel);
$queue->setName('event_band.test.event');
$queue->declareQueue();
$queue->bind('event_band.test.exchange', 'event.#');
}
示例10: createExchange
/**
* {@inheritDoc}
*/
public function createExchange()
{
// Create AMQP connection
$amqpConnection = new \AMQPConnection(['host' => $this->host, 'port' => $this->port, 'vhost' => $this->vhost, 'login' => $this->login, 'password' => $this->password]);
$amqpConnection->connect();
// Create channel
$channel = new \AMQPChannel($amqpConnection);
// Create exchange
$exchange = new \AMQPExchange($channel);
$exchange->setName($this->exchangeName);
$exchange->setType($this->exchangeType);
$exchange->setFlags(AMQP_DURABLE);
$exchange->declareExchange();
return $exchange;
}
示例11: main
public static function main()
{
self::$pool = new Pool(MAX_CONCURRENCY_JOB, \CALLWorker::class, []);
$conn_args = (require 'mq.config.php');
$e_name = 'e_linvo';
//交换机名
$q_name = 'q_linvo';
//队列名
$k_route = 'key_1';
//路由key
//创建连接和channel
$conn = new AMQPConnection($conn_args);
if (!$conn->connect()) {
write_log('mq.hx9999.com 无法连接上');
return;
}
$channel = new AMQPChannel($conn);
//创建交换机
$ex = new AMQPExchange($channel);
$ex->setName($e_name);
$ex->setType(AMQP_EX_TYPE_DIRECT);
//direct类型
$ex->setFlags(AMQP_DURABLE);
//持久化
//创建队列
$q = new AMQPQueue($channel);
$q->setName($q_name);
$q->setFlags(AMQP_DURABLE);
//持久化
while (True) {
$q->consume(function ($envelope, $queue) {
$msg = $envelope->getBody();
$queue->ack($envelope->getDeliveryTag());
//手动发送ACK应答
self::$pool->submit(new Sendsms($msg));
});
}
self::$pool->shutdown();
$conn->disconnect();
//睡眠
sleep(5);
}
示例12: send
public function send($msg)
{
$channel = new \AMQPChannel($this->connection);
$exchange = new \AMQPExchange($channel);
$exchange->setFlags(AMQP_DURABLE);
$exchange->setName('exchange2');
$exchange->setType('direct');
//$exchange->declare();
$exchange->declareExchange();
$queue = new \AMQPQueue($channel);
$queue->setName('series');
$queue->setFlags(AMQP_DURABLE | AMQP_AUTODELETE);
//$queue->declare();
$queue->declareQueue();
$queue->bind('exchange2', 'series');
$channel->startTransaction();
$message = $exchange->publish(json_encode($msg), 'series', AMQP_MANDATORY, array('content_type' => 'application/json', 'delivery_mode' => 2));
$channel->commitTransaction();
if (!$message) {
throw new \SYSTEM\LOG\ERROR("Error: Message '" . $message . "' was not sent to queue.!");
}
}
示例13: writeRMQ
/**
* 批量打入v3work_seo_pdrec数据,用于预热本企业推荐产品
*/
function writeRMQ($exchangeName = 'v3www', $router, $data = '')
{
$cfg = array('host' => '192.168.8.18', 'port' => '5672', 'login' => 'v3work', 'password' => 'gc7232275', 'vhost' => '/');
if (empty($exchangeName) || empty($data) || empty($cfg)) {
return false;
}
$reTryNum = 3;
$errMsg = array();
do {
try {
//建立到rmq服务器链接
$connection = new AMQPConnection($cfg);
$connection->connect();
//建立channel对象
$channel = new AMQPChannel($connection);
//建立交换机
$exchange = new AMQPExchange($channel);
$exchange->setName($exchangeName);
$exchange->setType(AMQP_EX_TYPE_DIRECT);
$exchange->setFlags(AMQP_DURABLE);
$exchange->declare();
$routingKey = $router;
//发消息
$ret = $exchange->publish($data, $routingKey, AMQP_NOPARAM, array('delivery_mode' => '2'));
//关闭链接
$connection->disconnect();
return $ret;
} catch (Exception $e) {
$connection->disconnect();
$errMsg[] = $e->getMessage();
usleep(5000);
$reTryNum -= 1;
}
} while ($reTryNum);
return false;
}
示例14: set
/**
* 入RabbitMQ队列
* @param [type] $exName [交换机名]
* @param [type] $routingKey [路由名]
* @param [type] $value [队列的值]
* @param [type] $dbType [数据库类型,默认为mysql]
* 按照此规则生成的默认队列名称为 exName_routeKey_dbType;值为value
*/
public function set($exName, $routingKey, $value, $dbType = 'mysql')
{
//创建交换机,设置交换机名
$ex = new \AMQPExchange($this->channel);
$ex->setName($exName);
$ex->setType(AMQP_EX_TYPE_DIRECT);
//广播模式
$ex->setFlags(AMQP_DURABLE);
//交换器进行持久化,即 RabbitMQ 重启后会自动重建
// $ex->declareExchange();
//设置队列名
$queue = new \AMQPQueue($this->channel);
$queue->setName($exName . '_' . $routingKey . '_' . $dbType);
$queue->setFlags(AMQP_DURABLE);
//队列进行持久化,即 RabbitMQ 重启后会自动重建
$queue->declareQueue();
//交换机和路由绑定到队列
$queue->bind($exName, $routingKey);
//入队列
if (is_array($value)) {
$value = json_encode($value);
}
$ex->publish($value, $routingKey, AMQP_NOPARAM, array('delivery_mode' => '2'));
}
示例15: AMQPConnection
//Establish connection to AMQP
$connection = new AMQPConnection();
$connection->setHost('127.0.0.1');
$connection->setLogin('guest');
$connection->setPassword('guest');
$connection->connect();
//Declare Channel
$channel = new AMQPChannel($connection);
$routing_key = $severity = isset($argv[1]) && !empty($argv[1]) ? $argv[1] : 'info';
$message = implode(' ', array_slice($argv, 2));
if (empty($message)) {
$message = 'Hello World!';
}
try {
//Declare Exchange
$exchange_name = 'direct_logs';
$exchange = new AMQPExchange($channel);
$exchange->setType(AMQP_EX_TYPE_DIRECT);
$exchange->setName($exchange_name);
$exchange->declareExchange();
$queue = new AMQPQueue($channel);
$queue->setFlags(AMQP_EXCLUSIVE);
$queue->setName('monitor.1');
$queue->declareQueue();
$queue->bind($exchange_name, $routing_key);
$exchange->publish($message, $routing_key);
echo " [x] Sent {$severity}:{$message}", PHP_EOL;
} catch (Exception $ex) {
print_r($ex);
}
$connection->disconnect();