本文整理汇总了PHP中AMQPExchange::setName方法的典型用法代码示例。如果您正苦于以下问题:PHP AMQPExchange::setName方法的具体用法?PHP AMQPExchange::setName怎么用?PHP AMQPExchange::setName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AMQPExchange
的用法示例。
在下文中一共展示了AMQPExchange::setName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param string $protocol
* @param string $encoding
* @param bool $synchronous
* @param array $endpoint
*/
public function __construct($protocol, $encoding, $synchronous = false, array $endpoint = [])
{
parent::__construct($protocol, $encoding, $synchronous, $endpoint);
list($exchangeName, $routingKey) = array_values($this->endpoint);
$credentials = array_filter($this->endpoint);
$this->connection = new \AMQPConnection($credentials);
$this->connection->connect();
$this->channel = new \AMQPChannel($this->connection);
$this->exchange = new \AMQPExchange($this->channel);
$this->exchange->setName($exchangeName);
}
示例2: 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;
}
示例3:
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();
}
示例4: send
public function send($msg)
{
$ex = new \AMQPExchange($this->amqpChannel);
$ex->setName($this->name);
$ex->publish($msg);
return $this;
}
示例5: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln(sprintf('Move messages from queue "%s" (vhost: "%s") to exchange "%s" with routingKey "%s" (vhost: "%s")', $input->getArgument('from_queue'), $input->getArgument('from_vhost'), $input->getArgument('to_exchange'), $input->getArgument('to_routing_key'), $input->getArgument('to_vhost')));
$fromChannel = $this->getChannel($input->getArgument('from_connection'), $input->getArgument('from_vhost'));
if (null === ($toConnectionName = $input->getOption('to_connection'))) {
$toChannel = $this->getChannel($input->getArgument('from_connection'), $input->getArgument('to_vhost'));
} else {
$toChannel = $this->getChannel($input->getOption('to_connection'), $input->getArgument('to_vhost'));
}
$queue = new \AMQPQueue($fromChannel);
$queue->setName($input->getArgument('from_queue'));
$exchange = new \AMQPExchange($toChannel);
$exchange->setName($input->getArgument('to_exchange'));
$messageProvider = new PeclPackageMessageProvider($queue);
$messagePublisher = new PeclPackageMessagePublisher($exchange);
$options = array();
$stack = new \Swarrot\Processor\Stack\Builder();
if (0 !== ($max = (int) $input->getOption('max-messages'))) {
$stack->push('Swarrot\\Processor\\MaxMessages\\MaxMessagesProcessor');
$options['max_messages'] = $max;
}
$stack->push('Swarrot\\Processor\\Insomniac\\InsomniacProcessor');
$stack->push('Swarrot\\Processor\\Ack\\AckProcessor', $messageProvider);
$processor = $stack->resolve(new MoveProcessor($messagePublisher, $input->getArgument('to_routing_key')));
$consumer = new Consumer($messageProvider, $processor);
$consumer->consume($options);
}
示例6: 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;
}
示例7: setBroadcast
/**
* 广播形式写入队列
*
* @Author tianyunzi
* @DateTime 2015-08-19T18:44:42+0800
*/
public function setBroadcast($exName, $routingKey, $value)
{
//创建交换机
$ex = new \AMQPExchange($this->channel);
$ex->setName($exName);
//入队列
$ex->publish($value, $routingKey, AMQP_NOPARAM, array('delivery_mode' => '2'));
}
示例8: PostToExchange
/**
* Post a task to exchange specified in $details
* @param AMQPConnection $connection Connection object
* @param array $details Array of connection details
* @param string $task JSON-encoded task
* @param array $params AMQP message parameters
*/
function PostToExchange($connection, $details, $task, $params)
{
$ch = $connection->channel;
$xchg = new AMQPExchange($ch);
$xchg->setName($details['exchange']);
$success = $xchg->publish($task, $details['binding'], 0, $params);
return $success;
}
示例9: 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;
}
示例10: 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);
}
示例11: getAMQPExchange
protected function getAMQPExchange()
{
$connection = new \AMQPConnection(array('vhost' => 'swarrot'));
$connection->connect();
$channel = new \AMQPChannel($connection);
$exchange = new \AMQPExchange($channel);
$exchange->setName('exchange');
return $exchange;
}
示例12: register
/**
* {@inheritDoc}
*/
public function register(Container $c)
{
$c['amqp.connections.initializer'] = function ($c) {
$config = $c['amqp.options'];
$connections = array();
if (isset($config['connections'])) {
foreach ($config['connections'] as $name => $options) {
$connections[$name] = new \AMQPConnection($options);
}
return $connections;
}
if (isset($config['connection'])) {
return array('default' => new \AMQPConnection($config['connection']));
}
throw new \LogicException('No connection defined');
};
$c['queue.factory'] = function ($c) {
$connections = $c['amqp.connections.initializer'];
return function ($queueName, $connectionName = null) use($connections) {
$names = array_keys($connections);
if (null === $connectionName) {
$connectionName = reset($names);
}
if (!array_key_exists($connectionName, $connections)) {
throw new \InvalidArgumentException(sprintf('Unknown connection "%s". Available: [%s]', $connectionName, implode(', ', $names)));
}
$connection = $connections[$connectionName];
if (!$connection->isConnected()) {
$connection->connect();
}
$channel = new \AMQPChannel($connection);
$queue = new \AMQPQueue($channel);
$queue->setName($queueName);
return $queue;
};
};
$c['exchange.factory'] = function ($c) {
$connections = $c['amqp.connections.initializer'];
return function ($exchangeName, $connectionName = null) use($connections) {
$names = array_keys($connections);
if (null === $connectionName) {
$connectionName = reset($names);
}
if (!array_key_exists($connectionName, $connections)) {
throw new \InvalidArgumentException(sprintf('Unknown connection "%s". Available: [%s]', $connectionName, implode(', ', $names)));
}
$connection = $connections[$connectionName];
if (!$connection->isConnected()) {
$connection->connect();
}
$channel = new \AMQPChannel($connection);
$exchange = new \AMQPExchange($channel);
$exchange->setName($exchangeName);
return $exchange;
};
};
}
示例13: basic_publish
/**
* Publishes a message
*
* @param AMQPMessage $msg
* @param string $exchange
* @param string $routing_key
* @param bool $mandatory
* @param bool $immediate
* @param null $ticket
*/
public function basic_publish($msg, $exchange = '', $routing_key = '', $mandatory = false, $immediate = false, $ticket = null)
{
$flags = AMQP_NOPARAM;
$flags += $mandatory ? AMQP_MANDATORY : 0;
$flags += $immediate ? AMQP_IMMEDIATE : 0;
$xchange = new \AMQPExchange($this->channel);
$xchange->setName($exchange);
$xchange->publish($msg->body, $routing_key, $flags, $msg->get_properties());
}
示例14: getExchange
/**
* @param string $name
*
* @return \AMQPExchange
*/
protected function getExchange($name)
{
if (!isset($this->exchanges[$name])) {
$exchange = new \AMQPExchange($this->getChannel());
$exchange->setName($name);
$this->exchanges[$name] = $exchange;
}
return $this->exchanges[$name];
}
示例15: getExchange
/**
* getExchange
*
* @param string $name
* @param string $connection
*
* @return \AMQPExchange
*/
public function getExchange($name, $connection)
{
if (!isset($this->exchanges[$connection][$name])) {
if (!isset($this->exchanges[$connection])) {
$this->exchanges[$connection] = array();
}
$exchange = new \AMQPExchange($this->getChannel($connection));
$exchange->setName($name);
$this->exchanges[$connection][$name] = $exchange;
}
return $this->exchanges[$connection][$name];
}