lib/amqp/client/message.rb in amqp-client-1.0.2 vs lib/amqp/client/message.rb in amqp-client-1.1.0
- old
+ new
@@ -1,54 +1,111 @@
# frozen_string_literal: true
module AMQP
class Client
# A message delivered from the broker
- # @!attribute channel
- # @return [Connection::Channel] The channel the message was deliviered to
- # @!attribute delivery_tag
- # @return [Integer] The delivery tag of the message, used for acknowledge or reject the message
- # @!attribute exchange_name
- # @return [String] Name of the exchange the message was published to
- # @!attribute routing_key
- # @return [String] The routing key the message was published with
- # @!attribute properties
- # @return [Properties]
- # @!attribute body
- # @return [String] The message body
- # @!attribute redelivered
- # @return [Boolean] True if the message have been delivered before
- # @!attribute consumer_tag
- # @return [String] The tag of the consumer the message was deliviered to
- # @return [nil] Nil if the message was polled and not deliviered to a consumer
- Message =
- Struct.new(:channel, :delivery_tag, :exchange_name, :routing_key, :properties, :body, :redelivered, :consumer_tag) do
- # Acknowledge the message
- # @return [nil]
- def ack
- channel.basic_ack(delivery_tag)
- end
+ class Message
+ # @api private
+ def initialize(channel, consumer_tag, delivery_tag, exchange, routing_key, redelivered)
+ @channel = channel
+ @consumer_tag = consumer_tag
+ @delivery_tag = delivery_tag
+ @exchange = exchange
+ @routing_key = routing_key
+ @redelivered = redelivered
+ @properties = nil
+ @body = ""
+ end
- # Reject the message
- # @param requeue [Boolean] If true the message will be put back into the queue again, ready to be redelivered
- # @return [nil]
- def reject(requeue: false)
- channel.basic_reject(delivery_tag, requeue: requeue)
- end
+ # The channel the message was deliviered to
+ # @return [Connection::Channel]
+ attr_reader :channel
+
+ # The tag of the consumer the message was deliviered to
+ # @return [String]
+ # @return [nil] If the message was polled and not deliviered to a consumer
+ attr_reader :consumer_tag
+
+ # The delivery tag of the message, used for acknowledge or reject the message
+ # @return [Integer]
+ attr_reader :delivery_tag
+
+ # Name of the exchange the message was published to
+ # @return [String]
+ attr_reader :exchange
+
+ # The routing key the message was published with
+ # @return [String]
+ attr_reader :routing_key
+
+ # True if the message have been delivered before
+ # @return [Boolean]
+ attr_reader :redelivered
+
+ # Message properties
+ # @return [Properties]
+ attr_accessor :properties
+
+ # The message body
+ # @return [String]
+ attr_accessor :body
+
+ # Acknowledge the message
+ # @return [nil]
+ def ack
+ @channel.basic_ack(@delivery_tag)
end
+ # Reject the message
+ # @param requeue [Boolean] If true the message will be put back into the queue again, ready to be redelivered
+ # @return [nil]
+ def reject(requeue: false)
+ @channel.basic_reject(@delivery_tag, requeue: requeue)
+ end
+
+ # @see #exchange
+ # @deprecated
+ # @!attribute [r] exchange_name
+ # @return [String]
+ def exchange_name
+ @exchange
+ end
+ end
+
# A published message returned by the broker due to some error
- # @!attribute reply_code
- # @return [Integer] Error code
- # @!attribute reply_text
- # @return [String] Description on why the message was returned
- # @!attribute exchange
- # @return [String] Name of the exchange the message was published to
- # @!attribute routing_key
- # @return [String] The routing key the message was published with
- # @!attribute properties
- # @return [Properties]
- # @!attribute body
- # @return [String] The message body
- ReturnMessage = Struct.new(:reply_code, :reply_text, :exchange, :routing_key, :properties, :body)
+ class ReturnMessage
+ # @api private
+ def initialize(reply_code, reply_text, exchange, routing_key)
+ @reply_code = reply_code
+ @reply_text = reply_text
+ @exchange = exchange
+ @routing_key = routing_key
+ @properties = nil
+ @body = ""
+ end
+
+ # Error code
+ # @return [Integer]
+ attr_reader :reply_code
+
+ # Description on why the message was returned
+ # @return [String]
+ attr_reader :reply_text
+
+ # Name of the exchange the message was published to
+ # @return [String]
+ attr_reader :exchange
+
+ # The routing key the message was published with
+ # @return [String]
+ attr_reader :routing_key
+
+ # Message properties
+ # @return [Properties]
+ attr_accessor :properties
+
+ # The message body
+ # @return [String]
+ attr_accessor :body
+ end
end
end