/** * 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. */ 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; }
/** * Remove a routing key binding on an exchange from the given queue. * * @param string $exchange_name The name of the exchange on which the * queue is bound. * @param string $routing_key The binding routing key used by the * queue. * @param array $arguments Additional binding arguments. * * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. * * @return boolean */ public function unbind($exchange_name, $routing_key = null, array $arguments = array()) { if ($routing_key === null) { $routing_key = ''; } $bind_arguments = new AMQPTable($arguments); try { $this->channel->_getChannel()->queue_unbind($this->name, $exchange_name, $routing_key, $bind_arguments); } catch (AMQPRuntimeException $e) { throw new AMQPConnectionException($e->getMessage(), $e->getCode(), $e->getPrevious()); } catch (Exception $e) { return false; } return true; }