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;
    }