AMQPExchange::publish PHP Method

publish() public method

Publish a message to the exchange represented by the AMQPExchange object.
public publish ( string $message, string $routing_key = null, integer $flags = AMQP_NOPARAM, array $attributes = [] ) : boolean
$message string The message to publish.
$routing_key string The optional routing key to which to publish to.
$flags integer One or more of AMQP_MANDATORY and AMQP_IMMEDIATE.
$attributes array One of content_type, content_encoding, message_id, user_id, app_id, delivery_mode, priority, timestamp, expiration, type or reply_to, headers.
return boolean TRUE on success or FALSE on failure.
    public function publish($message, $routing_key = null, $flags = AMQP_NOPARAM, array $attributes = array())
    {
    }

Usage Example

コード例 #1
0
ファイル: rpc_client.php プロジェクト: seyfer/rabbitmq-learn
 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);
     }
 }
All Usage Examples Of AMQPExchange::publish