azure-storage-queue 1.1.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,755 +1,755 @@
1
- # frozen_string_literal: true
2
-
3
- #-------------------------------------------------------------------------
4
- # # Copyright (c) Microsoft and contributors. All rights reserved.
5
- #
6
- # The MIT License(MIT)
7
-
8
- # Permission is hereby granted, free of charge, to any person obtaining a copy
9
- # of this software and associated documentation files(the "Software"), to deal
10
- # in the Software without restriction, including without limitation the rights
11
- # to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12
- # copies of the Software, and to permit persons to whom the Software is
13
- # furnished to do so, subject to the following conditions :
14
-
15
- # The above copyright notice and this permission notice shall be included in
16
- # all copies or substantial portions of the Software.
17
-
18
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
- # THE SOFTWARE.
25
- #--------------------------------------------------------------------------
26
- module Azure::Storage
27
- include Azure::Storage::Common::Service
28
- StorageService = Azure::Storage::Common::Service::StorageService
29
-
30
- module Queue
31
- class QueueService < StorageService
32
- class << self
33
- # Public: Creates an instance of [Azure::Storage::Queue::QueueService]
34
- #
35
- # ==== Attributes
36
- #
37
- # * +options+ - Hash. Optional parameters.
38
- #
39
- # ==== Options
40
- #
41
- # Accepted key/value pairs in options parameter are:
42
- #
43
- # * +:use_development_storage+ - TrueClass|FalseClass. Whether to use storage emulator.
44
- # * +:development_storage_proxy_uri+ - String. Used with +:use_development_storage+ if emulator is hosted other than localhost.
45
- # * +:storage_account_name+ - String. The name of the storage account.
46
- # * +:storage_access_key+ - Base64 String. The access key of the storage account.
47
- # * +:storage_sas_token+ - String. The signed access signature for the storage account or one of its service.
48
- # * +:storage_queue_host+ - String. Specified Queue service endpoint or hostname
49
- # * +:storage_dns_suffix+ - String. The suffix of a regional Storage Service, to
50
- # * +:default_endpoints_protocol+ - String. http or https
51
- # * +:use_path_style_uri+ - String. Whether use path style URI for specified endpoints
52
- # * +:ca_file+ - String. File path of the CA file if having issue with SSL
53
- # * +:ssl_version+ - Symbol. The ssl version to be used, sample: :TLSv1_1, :TLSv1_2, for the details, see https://github.com/ruby/openssl/blob/master/lib/openssl/ssl.rb
54
- # * +:ssl_min_version+ - Symbol. The min ssl version supported, only supported in Ruby 2.5+
55
- # * +:ssl_max_version+ - Symbol. The max ssl version supported, only supported in Ruby 2.5+
56
- # * +:user_agent_prefix+ - String. The user agent prefix that can identify the application calls the library
57
- #
58
- # The valid set of options include:
59
- # * Storage Emulator: +:use_development_storage+ required, +:development_storage_proxy_uri+ optionally
60
- # * Storage account name and key: +:storage_account_name+ and +:storage_access_key+ required, set +:storage_dns_suffix+ necessarily
61
- # * Storage account name and SAS token: +:storage_account_name+ and +:storage_sas_token+ required, set +:storage_dns_suffix+ necessarily
62
- # * Specified hosts and SAS token: At least one of the service host and SAS token. It's up to user to ensure the SAS token is suitable for the serivce
63
- # * Anonymous Queue: only +:storage_queue_host+, if it is to only access queues within a container
64
- #
65
- # Additional notes:
66
- # * Specified hosts can be set when use account name with access key or sas token
67
- # * +:default_endpoints_protocol+ can be set if the scheme is not specified in hosts
68
- # * Storage emulator always use path style URI
69
- # * +:ca_file+ is independent.
70
- #
71
- # When empty options are given, it will try to read settings from Environment Variables. Refer to [Azure::Storage::Common::ClientOptions.env_vars_mapping] for the mapping relationship
72
- #
73
- # @return [Azure::Storage::Queue::QueueService]
74
- def create(options = {}, &block)
75
- service_options = { client: Azure::Storage::Common::Client::create(options, &block), api_version: Azure::Storage::Queue::Default::STG_VERSION }
76
- service_options[:user_agent_prefix] = options[:user_agent_prefix] if options[:user_agent_prefix]
77
- Azure::Storage::Queue::QueueService.new(service_options, &block)
78
- end
79
-
80
- # Public: Creates an instance of [Azure::Storage::Queue::QueueService] with Storage Emulator
81
- #
82
- # ==== Attributes
83
- #
84
- # * +proxy_uri+ - String. Used with +:use_development_storage+ if emulator is hosted other than localhost.
85
- #
86
- # @return [Azure::Storage::Queue::QueueService]
87
- def create_development(proxy_uri = nil, &block)
88
- service_options = { client: Azure::Storage::Common::Client::create_development(proxy_uri, &block), api_version: Azure::Storage::Queue::Default::STG_VERSION }
89
- Azure::Storage::Queue::QueueService.new(service_options, &block)
90
- end
91
-
92
- # Public: Creates an instance of [Azure::Storage::Queue::QueueService] from Environment Variables
93
- #
94
- # @return [Azure::Storage::Queue::QueueService]
95
- def create_from_env(&block)
96
- service_options = { client: Azure::Storage::Common::Client::create_from_env(&block), api_version: Azure::Storage::Queue::Default::STG_VERSION }
97
- Azure::Storage::Queue::QueueService.new(service_options, &block)
98
- end
99
-
100
- # Public: Creates an instance of [Azure::Storage::Queue::QueueService] from Environment Variables
101
- #
102
- # ==== Attributes
103
- #
104
- # * +connection_string+ - String. Please refer to https://azure.microsoft.com/en-us/documentation/articles/storage-configure-connection-string/.
105
- #
106
- # @return [Azure::Storage::Queue::QueueService]
107
- def create_from_connection_string(connection_string, &block)
108
- service_options = { client: Azure::Storage::Common::Client::create_from_connection_string(connection_string, &block), api_version: Azure::Storage::Queue::Default::STG_VERSION }
109
- Azure::Storage::Queue::QueueService.new(service_options, &block)
110
- end
111
- end
112
-
113
- # Public: Initializes an instance of [Azure::Storage::Queue::QueueService]
114
- #
115
- # ==== Attributes
116
- #
117
- # * +options+ - Hash. Optional parameters.
118
- #
119
- # ==== Options
120
- #
121
- # Accepted key/value pairs in options parameter are:
122
- #
123
- # * +:use_development_storage+ - TrueClass|FalseClass. Whether to use storage emulator.
124
- # * +:development_storage_proxy_uri+ - String. Used with +:use_development_storage+ if emulator is hosted other than localhost.
125
- # * +:storage_connection_string+ - String. The storage connection string.
126
- # * +:storage_account_name+ - String. The name of the storage account.
127
- # * +:storage_access_key+ - Base64 String. The access key of the storage account.
128
- # * +:storage_sas_token+ - String. The signed access signature for the storage account or one of its service.
129
- # * +:storage_queue_host+ - String. Specified Queue serivce endpoint or hostname
130
- # * +:storage_dns_suffix+ - String. The suffix of a regional Storage Serivce, to
131
- # * +:default_endpoints_protocol+ - String. http or https
132
- # * +:use_path_style_uri+ - String. Whether use path style URI for specified endpoints
133
- # * +:ca_file+ - String. File path of the CA file if having issue with SSL
134
- # * +:ssl_version+ - Symbol. The ssl version to be used, sample: :TLSv1_1, :TLSv1_2, for the details, see https://github.com/ruby/openssl/blob/master/lib/openssl/ssl.rb
135
- # * +:ssl_min_version+ - Symbol. The min ssl version supported, only supported in Ruby 2.5+
136
- # * +:ssl_max_version+ - Symbol. The max ssl version supported, only supported in Ruby 2.5+
137
- # * +:user_agent_prefix+ - String. The user agent prefix that can identify the application calls the library
138
- # * +:client+ - Azure::Storage::Common::Client. The common client used to initalize the service.
139
- #
140
- # The valid set of options include:
141
- # * Storage Emulator: +:use_development_storage+ required, +:development_storage_proxy_uri+ optionally
142
- # * Storage account name and key: +:storage_account_name+ and +:storage_access_key+ required, set +:storage_dns_suffix+ necessarily
143
- # * Storage account name and SAS token: +:storage_account_name+ and +:storage_sas_token+ required, set +:storage_dns_suffix+ necessarily
144
- # * Specified hosts and SAS token: At least one of the service host and SAS token. It's up to user to ensure the SAS token is suitable for the serivce
145
- # * Azure::Storage::Common::Client: The common client used to initalize the service. This client can be initalized and used repeatedly.
146
- # * Anonymous Queue: only +:storage_queue_host+, if it is to only access queues within a container
147
- #
148
- # Additional notes:
149
- # * Specified hosts can be set when use account name with access key or sas token
150
- # * +:default_endpoints_protocol+ can be set if the scheme is not specified in hosts
151
- # * Storage emulator always use path style URI
152
- # * +:ca_file+ is independent.
153
- #
154
- # When empty options are given, it will try to read settings from Environment Variables. Refer to [Azure::Storage::Common::ClientOptions.env_vars_mapping] for the mapping relationship
155
- def initialize(options = {}, &block)
156
- service_options = options.clone
157
- client_config = service_options[:client] ||= Azure::Storage::Common::Client::create(service_options, &block)
158
- @user_agent_prefix = service_options[:user_agent_prefix] if service_options[:user_agent_prefix]
159
- @api_version = service_options[:api_version] || Azure::Storage::Queue::Default::STG_VERSION
160
- signer = service_options[:signer] || client_config.signer || Azure::Storage::Common::Core::Auth::SharedKey.new(client_config.storage_account_name, client_config.storage_access_key)
161
- signer.api_ver = @api_version if signer.is_a? Azure::Storage::Common::Core::Auth::SharedAccessSignatureSigner
162
- super(signer, client_config.storage_account_name, service_options, &block)
163
- @storage_service_host[:primary] = client.storage_queue_host
164
- @storage_service_host[:secondary] = client.storage_queue_host true
165
- end
166
-
167
- # Public: Get a list of Queues from the server
168
- #
169
- # ==== Attributes
170
- #
171
- # * +options+ - Hash. Optional parameters.
172
- #
173
- # ==== Options
174
- #
175
- # Accepted key/value pairs in options parameter are:
176
- # * +:prefix+ - String. Filters the results to return only containers
177
- # whose name begins with the specified prefix. (optional)
178
- # * +:marker+ - String. An identifier the specifies the portion of the
179
- # list to be returned. This value comes from the property
180
- # Azure::Service::EnumerationResults.continuation_token when there
181
- # are more containers available than were returned. The
182
- # marker value may then be used here to request the next set
183
- # of list items. (optional)
184
- # * +:max_results+ - Integer. Specifies the maximum number of containers to return.
185
- # If max_results is not specified, or is a value greater than
186
- # 5,000, the server will return up to 5,000 items. If it is set
187
- # to a value less than or equal to zero, the server will return
188
- # status code 400 (Bad Request). (optional)
189
- # * +:metadata+ - Boolean. Specifies whether or not to return the container metadata.
190
- # (optional, Default=false)
191
- # * +:timeout+ - Integer. A timeout in seconds.
192
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
193
- # in the analytics logs when storage analytics logging is enabled.
194
- # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
195
- # which location the request should be sent to.
196
- #
197
- # NOTE: Metadata requested with the :metadata parameter must have been stored in
198
- # accordance with the naming restrictions imposed by the 2009-09-19 version of the queue
199
- # service. Beginning with that version, all metadata names must adhere to the naming
200
- # conventions for C# identifiers.
201
- #
202
- # See http://msdn.microsoft.com/en-us/library/azure/dd179466
203
- #
204
- # Any metadata with invalid names which were previously stored, will be returned with the
205
- # key "x-ms-invalid-name" in the metadata hash. This may contain multiple values and be an
206
- # Array (vs a String if it only contains a single value).
207
- #
208
- # Returns an Azure::Storage::Common::EnumerationResults
209
- def list_queues(options = {})
210
- query = {}
211
- query["prefix"] = options[:prefix] if options[:prefix]
212
- query["marker"] = options[:marker] if options[:marker]
213
- query["maxresults"] = options[:max_results].to_s if options[:max_results]
214
- query["include"] = "metadata" if options[:metadata] == true
215
- query["timeout"] = options[:timeout].to_s if options[:timeout]
216
-
217
- options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
218
- uri = collection_uri(query, options)
219
- response = call(:get, uri, nil, {}, options)
220
-
221
- Serialization.queue_enumeration_results_from_xml(response.body)
222
- end
223
-
224
- # Public: Clears all messages from the queue.
225
- #
226
- # If a queue contains a large number of messages, Clear Messages may time out
227
- # before all messages have been deleted. In this case the Queue service will
228
- # return status code 500 (Internal Server Error), with the additional error
229
- # code OperationTimedOut. If the operation times out, the client should
230
- # continue to retry Clear Messages until it succeeds, to ensure that all
231
- # messages have been deleted.
232
- #
233
- # ==== Attributes
234
- #
235
- # * +queue_name+ - String. The name of the queue.
236
- # * +options+ - Hash. Optional parameters.
237
- #
238
- # ==== Options
239
- #
240
- # Accepted key/value pairs in options parameter are:
241
- # * +:timeout+ - Integer. A timeout in seconds.
242
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
243
- # in the analytics logs when storage analytics logging is enabled.
244
- #
245
- # See http://msdn.microsoft.com/en-us/library/azure/dd179454
246
- #
247
- # Returns nil on success
248
- def clear_messages(queue_name, options = {})
249
- query = {}
250
- query["timeout"] = options[:timeout].to_s if options[:timeout]
251
- uri = messages_uri(queue_name, query)
252
- call(:delete, uri, nil, {}, options)
253
- nil
254
- end
255
-
256
- # Public: Creates a new queue under the storage account.
257
- #
258
- # ==== Attributes
259
- #
260
- # * +queue_name+ - String. The queue name.
261
- # * +options+ - Hash. Optional parameters.
262
- #
263
- # ==== Options
264
- #
265
- # Accepted key/value pairs in options parameter are:
266
- # * +:metadata+ - Hash. A hash of user defined metadata.
267
- # * +:timeout+ - Integer. A timeout in seconds.
268
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
269
- # in the analytics logs when storage analytics logging is enabled.
270
- #
271
- # See http://msdn.microsoft.com/en-us/library/azure/dd179342
272
- #
273
- # Returns nil on success
274
- def create_queue(queue_name, options = {})
275
- query = {}
276
- query["timeout"] = options[:timeout].to_s if options[:timeout]
277
-
278
- uri = queue_uri(queue_name, query)
279
-
280
- headers = {}
281
- StorageService.add_metadata_to_headers(options[:metadata] || {}, headers) if options[:metadata]
282
-
283
- call(:put, uri, nil, headers, options)
284
- nil
285
- end
286
-
287
- # Public: Deletes a queue.
288
- #
289
- # ==== Attributes
290
- #
291
- # * +queue_name+ - String. The queue name.
292
- # * +options+ - Hash. Optional parameters.
293
- #
294
- # ==== Options
295
- #
296
- # Accepted key/value pairs in options parameter are:
297
- # * +:timeout+ - Integer. A timeout in seconds.
298
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
299
- # in the analytics logs when storage analytics logging is enabled.
300
- #
301
- # See http://msdn.microsoft.com/en-us/library/azure/dd179436
302
- #
303
- # Returns nil on success
304
- def delete_queue(queue_name, options = {})
305
- query = {}
306
- query["timeout"] = options[:timeout].to_s if options[:timeout]
307
-
308
- uri = queue_uri(queue_name, query)
309
-
310
- call(:delete, uri, nil, {}, options)
311
- nil
312
- end
313
-
314
- # Public: Returns queue properties, including user-defined metadata.
315
- #
316
- # ==== Attributes
317
- #
318
- # * +queue_name+ - String. The queue name.
319
- # * +options+ - Hash. Optional parameters.
320
- #
321
- # ==== Options
322
- #
323
- # Accepted key/value pairs in options parameter are:
324
- # * +:timeout+ - Integer. A timeout in seconds.
325
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
326
- # in the analytics logs when storage analytics logging is enabled.
327
- # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
328
- # which location the request should be sent to.
329
- #
330
- # See http://msdn.microsoft.com/en-us/library/azure/dd179384
331
- #
332
- # Returns a tuple of (approximate_message_count, metadata)
333
- # * approximate_messages_count - Integer. The approximate number of messages in the queue. This number is not
334
- # lower than the actual number of messages in the queue, but could be higher.
335
- # * metadata - Hash. The queue metadata (Default: {})
336
- #
337
- def get_queue_metadata(queue_name, options = {})
338
- query = { "comp" => "metadata" }
339
- query["timeout"] = options[:timeout].to_s if options[:timeout]
340
-
341
- options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
342
- uri = queue_uri(queue_name, query, options)
343
-
344
- response = call(:get, uri, nil, {}, options)
345
-
346
- approximate_messages_count = response.headers["x-ms-approximate-messages-count"]
347
- metadata = Serialization.metadata_from_headers(response.headers)
348
-
349
- return approximate_messages_count.to_i, metadata
350
- end
351
-
352
- # Public: Sets user-defined metadata on the queue. To delete queue metadata, call
353
- # this API with an empty hash in the metadata parameter.
354
- #
355
- # ==== Attributes
356
- #
357
- # * +queue_name+ - String. The queue name.
358
- # * +metadata+ - Hash. A hash of user defined metadata
359
- # * +options+ - Hash. Optional parameters.
360
- #
361
- # ==== Options
362
- #
363
- # Accepted key/value pairs in options parameter are:
364
- # * +:timeout+ - Integer. A timeout in seconds.
365
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
366
- # in the analytics logs when storage analytics logging is enabled.
367
- #
368
- # See http://msdn.microsoft.com/en-us/library/azure/dd179348
369
- #
370
- # Returns nil on success
371
- def set_queue_metadata(queue_name, metadata, options = {})
372
- query = { "comp" => "metadata" }
373
- query["timeout"] = options[:timeout].to_s if options[:timeout]
374
-
375
- uri = queue_uri(queue_name, query)
376
-
377
- headers = {}
378
- StorageService.add_metadata_to_headers(metadata || {}, headers)
379
-
380
- call(:put, uri, nil, headers, options)
381
- nil
382
- end
383
-
384
- # Public: Gets the access control list (ACL) for the queue.
385
- #
386
- # ==== Attributes
387
- #
388
- # * +queue_name+ - String. The queue name.
389
- # * +options+ - Hash. Optional parameters.
390
- #
391
- # ==== Options
392
- #
393
- # Accepted key/value pairs in options parameter are:
394
- # * +:timeout+ - Integer. A timeout in seconds.
395
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
396
- # in the analytics logs when storage analytics logging is enabled.
397
- # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
398
- # which location the request should be sent to.
399
- #
400
- # See http://msdn.microsoft.com/en-us/library/azure/jj159101
401
- #
402
- # Returns a list of Azure::Storage::Entity::SignedIdentifier instances
403
- def get_queue_acl(queue_name, options = {})
404
- query = { "comp" => "acl" }
405
- query["timeout"] = options[:timeout].to_s if options[:timeout]
406
-
407
- options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
408
- response = call(:get, queue_uri(queue_name, query, options), nil, {}, options)
409
-
410
- signed_identifiers = []
411
- signed_identifiers = Serialization.signed_identifiers_from_xml(response.body) unless response.body == (nil) || response.body.length < (1)
412
- signed_identifiers
413
- end
414
-
415
- # Public: Sets the access control list (ACL) for the queue.
416
- #
417
- # ==== Attributes
418
- #
419
- # * +queue_name+ - String. The queue name.
420
- # * +options+ - Hash. Optional parameters.
421
- #
422
- # ==== Options
423
- #
424
- # Accepted key/value pairs in options parameter are:
425
- # * +:signed_identifiers+ - Array. A list of Azure::Storage::Entity::SignedIdentifier instances
426
- # * +:timeout+ - Integer. A timeout in seconds.
427
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
428
- # in the analytics logs when storage analytics logging is enabled.
429
- #
430
- # See http://msdn.microsoft.com/en-us/library/azure/jj159099
431
- #
432
- # Returns nil on success
433
- def set_queue_acl(queue_name, options = {})
434
- query = { "comp" => "acl" }
435
- query["timeout"] = options[:timeout].to_s if options[:timeout]
436
-
437
- uri = queue_uri(queue_name, query)
438
- body = nil
439
- body = Serialization.signed_identifiers_to_xml(options[:signed_identifiers]) if options[:signed_identifiers] && options[:signed_identifiers].length > 0
440
-
441
- call(:put, uri, body, {}, options)
442
- nil
443
- end
444
-
445
- # Public: Adds a message to the queue and optionally sets a visibility timeout for the message.
446
- #
447
- # ==== Attributes
448
- #
449
- # * +queue_name+ - String. The queue name.
450
- # * +message_text+ - String. The message contents. Note that the message content must be in a format that may be encoded with UTF-8.
451
- # * +options+ - Hash. Optional parameters.
452
- #
453
- # ==== Options
454
- #
455
- # Accepted key/value pairs in options parameter are:
456
- # * +:visibility_timeout+ - Integer. Specifies the new visibility timeout value, in seconds, relative to server
457
- # time. The new value must be larger than or equal to 0, and cannot be larger than 7
458
- # days. The visibility timeout of a message cannot be set to a value later than the
459
- # expiry time. :visibility_timeout should be set to a value smaller than the
460
- # time-to-live value. If not specified, the default value is 0.
461
- # * +:message_ttl+ - Integer. Specifies the time-to-live interval for the message, in seconds. The maximum
462
- # time-to-live allowed is 7 days. If not specified, the default time-to-live is 7 days.
463
- # * +:encode+ - Boolean. If set to true, the message will be base64 encoded.
464
- # * +:timeout+ - Integer. A timeout in seconds.
465
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
466
- # in the analytics logs when storage analytics logging is enabled.
467
- #
468
- # See http://msdn.microsoft.com/en-us/library/azure/dd179346
469
- #
470
- # Returns a list of Azure::Storage::Queue::Message object containing only the echo of request on success
471
- def create_message(queue_name, message_text, options = {})
472
- query = {}
473
-
474
- unless options.empty?
475
- query["visibilitytimeout"] = options[:visibility_timeout] if options[:visibility_timeout]
476
- query["messagettl"] = options[:message_ttl] if options[:message_ttl]
477
- query["timeout"] = options[:timeout].to_s if options[:timeout]
478
- end
479
-
480
- uri = messages_uri(queue_name, query)
481
- body = Serialization.message_to_xml(message_text, options[:encode])
482
-
483
- response = call(:post, uri, body, {}, options)
484
- Serialization.queue_messages_from_xml(response.body, options[:decode])
485
- end
486
-
487
- # Public: Deletes a specified message from the queue.
488
- #
489
- # ==== Attributes
490
- #
491
- # * +queue_name+ - String. The queue name.
492
- # * +message_id+ - String. The id of the message.
493
- # * +pop_receipt+ - String. The valid pop receipt value returned from an earlier call to the Get Messages or
494
- # Update Message operation.
495
- # * +options+ - Hash. Optional parameters.
496
- #
497
- # ==== Options
498
- #
499
- # Accepted key/value pairs in options parameter are:
500
- # * +:timeout+ - Integer. A timeout in seconds.
501
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
502
- # in the analytics logs when storage analytics logging is enabled.
503
- #
504
- # See http://msdn.microsoft.com/en-us/library/azure/dd179347
505
- #
506
- # Returns nil on success
507
- #
508
- # Remarks:
509
- #
510
- # When a message is successfully deleted, it is immediately marked for deletion and is no longer accessible to
511
- # clients. The message is later removed from the queue during garbage collection.
512
- #
513
- # After a client retrieves a message with the Get Messages operation, the client is expected to process and
514
- # delete the message. To delete the message, you must have two items of data returned in the response body of
515
- # the Get Messages operation:
516
- #
517
- # * The message ID, an opaque GUID value that identifies the message in the queue.
518
- #
519
- # * A valid pop receipt, an opaque value that indicates that the message has been retrieved.
520
- #
521
- # The message ID is returned from the previous Get Messages operation. The pop receipt is returned from the most
522
- # recent Get Messages or Update Message operation. In order for the Delete Message operation to succeed, the pop
523
- # receipt specified on the request must match the pop receipt returned from the Get Messages or Update Message
524
- # operation.
525
- #
526
- # Pop receipts remain valid until one of the following events occurs:
527
- #
528
- # * The message has expired.
529
- #
530
- # * The message has been deleted using the last pop receipt received either from Get Messages or Update Message.
531
- #
532
- # * The invisibility time has elapsed and the message has been dequeued by a Get Messages request. When the
533
- # invisibility time elapses, the message becomes visible again. If it is retrieved by another Get Messages
534
- # request, the returned pop receipt can be used to delete or update the message.
535
- #
536
- # * The message has been updated with a new visibility timeout. When the message is updated, a new pop receipt
537
- # will be returned.
538
- #
539
- # If the message has already been deleted when Delete Message is called, the Queue service returns status code
540
- # 404 (Not Found).
541
- #
542
- # If a message with a matching pop receipt is not found, the service returns status code 400 (Bad Request), with
543
- # additional error information indicating that the cause of the failure was a mismatched pop receipt.
544
- #
545
- def delete_message(queue_name, message_id, pop_receipt, options = {})
546
- query = { "popreceipt" => pop_receipt }
547
- query["timeout"] = options[:timeout].to_s if options[:timeout]
548
-
549
- uri = message_uri(queue_name, message_id, query)
550
-
551
- call(:delete, uri, nil, {}, options)
552
- nil
553
- end
554
-
555
- # Public: Retrieves one or more messages from the front of the queue, without changing the message visibility.
556
- #
557
- # ==== Attributes
558
- #
559
- # * +queue_name+ - String. The queue name.
560
- # * +options+ - Hash. Optional parameters.
561
- #
562
- # ==== Options
563
- #
564
- # Accepted key/value pairs in options parameter are:
565
- # * +:number_of_messages+ - Integer. How many messages to return. (optional, Default: 1)
566
- # * +:decode+ - Boolean. Boolean value indicating if the message should be base64 decoded.
567
- # * +:timeout+ - Integer. A timeout in seconds.
568
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
569
- # in the analytics logs when storage analytics logging is enabled.
570
- # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
571
- # which location the request should be sent to.
572
- #
573
- # See http://msdn.microsoft.com/en-us/library/azure/dd179472
574
- #
575
- # Returns a list of Azure::Storage::Entity::Queue::Message instances
576
- def peek_messages(queue_name, options = {})
577
- number_of_messages = 1
578
- number_of_messages = options[:number_of_messages] if options[:number_of_messages]
579
-
580
- query = { "peekonly" => "true", "numofmessages" => number_of_messages.to_s }
581
- query["timeout"] = options[:timeout].to_s if options[:timeout]
582
-
583
- options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
584
- uri = messages_uri(queue_name, query, options)
585
- response = call(:get, uri, nil, {}, options)
586
-
587
- messages = Serialization.queue_messages_from_xml(response.body, options[:decode])
588
- messages
589
- end
590
-
591
- # Public: Retrieves one or more messages from the front of the queue.
592
- #
593
- # ==== Attributes
594
- #
595
- # * +queue_name+ - String. The queue name.
596
- # * +visibility_timeout+ - Integer. The new visibility timeout value, in seconds, relative to server time.
597
- # * +options+ - Hash. Optional parameters.
598
- #
599
- # ==== Options
600
- #
601
- # Accepted key/value pairs in options parameter are:
602
- # * +:number_of_messages+ - Integer. How many messages to return. (optional, Default: 1)
603
- # * +:timeout+ - Integer. A timeout in seconds.
604
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
605
- # in the analytics logs when storage analytics logging is enabled.
606
- # * +:decode+ - Boolean. Boolean value indicating if the message should be base64 decoded.
607
- #
608
- # See http://msdn.microsoft.com/en-us/library/azure/dd179474
609
- #
610
- # Returns a list of Azure::Storage::Entity::Queue::Message instances
611
- def list_messages(queue_name, visibility_timeout, options = {})
612
- number_of_messages = 1
613
- number_of_messages = options[:number_of_messages] if options[:number_of_messages]
614
-
615
- query = { "visibilitytimeout" => visibility_timeout.to_s, "numofmessages" => number_of_messages.to_s }
616
- query["timeout"] = options[:timeout].to_s if options[:timeout]
617
-
618
- uri = messages_uri(queue_name, query)
619
- response = call(:get, uri, nil, {}, options)
620
-
621
- messages = Serialization.queue_messages_from_xml(response.body, options[:decode])
622
- messages
623
- end
624
-
625
- # Public: Adds a message to the queue and optionally sets a visibility timeout for the message.
626
- #
627
- # ==== Attributes
628
- #
629
- # * +queue_name+ - String. The queue name.
630
- # * +message_id+ - String. The id of the message.
631
- # * +pop_receipt+ - String. The valid pop receipt value returned from an earlier call to the Get Messages or
632
- # update Message operation.
633
- # * +message_text+ - String. The message contents. Note that the message content must be in a format that may
634
- # be encoded with UTF-8.
635
- # * +visibility_timeout+ - Integer. The new visibility timeout value, in seconds, relative to server time.
636
- # * +options+ - Hash. Optional parameters.
637
- #
638
- # ==== Options
639
- #
640
- # Accepted key/value pairs in options parameter are:
641
- # * +:encode+ - Boolean. If set to true, the message will be base64 encoded.
642
- # * +:timeout+ - Integer. A timeout in seconds.
643
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
644
- # in the analytics logs when storage analytics logging is enabled.
645
- #
646
- # See http://msdn.microsoft.com/en-us/library/azure/hh452234
647
- #
648
- # Returns a tuple of (pop_receipt, time_next_visible)
649
- # * pop_receipt - String. The pop receipt of the queue message.
650
- # * time_next_visible - String. A UTC date/time value that represents when the message will be visible on the queue.
651
- #
652
- # Remarks:
653
- #
654
- # An Update Message operation will fail if the specified message does not exist in the queue, or if the
655
- # specified pop receipt does not match the message.
656
- #
657
- # A pop receipt is returned by the Get Messages operation or the Update Message operation. Pop receipts
658
- # remain valid until one of the following events occurs:
659
- #
660
- # * The message has expired.
661
- #
662
- # * The message has been deleted using the last pop receipt received either from Get Messages or
663
- # Update Message.
664
- #
665
- # * The invisibility time has elapsed and the message has been dequeued by a Get Messages request. When
666
- # the invisibility time elapses, the message becomes visible again. If it is retrieved by another
667
- # Get Messages request, the returned pop receipt can be used to delete or update the message.
668
- #
669
- # * The message has been updated with a new visibility timeout. When the message is updated, a new pop
670
- # receipt will be returned.
671
- #
672
- # The Update Message operation can be used to continually extend the invisibility of a queue message. This
673
- # functionality can be useful if you want a worker role to "lease" a queue message. For example, if a worker
674
- # role calls Get Messages and recognizes that it needs more time to process a message, it can continually
675
- # extend the message's invisibility until it is processed. If the worker role were to fail during processing,
676
- # eventually the message would become visible again and another worker role could process it.
677
- #
678
- def update_message(queue_name, message_id, pop_receipt, message_text, visibility_timeout, options = {})
679
- query = { "visibilitytimeout" => visibility_timeout.to_s, "popreceipt" => pop_receipt }
680
- query["timeout"] = options[:timeout].to_s if options[:timeout]
681
-
682
- uri = message_uri(queue_name, message_id, query)
683
- body = Serialization.message_to_xml(message_text, options[:encode])
684
-
685
- response = call(:put, uri, body, {}, options)
686
- new_pop_receipt = response.headers["x-ms-popreceipt"]
687
- time_next_visible = response.headers["x-ms-time-next-visible"]
688
- return new_pop_receipt, time_next_visible
689
- end
690
-
691
- # Protected: Generate the URI for the collection of queues.
692
- #
693
- # ==== Attributes
694
- #
695
- # * +query+ - A Hash of query parameters (default: {}).
696
- #
697
- # Returns a URI.
698
- protected
699
- def collection_uri(query = {}, options = {})
700
- query.update(comp: "list", include: "metadata")
701
- generate_uri("", query, options)
702
- end
703
-
704
- # Protected: Generate the URI for a given queue.
705
- #
706
- # ==== Attributes
707
- #
708
- # * +queue_name+ - The name of the queue.
709
- # * +query+ - A Hash of query parameters (default: {}).
710
- #
711
- # Returns a URI.
712
- protected
713
- def queue_uri(queue_name, query = {}, options = {})
714
- return queue_name if queue_name.kind_of? ::URI
715
- generate_uri(queue_name, query, options)
716
- end
717
-
718
- # Protected: Generate the messages URI for the given queue.
719
- #
720
- # ==== Attributes
721
- #
722
- # * +queue_name+ - The name of the queue.
723
- # * +query+ - A Hash of query parameters (default: {}).
724
- #
725
- # Returns a URI.
726
- protected
727
- def messages_uri(queue_name, query = {}, options = {})
728
- generate_uri("#{queue_name}/messages", query, options)
729
- end
730
-
731
- # Protected: Generate the URI for a given message
732
- #
733
- # ==== Attributes
734
- #
735
- # * +queue_name+ - The name of the queue.
736
- # * +message_id+ - The id of the message.
737
- # * +query+ - A Hash of query parameters (default: {}).
738
- #
739
- # Returns a URI.
740
- protected
741
- def message_uri(queue_name, message_id, query = {}, options = {})
742
- generate_uri("#{queue_name}/messages/#{message_id}", query, options)
743
- end
744
-
745
- protected
746
- def call(method, uri, body = nil, headers = {}, options = {})
747
- headers["x-ms-version"] = @api_version ? @api_version : Default::STG_VERSION
748
- headers["User-Agent"] = @user_agent_prefix ? "#{@user_agent_prefix}; #{Default::USER_AGENT}" : Default::USER_AGENT
749
- super
750
- end
751
- end
752
- end
753
- end
754
-
755
- Azure::Storage::QueueService = Azure::Storage::Queue::QueueService
1
+ # frozen_string_literal: true
2
+
3
+ #-------------------------------------------------------------------------
4
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
5
+ #
6
+ # The MIT License(MIT)
7
+
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files(the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions :
14
+
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ # THE SOFTWARE.
25
+ #--------------------------------------------------------------------------
26
+ module Azure::Storage
27
+ include Azure::Storage::Common::Service
28
+ StorageService = Azure::Storage::Common::Service::StorageService
29
+
30
+ module Queue
31
+ class QueueService < StorageService
32
+ class << self
33
+ # Public: Creates an instance of [Azure::Storage::Queue::QueueService]
34
+ #
35
+ # ==== Attributes
36
+ #
37
+ # * +options+ - Hash. Optional parameters.
38
+ #
39
+ # ==== Options
40
+ #
41
+ # Accepted key/value pairs in options parameter are:
42
+ #
43
+ # * +:use_development_storage+ - TrueClass|FalseClass. Whether to use storage emulator.
44
+ # * +:development_storage_proxy_uri+ - String. Used with +:use_development_storage+ if emulator is hosted other than localhost.
45
+ # * +:storage_account_name+ - String. The name of the storage account.
46
+ # * +:storage_access_key+ - Base64 String. The access key of the storage account.
47
+ # * +:storage_sas_token+ - String. The signed access signature for the storage account or one of its service.
48
+ # * +:storage_queue_host+ - String. Specified Queue service endpoint or hostname
49
+ # * +:storage_dns_suffix+ - String. The suffix of a regional Storage Service, to
50
+ # * +:default_endpoints_protocol+ - String. http or https
51
+ # * +:use_path_style_uri+ - String. Whether use path style URI for specified endpoints
52
+ # * +:ca_file+ - String. File path of the CA file if having issue with SSL
53
+ # * +:ssl_version+ - Symbol. The ssl version to be used, sample: :TLSv1_1, :TLSv1_2, for the details, see https://github.com/ruby/openssl/blob/master/lib/openssl/ssl.rb
54
+ # * +:ssl_min_version+ - Symbol. The min ssl version supported, only supported in Ruby 2.5+
55
+ # * +:ssl_max_version+ - Symbol. The max ssl version supported, only supported in Ruby 2.5+
56
+ # * +:user_agent_prefix+ - String. The user agent prefix that can identify the application calls the library
57
+ #
58
+ # The valid set of options include:
59
+ # * Storage Emulator: +:use_development_storage+ required, +:development_storage_proxy_uri+ optionally
60
+ # * Storage account name and key: +:storage_account_name+ and +:storage_access_key+ required, set +:storage_dns_suffix+ necessarily
61
+ # * Storage account name and SAS token: +:storage_account_name+ and +:storage_sas_token+ required, set +:storage_dns_suffix+ necessarily
62
+ # * Specified hosts and SAS token: At least one of the service host and SAS token. It's up to user to ensure the SAS token is suitable for the serivce
63
+ # * Anonymous Queue: only +:storage_queue_host+, if it is to only access queues within a container
64
+ #
65
+ # Additional notes:
66
+ # * Specified hosts can be set when use account name with access key or sas token
67
+ # * +:default_endpoints_protocol+ can be set if the scheme is not specified in hosts
68
+ # * Storage emulator always use path style URI
69
+ # * +:ca_file+ is independent.
70
+ #
71
+ # When empty options are given, it will try to read settings from Environment Variables. Refer to [Azure::Storage::Common::ClientOptions.env_vars_mapping] for the mapping relationship
72
+ #
73
+ # @return [Azure::Storage::Queue::QueueService]
74
+ def create(options = {}, &block)
75
+ service_options = { client: Azure::Storage::Common::Client::create(options, &block), api_version: Azure::Storage::Queue::Default::STG_VERSION }
76
+ service_options[:user_agent_prefix] = options[:user_agent_prefix] if options[:user_agent_prefix]
77
+ Azure::Storage::Queue::QueueService.new(service_options, &block)
78
+ end
79
+
80
+ # Public: Creates an instance of [Azure::Storage::Queue::QueueService] with Storage Emulator
81
+ #
82
+ # ==== Attributes
83
+ #
84
+ # * +proxy_uri+ - String. Used with +:use_development_storage+ if emulator is hosted other than localhost.
85
+ #
86
+ # @return [Azure::Storage::Queue::QueueService]
87
+ def create_development(proxy_uri = nil, &block)
88
+ service_options = { client: Azure::Storage::Common::Client::create_development(proxy_uri, &block), api_version: Azure::Storage::Queue::Default::STG_VERSION }
89
+ Azure::Storage::Queue::QueueService.new(service_options, &block)
90
+ end
91
+
92
+ # Public: Creates an instance of [Azure::Storage::Queue::QueueService] from Environment Variables
93
+ #
94
+ # @return [Azure::Storage::Queue::QueueService]
95
+ def create_from_env(&block)
96
+ service_options = { client: Azure::Storage::Common::Client::create_from_env(&block), api_version: Azure::Storage::Queue::Default::STG_VERSION }
97
+ Azure::Storage::Queue::QueueService.new(service_options, &block)
98
+ end
99
+
100
+ # Public: Creates an instance of [Azure::Storage::Queue::QueueService] from Environment Variables
101
+ #
102
+ # ==== Attributes
103
+ #
104
+ # * +connection_string+ - String. Please refer to https://azure.microsoft.com/en-us/documentation/articles/storage-configure-connection-string/.
105
+ #
106
+ # @return [Azure::Storage::Queue::QueueService]
107
+ def create_from_connection_string(connection_string, &block)
108
+ service_options = { client: Azure::Storage::Common::Client::create_from_connection_string(connection_string, &block), api_version: Azure::Storage::Queue::Default::STG_VERSION }
109
+ Azure::Storage::Queue::QueueService.new(service_options, &block)
110
+ end
111
+ end
112
+
113
+ # Public: Initializes an instance of [Azure::Storage::Queue::QueueService]
114
+ #
115
+ # ==== Attributes
116
+ #
117
+ # * +options+ - Hash. Optional parameters.
118
+ #
119
+ # ==== Options
120
+ #
121
+ # Accepted key/value pairs in options parameter are:
122
+ #
123
+ # * +:use_development_storage+ - TrueClass|FalseClass. Whether to use storage emulator.
124
+ # * +:development_storage_proxy_uri+ - String. Used with +:use_development_storage+ if emulator is hosted other than localhost.
125
+ # * +:storage_connection_string+ - String. The storage connection string.
126
+ # * +:storage_account_name+ - String. The name of the storage account.
127
+ # * +:storage_access_key+ - Base64 String. The access key of the storage account.
128
+ # * +:storage_sas_token+ - String. The signed access signature for the storage account or one of its service.
129
+ # * +:storage_queue_host+ - String. Specified Queue serivce endpoint or hostname
130
+ # * +:storage_dns_suffix+ - String. The suffix of a regional Storage Serivce, to
131
+ # * +:default_endpoints_protocol+ - String. http or https
132
+ # * +:use_path_style_uri+ - String. Whether use path style URI for specified endpoints
133
+ # * +:ca_file+ - String. File path of the CA file if having issue with SSL
134
+ # * +:ssl_version+ - Symbol. The ssl version to be used, sample: :TLSv1_1, :TLSv1_2, for the details, see https://github.com/ruby/openssl/blob/master/lib/openssl/ssl.rb
135
+ # * +:ssl_min_version+ - Symbol. The min ssl version supported, only supported in Ruby 2.5+
136
+ # * +:ssl_max_version+ - Symbol. The max ssl version supported, only supported in Ruby 2.5+
137
+ # * +:user_agent_prefix+ - String. The user agent prefix that can identify the application calls the library
138
+ # * +:client+ - Azure::Storage::Common::Client. The common client used to initalize the service.
139
+ #
140
+ # The valid set of options include:
141
+ # * Storage Emulator: +:use_development_storage+ required, +:development_storage_proxy_uri+ optionally
142
+ # * Storage account name and key: +:storage_account_name+ and +:storage_access_key+ required, set +:storage_dns_suffix+ necessarily
143
+ # * Storage account name and SAS token: +:storage_account_name+ and +:storage_sas_token+ required, set +:storage_dns_suffix+ necessarily
144
+ # * Specified hosts and SAS token: At least one of the service host and SAS token. It's up to user to ensure the SAS token is suitable for the serivce
145
+ # * Azure::Storage::Common::Client: The common client used to initalize the service. This client can be initalized and used repeatedly.
146
+ # * Anonymous Queue: only +:storage_queue_host+, if it is to only access queues within a container
147
+ #
148
+ # Additional notes:
149
+ # * Specified hosts can be set when use account name with access key or sas token
150
+ # * +:default_endpoints_protocol+ can be set if the scheme is not specified in hosts
151
+ # * Storage emulator always use path style URI
152
+ # * +:ca_file+ is independent.
153
+ #
154
+ # When empty options are given, it will try to read settings from Environment Variables. Refer to [Azure::Storage::Common::ClientOptions.env_vars_mapping] for the mapping relationship
155
+ def initialize(options = {}, &block)
156
+ service_options = options.clone
157
+ client_config = service_options[:client] ||= Azure::Storage::Common::Client::create(service_options, &block)
158
+ @user_agent_prefix = service_options[:user_agent_prefix] if service_options[:user_agent_prefix]
159
+ @api_version = service_options[:api_version] || Azure::Storage::Queue::Default::STG_VERSION
160
+ signer = service_options[:signer] || client_config.signer || Azure::Storage::Common::Core::Auth::SharedKey.new(client_config.storage_account_name, client_config.storage_access_key)
161
+ signer.api_ver = @api_version if signer.is_a? Azure::Storage::Common::Core::Auth::SharedAccessSignatureSigner
162
+ super(signer, client_config.storage_account_name, service_options, &block)
163
+ @storage_service_host[:primary] = client.storage_queue_host
164
+ @storage_service_host[:secondary] = client.storage_queue_host true
165
+ end
166
+
167
+ # Public: Get a list of Queues from the server
168
+ #
169
+ # ==== Attributes
170
+ #
171
+ # * +options+ - Hash. Optional parameters.
172
+ #
173
+ # ==== Options
174
+ #
175
+ # Accepted key/value pairs in options parameter are:
176
+ # * +:prefix+ - String. Filters the results to return only containers
177
+ # whose name begins with the specified prefix. (optional)
178
+ # * +:marker+ - String. An identifier the specifies the portion of the
179
+ # list to be returned. This value comes from the property
180
+ # Azure::Service::EnumerationResults.continuation_token when there
181
+ # are more containers available than were returned. The
182
+ # marker value may then be used here to request the next set
183
+ # of list items. (optional)
184
+ # * +:max_results+ - Integer. Specifies the maximum number of containers to return.
185
+ # If max_results is not specified, or is a value greater than
186
+ # 5,000, the server will return up to 5,000 items. If it is set
187
+ # to a value less than or equal to zero, the server will return
188
+ # status code 400 (Bad Request). (optional)
189
+ # * +:metadata+ - Boolean. Specifies whether or not to return the container metadata.
190
+ # (optional, Default=false)
191
+ # * +:timeout+ - Integer. A timeout in seconds.
192
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
193
+ # in the analytics logs when storage analytics logging is enabled.
194
+ # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
195
+ # which location the request should be sent to.
196
+ #
197
+ # NOTE: Metadata requested with the :metadata parameter must have been stored in
198
+ # accordance with the naming restrictions imposed by the 2009-09-19 version of the queue
199
+ # service. Beginning with that version, all metadata names must adhere to the naming
200
+ # conventions for C# identifiers.
201
+ #
202
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179466
203
+ #
204
+ # Any metadata with invalid names which were previously stored, will be returned with the
205
+ # key "x-ms-invalid-name" in the metadata hash. This may contain multiple values and be an
206
+ # Array (vs a String if it only contains a single value).
207
+ #
208
+ # Returns an Azure::Storage::Common::EnumerationResults
209
+ def list_queues(options = {})
210
+ query = {}
211
+ query["prefix"] = options[:prefix] if options[:prefix]
212
+ query["marker"] = options[:marker] if options[:marker]
213
+ query["maxresults"] = options[:max_results].to_s if options[:max_results]
214
+ query["include"] = "metadata" if options[:metadata] == true
215
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
216
+
217
+ options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
218
+ uri = collection_uri(query, options)
219
+ response = call(:get, uri, nil, {}, options)
220
+
221
+ Serialization.queue_enumeration_results_from_xml(response.body)
222
+ end
223
+
224
+ # Public: Clears all messages from the queue.
225
+ #
226
+ # If a queue contains a large number of messages, Clear Messages may time out
227
+ # before all messages have been deleted. In this case the Queue service will
228
+ # return status code 500 (Internal Server Error), with the additional error
229
+ # code OperationTimedOut. If the operation times out, the client should
230
+ # continue to retry Clear Messages until it succeeds, to ensure that all
231
+ # messages have been deleted.
232
+ #
233
+ # ==== Attributes
234
+ #
235
+ # * +queue_name+ - String. The name of the queue.
236
+ # * +options+ - Hash. Optional parameters.
237
+ #
238
+ # ==== Options
239
+ #
240
+ # Accepted key/value pairs in options parameter are:
241
+ # * +:timeout+ - Integer. A timeout in seconds.
242
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
243
+ # in the analytics logs when storage analytics logging is enabled.
244
+ #
245
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179454
246
+ #
247
+ # Returns nil on success
248
+ def clear_messages(queue_name, options = {})
249
+ query = {}
250
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
251
+ uri = messages_uri(queue_name, query)
252
+ call(:delete, uri, nil, {}, options)
253
+ nil
254
+ end
255
+
256
+ # Public: Creates a new queue under the storage account.
257
+ #
258
+ # ==== Attributes
259
+ #
260
+ # * +queue_name+ - String. The queue name.
261
+ # * +options+ - Hash. Optional parameters.
262
+ #
263
+ # ==== Options
264
+ #
265
+ # Accepted key/value pairs in options parameter are:
266
+ # * +:metadata+ - Hash. A hash of user defined metadata.
267
+ # * +:timeout+ - Integer. A timeout in seconds.
268
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
269
+ # in the analytics logs when storage analytics logging is enabled.
270
+ #
271
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179342
272
+ #
273
+ # Returns nil on success
274
+ def create_queue(queue_name, options = {})
275
+ query = {}
276
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
277
+
278
+ uri = queue_uri(queue_name, query)
279
+
280
+ headers = {}
281
+ StorageService.add_metadata_to_headers(options[:metadata] || {}, headers) if options[:metadata]
282
+
283
+ call(:put, uri, nil, headers, options)
284
+ nil
285
+ end
286
+
287
+ # Public: Deletes a queue.
288
+ #
289
+ # ==== Attributes
290
+ #
291
+ # * +queue_name+ - String. The queue name.
292
+ # * +options+ - Hash. Optional parameters.
293
+ #
294
+ # ==== Options
295
+ #
296
+ # Accepted key/value pairs in options parameter are:
297
+ # * +:timeout+ - Integer. A timeout in seconds.
298
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
299
+ # in the analytics logs when storage analytics logging is enabled.
300
+ #
301
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179436
302
+ #
303
+ # Returns nil on success
304
+ def delete_queue(queue_name, options = {})
305
+ query = {}
306
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
307
+
308
+ uri = queue_uri(queue_name, query)
309
+
310
+ call(:delete, uri, nil, {}, options)
311
+ nil
312
+ end
313
+
314
+ # Public: Returns queue properties, including user-defined metadata.
315
+ #
316
+ # ==== Attributes
317
+ #
318
+ # * +queue_name+ - String. The queue name.
319
+ # * +options+ - Hash. Optional parameters.
320
+ #
321
+ # ==== Options
322
+ #
323
+ # Accepted key/value pairs in options parameter are:
324
+ # * +:timeout+ - Integer. A timeout in seconds.
325
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
326
+ # in the analytics logs when storage analytics logging is enabled.
327
+ # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
328
+ # which location the request should be sent to.
329
+ #
330
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179384
331
+ #
332
+ # Returns a tuple of (approximate_message_count, metadata)
333
+ # * approximate_messages_count - Integer. The approximate number of messages in the queue. This number is not
334
+ # lower than the actual number of messages in the queue, but could be higher.
335
+ # * metadata - Hash. The queue metadata (Default: {})
336
+ #
337
+ def get_queue_metadata(queue_name, options = {})
338
+ query = { "comp" => "metadata" }
339
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
340
+
341
+ options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
342
+ uri = queue_uri(queue_name, query, options)
343
+
344
+ response = call(:get, uri, nil, {}, options)
345
+
346
+ approximate_messages_count = response.headers["x-ms-approximate-messages-count"]
347
+ metadata = Serialization.metadata_from_headers(response.headers)
348
+
349
+ return approximate_messages_count.to_i, metadata
350
+ end
351
+
352
+ # Public: Sets user-defined metadata on the queue. To delete queue metadata, call
353
+ # this API with an empty hash in the metadata parameter.
354
+ #
355
+ # ==== Attributes
356
+ #
357
+ # * +queue_name+ - String. The queue name.
358
+ # * +metadata+ - Hash. A hash of user defined metadata
359
+ # * +options+ - Hash. Optional parameters.
360
+ #
361
+ # ==== Options
362
+ #
363
+ # Accepted key/value pairs in options parameter are:
364
+ # * +:timeout+ - Integer. A timeout in seconds.
365
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
366
+ # in the analytics logs when storage analytics logging is enabled.
367
+ #
368
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179348
369
+ #
370
+ # Returns nil on success
371
+ def set_queue_metadata(queue_name, metadata, options = {})
372
+ query = { "comp" => "metadata" }
373
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
374
+
375
+ uri = queue_uri(queue_name, query)
376
+
377
+ headers = {}
378
+ StorageService.add_metadata_to_headers(metadata || {}, headers)
379
+
380
+ call(:put, uri, nil, headers, options)
381
+ nil
382
+ end
383
+
384
+ # Public: Gets the access control list (ACL) for the queue.
385
+ #
386
+ # ==== Attributes
387
+ #
388
+ # * +queue_name+ - String. The queue name.
389
+ # * +options+ - Hash. Optional parameters.
390
+ #
391
+ # ==== Options
392
+ #
393
+ # Accepted key/value pairs in options parameter are:
394
+ # * +:timeout+ - Integer. A timeout in seconds.
395
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
396
+ # in the analytics logs when storage analytics logging is enabled.
397
+ # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
398
+ # which location the request should be sent to.
399
+ #
400
+ # See http://msdn.microsoft.com/en-us/library/azure/jj159101
401
+ #
402
+ # Returns a list of Azure::Storage::Entity::SignedIdentifier instances
403
+ def get_queue_acl(queue_name, options = {})
404
+ query = { "comp" => "acl" }
405
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
406
+
407
+ options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
408
+ response = call(:get, queue_uri(queue_name, query, options), nil, {}, options)
409
+
410
+ signed_identifiers = []
411
+ signed_identifiers = Serialization.signed_identifiers_from_xml(response.body) unless response.body == (nil) || response.body.length < (1)
412
+ signed_identifiers
413
+ end
414
+
415
+ # Public: Sets the access control list (ACL) for the queue.
416
+ #
417
+ # ==== Attributes
418
+ #
419
+ # * +queue_name+ - String. The queue name.
420
+ # * +options+ - Hash. Optional parameters.
421
+ #
422
+ # ==== Options
423
+ #
424
+ # Accepted key/value pairs in options parameter are:
425
+ # * +:signed_identifiers+ - Array. A list of Azure::Storage::Entity::SignedIdentifier instances
426
+ # * +:timeout+ - Integer. A timeout in seconds.
427
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
428
+ # in the analytics logs when storage analytics logging is enabled.
429
+ #
430
+ # See http://msdn.microsoft.com/en-us/library/azure/jj159099
431
+ #
432
+ # Returns nil on success
433
+ def set_queue_acl(queue_name, options = {})
434
+ query = { "comp" => "acl" }
435
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
436
+
437
+ uri = queue_uri(queue_name, query)
438
+ body = nil
439
+ body = Serialization.signed_identifiers_to_xml(options[:signed_identifiers]) if options[:signed_identifiers] && options[:signed_identifiers].length > 0
440
+
441
+ call(:put, uri, body, {}, options)
442
+ nil
443
+ end
444
+
445
+ # Public: Adds a message to the queue and optionally sets a visibility timeout for the message.
446
+ #
447
+ # ==== Attributes
448
+ #
449
+ # * +queue_name+ - String. The queue name.
450
+ # * +message_text+ - String. The message contents. Note that the message content must be in a format that may be encoded with UTF-8.
451
+ # * +options+ - Hash. Optional parameters.
452
+ #
453
+ # ==== Options
454
+ #
455
+ # Accepted key/value pairs in options parameter are:
456
+ # * +:visibility_timeout+ - Integer. Specifies the new visibility timeout value, in seconds, relative to server
457
+ # time. The new value must be larger than or equal to 0, and cannot be larger than 7
458
+ # days. The visibility timeout of a message cannot be set to a value later than the
459
+ # expiry time. :visibility_timeout should be set to a value smaller than the
460
+ # time-to-live value. If not specified, the default value is 0.
461
+ # * +:message_ttl+ - Integer. Specifies the time-to-live interval for the message, in seconds. The maximum
462
+ # time-to-live allowed is 7 days. If not specified, the default time-to-live is 7 days.
463
+ # * +:encode+ - Boolean. If set to true, the message will be base64 encoded.
464
+ # * +:timeout+ - Integer. A timeout in seconds.
465
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
466
+ # in the analytics logs when storage analytics logging is enabled.
467
+ #
468
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179346
469
+ #
470
+ # Returns a list of Azure::Storage::Queue::Message object containing only the echo of request on success
471
+ def create_message(queue_name, message_text, options = {})
472
+ query = {}
473
+
474
+ unless options.empty?
475
+ query["visibilitytimeout"] = options[:visibility_timeout] if options[:visibility_timeout]
476
+ query["messagettl"] = options[:message_ttl] if options[:message_ttl]
477
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
478
+ end
479
+
480
+ uri = messages_uri(queue_name, query)
481
+ body = Serialization.message_to_xml(message_text, options[:encode])
482
+
483
+ response = call(:post, uri, body, {}, options)
484
+ Serialization.queue_messages_from_xml(response.body, options[:decode])
485
+ end
486
+
487
+ # Public: Deletes a specified message from the queue.
488
+ #
489
+ # ==== Attributes
490
+ #
491
+ # * +queue_name+ - String. The queue name.
492
+ # * +message_id+ - String. The id of the message.
493
+ # * +pop_receipt+ - String. The valid pop receipt value returned from an earlier call to the Get Messages or
494
+ # Update Message operation.
495
+ # * +options+ - Hash. Optional parameters.
496
+ #
497
+ # ==== Options
498
+ #
499
+ # Accepted key/value pairs in options parameter are:
500
+ # * +:timeout+ - Integer. A timeout in seconds.
501
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
502
+ # in the analytics logs when storage analytics logging is enabled.
503
+ #
504
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179347
505
+ #
506
+ # Returns nil on success
507
+ #
508
+ # Remarks:
509
+ #
510
+ # When a message is successfully deleted, it is immediately marked for deletion and is no longer accessible to
511
+ # clients. The message is later removed from the queue during garbage collection.
512
+ #
513
+ # After a client retrieves a message with the Get Messages operation, the client is expected to process and
514
+ # delete the message. To delete the message, you must have two items of data returned in the response body of
515
+ # the Get Messages operation:
516
+ #
517
+ # * The message ID, an opaque GUID value that identifies the message in the queue.
518
+ #
519
+ # * A valid pop receipt, an opaque value that indicates that the message has been retrieved.
520
+ #
521
+ # The message ID is returned from the previous Get Messages operation. The pop receipt is returned from the most
522
+ # recent Get Messages or Update Message operation. In order for the Delete Message operation to succeed, the pop
523
+ # receipt specified on the request must match the pop receipt returned from the Get Messages or Update Message
524
+ # operation.
525
+ #
526
+ # Pop receipts remain valid until one of the following events occurs:
527
+ #
528
+ # * The message has expired.
529
+ #
530
+ # * The message has been deleted using the last pop receipt received either from Get Messages or Update Message.
531
+ #
532
+ # * The invisibility time has elapsed and the message has been dequeued by a Get Messages request. When the
533
+ # invisibility time elapses, the message becomes visible again. If it is retrieved by another Get Messages
534
+ # request, the returned pop receipt can be used to delete or update the message.
535
+ #
536
+ # * The message has been updated with a new visibility timeout. When the message is updated, a new pop receipt
537
+ # will be returned.
538
+ #
539
+ # If the message has already been deleted when Delete Message is called, the Queue service returns status code
540
+ # 404 (Not Found).
541
+ #
542
+ # If a message with a matching pop receipt is not found, the service returns status code 400 (Bad Request), with
543
+ # additional error information indicating that the cause of the failure was a mismatched pop receipt.
544
+ #
545
+ def delete_message(queue_name, message_id, pop_receipt, options = {})
546
+ query = { "popreceipt" => pop_receipt }
547
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
548
+
549
+ uri = message_uri(queue_name, message_id, query)
550
+
551
+ call(:delete, uri, nil, {}, options)
552
+ nil
553
+ end
554
+
555
+ # Public: Retrieves one or more messages from the front of the queue, without changing the message visibility.
556
+ #
557
+ # ==== Attributes
558
+ #
559
+ # * +queue_name+ - String. The queue name.
560
+ # * +options+ - Hash. Optional parameters.
561
+ #
562
+ # ==== Options
563
+ #
564
+ # Accepted key/value pairs in options parameter are:
565
+ # * +:number_of_messages+ - Integer. How many messages to return. (optional, Default: 1)
566
+ # * +:decode+ - Boolean. Boolean value indicating if the message should be base64 decoded.
567
+ # * +:timeout+ - Integer. A timeout in seconds.
568
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
569
+ # in the analytics logs when storage analytics logging is enabled.
570
+ # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
571
+ # which location the request should be sent to.
572
+ #
573
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179472
574
+ #
575
+ # Returns a list of Azure::Storage::Entity::Queue::Message instances
576
+ def peek_messages(queue_name, options = {})
577
+ number_of_messages = 1
578
+ number_of_messages = options[:number_of_messages] if options[:number_of_messages]
579
+
580
+ query = { "peekonly" => "true", "numofmessages" => number_of_messages.to_s }
581
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
582
+
583
+ options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
584
+ uri = messages_uri(queue_name, query, options)
585
+ response = call(:get, uri, nil, {}, options)
586
+
587
+ messages = Serialization.queue_messages_from_xml(response.body, options[:decode])
588
+ messages
589
+ end
590
+
591
+ # Public: Retrieves one or more messages from the front of the queue.
592
+ #
593
+ # ==== Attributes
594
+ #
595
+ # * +queue_name+ - String. The queue name.
596
+ # * +visibility_timeout+ - Integer. The new visibility timeout value, in seconds, relative to server time.
597
+ # * +options+ - Hash. Optional parameters.
598
+ #
599
+ # ==== Options
600
+ #
601
+ # Accepted key/value pairs in options parameter are:
602
+ # * +:number_of_messages+ - Integer. How many messages to return. (optional, Default: 1)
603
+ # * +:timeout+ - Integer. A timeout in seconds.
604
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
605
+ # in the analytics logs when storage analytics logging is enabled.
606
+ # * +:decode+ - Boolean. Boolean value indicating if the message should be base64 decoded.
607
+ #
608
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179474
609
+ #
610
+ # Returns a list of Azure::Storage::Entity::Queue::Message instances
611
+ def list_messages(queue_name, visibility_timeout, options = {})
612
+ number_of_messages = 1
613
+ number_of_messages = options[:number_of_messages] if options[:number_of_messages]
614
+
615
+ query = { "visibilitytimeout" => visibility_timeout.to_s, "numofmessages" => number_of_messages.to_s }
616
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
617
+
618
+ uri = messages_uri(queue_name, query)
619
+ response = call(:get, uri, nil, {}, options)
620
+
621
+ messages = Serialization.queue_messages_from_xml(response.body, options[:decode])
622
+ messages
623
+ end
624
+
625
+ # Public: Adds a message to the queue and optionally sets a visibility timeout for the message.
626
+ #
627
+ # ==== Attributes
628
+ #
629
+ # * +queue_name+ - String. The queue name.
630
+ # * +message_id+ - String. The id of the message.
631
+ # * +pop_receipt+ - String. The valid pop receipt value returned from an earlier call to the Get Messages or
632
+ # update Message operation.
633
+ # * +message_text+ - String. The message contents. Note that the message content must be in a format that may
634
+ # be encoded with UTF-8.
635
+ # * +visibility_timeout+ - Integer. The new visibility timeout value, in seconds, relative to server time.
636
+ # * +options+ - Hash. Optional parameters.
637
+ #
638
+ # ==== Options
639
+ #
640
+ # Accepted key/value pairs in options parameter are:
641
+ # * +:encode+ - Boolean. If set to true, the message will be base64 encoded.
642
+ # * +:timeout+ - Integer. A timeout in seconds.
643
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
644
+ # in the analytics logs when storage analytics logging is enabled.
645
+ #
646
+ # See http://msdn.microsoft.com/en-us/library/azure/hh452234
647
+ #
648
+ # Returns a tuple of (pop_receipt, time_next_visible)
649
+ # * pop_receipt - String. The pop receipt of the queue message.
650
+ # * time_next_visible - String. A UTC date/time value that represents when the message will be visible on the queue.
651
+ #
652
+ # Remarks:
653
+ #
654
+ # An Update Message operation will fail if the specified message does not exist in the queue, or if the
655
+ # specified pop receipt does not match the message.
656
+ #
657
+ # A pop receipt is returned by the Get Messages operation or the Update Message operation. Pop receipts
658
+ # remain valid until one of the following events occurs:
659
+ #
660
+ # * The message has expired.
661
+ #
662
+ # * The message has been deleted using the last pop receipt received either from Get Messages or
663
+ # Update Message.
664
+ #
665
+ # * The invisibility time has elapsed and the message has been dequeued by a Get Messages request. When
666
+ # the invisibility time elapses, the message becomes visible again. If it is retrieved by another
667
+ # Get Messages request, the returned pop receipt can be used to delete or update the message.
668
+ #
669
+ # * The message has been updated with a new visibility timeout. When the message is updated, a new pop
670
+ # receipt will be returned.
671
+ #
672
+ # The Update Message operation can be used to continually extend the invisibility of a queue message. This
673
+ # functionality can be useful if you want a worker role to "lease" a queue message. For example, if a worker
674
+ # role calls Get Messages and recognizes that it needs more time to process a message, it can continually
675
+ # extend the message's invisibility until it is processed. If the worker role were to fail during processing,
676
+ # eventually the message would become visible again and another worker role could process it.
677
+ #
678
+ def update_message(queue_name, message_id, pop_receipt, message_text, visibility_timeout, options = {})
679
+ query = { "visibilitytimeout" => visibility_timeout.to_s, "popreceipt" => pop_receipt }
680
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
681
+
682
+ uri = message_uri(queue_name, message_id, query)
683
+ body = Serialization.message_to_xml(message_text, options[:encode])
684
+
685
+ response = call(:put, uri, body, {}, options)
686
+ new_pop_receipt = response.headers["x-ms-popreceipt"]
687
+ time_next_visible = response.headers["x-ms-time-next-visible"]
688
+ return new_pop_receipt, time_next_visible
689
+ end
690
+
691
+ # Protected: Generate the URI for the collection of queues.
692
+ #
693
+ # ==== Attributes
694
+ #
695
+ # * +query+ - A Hash of query parameters (default: {}).
696
+ #
697
+ # Returns a URI.
698
+ protected
699
+ def collection_uri(query = {}, options = {})
700
+ query.update(comp: "list", include: "metadata")
701
+ generate_uri("", query, options)
702
+ end
703
+
704
+ # Protected: Generate the URI for a given queue.
705
+ #
706
+ # ==== Attributes
707
+ #
708
+ # * +queue_name+ - The name of the queue.
709
+ # * +query+ - A Hash of query parameters (default: {}).
710
+ #
711
+ # Returns a URI.
712
+ protected
713
+ def queue_uri(queue_name, query = {}, options = {})
714
+ return queue_name if queue_name.kind_of? ::URI
715
+ generate_uri(queue_name, query, options)
716
+ end
717
+
718
+ # Protected: Generate the messages URI for the given queue.
719
+ #
720
+ # ==== Attributes
721
+ #
722
+ # * +queue_name+ - The name of the queue.
723
+ # * +query+ - A Hash of query parameters (default: {}).
724
+ #
725
+ # Returns a URI.
726
+ protected
727
+ def messages_uri(queue_name, query = {}, options = {})
728
+ generate_uri("#{queue_name}/messages", query, options)
729
+ end
730
+
731
+ # Protected: Generate the URI for a given message
732
+ #
733
+ # ==== Attributes
734
+ #
735
+ # * +queue_name+ - The name of the queue.
736
+ # * +message_id+ - The id of the message.
737
+ # * +query+ - A Hash of query parameters (default: {}).
738
+ #
739
+ # Returns a URI.
740
+ protected
741
+ def message_uri(queue_name, message_id, query = {}, options = {})
742
+ generate_uri("#{queue_name}/messages/#{message_id}", query, options)
743
+ end
744
+
745
+ protected
746
+ def call(method, uri, body = nil, headers = {}, options = {})
747
+ headers["x-ms-version"] = @api_version ? @api_version : Default::STG_VERSION
748
+ headers["User-Agent"] = @user_agent_prefix ? "#{@user_agent_prefix}; #{Default::USER_AGENT}" : Default::USER_AGENT
749
+ super
750
+ end
751
+ end
752
+ end
753
+ end
754
+
755
+ Azure::Storage::QueueService = Azure::Storage::Queue::QueueService