当前位置: 首页>>代码示例>>PHP>>正文


PHP AMQPExchange::publish方法代码示例

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


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

示例1: call

 public function call($value)
 {
     $this->response = NULL;
     $this->corrId = uniqid();
     try {
         //Declare an nonymous channel
         $this->queue = new AMQPQueue($this->channel);
         $this->queue->setFlags(AMQP_EXCLUSIVE);
         $this->queue->declareQueue();
         $this->callbackQueueName = $this->queue->getName();
         //Set Publish Attributes
         $attributes = ['correlation_id' => $this->corrId, 'reply_to' => $this->callbackQueueName];
         $this->exchange->publish($value, $this->rpcQueue, AMQP_NOPARAM, $attributes);
         $callback = function (AMQPEnvelope $message, AMQPQueue $q) {
             if ($message->getCorrelationId() == $this->corrId) {
                 //echo sprintf("CorrelationID: %s",$message->getCorrelationId()), PHP_EOL;
                 //echo sprintf("Response: %s",$message->getBody()), PHP_EOL;
                 $this->response = $message->getBody();
                 $q->nack($message->getDeliveryTag());
                 return false;
             }
         };
         $this->queue->consume($callback);
         //Return RPC Results
         return $this->response;
     } catch (AMQPQueueException $ex) {
         print_r($ex);
     } catch (Exception $ex) {
         print_r($ex);
     }
 }
开发者ID:seyfer,项目名称:rabbitmq-learn,代码行数:31,代码来源:rpc_client.php

示例2: sendRequest

 /**
  * @param Request $rpcRequest
  *
  * @return Response|null
  */
 protected function sendRequest(Request $rpcRequest)
 {
     $message = $this->serializer->serialize($rpcRequest, $this->protocol, ['encoding' => $this->encoding]);
     $routingKey = $this->routingKey;
     $flags = $this->flags;
     $attributes = ['content_type' => 'application/' . $this->encoding, 'rpc_type' => $this->protocol];
     $this->exchange->publish($message, $routingKey, $flags, $attributes);
 }
开发者ID:mihai-stancu,项目名称:rpc-bundle,代码行数:13,代码来源:AmqpConnection.php

示例3: Run

 public function Run()
 {
     // Declare a new exchange
     $ex = new AMQPExchange($this->cnn);
     $ex->declare('game', AMQP_EX_TYPE_TOPIC);
     // Create a new queue
     $q1 = new AMQPQueue($this->cnn);
     $q1->declare('queue1');
     $q1->purge('queue1');
     $q2 = new AMQPQueue($this->cnn);
     $q2->declare('queue2');
     $q1->purge('queue2');
     $q3 = new AMQPQueue($this->cnn);
     $q3->declare('queue3');
     $q3->purge('queue3');
     $options = array('min' => 0, 'max' => 10, 'ack' => true);
     // Bind it on the exchange to routing.key
     $ex->bind('queue1', 'game1.#');
     $ex->bind('queue2', 'game1.#');
     $ex->bind('queue3', 'game1.#');
     $ex->bind('queue3', 'queue3.#');
     $msgbody1 = 'hello';
     // Publish a message to the exchange with a routing key
     $result = $ex->publish($msgbody1, 'game1.msg');
     $this->AssertEquals($result, TRUE, 'publish message failed');
     $msgbody2 = 'world';
     // Publish a message to the exchange with a routing key
     $result = $ex->publish($msgbody2, 'game1.msg');
     $this->AssertEquals($result, TRUE, 'publish message failed');
     $msgbody3 = 'hello player3';
     // Publish a message to the exchange with a routing key
     $result = $ex->publish($msgbody3, 'queue3.command');
     $this->AssertEquals($result, TRUE, 'publish message failed');
     // Read from the queue
     $msg = $q1->consume($options);
     $this->AddMessage(var_export($msg, true));
     $this->AssertEquals(count($msg), 2);
     $this->AssertEquals($msg[0]['message_body'], $msgbody1, 'message not equal');
     $this->AssertEquals($msg[1]['message_body'], $msgbody2, 'message not equal');
     // Read from the queue
     $msg = $q2->consume($options);
     $this->AssertEquals(count($msg), 2);
     $this->AssertEquals($msg[0]['message_body'], $msgbody1, 'message not equal');
     $this->AssertEquals($msg[1]['message_body'], $msgbody2, 'message not equal');
     // Read from the queue
     $msg = $q3->consume($options);
     $this->AddMessage(var_export($msg, true));
     $this->AssertEquals(count($msg), 3);
     $this->AssertEquals($msg[0]['message_body'], $msgbody1, 'message not equal');
     $this->AssertEquals($msg[1]['message_body'], $msgbody2, 'message not equal');
     $this->AssertEquals($msg[2]['message_body'], $msgbody3, 'message not equal');
     $msg = $q3->consume($options);
     $this->AssertEquals(count($msg), 0);
 }
开发者ID:JasonOcean,项目名称:iOS_Interest_Group,代码行数:54,代码来源:amqp_topic_ut.php

示例4: publish

 /**
  * {@inheritdoc}
  */
 public function publish($message, $routingKey = '', array $properties = array())
 {
     if (!isset($properties['timestamp'])) {
         $properties['timestamp'] = microtime(true);
     }
     // make messages durable by default
     if (!isset($properties['delivery_mode'])) {
         $properties['delivery_mode'] = 2;
     }
     $response = $this->exchange->publish($message, $routingKey, AMQP_NOPARAM, $properties);
     return $response;
 }
开发者ID:vstepanyuk,项目名称:amqp-base,代码行数:15,代码来源:Simple.php

示例5: enqueue

 /**
  * Enqueues given $message
  *
  * @throws FailedEnqueueException
  */
 public function enqueue(Message $message, $timeout = 0, callable $onTimeout = null)
 {
     if ($message instanceof Delayable) {
         if ($message->delayedUntil() < new \DateTime('now')) {
             throw new \OutOfBoundsException('Cannot enqueue messages in the past');
             // do something
         }
     }
     $body = $message->getBody();
     $route = $message->getRoutingKey();
     $props = $message->getHeaders();
     return $this->exchange->publish($body, $route, $flags, $props);
 }
开发者ID:bashilbers,项目名称:messaging,代码行数:18,代码来源:AmqpAdapter.php

示例6: Run

 public function Run()
 {
     // Declare a new exchange
     $ex = new AMQPExchange($this->cnn);
     $ex->declare('game', AMQP_EX_TYPE_HEADER);
     // Create a new queue
     $q1 = new AMQPQueue($this->cnn);
     $q1->declare('queue1');
     $q1->purge('queue1');
     $q2 = new AMQPQueue($this->cnn);
     $q2->declare('queue2');
     $q1->purge('queue2');
     $q3 = new AMQPQueue($this->cnn);
     $q3->declare('queue3');
     $q3->purge('queue3');
     $options = array('min' => 0, 'max' => 10, 'ack' => true);
     // Bind it on the exchange to routing.key
     $ex->bind('queue1', 'broadcast=1,target=1,x-match=any');
     $ex->bind('queue2', 'broadcast=1,target=2,x-match=any');
     $ex->bind('queue3', 'broadcast=1,target=3,x-match=any');
     $msgbody1 = 'hello';
     // Publish a message to the exchange with a routing key
     $result = $ex->publish($msgbody1, NULL, AMQP_IMMEDIATE, array('headers' => array('broadcast' => 1)));
     $this->AssertEquals($result, TRUE, 'publish message failed');
     $msgbody2 = 'world';
     // Publish a message to the exchange with a routing key
     $result = $ex->publish($msgbody2, NULL, AMQP_IMMEDIATE, array('headers' => array('broadcast' => 1)));
     $this->AssertEquals($result, TRUE, 'publish message failed');
     $msgbody3 = 'queue3';
     // Publish a message to the exchange with a routing key
     $result = $ex->publish($msgbody1, NULL, AMQP_IMMEDIATE, array('headers' => array('target' => 3)));
     $this->AssertEquals($result, TRUE, 'publish message failed');
     // Read from the queue
     $msg = $q1->consume($options);
     $this->AddMessage(var_export($msg, true));
     $this->AssertEquals(count($msg), 2);
     //$this->AssertEquals($msg[0]['message_body'], $msgbody1, 'message not equal');
     //$this->AssertEquals($msg[1]['message_body'], $msgbody2, 'message not equal');
     // Read from the queue
     $msg = $q2->consume($options);
     $this->AssertEquals(count($msg), 2);
     //$this->AssertEquals($msg[0]['message_body'], $msgbody1, 'message not equal');
     //$this->AssertEquals($msg[1]['message_body'], $msgbody2, 'message not equal');
     // Read from the queue
     $msg = $q3->consume($options);
     $this->AssertEquals(count($msg), 3);
     //$this->AssertEquals($msg[0]['message_body'], $msgbody1, 'message not equal');
     //$this->AssertEquals($msg[1]['message_body'], $msgbody2, 'message not equal');
     //$this->AssertEquals($msg[2]['message_body'], $msgbody3, 'message not equal');
 }
开发者ID:JasonOcean,项目名称:iOS_Interest_Group,代码行数:50,代码来源:amqp_xmatch_ut.php

示例7: publish

 /**
  * Publish a message to an exchange.
  *
  * Publish a message to the exchange represented by the AMQPExchange object.
  *
  * @param string $message The message to publish.
  * @param string $routingKey The optional routing key to which to publish to.
  * @param integer $flags One or more of AMQP_MANDATORY and AMQP_IMMEDIATE.
  * @param array $attributes One of content_type, content_encoding,
  *                          message_id, user_id, app_id, delivery_mode,
  *                          priority, timestamp, expiration, type
  *                          or reply_to, headers.
  *
  * @throws \AMQPExchangeException   On failure.
  * @throws \AMQPChannelException    If the channel is not open.
  * @throws \AMQPConnectionException If the connection to the broker was lost.
  */
 public function publish($message, $routingKey = null, $flags = AMQP_NOPARAM, array $attributes = [])
 {
     if (!$this->exchangeDeclared) {
         $this->exchangeDeclare();
     }
     $this->exchange->publish($message, $routingKey, $flags, $attributes);
 }
开发者ID:umpirsky,项目名称:ko-worker,代码行数:24,代码来源:Producer.php

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: publish

 /**
  * @param mixed  $message
  * @param string $routingKey
  * @param int    $flags
  * @param array  $attributes
  *
  * @return bool
  */
 public function publish($message, $routingKey = null, $flags = Client::NOPARAM, array $attributes = [])
 {
     try {
         return $this->rawExchange->publish($this->encodeStrategy->encode($message), $routingKey, $flags, $attributes);
     } catch (\Exception $e) {
         ClientHelper::throwRightException($e);
     }
 }
开发者ID:csharpru,项目名称:yii2-amqp,代码行数:16,代码来源:Exchange.php

示例14: doPush

 /**
  * @param string $data
  * @param array  $context
  */
 protected function doPush($data, array $context)
 {
     $config = $this->getConfig();
     if (false === $this->connected) {
         if (!extension_loaded('amqp')) {
             throw new \RuntimeException(sprintf('%s pusher require %s php extension', get_class($this), 'amqp'));
         }
         $this->connection = new \AMQPConnection($config);
         $this->connection->connect();
         list(, $this->exchange) = Utils::setupConnection($this->connection, $config);
         $this->setConnected();
     }
     $resolver = new OptionsResolver();
     $resolver->setDefaults(['routing_key' => null, 'publish_flags' => AMQP_NOPARAM, 'attributes' => array()]);
     $context = $resolver->resolve($context);
     $this->exchange->publish($data, $context['routing_key'], $context['publish_flags'], $context['attributes']);
 }
开发者ID:rsrodrig,项目名称:MeetMeSoftware,代码行数:21,代码来源:AmqpPusher.php

示例15: 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


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