• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP AMQPExchange类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中AMQPExchange的典型用法代码示例。如果您正苦于以下问题:PHP AMQPExchange类的具体用法?PHP AMQPExchange怎么用?PHP AMQPExchange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了AMQPExchange类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: 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;
 }
开发者ID:fproject,项目名称:amqp-helper,代码行数:38,代码来源:ActivityNoticeManager.php


示例2: Run

 public function Run()
 {
     // Declare a new exchange
     $ex = new AMQPExchange($this->cnn);
     $ex->declare('game', AMQP_EX_TYPE_FANOUT);
     // Create a new queue
     $q1 = new AMQPQueue($this->cnn);
     $q1->declare('queue1');
     $q2 = new AMQPQueue($this->cnn);
     $q2->declare('queue2');
     // Bind it on the exchange to routing.key
     //$ex->bind('queue1', 'broadcast=true,target=queue1,x-match=any');
     $ex->bind('queue1', '');
     $ex->bind('queue2', '');
     $msgBody = 'hello';
     // Publish a message to the exchange with a routing key
     $ex->publish($msgBody, 'foo');
     // Read from the queue
     $msg = $q1->consume();
     $this->AssertEquals(count($msg), 1);
     $this->AssertEquals($msg[0]['message_body'], $msgBody, 'message not equal');
     // Read from the queue
     $msg = $q2->consume();
     $this->AssertEquals(count($msg), 1);
     $this->AssertEquals($msg[0]['message_body'], $msgBody, 'message not equal');
     $this->AddMessage(var_export($msg[0], true));
 }
开发者ID:JasonOcean,项目名称:iOS_Interest_Group,代码行数:27,代码来源:amqp_ut.php


示例3: publish

 /**
  * On dispatch event listener - called on any event
  * AMQP_MANDATORY: When publishing a message, the message must be routed to a valid queue. If it is not, an error will be returned.
  *  if the client publishes a message with the "mandatory" flag set to an exchange of "direct" type which is not bound to a queue.
  * AMQP_IMMEDIATE: When publishing a message, mark this message for immediate processing by the broker.
  *      REMOVED from rabbitmq > 3-0 http://www.rabbitmq.com/blog/2012/11/19/breaking-things-with-rabbitmq-3-0
  * @param Event $event
  * @param string $eventName
  * @return void
  */
 public function publish(Amqp\PublishEvent $event, $eventName, \AMQPExchange $exchange)
 {
     $success = $exchange->publish($event->getBody(), $eventName, $event->getFlags(), $event->jsonSerialize());
     if ($this->stopPropagation) {
         $event->stopPropagation();
     }
 }
开发者ID:gallna,项目名称:amqp-event,代码行数:17,代码来源:AbstractPublisher.php


示例4: 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);
 }
开发者ID:stof,项目名称:rabbit-mq-admin-toolkit,代码行数:27,代码来源:MessageMoveCommand.php


示例5: send

 public function send($msg)
 {
     $ex = new \AMQPExchange($this->amqpChannel);
     $ex->setName($this->name);
     $ex->publish($msg);
     return $this;
 }
开发者ID:xezzus,项目名称:amqp-im,代码行数:7,代码来源:Message.php


示例6: bind

 /**
  * Bind queue to exchange using dispatcher event names as routing keys
  *
  * @return void
  * @throws AMQPExchangeException
  */
 public function bind(\AMQPQueue $queue, \AMQPExchange $exchange)
 {
     $events = preg_grep($this->pattern, array_keys($this->getDispatcher()->getListeners()));
     foreach ($events as $eventName) {
         $queue->bind($exchange->getName(), $eventName);
     }
     $this->dispatcher->dispatch(static::BIND_EVENT, new SymfonyEvent($events, ["pattern" => $this->pattern, "exchange" => $exchange->getName(), "queue" => $queue->getName()]));
 }
开发者ID:gallna,项目名称:amqp-event,代码行数:14,代码来源:Consumer.php


示例7: publishToExchange

 /**
  * Publish the message to AMQP exchange
  *
  * @param Message $message
  * @param \AMQPExchange $exchange
  * @return bool
  * @throws \AMQPException
  */
 protected function publishToExchange(Message $message, \AMQPExchange $exchange)
 {
     $isPublished = $exchange->publish($message->getMessage(), $message->getRoutingKey(), $message->getFlags(), $message->getAttributes());
     if (!$isPublished) {
         throw FailedToPublishException::fromMessage($message);
     }
     return $isPublished;
 }
开发者ID:boekkooi,项目名称:tactician-amqp,代码行数:16,代码来源:ExchangePublisher.php


示例8: 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'));
 }
开发者ID:tianyunchong,项目名称:php,代码行数:14,代码来源:RabbitMQ.php


示例9: 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;
 }
开发者ID:UGuarder,项目名称:celery-php,代码行数:15,代码来源:amqppeclconnector.php


示例10: 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;
         };
     };
 }
开发者ID:odolbeau,项目名称:amqp-service-provider,代码行数:60,代码来源:AMQPServiceProvider.php


示例11: 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());
 }
开发者ID:remi-san,项目名称:universal-amqp,代码行数:19,代码来源:AMQPExtensionChannel.php


示例12: 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];
 }
开发者ID:event-band,项目名称:band-transport-amqp-pecl,代码行数:14,代码来源:PeclAmqpDriver.php


示例13: 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;
 }
开发者ID:Niktux,项目名称:swarrot,代码行数:9,代码来源:PeclPackageMessagePublisherTest.php


示例14: 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);
 }
开发者ID:treehouselabs,项目名称:queue,代码行数:12,代码来源:AmqpFactory.php


示例15: resend

 public static function resend($message, $routekey, $exchange = 'momo_nd', $appid = 0, $uid = 0)
 {
     try {
         $obj_conn = new AMQPConnect(Kohana::config('uap.rabbitmq'));
         $obj_exchange = new AMQPExchange($obj_conn, $exchange);
         $obj_exchange->publish($message, $routekey, AMQP_MANDATORY, array('app_id' => "{$appid}", 'user_id' => "{$uid}"));
     } catch (Exception $e) {
         Kohana::log('error', "再次发送消息失败 message = " . $message . "\n" . $e->getTraceAsString());
     }
 }
开发者ID:momoim,项目名称:momo-api,代码行数:10,代码来源:mq.php


示例16: publishToExchange

 protected function publishToExchange(Message $message, \AMQPExchange $exchange)
 {
     $attributes = (array) $message->getAttributes();
     $attributes['correlation_id'] = $this->correlationId;
     $isPublished = $exchange->publish($message->getMessage(), $this->routingKey, $message->getFlags(), $attributes);
     if (!$isPublished) {
         throw FailedToPublishException::fromMessage($message);
     }
     return $isPublished;
 }
开发者ID:boekkooi,项目名称:tactician-amqp,代码行数:10,代码来源:ResponsePublisher.php


示例17: declareResponseQueue

 /**
  * @param \AMQPExchange $exchange
  * @return \AMQPQueue
  */
 protected function declareResponseQueue(\AMQPExchange $exchange)
 {
     $queue = new \AMQPQueue($exchange->getChannel());
     $queue->setFlags(AMQP_EXCLUSIVE);
     if ($this->queueTimeout !== null) {
         $queue->setArgument("x-expires", $this->queueTimeout);
     }
     $queue->declareQueue();
     return $queue;
 }
开发者ID:boekkooi,项目名称:tactician-amqp,代码行数:14,代码来源:CommandPublisher.php


示例18: publishResponse

 /**
  * Responds to an rpc call. The response is broadcasted on the default exchange of the incoming queue, in order to
  * avoid publishing on the wrong exchange and never receiving the answer
  *
  * @param AMQPEnvelope $message  The message to be processed
  * @param bool         $response The response that was retrieved from the processor
  *
  * @throws Exception If the response cannot be republished
  */
 protected function publishResponse(AMQPEnvelope $message, $response = false)
 {
     // get the queue's channel
     $channel = $this->queue->getChannel();
     $exchange = new \AMQPExchange($channel);
     // publish on exchange the response message
     $result = $exchange->publish($response, $message->getReplyTo());
     if ($result === false) {
         throw new Exception('Cannot publish response on reply queue!');
     }
 }
开发者ID:c-datculescu,项目名称:amqp-base,代码行数:20,代码来源:Rpc.php


示例19: 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];
 }
开发者ID:antoox,项目名称:SwarrotBundle,代码行数:20,代码来源:PeclFactory.php


示例20: send

 /**
  * Sends a message to the specified exchange.
  * ATM, exchange must already exists on the broker.
  *
  * @param string $msg
  * @param string $exchangeName
  * @param string $routingKey
  * @param boolean $mandatory
  * @param boolean $immediate
  * @param array $attributes
  * @return boolean
  * @see http://www.php.net/manual/en/amqpexchange.publish.php
  */
 public function send($msg, $exchangeName = '', $routingKey = '', $mandatory = false, $immediate = false, array $attributes = array())
 {
     $exchange = new AMQPExchange($this->_channel);
     $exchange->setName($exchangeName);
     $flags = AMQP_NOPARAM;
     if ($mandatory) {
         $flags |= AMQP_MANDATORY;
     }
     if ($immediate) {
         $flags |= AMQP_IMMEDIATE;
     }
     return $exchange->publish((string) $msg, (string) $routingKey, $flags, $attributes);
 }
开发者ID:technomagegithub,项目名称:magento-amqp,代码行数:26,代码来源:Broker.php



注:本文中的AMQPExchange类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP AMQPQueue类代码示例发布时间:2022-05-23
下一篇:
PHP AMQPConnection类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap