Method: Bunny::Exchange#publish
- Defined in:
- lib/bunny/exchange.rb
#publish(payload, opts = {}) ⇒ Bunny::Exchange
Publishes a message
Parameters:
-
payload
(String)
—
Message payload. It will never be modified by Bunny or RabbitMQ in any way.
-
opts
(Hash)
(defaults to: {})
—
Message properties (metadata) and delivery settings
Options Hash (opts):
-
:routing_key
(String)
—
Routing key
-
:persistent
(Boolean)
—
Should the message be persisted to disk?
-
:mandatory
(Boolean)
—
Should the message be returned if it cannot be routed to any queue?
-
:timestamp
(Integer)
—
A timestamp associated with this message
-
:expiration
(Integer)
—
Expiration time after which the message will be deleted
-
:type
(String)
—
Message type, e.g. what type of event or command this message represents. Can be any string
-
:reply_to
(String)
—
Queue name other apps should send the response to
-
:content_type
(String)
—
Message content type (e.g. application/json)
-
:content_encoding
(String)
—
Message content encoding (e.g. gzip)
-
:correlation_id
(String)
—
Message correlated to this one, e.g. what request this message is a reply for
-
:priority
(Integer)
—
Message priority, 0 to 9. Not used by RabbitMQ, only applications
-
:message_id
(String)
—
Any message identifier
-
:user_id
(String)
—
Optional user ID. Verified by RabbitMQ against the actual connection username
-
:app_id
(String)
—
Optional application ID
Returns:
-
(Bunny::Exchange)
—
Self
See Also:
145 146 147 148 149 150 |
# File 'lib/bunny/exchange.rb', line 145 def publish(payload, opts = {}) rk = opts[:routing_key] || opts[:key] @channel.basic_publish(payload, self.name, rk, opts) self end |