AMQPExchange
在线手册:中文 英文
PHP手册

AMQPExchange::publish

(PECL amqp >= Unknown)

AMQPExchange::publishPublish a message to an exchange.

说明

public bool AMQPExchange::publish ( string $message , string $routing_key [, int $flags = AMQP_NOPARAM [, array $attributes = array() ]] )

Publish a message to the exchange represented by the AMQPExchange object.

参数

message

The message to publish.

routing_key

The routing key to which to publish.

flags

One or more of AMQP_MANDATORY and AMQP_IMMEDIATE.

attributes

Supported indexes
key Description Default value
content_type   text/plain
content_encoding   NULL
message_id   NULL
user_id   NULL
app_id   NULL
delivery_mode   NULL
priority   NULL
timestamp   NULL
expiration   NULL
type   NULL
reply_to   NULL

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE.

错误/异常

Throws an AMQPExchangeException on failure.

Throws AMQPChannelException if the channel is not open.

Throws AMQPConnectionException if the connection to the broker was lost.


AMQPExchange
在线手册:中文 英文
PHP手册
PHP手册 - N: Publish a message to an exchange.

用户评论:

glenjamin at gmail dot com (20-Feb-2012 04:27)

Any unused attributes will be assigned as custom headers attached to the outgoing message's headers collection.

This isn't exactly clear from the documentation above, but I've checked the C source, and that's how you set custom headers.

prudkiy at mail dot ru (25-Dec-2011 09:26)

Please note, here no way to be sure if message really published
The use of flags AMQP_MANDATORY and AMQP_IMMEDIATE not force to return any errors (in case if queue not exists etc) and "publish" returns TRUE anyway