Class: SimpleQS::Message
- Inherits:
-
Object
- Object
- SimpleQS::Message
- Defined in:
- lib/simple_qs/message.rb
Defined Under Namespace
Classes: DoubleSendError, NotReceivedError
Instance Attribute Summary collapse
-
#approximate_first_receive_timestamp ⇒ Object
readonly
Returns the value of attribute approximate_first_receive_timestamp.
-
#approximate_receive_count ⇒ Object
readonly
Returns the value of attribute approximate_receive_count.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#md5_of_body ⇒ Object
readonly
Returns the value of attribute md5_of_body.
-
#message_id ⇒ Object
readonly
Returns the value of attribute message_id.
-
#queue ⇒ Object
Returns the value of attribute queue.
-
#receipt_handle ⇒ Object
readonly
Returns the value of attribute receipt_handle.
-
#sender_id ⇒ Object
readonly
Returns the value of attribute sender_id.
-
#sent_timestamp ⇒ Object
readonly
Returns the value of attribute sent_timestamp.
Class Method Summary collapse
- .receive(queue, attributes = nil, max_number_of_messages = nil, visibility_timeout = nil) ⇒ Object
- .send(queue, message_body) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #change_visibility(visibility_timeout) ⇒ Object
- #delete ⇒ Object (also: #destroy)
- #dup ⇒ Object
-
#initialize(queue, params = nil) ⇒ Message
constructor
A new instance of Message.
- #resend ⇒ Object
- #send ⇒ Object
Constructor Details
#initialize(queue, params = nil) ⇒ Message
Returns a new instance of Message.
11 12 13 14 15 16 17 |
# File 'lib/simple_qs/message.rb', line 11 def initialize(queue, params = nil) @queue = queue @body = params if params.class == String _from_responce(params) if params.class == SimpleQS::Responce _from_hash(params) if params.class == Hash end |
Instance Attribute Details
#approximate_first_receive_timestamp ⇒ Object (readonly)
Returns the value of attribute approximate_first_receive_timestamp.
9 10 11 |
# File 'lib/simple_qs/message.rb', line 9 def @approximate_first_receive_timestamp end |
#approximate_receive_count ⇒ Object (readonly)
Returns the value of attribute approximate_receive_count.
9 10 11 |
# File 'lib/simple_qs/message.rb', line 9 def approximate_receive_count @approximate_receive_count end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
8 9 10 |
# File 'lib/simple_qs/message.rb', line 8 def body @body end |
#md5_of_body ⇒ Object (readonly)
Returns the value of attribute md5_of_body.
8 9 10 |
# File 'lib/simple_qs/message.rb', line 8 def md5_of_body @md5_of_body end |
#message_id ⇒ Object (readonly)
Returns the value of attribute message_id.
8 9 10 |
# File 'lib/simple_qs/message.rb', line 8 def @message_id end |
#queue ⇒ Object
Returns the value of attribute queue.
7 8 9 |
# File 'lib/simple_qs/message.rb', line 7 def queue @queue end |
#receipt_handle ⇒ Object (readonly)
Returns the value of attribute receipt_handle.
8 9 10 |
# File 'lib/simple_qs/message.rb', line 8 def receipt_handle @receipt_handle end |
#sender_id ⇒ Object (readonly)
Returns the value of attribute sender_id.
9 10 11 |
# File 'lib/simple_qs/message.rb', line 9 def sender_id @sender_id end |
#sent_timestamp ⇒ Object (readonly)
Returns the value of attribute sent_timestamp.
9 10 11 |
# File 'lib/simple_qs/message.rb', line 9 def @sent_timestamp end |
Class Method Details
.receive(queue, attributes = nil, max_number_of_messages = nil, visibility_timeout = nil) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/simple_qs/message.rb', line 80 def receive(queue, attributes = nil, = nil, visibility_timeout = nil) SimpleQS::Queue.check_visibility_timeout(visibility_timeout) if visibility_timeout if && !(1..10).include?() raise ArgumentError, "Maximum number of messages should be in 1..10 range" end params = { 'Action' => 'ReceiveMessage' } if attributes attributes = [attributes] unless attributes.class == Array attributes.uniq! unless (attributes - [:All, :SenderId, :SentTimestamp, :ApproximateReceiveCount, :ApproximateFirstReceiveTimestamp]).empty? raise ArgumentError,\ "Allowed attributes: :All, :SenderId, :SentTimestamp, :ApproximateReceiveCount, :ApproximateFirstReceiveTimestamp" end attributes.each_index do |i| params["AttributeName.#{i + 1}"] = attributes[i] end end params['MaxNumberOfMessages'] = if params['VisibilityTimeout'] = visibility_timeout if visibility_timeout request = queue.build_request(:get, params) responce = request.perform if responce.respond_to?(:message) = (responce..class == Array ? responce. : [responce.]) .map {|| new(queue, )} else [] end end |
.send(queue, message_body) ⇒ Object
76 77 78 |
# File 'lib/simple_qs/message.rb', line 76 def send(queue, ) new(queue, ).send end |
Instance Method Details
#==(other) ⇒ Object
71 72 73 |
# File 'lib/simple_qs/message.rb', line 71 def ==(other) == other. && receipt_handle == other.receipt_handle end |
#change_visibility(visibility_timeout) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/simple_qs/message.rb', line 51 def change_visibility(visibility_timeout) SimpleQS::Queue.check_visibility_timeout(visibility_timeout) raise NotReceivedError, "Cann't change visibility timeout for message that was not received" unless receipt_handle params = { 'Action' => 'ChangeMessageVisibility', 'ReceiptHandle' => receipt_handle, 'VisibilityTimeout' => visibility_timeout } request = queue.build_request(:get, params) responce = request.perform raise responce.to_error unless responce.successful? end |
#delete ⇒ Object Also known as: destroy
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/simple_qs/message.rb', line 39 def delete raise NotReceivedError, "Cann't delete message that was not received" unless receipt_handle params = { 'Action' => 'DeleteMessage', 'ReceiptHandle' => receipt_handle } request = queue.build_request(:get, params) responce = request.perform raise responce.to_error unless responce.successful? end |
#dup ⇒ Object
67 68 69 |
# File 'lib/simple_qs/message.rb', line 67 def dup self.class.new(queue, body) end |
#resend ⇒ Object
35 36 37 |
# File 'lib/simple_qs/message.rb', line 35 def resend dup.send end |
#send ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/simple_qs/message.rb', line 19 def send raise DoubleSendError, "Cann't send already sent message. Use resend() method." if raise DoubleSendError, "Cann't send received message. Use resend() method." if receipt_handle params = { 'Action' => 'SendMessage', 'MessageBody' => body } request = queue.build_request(:post, params) responce = request.perform raise responce.to_error unless responce.successful? _from_responce(responce) self end |