public function publish($message, $routing_key = null, $flags = AMQP_NOPARAM, array $attributes = array()) {


        $mandatory = boolval($flags & AMQP_MANDATORY);
        $immediate = boolval($flags & AMQP_IMMEDIATE);

        if($routing_key === null)
            $routing_key = '';

        //Why different keys?
        if(isset($attributes['headers'])){
            $attributes['application_headers'] = new AMQPTable($attributes['headers']);
            unset($attributes['headers']);
        }

        $amqp_message = new AMQPMessage($message, $attributes);

        try {
            $this->channel->_getChannel()->basic_publish($amqp_message, $this->name, $routing_key, $mandatory, $immediate);

            if ($this->publisherAcks === true) {
                $this->channel->_getChannel()->wait_for_pending_acks_returns(1);
            }
        } catch (AMQPRuntimeException $e) {
            throw new AMQPConnectionException($e->getMessage(), $e->getCode(), $e->getPrevious());
        } catch (Exception $e) {
            throw new AMQPExchangeException($e->getMessage(), $e->getCode(), $e->getPrevious());
        }

        return true;
    }
public function publish($message, $routing_key = null, $flags = AMQP_NOPARAM, array $attributes = array()) {


        $mandatory = boolval($flags & AMQP_MANDATORY);
        $immediate = boolval($flags & AMQP_IMMEDIATE);

        if($routing_key === null)
            $routing_key = '';

        //Why different keys?
        if(isset($attributes['headers'])){
            $attributes['application_headers'] = new AMQPTable($attributes['headers']);
            unset($attributes['headers']);
        }

        $amqp_message = new AMQPMessage($message, $attributes);

        try {
            $this->channel->_getChannel()->basic_publish($amqp_message, $this->name, $routing_key, $mandatory, $immediate);

            if ($this->publisherAcks === true) {
                $this->channel->_getChannel()->wait_for_pending_acks_returns(1);
            }
        } catch (AMQPRuntimeException $e) {
            throw new AMQPConnectionException($e->getMessage(), $e->getCode(), $e->getPrevious());
        } catch (Exception $e) {
            throw new AMQPExchangeException($e->getMessage(), $e->getCode(), $e->getPrevious());
        }

        return true;
    }
public function publish ( $ message , $ routing_key = null , $ flags = AMQP_NOPARAM , array $ attributes = array ( ) ) { $ mandatory = boolval ( $ flags & AMQP_MANDATORY ) ; $ immediate = boolval ( $ flags & AMQP_IMMEDIATE ) ; if ( $ routing_key === null ) $ routing_key = '' ; //Why different keys? if ( isset ( $ attributes [ 'headers' ] ) ) { $ attributes [ 'application_headers' ] = new AMQPTable ( $ attributes [ 'headers' ] ) ; unset ( $ attributes [ 'headers' ] ) ; } $ amqp_message = new AMQPMessage ( $ message , $ attributes ) ; try { $ this -> channel -> _getChannel ( ) -> basic_publish ( $ amqp_message , $ this -> name , $ routing_key , $ mandatory , $ immediate ) ; if ( $ this -> publisherAcks === true ) { $ this -> channel -> _getChannel ( ) -> wait_for_pending_acks_returns ( 1 ) ; } } catch ( AMQPRuntimeException $ e ) { throw new AMQPConnectionException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e -> getPrevious ( ) ) ; } catch ( Exception $ e ) { throw new AMQPExchangeException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e -> getPrevious ( ) ) ; } return true ; }
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 $routing_key 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.

@return boolean TRUE on success or FALSE on failure.
Publish a message to an exchange .