public function publish($payload, $routingKey = null, $deliveryMode = 1)
    {

        if (empty($payload)) {
            throw new Exception('publish: payload not set.');
        }

        $channel = $this->connection->channel();

        // Exchange setup
        $this->setupExchange($this->exchangeOptions['name'], $this->exchangeOptions['type'], $channel);

        foreach ($this->queueOptions as $queueOption) {
            // Queue setup
            list($channel, ) = $this->setupQueue($queueOption['name'], $channel);

            // Bind the queue to the exchange
            $channel->queue_bind($queueOption['name'], $this->exchangeOptions['name'], $queueOption['bindingKey']);
        }

        // Routing key value can be a parameter to publishMessage() or a setting in the settings array sent
        // to the instantiation of the Message Broker object.
        $routingKey = isset($routingKey) ? $routingKey : $this->routingKey;
        $messageProperties = [
            'delivery_mode' => $deliveryMode,
        ];
        $message = new AMQPMessage($payload, $messageProperties);
        $channel->basic_publish($message, $this->exchangeOptions['name'], $routingKey);

        $channel->close();
    }
public function publish($payload, $routingKey = null, $deliveryMode = 1)
    {

        if (empty($payload)) {
            throw new Exception('publish: payload not set.');
        }

        $channel = $this->connection->channel();

        // Exchange setup
        $this->setupExchange($this->exchangeOptions['name'], $this->exchangeOptions['type'], $channel);

        foreach ($this->queueOptions as $queueOption) {
            // Queue setup
            list($channel, ) = $this->setupQueue($queueOption['name'], $channel);

            // Bind the queue to the exchange
            $channel->queue_bind($queueOption['name'], $this->exchangeOptions['name'], $queueOption['bindingKey']);
        }

        // Routing key value can be a parameter to publishMessage() or a setting in the settings array sent
        // to the instantiation of the Message Broker object.
        $routingKey = isset($routingKey) ? $routingKey : $this->routingKey;
        $messageProperties = [
            'delivery_mode' => $deliveryMode,
        ];
        $message = new AMQPMessage($payload, $messageProperties);
        $channel->basic_publish($message, $this->exchangeOptions['name'], $routingKey);

        $channel->close();
    }
public function publish ( $ payload , $ routingKey = null , $ deliveryMode = 1 ) { if ( empty ( $ payload ) ) { throw new Exception ( 'publish: payload not set.' ) ; } $ channel = $ this -> connection -> channel ( ) ; // Exchange setup $ this -> setupExchange ( $ this -> exchangeOptions [ 'name' ] , $ this -> exchangeOptions [ 'type' ] , $ channel ) ; foreach ( $ this -> queueOptions as $ queueOption ) { // Queue setup list ( $ channel , ) = $ this -> setupQueue ( $ queueOption [ 'name' ] , $ channel ) ; // Bind the queue to the exchange $ channel -> queue_bind ( $ queueOption [ 'name' ] , $ this -> exchangeOptions [ 'name' ] , $ queueOption [ 'bindingKey' ] ) ; } // Routing key value can be a parameter to publishMessage() or a setting in the settings array sent // to the instantiation of the Message Broker object. $ routingKey = isset ( $ routingKey ) ? $ routingKey : $ this -> routingKey ; $ messageProperties = [ 'delivery_mode' => $ deliveryMode , ] ; $ message = new AMQPMessage ( $ payload , $ messageProperties ) ; $ channel -> basic_publish ( $ message , $ this -> exchangeOptions [ 'name' ] , $ routingKey ) ; $ channel -> close ( ) ; }
Publish a message to the message broker system.

@param string $payload
Data to wrap in the message.
@param string $routingKey
The key or pattern the message will use for submission to the exchange for distribution to the
attached queues. Depending on the exchange type the key defines what queues get a copy of
the message.
@param int $deliveryMode
1: non-persistent, faster but no logging to disk, ~ 3x
2: persistent, write a copy of the message to disk

The related queue must also be set to durable for the setting
to work. If the server crashes, persistent messages will be recovered.
Crash tolerance comes at a price.
Publish a message to the message broker system .