azure 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/Gemfile.lock +36 -0
- data/README.md +3 -0
- data/Rakefile +81 -0
- data/azure.gemspec +20 -9
- data/lib/azure.rb +4 -0
- data/lib/azure/atom.rb +170 -0
- data/lib/azure/auth.rb +29 -0
- data/lib/azure/blobs.rb +620 -0
- data/lib/azure/blobs/blob.rb +360 -0
- data/lib/azure/blobs/container.rb +209 -0
- data/lib/azure/blobs/service.rb +396 -0
- data/lib/azure/blobs/shared_access_signature.rb +84 -0
- data/lib/azure/blobs/uri.rb +60 -0
- data/lib/azure/configuration.rb +121 -0
- data/lib/azure/core/auth/shared_key.rb +95 -0
- data/lib/azure/core/auth/shared_key_lite.rb +34 -0
- data/lib/azure/core/collection.rb +118 -0
- data/lib/azure/core/service.rb +43 -0
- data/lib/azure/core/signer.rb +32 -0
- data/lib/azure/core/utils/interval.rb +97 -0
- data/lib/azure/core/utils/queryable.rb +74 -0
- data/lib/azure/core/utils/storage_service_properties.rb +83 -0
- data/lib/azure/core/utils/string.rb +59 -0
- data/lib/azure/error.rb +72 -0
- data/lib/azure/queues.rb +272 -0
- data/lib/azure/queues/message.rb +174 -0
- data/lib/azure/queues/queue.rb +187 -0
- data/lib/azure/queues/service.rb +263 -0
- data/lib/azure/queues/service_properties.rb +152 -0
- data/lib/azure/queues/uri.rb +78 -0
- data/lib/azure/request.rb +102 -0
- data/lib/azure/response.rb +93 -0
- data/lib/azure/service_bus.rb +4 -0
- data/lib/azure/service_bus/auth/authorizer.rb +22 -0
- data/lib/azure/service_bus/auth/uri.rb +52 -0
- data/lib/azure/service_bus/auth/wrap.rb +37 -0
- data/lib/azure/service_bus/auth/wrap_service.rb +76 -0
- data/lib/azure/service_bus/auth/wrap_token.rb +45 -0
- data/lib/azure/service_bus/auth/wrap_token_manager.rb +46 -0
- data/lib/azure/service_bus/brokered_message.rb +139 -0
- data/lib/azure/service_bus/brokered_message_serializer.rb +113 -0
- data/lib/azure/service_bus/queues.rb +194 -0
- data/lib/azure/service_bus/queues/queue.rb +100 -0
- data/lib/azure/service_bus/queues/queue_serializer.rb +51 -0
- data/lib/azure/service_bus/queues/service.rb +154 -0
- data/lib/azure/service_bus/queues/uri.rb +80 -0
- data/lib/azure/service_bus/rules.rb +110 -0
- data/lib/azure/service_bus/rules/rule.rb +97 -0
- data/lib/azure/service_bus/rules/service.rb +122 -0
- data/lib/azure/service_bus/rules/uri.rb +39 -0
- data/lib/azure/service_bus/service_bus_service.rb +22 -0
- data/lib/azure/service_bus/subscriptions.rb +170 -0
- data/lib/azure/service_bus/subscriptions/service.rb +133 -0
- data/lib/azure/service_bus/subscriptions/subscription.rb +164 -0
- data/lib/azure/service_bus/subscriptions/subscription_serializer.rb +74 -0
- data/lib/azure/service_bus/subscriptions/uri.rb +71 -0
- data/lib/azure/service_bus/topics.rb +120 -0
- data/lib/azure/service_bus/topics/service.rb +98 -0
- data/lib/azure/service_bus/topics/topic.rb +122 -0
- data/lib/azure/service_bus/topics/topic_serializer.rb +44 -0
- data/lib/azure/service_bus/topics/uri.rb +58 -0
- data/lib/azure/service_runtime/client/goal_state_pipe_monitor.rb +21 -0
- data/lib/azure/service_runtime/client/goal_state_protocol.rb +18 -0
- data/lib/azure/service_runtime/client/runtime_client.rb +135 -0
- data/lib/azure/service_runtime/deployment.rb +24 -0
- data/lib/azure/service_runtime/local_resource.rb +15 -0
- data/lib/azure/service_runtime/role.rb +17 -0
- data/lib/azure/service_runtime/role_environment.rb +206 -0
- data/lib/azure/service_runtime/role_environment_change.rb +32 -0
- data/lib/azure/service_runtime/role_instance.rb +35 -0
- data/lib/azure/service_runtime/role_instance_endpoint.rb +14 -0
- data/lib/azure/tables.rb +215 -0
- data/lib/azure/tables/auth/shared_key.rb +71 -0
- data/lib/azure/tables/auth/shared_key_lite.rb +30 -0
- data/lib/azure/tables/entities_collection.rb +66 -0
- data/lib/azure/tables/entity.rb +127 -0
- data/lib/azure/tables/service.rb +211 -0
- data/lib/azure/tables/table.rb +129 -0
- data/lib/azure/tables/tables_collection.rb +62 -0
- data/lib/azure/tables/types.rb +65 -0
- data/lib/azure/tables/uri.rb +62 -0
- data/test/fixtures/32px-fulls-black.jpg +0 -0
- data/test/fixtures/all_containers.xml +20 -0
- data/test/fixtures/all_tables.xml +22 -0
- data/test/fixtures/create_table_response_entry.xml +15 -0
- data/test/fixtures/error.xml +5 -0
- data/test/fixtures/insert_entity_response_entry.xml +25 -0
- data/test/fixtures/messages.xml +12 -0
- data/test/fixtures/query_entities_empty_response.xml +7 -0
- data/test/fixtures/query_entities_response.xml +45 -0
- data/test/fixtures/queue_service_properties.xml +22 -0
- data/test/fixtures/queue_service_properties_original.xml +19 -0
- data/test/fixtures/queues.xml +16 -0
- data/test/fixtures/sb_default_create_queue_response.xml +23 -0
- data/test/fixtures/sb_default_create_topic_response.xml +18 -0
- data/test/fixtures/sb_get_access_token_response.txt +1 -0
- data/test/fixtures/sb_queues_runtime_peek_message_response_headers.txt +9 -0
- data/test/integration/blobs/auth_test.rb +19 -0
- data/test/integration/blobs/blob_test.rb +61 -0
- data/test/integration/blobs/clear_page_range_test.rb +19 -0
- data/test/integration/blobs/copy_test.rb +33 -0
- data/test/integration/blobs/create_blobs_test.rb +51 -0
- data/test/integration/blobs/create_container_test.rb +13 -0
- data/test/integration/blobs/create_snapshot_test.rb +17 -0
- data/test/integration/blobs/delete_blob_snapshots_test.rb +19 -0
- data/test/integration/blobs/delete_blobs_test.rb +25 -0
- data/test/integration/blobs/delete_container_test.rb +24 -0
- data/test/integration/blobs/delete_snapshot_test.rb +17 -0
- data/test/integration/blobs/get_blob_snapshot_test.rb +18 -0
- data/test/integration/blobs/get_blobs_test.rb +31 -0
- data/test/integration/blobs/get_page_range_test.rb +19 -0
- data/test/integration/blobs/list_blobs_test.rb +39 -0
- data/test/integration/blobs/list_containers_test.rb +28 -0
- data/test/integration/blobs/manage_blob_leases_test.rb +45 -0
- data/test/integration/blobs/manage_blob_metadata_test.rb +51 -0
- data/test/integration/blobs/manage_blob_properties_test.rb +25 -0
- data/test/integration/blobs/manage_blob_service_properties_test.rb +38 -0
- data/test/integration/blobs/manage_container_metadata_test.rb +46 -0
- data/test/integration/blobs/manage_container_permissions_test.rb +17 -0
- data/test/integration/blobs/update_page_range_test.rb +20 -0
- data/test/integration/queues/clear_messages_test.rb +22 -0
- data/test/integration/queues/create_queue_test.rb +13 -0
- data/test/integration/queues/delete_message_test.rb +42 -0
- data/test/integration/queues/delete_queue_test.rb +24 -0
- data/test/integration/queues/get_messages_test.rb +39 -0
- data/test/integration/queues/list_queues_test.rb +43 -0
- data/test/integration/queues/manage_queue_metadata_test.rb +45 -0
- data/test/integration/queues/manage_queue_service_properties_test.rb +27 -0
- data/test/integration/queues/peek_messages_test.rb +55 -0
- data/test/integration/queues/put_message_test.rb +31 -0
- data/test/integration/queues/update_message_test.rb +46 -0
- data/test/integration/service_bus/auth_test.rb +18 -0
- data/test/integration/service_bus/queues/create_queue_test.rb +25 -0
- data/test/integration/service_bus/queues/delete_message_from_queue_test.rb +29 -0
- data/test/integration/service_bus/queues/delete_queue_test.rb +25 -0
- data/test/integration/service_bus/queues/get_queue_test.rb +23 -0
- data/test/integration/service_bus/queues/list_queues_test.rb +39 -0
- data/test/integration/service_bus/queues/peek_message_from_queue_test.rb +34 -0
- data/test/integration/service_bus/queues/read_and_delete_message_from_queue_test.rb +31 -0
- data/test/integration/service_bus/queues/send_message_to_queue_test.rb +22 -0
- data/test/integration/service_bus/queues/unlock_message_from_queue_test.rb +36 -0
- data/test/integration/service_bus/rules/create_rule_test.rb +19 -0
- data/test/integration/service_bus/rules/delete_rule_test.rb +17 -0
- data/test/integration/service_bus/rules/get_rule_test.rb +21 -0
- data/test/integration/service_bus/rules/list_rules_test.rb +24 -0
- data/test/integration/service_bus/rules/rule_test.rb +16 -0
- data/test/integration/service_bus/subscriptions/create_subscription_test.rb +25 -0
- data/test/integration/service_bus/subscriptions/delete_message_from_subscription_test.rb +31 -0
- data/test/integration/service_bus/subscriptions/delete_subscription_test.rb +30 -0
- data/test/integration/service_bus/subscriptions/fetch_subscription_test.rb +28 -0
- data/test/integration/service_bus/subscriptions/list_subscriptions_test.rb +23 -0
- data/test/integration/service_bus/subscriptions/peek_lock_message_from_subscription_test.rb +42 -0
- data/test/integration/service_bus/subscriptions/read_delete_message_from_subscription_test.rb +36 -0
- data/test/integration/service_bus/subscriptions/subscription_test.rb +31 -0
- data/test/integration/service_bus/subscriptions/unlock_message_from_subscription_test.rb +43 -0
- data/test/integration/service_bus/topics/create_topic_test.rb +25 -0
- data/test/integration/service_bus/topics/delete_topic_test.rb +25 -0
- data/test/integration/service_bus/topics/get_topic_test.rb +23 -0
- data/test/integration/service_bus/topics/list_topics_test.rb +39 -0
- data/test/integration/service_bus/topics/send_message_to_topic_test.rb +23 -0
- data/test/integration/tables/auth_test.rb +29 -0
- data/test/integration/tables/creating_tables_test.rb +16 -0
- data/test/integration/tables/delete_entity_test.rb +39 -0
- data/test/integration/tables/deleting_table_test.rb +22 -0
- data/test/integration/tables/insert_entity_test.rb +23 -0
- data/test/integration/tables/merge_entity_test.rb +28 -0
- data/test/integration/tables/query_entities_test.rb +131 -0
- data/test/integration/tables/query_tables_test.rb +63 -0
- data/test/integration/tables/update_entity_test.rb +54 -0
- data/test/integration/test_helper.rb +14 -0
- data/test/support/blobs.rb +12 -0
- data/test/support/env.rb +5 -0
- data/test/support/fixtures.rb +22 -0
- data/test/support/stubs.rb +28 -0
- data/test/support/table_names.rb +44 -0
- data/test/test_helper.rb +10 -0
- data/test/unit/atom_test.rb +58 -0
- data/test/unit/auth_test.rb +24 -0
- data/test/unit/blobs/blob_test.rb +5 -0
- data/test/unit/blobs/container_test.rb +67 -0
- data/test/unit/blobs/service_test.rb +17 -0
- data/test/unit/blobs/shared_access_signature_test.rb +66 -0
- data/test/unit/blobs_test.rb +156 -0
- data/test/unit/core/service_test.rb +57 -0
- data/test/unit/core/utils/interval_test.rb +70 -0
- data/test/unit/core/utils/queryable_test.rb +69 -0
- data/test/unit/core/utils/storage_service_properties_test.rb +66 -0
- data/test/unit/error_test.rb +39 -0
- data/test/unit/queues/message_test.rb +40 -0
- data/test/unit/queues/queue_test.rb +64 -0
- data/test/unit/queues/service_properties.rb +35 -0
- data/test/unit/request_test.rb +38 -0
- data/test/unit/response_test.rb +43 -0
- data/test/unit/service_bus/auth/authorizer_test.rb +27 -0
- data/test/unit/service_bus/auth/wrap_token_test.rb +28 -0
- data/test/unit/service_bus/queues/queue_test.rb +38 -0
- data/test/unit/service_bus/topics/topic_test.rb +33 -0
- data/test/unit/service_runtime/data/goalstate.xml +9 -0
- data/test/unit/service_runtime/data/roleenvironmentdata.xml +29 -0
- data/test/unit/service_runtime/data/runtime.xml +6 -0
- data/test/unit/service_runtime/role_environment_test.rb +144 -0
- data/test/unit/tables/auth/shared_key_lite_test.rb +39 -0
- data/test/unit/tables/auth/shared_key_test.rb +45 -0
- data/test/unit/tables/entities_collection_test.rb +39 -0
- data/test/unit/tables/entity_test.rb +72 -0
- data/test/unit/tables/table_test.rb +57 -0
- data/test/unit/tables_test.rb +302 -0
- data/test/unit/types_test.rb +67 -0
- metadata +310 -47
- data/LICENSE +0 -0
- data/README +0 -0
@@ -0,0 +1,174 @@
|
|
1
|
+
require "azure/queues"
|
2
|
+
require "azure/queues/uri"
|
3
|
+
require "azure/error"
|
4
|
+
require "uri"
|
5
|
+
require "time"
|
6
|
+
|
7
|
+
module Azure
|
8
|
+
module Queues
|
9
|
+
# Public: Representation of a Message in a message queue.
|
10
|
+
class Message
|
11
|
+
include Azure::ErrorHandler
|
12
|
+
|
13
|
+
# The message queue for this message
|
14
|
+
#
|
15
|
+
# Returns a Azure::Queues::Queue object
|
16
|
+
attr_accessor :queue
|
17
|
+
|
18
|
+
# MessageId
|
19
|
+
# GUID value that identifies the message in the queue
|
20
|
+
#
|
21
|
+
# returns a String
|
22
|
+
attr_accessor :id
|
23
|
+
|
24
|
+
# InsertionTime
|
25
|
+
# UTC value formatted as described in RFC 1123
|
26
|
+
#
|
27
|
+
# Returns a String
|
28
|
+
attr_accessor :insertion_time
|
29
|
+
|
30
|
+
# ExpirationTime
|
31
|
+
# UTC value formatted as described in RFC 1123
|
32
|
+
#
|
33
|
+
# Returns a String
|
34
|
+
attr_accessor :expiration_time
|
35
|
+
|
36
|
+
# TimeNextVisible
|
37
|
+
# UTC value formatted as described in RFC 1123
|
38
|
+
#
|
39
|
+
# Returns a String
|
40
|
+
attr_accessor :time_next_visible
|
41
|
+
|
42
|
+
# PopReceipt
|
43
|
+
#
|
44
|
+
# Returns a String
|
45
|
+
attr_accessor :pop_receipt
|
46
|
+
|
47
|
+
# DequeueCount
|
48
|
+
# Has a value of 1 the first time the message is dequeued. This value is incremented each time the message is subsequently dequeued.
|
49
|
+
#
|
50
|
+
# Returns an Integer
|
51
|
+
attr_accessor :dequeue_count
|
52
|
+
|
53
|
+
# MessageText
|
54
|
+
#
|
55
|
+
# Returns a String
|
56
|
+
attr_accessor :text
|
57
|
+
|
58
|
+
# Amount of time in seconds the message remains invisible for GET
|
59
|
+
# operations.
|
60
|
+
#
|
61
|
+
# Returns an Integer.
|
62
|
+
attr_accessor :visibility_timeout
|
63
|
+
|
64
|
+
# Amount of seconds until this message expires.
|
65
|
+
#
|
66
|
+
# Returns an Integer.
|
67
|
+
attr_accessor :ttl
|
68
|
+
|
69
|
+
# Public: Instantiate a message from an XML entry.
|
70
|
+
#
|
71
|
+
# entry - An XML::Node element.
|
72
|
+
#
|
73
|
+
# Returns a Message.
|
74
|
+
def self.from_node(node)
|
75
|
+
pop_receipt = (node % "PopReceipt")
|
76
|
+
time_next_visible = (node % "TimeNextVisible")
|
77
|
+
text = (node % "MessageText").text
|
78
|
+
|
79
|
+
new(text) do |m|
|
80
|
+
m.id = (node % "MessageId").text
|
81
|
+
m.insertion_time = Time.parse((node % "InsertionTime").text)
|
82
|
+
m.expiration_time = Time.parse((node % "ExpirationTime").text)
|
83
|
+
m.dequeue_count = (node % "DequeueCount").text.to_i
|
84
|
+
m.pop_receipt = pop_receipt && pop_receipt.text
|
85
|
+
m.time_next_visible = time_next_visible && Time.parse(time_next_visible.text)
|
86
|
+
yield m if block_given?
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Public: Instantiate a message from an error object.
|
91
|
+
#
|
92
|
+
# error - An Azure::Error.
|
93
|
+
#
|
94
|
+
# Returns a Message.
|
95
|
+
def self.from_error(error)
|
96
|
+
message = new(nil)
|
97
|
+
message.error = error
|
98
|
+
message
|
99
|
+
end
|
100
|
+
|
101
|
+
# Public: Attempt to convert an object into a Message. If the object can't
|
102
|
+
# be converted, we return nil.
|
103
|
+
#
|
104
|
+
# object - An object that might be converted into a Message.
|
105
|
+
#
|
106
|
+
# Returns a Message or nil.
|
107
|
+
def self.try_convert(object)
|
108
|
+
if object.respond_to?(:to_message)
|
109
|
+
object.to_message
|
110
|
+
elsif object.respond_to?(:to_str)
|
111
|
+
new(object.to_str)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# Public: Initialize the message.
|
116
|
+
#
|
117
|
+
# text - The message text
|
118
|
+
# service - The Queue service to perform external calls.
|
119
|
+
def initialize(text, service=Azure::Queues)
|
120
|
+
@text = text
|
121
|
+
@visibility_timeout = 0
|
122
|
+
@ttl = 7 * 24 * 3600 # one week
|
123
|
+
@service = service
|
124
|
+
yield self if block_given?
|
125
|
+
end
|
126
|
+
|
127
|
+
# Public: Compare two messages to see if they are the same.
|
128
|
+
#
|
129
|
+
# other - A Message.
|
130
|
+
#
|
131
|
+
# Returns true|false.
|
132
|
+
def ==(other)
|
133
|
+
id == other.id
|
134
|
+
end
|
135
|
+
|
136
|
+
# Public: Deletes this message from the message queue.
|
137
|
+
#
|
138
|
+
# Returns true|false to indicate success.
|
139
|
+
def delete
|
140
|
+
@service.delete_message(self)
|
141
|
+
end
|
142
|
+
|
143
|
+
# Public: Updates this message with a new visibility timeout and new text
|
144
|
+
# if modified.
|
145
|
+
#
|
146
|
+
# Returns true|false to indicate success.
|
147
|
+
def update!
|
148
|
+
@service.update_message(self)
|
149
|
+
end
|
150
|
+
|
151
|
+
# Public: Turn this object into an Azure::Queues::Message. This is here
|
152
|
+
# just so we can use Message.try_convert and Message().
|
153
|
+
#
|
154
|
+
# Returns self.
|
155
|
+
def to_message
|
156
|
+
self
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
module ::Kernel
|
161
|
+
# Attempt to convert an object into a Message, or fail if the conversion
|
162
|
+
# can't be done.
|
163
|
+
#
|
164
|
+
# object - An object that might be converted into a message.
|
165
|
+
#
|
166
|
+
# Returns a Message.
|
167
|
+
# Raises ArgumentError if the object can't be converted into a Message.
|
168
|
+
def Message(object)
|
169
|
+
Message.try_convert(object) ||
|
170
|
+
raise(ArgumentError, "invalid value for Message(): #{object.inspect}")
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
require "azure/queues"
|
2
|
+
require "azure/queues/uri"
|
3
|
+
require "azure/error"
|
4
|
+
require "uri"
|
5
|
+
|
6
|
+
module Azure
|
7
|
+
module Queues
|
8
|
+
# Public: Representation of a Queue in the storage system.
|
9
|
+
class Queue
|
10
|
+
include Azure::ErrorHandler
|
11
|
+
|
12
|
+
# Get the Queue's URI.
|
13
|
+
#
|
14
|
+
# Returns a URI.
|
15
|
+
attr :url
|
16
|
+
|
17
|
+
# Get the Queue's name.
|
18
|
+
#
|
19
|
+
# Returns a String.
|
20
|
+
attr :name
|
21
|
+
|
22
|
+
# Get the Queue's metadata.
|
23
|
+
#
|
24
|
+
# Returns a Hash.
|
25
|
+
attr_accessor :metadata
|
26
|
+
|
27
|
+
# Public: Instantiate a queue from an XML entry.
|
28
|
+
#
|
29
|
+
# entry - An XML::Node element.
|
30
|
+
#
|
31
|
+
# Returns a Queue.
|
32
|
+
def self.from_node(node)
|
33
|
+
name = (node % "Name").text
|
34
|
+
url = URI((node % "Url").text)
|
35
|
+
|
36
|
+
metadata = (node / "Metadata *").each_with_object({}) do |n, metadata|
|
37
|
+
metadata[n.name] = n.text
|
38
|
+
end
|
39
|
+
|
40
|
+
new(name, url, metadata)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Public: Instantiate a queue from an error object.
|
44
|
+
#
|
45
|
+
# error - An Azure::Error.
|
46
|
+
#
|
47
|
+
# Returns a Queue.
|
48
|
+
def self.from_error(error)
|
49
|
+
queue = new(nil)
|
50
|
+
queue.error = error
|
51
|
+
queue
|
52
|
+
end
|
53
|
+
|
54
|
+
# Public: Initialize the queue.
|
55
|
+
#
|
56
|
+
# name - A String with the name of the queue.
|
57
|
+
# url - The URI of the queue in the service.
|
58
|
+
# metadata - A Hash with metadata key-value pairs.
|
59
|
+
# service - The Queue service to perform external calls.
|
60
|
+
def initialize(name, url=Azure::Queues::URI.queue(name), metadata = {}, service=Azure::Queues)
|
61
|
+
@name = name
|
62
|
+
@url = url
|
63
|
+
@metadata = metadata
|
64
|
+
@service = service
|
65
|
+
end
|
66
|
+
|
67
|
+
# Public: Add a message into the queue.
|
68
|
+
#
|
69
|
+
# message - An Azure::Queues::Message.
|
70
|
+
#
|
71
|
+
# Returns self.
|
72
|
+
def push(message)
|
73
|
+
message = Message(message)
|
74
|
+
|
75
|
+
@service.put_message(self, message, {
|
76
|
+
visibilitytimeout: message.visibility_timeout,
|
77
|
+
messagettl: message.ttl
|
78
|
+
})
|
79
|
+
|
80
|
+
self
|
81
|
+
end
|
82
|
+
alias_method :<<, :push
|
83
|
+
alias_method :enq, :push
|
84
|
+
|
85
|
+
# Public: Get the latest message from the queue.
|
86
|
+
#
|
87
|
+
# options - A Hash of options (optional):
|
88
|
+
# :visibilitytimeout - Update the message returned to be
|
89
|
+
# invisible for this many seconds
|
90
|
+
# (default: 0).
|
91
|
+
#
|
92
|
+
# Returns the message, or nil if the queue is empty.
|
93
|
+
def pop(options={})
|
94
|
+
get(1, options).first
|
95
|
+
end
|
96
|
+
alias_method :deq, :pop
|
97
|
+
alias_method :shift, :pop
|
98
|
+
|
99
|
+
# Public: Get a list of messages from the queue.
|
100
|
+
#
|
101
|
+
# num - The amount of messages to peek (must be 1 <= num <= 32).
|
102
|
+
# options - A Hash of options (optional):
|
103
|
+
# :visibilitytimeout - Update the messages returned to be
|
104
|
+
# invisible for this many seconds (must be
|
105
|
+
# 1 second <= timeout <= 7 days).
|
106
|
+
# (default: 1 second).
|
107
|
+
#
|
108
|
+
# Returns an Array of Messages.
|
109
|
+
def get(num, options={})
|
110
|
+
options[:numofmessages] = num
|
111
|
+
@service.get_messages(self, options)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Public: Peek the latest message from the queue (without changing its
|
115
|
+
# visibility).
|
116
|
+
#
|
117
|
+
# Returns the message, or nil if the queue is empty.
|
118
|
+
def peek
|
119
|
+
look_at(1).first
|
120
|
+
end
|
121
|
+
|
122
|
+
# Public: Peek a list of messages from the queue (without changing their
|
123
|
+
# visibility).
|
124
|
+
#
|
125
|
+
# num - The amount of messages to peek (must be 1 <= num <= 32).
|
126
|
+
#
|
127
|
+
# Returns an Array of Messages.
|
128
|
+
def look_at(num)
|
129
|
+
@service.peek_messages(self, numofmessages: num)
|
130
|
+
end
|
131
|
+
|
132
|
+
# Public: Remove all messages from the queue.
|
133
|
+
#
|
134
|
+
# Returns true|false to indicate success.
|
135
|
+
def clear
|
136
|
+
@service.clear_messages(self)
|
137
|
+
end
|
138
|
+
|
139
|
+
# Public: Compare two queues to see if they are the same.
|
140
|
+
#
|
141
|
+
# other - A queue.
|
142
|
+
#
|
143
|
+
# Returns true|false.
|
144
|
+
def ==(other)
|
145
|
+
name == other.name
|
146
|
+
end
|
147
|
+
|
148
|
+
# Public: Force a reload of this queue metadata from the server.
|
149
|
+
#
|
150
|
+
# Returns the Hash of metadata.
|
151
|
+
def load_metadata!
|
152
|
+
@service.load_metadata(self)
|
153
|
+
end
|
154
|
+
|
155
|
+
# Public: Put the current queue's metadata into the storage service.
|
156
|
+
#
|
157
|
+
# Returns true|false to indicate success.
|
158
|
+
def save_metadata!
|
159
|
+
@service.save_metadata(self)
|
160
|
+
end
|
161
|
+
|
162
|
+
# Public: Extracts metadata from a hash containing HTTP headers (so
|
163
|
+
# "x-ms-meta-Name" => "Foo" is extracted as "Name" => "Foo"). This
|
164
|
+
# replaces the metadata of this container.
|
165
|
+
#
|
166
|
+
# hash - A hash of String => String with HTTP header values.
|
167
|
+
#
|
168
|
+
# Returns a Hash with the extracted metadata.
|
169
|
+
def extract_metadata(hash)
|
170
|
+
new_metadata = hash.each_with_object({}) do |(k,v), hash|
|
171
|
+
if key = k[/^x-ms-meta-(?<key>.*)?/, :key]
|
172
|
+
hash[key] = v
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
metadata.replace(new_metadata)
|
177
|
+
end
|
178
|
+
|
179
|
+
# Public: Deletes this queue from the storage service.
|
180
|
+
#
|
181
|
+
# Returns true|false to indicate whether the delete was successful or not.
|
182
|
+
def delete
|
183
|
+
@service.delete(self)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -0,0 +1,263 @@
|
|
1
|
+
require "azure/core/service"
|
2
|
+
require "azure/core/auth/shared_key"
|
3
|
+
require "azure/queues/uri"
|
4
|
+
require "nokogiri"
|
5
|
+
|
6
|
+
module Azure
|
7
|
+
module Queues
|
8
|
+
|
9
|
+
class Service < Core::Service
|
10
|
+
def initialize(signer=Azure::Core::Auth::SharedKey.new)
|
11
|
+
super(signer)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module Services
|
16
|
+
|
17
|
+
# Public: gets the properties of a storage account’s Queue Service.
|
18
|
+
class GetServiceProperties < Service
|
19
|
+
|
20
|
+
# Public: Invoke the service.
|
21
|
+
#
|
22
|
+
# options - Options for this query:
|
23
|
+
# :timeout - (optional) timeout for the request in seconds
|
24
|
+
#
|
25
|
+
# Returns a Response.
|
26
|
+
def call(options = {})
|
27
|
+
uri = Queues::URI.service_properties(options)
|
28
|
+
|
29
|
+
super(:get, uri)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Public: sets the properties of a storage account’s Queue Service.
|
34
|
+
class SetServiceProperties < Service
|
35
|
+
|
36
|
+
# Public: Invoke the service.
|
37
|
+
#
|
38
|
+
# properties - an Azure::Queues::ServiceProperties object
|
39
|
+
# options - Options for this query:
|
40
|
+
# :timeout - (optional) timeout for the request in seconds
|
41
|
+
#
|
42
|
+
# Returns a Response.
|
43
|
+
def call(properties, options = {})
|
44
|
+
uri = Queues::URI.service_properties(options)
|
45
|
+
|
46
|
+
body = properties.to_xml
|
47
|
+
|
48
|
+
super(:put, uri, body)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Public: List queues from a storage account
|
53
|
+
class ListQueues < Service
|
54
|
+
# Public: Invoke the service.
|
55
|
+
#
|
56
|
+
# options - A hash of options
|
57
|
+
# :prefix - Filters the results to return only
|
58
|
+
# queues with names that begin with the
|
59
|
+
# specified prefix.
|
60
|
+
# :marker - A string value that identifies the
|
61
|
+
# portion of the list to be returned
|
62
|
+
# with the next list operation.
|
63
|
+
# :maxresults - Specifies the maximum number of queues
|
64
|
+
# to return.
|
65
|
+
#
|
66
|
+
# Returns a Response.
|
67
|
+
def call(options)
|
68
|
+
uri = Queues::URI.collection(options)
|
69
|
+
super(:get, uri)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Public: Add a queue to the storage account.
|
74
|
+
class CreateQueue < Service
|
75
|
+
|
76
|
+
# Public: Invoke the service.
|
77
|
+
#
|
78
|
+
# name - The name of the new container.
|
79
|
+
# metadata - User defined metadata for this queue (default: {}).
|
80
|
+
#
|
81
|
+
# Returns a Response.
|
82
|
+
def call(name, metadata = {})
|
83
|
+
uri = Queues::URI.queue(name)
|
84
|
+
|
85
|
+
super(:put, uri) do |request|
|
86
|
+
metadata.each do |name, value|
|
87
|
+
request.headers["x-ms-meta-#{name}"] = value
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Public: Deletes a queue from the storage account.
|
94
|
+
class DeleteQueue < Service
|
95
|
+
|
96
|
+
# Public: Invoke the service.
|
97
|
+
#
|
98
|
+
# name - The name of the queue.
|
99
|
+
#
|
100
|
+
# Returns a Response.
|
101
|
+
def call(name)
|
102
|
+
uri = Queues::URI.queue(name)
|
103
|
+
super(:delete, uri)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# Public: Get queue metadata
|
108
|
+
class GetMetadata < Service
|
109
|
+
# Public: Invoke the service.
|
110
|
+
#
|
111
|
+
# name - The queue name.
|
112
|
+
#
|
113
|
+
# Returns a Response.
|
114
|
+
def call(name)
|
115
|
+
uri = Queues::URI.queue(name, comp: "metadata")
|
116
|
+
super(:head, uri)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# Public: Set queue metadata.
|
121
|
+
class SetMetadata < Service
|
122
|
+
# Public: Invoke the service.
|
123
|
+
#
|
124
|
+
# name - The queue name.
|
125
|
+
# metadata - User defined metadata for this queue.
|
126
|
+
#
|
127
|
+
# Returns a Response.
|
128
|
+
def call(name, metadata)
|
129
|
+
uri = Queues::URI.queue(name, comp: "metadata")
|
130
|
+
|
131
|
+
super(:put, uri) do |request|
|
132
|
+
metadata.each do |name, value|
|
133
|
+
request.headers["x-ms-meta-#{name}"] = value
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
## Messages
|
140
|
+
|
141
|
+
# Public: Add a message to the message queue
|
142
|
+
class PutMessage < Service
|
143
|
+
# Public: Invoke the service.
|
144
|
+
#
|
145
|
+
# queue_name - The name of the queue.
|
146
|
+
# text - The message's text.
|
147
|
+
# options - A Hash of options for this message (optional):
|
148
|
+
# :visibilitytimeout - Amount of seconds during which the
|
149
|
+
# message will be invisible
|
150
|
+
# (default: 0).
|
151
|
+
# :messagettl - Time in seconds until the message is
|
152
|
+
# unreacable, between 1 second and 7
|
153
|
+
# days (default: 7 days).
|
154
|
+
#
|
155
|
+
# Returns a Response.
|
156
|
+
def call(queue_name, text, options = {})
|
157
|
+
uri = Queues::URI.messages(queue_name, options)
|
158
|
+
|
159
|
+
body = Nokogiri::XML::Builder.new do |xml|
|
160
|
+
xml.QueueMessage {
|
161
|
+
xml.MessageText text
|
162
|
+
}
|
163
|
+
end
|
164
|
+
|
165
|
+
super(:post, uri, body.to_xml)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# Public: Get a list of messages from the front of the message queue.
|
170
|
+
class GetMessages < Service
|
171
|
+
# Public: Invoke the service.
|
172
|
+
#
|
173
|
+
# queue_name - The name of the message queue.
|
174
|
+
# options - A Hash of options for this operation (optional):
|
175
|
+
# :visibilitytimeout - Update the returned messages'
|
176
|
+
# visibilitytimeout to this number (at
|
177
|
+
# least 1, the default).
|
178
|
+
# :numofmessages - A number between 1 and 32 of messages
|
179
|
+
# to return (default: 1).
|
180
|
+
#
|
181
|
+
# Returns a Response.
|
182
|
+
def call(queue_name, options={})
|
183
|
+
uri = Queues::URI.messages(queue_name, options)
|
184
|
+
super(:get, uri)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
# Public: Peek at a list of messages from the front of the message queue.
|
189
|
+
class PeekMessages < Service
|
190
|
+
# Public: Invoke the service.
|
191
|
+
#
|
192
|
+
# queue_name - The name of the message queue.
|
193
|
+
# options - A Hash of options for this operation (optional):
|
194
|
+
# :numofmessages - A number between 1 and 32 of messages
|
195
|
+
# to return (default: 1).
|
196
|
+
#
|
197
|
+
# Returns a Response.
|
198
|
+
def call(queue_name, options={})
|
199
|
+
options.update(peekonly: 'true')
|
200
|
+
uri = Queues::URI.messages(queue_name, options)
|
201
|
+
super(:get, uri)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
# Public: Deletes a message from the message queue.
|
206
|
+
class DeleteMessage < Service
|
207
|
+
# Public: Invoke the service.
|
208
|
+
#
|
209
|
+
# queue_name - The name of the message queue.
|
210
|
+
# message_id - The message id.
|
211
|
+
# pop_receipt - The receipt of a previous pop operation on this message.
|
212
|
+
#
|
213
|
+
# Returns a Response.
|
214
|
+
def call(queue_name, message_id, pop_receipt)
|
215
|
+
uri = Queues::URI.message(
|
216
|
+
queue_name, message_id, popreceipt: pop_receipt
|
217
|
+
)
|
218
|
+
super(:delete, uri)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
# Public: Deletes all messages on the given queue.
|
223
|
+
class ClearMessages < Service
|
224
|
+
# Public: Invoke the service.
|
225
|
+
#
|
226
|
+
# queue_name - The name of the queue.
|
227
|
+
#
|
228
|
+
# Returns a Response.
|
229
|
+
def call(queue_name)
|
230
|
+
uri = Queues::URI.messages(queue_name)
|
231
|
+
super(:delete, uri)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
# Public: Update a message from the message queue.
|
236
|
+
class UpdateMessage < Service
|
237
|
+
# Public: Invoke the service.
|
238
|
+
#
|
239
|
+
# queue_name - The name of the message queue.
|
240
|
+
# message_id - The message's id.
|
241
|
+
# text - The message's new text.
|
242
|
+
# timeout - A New visibilitytimeout for the message.
|
243
|
+
# pop_receipt - The receipt of a previous pop operation on this message.
|
244
|
+
#
|
245
|
+
# Returns a Response.
|
246
|
+
def call(queue_name, message_id, text, timeout, pop_receipt)
|
247
|
+
uri = Queues::URI.message(queue_name, message_id, {
|
248
|
+
popreceipt: pop_receipt, visibilitytimeout: timeout
|
249
|
+
})
|
250
|
+
|
251
|
+
body = Nokogiri::XML::Builder.new do |xml|
|
252
|
+
xml.QueueMessage {
|
253
|
+
xml.MessageText text
|
254
|
+
}
|
255
|
+
end
|
256
|
+
|
257
|
+
super(:put, uri, body.to_xml)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|