azure 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +11 -11
- data/.travis.yml +11 -33
- data/ChangeLog.txt +20 -5
- data/Gemfile +15 -15
- data/README.md +541 -537
- data/Rakefile +129 -127
- data/azure.gemspec +43 -42
- data/lib/azure.rb +52 -51
- data/lib/azure/base_management/affinity_group.rb +32 -32
- data/lib/azure/base_management/base_management_service.rb +234 -234
- data/lib/azure/base_management/location.rb +27 -27
- data/lib/azure/base_management/management_http_request.rb +171 -148
- data/lib/azure/base_management/serialization.rb +129 -129
- data/lib/azure/base_management/sql_management_http_request.rb +45 -0
- data/lib/azure/blob/blob.rb +31 -31
- data/lib/azure/blob/blob_service.rb +1423 -1423
- data/lib/azure/blob/block.rb +30 -30
- data/lib/azure/blob/container.rb +31 -31
- data/lib/azure/blob/serialization.rb +284 -284
- data/lib/azure/cloud_service_management/cloud_service.rb +38 -31
- data/lib/azure/cloud_service_management/cloud_service_management_service.rb +134 -125
- data/lib/azure/cloud_service_management/serialization.rb +101 -63
- data/lib/azure/core.rb +39 -36
- data/lib/azure/core/auth/authorizer.rb +36 -36
- data/lib/azure/core/auth/shared_key.rb +110 -110
- data/lib/azure/core/auth/shared_key_lite.rb +48 -48
- data/lib/azure/core/auth/signer.rb +48 -48
- data/lib/azure/core/configuration.rb +211 -184
- data/lib/azure/core/error.rb +22 -22
- data/lib/azure/core/filtered_service.rb +43 -43
- data/lib/azure/core/http/debug_filter.rb +35 -35
- data/lib/azure/core/http/http_error.rb +88 -88
- data/lib/azure/core/http/http_filter.rb +52 -52
- data/lib/azure/core/http/http_request.rb +157 -157
- data/lib/azure/core/http/http_response.rb +140 -140
- data/lib/azure/core/http/retry_policy.rb +73 -73
- data/lib/azure/core/http/signer_filter.rb +33 -33
- data/lib/azure/core/service.rb +62 -62
- data/lib/azure/core/signed_service.rb +42 -42
- data/lib/azure/core/utility.rb +190 -190
- data/lib/azure/queue/message.rb +29 -29
- data/lib/azure/queue/queue.rb +28 -28
- data/lib/azure/queue/queue_service.rb +567 -567
- data/lib/azure/queue/serialization.rb +106 -106
- data/lib/azure/service/access_policy.rb +25 -25
- data/lib/azure/service/enumeration_results.rb +20 -20
- data/lib/azure/service/logging.rb +31 -31
- data/lib/azure/service/metrics.rb +30 -30
- data/lib/azure/service/retention_policy.rb +24 -24
- data/lib/azure/service/serialization.rb +239 -239
- data/lib/azure/service/signed_identifier.rb +29 -29
- data/lib/azure/service/storage_service.rb +78 -78
- data/lib/azure/service/storage_service_properties.rb +31 -31
- data/lib/azure/service_bus/action.rb +21 -21
- data/lib/azure/service_bus/auth/wrap_service.rb +88 -88
- data/lib/azure/service_bus/auth/wrap_signer.rb +68 -68
- data/lib/azure/service_bus/brokered_message.rb +123 -123
- data/lib/azure/service_bus/brokered_message_serializer.rb +159 -159
- data/lib/azure/service_bus/correlation_filter.rb +45 -45
- data/lib/azure/service_bus/empty_rule_action.rb +29 -29
- data/lib/azure/service_bus/false_filter.rb +38 -38
- data/lib/azure/service_bus/filter.rb +21 -21
- data/lib/azure/service_bus/interval.rb +103 -103
- data/lib/azure/service_bus/queue.rb +229 -229
- data/lib/azure/service_bus/resource.rb +108 -108
- data/lib/azure/service_bus/rule.rb +97 -97
- data/lib/azure/service_bus/rule_aspect.rb +34 -34
- data/lib/azure/service_bus/serialization.rb +160 -160
- data/lib/azure/service_bus/service_bus_service.rb +828 -828
- data/lib/azure/service_bus/sql_filter.rb +50 -50
- data/lib/azure/service_bus/sql_rule_action.rb +50 -50
- data/lib/azure/service_bus/subscription.rb +183 -183
- data/lib/azure/service_bus/topic.rb +186 -186
- data/lib/azure/service_bus/true_filter.rb +38 -38
- data/lib/azure/sql_database_management/serialization.rb +111 -90
- data/lib/azure/sql_database_management/sql_database.rb +31 -31
- data/lib/azure/sql_database_management/sql_database_management_service.rb +200 -202
- data/lib/azure/storage_management/serialization.rb +190 -50
- data/lib/azure/storage_management/storage_account.rb +40 -29
- data/lib/azure/storage_management/storage_management_service.rb +166 -99
- data/lib/azure/table/auth/shared_key.rb +92 -92
- data/lib/azure/table/auth/shared_key_lite.rb +44 -44
- data/lib/azure/table/batch.rb +329 -329
- data/lib/azure/table/batch_response.rb +118 -118
- data/lib/azure/table/edmtype.rb +126 -126
- data/lib/azure/table/entity.rb +30 -30
- data/lib/azure/table/guid.rb +23 -23
- data/lib/azure/table/query.rb +111 -111
- data/lib/azure/table/serialization.rb +107 -107
- data/lib/azure/table/table_service.rb +559 -559
- data/lib/azure/version.rb +30 -30
- data/lib/azure/virtual_machine_image_management/serialization.rb +49 -49
- data/lib/azure/virtual_machine_image_management/virtual_machine_disk.rb +27 -27
- data/lib/azure/virtual_machine_image_management/virtual_machine_image.rb +27 -27
- data/lib/azure/virtual_machine_image_management/virtual_machine_image_management_service.rb +66 -66
- data/lib/azure/virtual_machine_management/serialization.rb +257 -247
- data/lib/azure/virtual_machine_management/virtual_machine.rb +41 -57
- data/lib/azure/virtual_machine_management/virtual_machine_management_service.rb +317 -304
- data/lib/azure/virtual_network_management/serialization.rb +186 -186
- data/lib/azure/virtual_network_management/virtual_network.rb +36 -36
- data/lib/azure/virtual_network_management/virtual_network_management_service.rb +109 -109
- data/test/fixtures/affinity_group.xml +33 -33
- data/test/fixtures/all_containers.xml +20 -20
- data/test/fixtures/all_tables.xml +22 -22
- data/test/fixtures/certificate.pem +21 -21
- data/test/fixtures/container_acl.xml +11 -11
- data/test/fixtures/create_sql_database_server.xml +1 -1
- data/test/fixtures/create_storage_desc_error.xml +5 -0
- data/test/fixtures/create_storage_extendedprop_error.xml +8 -0
- data/test/fixtures/create_storage_extendedpropname_error.xml +6 -0
- data/test/fixtures/create_storage_full_error.xml +6 -0
- data/test/fixtures/create_storage_label_error.xml +5 -0
- data/test/fixtures/create_storage_location_error.xml +5 -0
- data/test/fixtures/create_storage_name_error.xml +6 -0
- data/test/fixtures/create_table_response_entry.xml +15 -15
- data/test/fixtures/delete_storage_container_error.xml +5 -0
- data/test/fixtures/delete_storage_error.xml +5 -0
- data/test/fixtures/deployment_error.xml +5 -5
- data/test/fixtures/get_storage_account_error.xml +5 -0
- data/test/fixtures/get_storage_account_properties.xml +32 -0
- data/test/fixtures/get_storage_account_properties_new.xml +32 -0
- data/test/fixtures/http_error.xml +5 -5
- data/test/fixtures/insert_entity_response_entry.xml +25 -25
- data/test/fixtures/list_affinity_groups.xml +22 -22
- data/test/fixtures/list_blobs.xml +120 -120
- data/test/fixtures/list_block_all_with_none_committed.xml +21 -21
- data/test/fixtures/list_blocks_all.xml +22 -22
- data/test/fixtures/list_blocks_committed.xml +12 -12
- data/test/fixtures/list_cloud_services.xml +38 -28
- data/test/fixtures/list_containers.xml +37 -37
- data/test/fixtures/list_firewall_management_endpoint.xml +27 -0
- data/test/fixtures/list_images.xml +110 -110
- data/test/fixtures/list_locations.xml +62 -62
- data/test/fixtures/list_page_ranges.xml +10 -10
- data/test/fixtures/list_sql_database.xml +36 -36
- data/test/fixtures/list_sql_server_firewall.xml +23 -23
- data/test/fixtures/list_storage_accounts.xml +45 -45
- data/test/fixtures/list_virtual_networks.xml +92 -92
- data/test/fixtures/logging.xml +11 -11
- data/test/fixtures/management_certificate.pem +55 -55
- data/test/fixtures/messages.xml +12 -12
- data/test/fixtures/metrics.xml +10 -10
- data/test/fixtures/privatekey.key +28 -28
- data/test/fixtures/query_entities_empty_response.xml +7 -7
- data/test/fixtures/query_entities_response.xml +45 -45
- data/test/fixtures/queue_service_properties.xml +22 -22
- data/test/fixtures/queue_service_properties_original.xml +19 -19
- data/test/fixtures/queues.xml +16 -16
- data/test/fixtures/retention_policy.xml +5 -5
- data/test/fixtures/sb_default_create_queue_response.xml +23 -23
- data/test/fixtures/sb_default_create_topic_response.xml +18 -18
- data/test/fixtures/sb_get_access_token_response.txt +1 -1
- data/test/fixtures/sb_queues_runtime_peek_message_response_headers.txt +9 -9
- data/test/fixtures/storage_service_properties.xml +23 -23
- data/test/fixtures/update_storage_account.xml +16 -0
- data/test/fixtures/update_storage_error.xml +5 -0
- data/test/fixtures/updated_storage_accounts.xml +53 -0
- data/test/fixtures/virtual_machine.xml +108 -107
- data/test/fixtures/windows_virtual_machine.xml +106 -106
- data/test/integration/affinity_group/Affinity_test.rb +55 -55
- data/test/integration/affinity_group/Create_Affinity_test.rb +63 -63
- data/test/integration/affinity_group/Delete_Affinity_test.rb +56 -56
- data/test/integration/affinity_group/List_Affinity_test.rb +41 -41
- data/test/integration/affinity_group/Update_Affinity_test.rb +82 -82
- data/test/integration/blob/blob_gb18030_test.rb +199 -199
- data/test/integration/blob/blob_metadata_test.rb +75 -75
- data/test/integration/blob/blob_pages_test.rb +119 -119
- data/test/integration/blob/blob_properties_test.rb +77 -77
- data/test/integration/blob/block_blob_test.rb +254 -254
- data/test/integration/blob/container/container_acl_test.rb +69 -69
- data/test/integration/blob/container/container_metadata_test.rb +50 -50
- data/test/integration/blob/container/create_container_test.rb +60 -60
- data/test/integration/blob/container/delete_container_test.rb +39 -39
- data/test/integration/blob/container/get_container_properties_test.rb +48 -48
- data/test/integration/blob/container/list_containers_test.rb +79 -79
- data/test/integration/blob/container/root_container_test.rb +53 -53
- data/test/integration/blob/copy_blob_test.rb +113 -113
- data/test/integration/blob/create_blob_snapshot_test.rb +80 -80
- data/test/integration/blob/create_page_blob_test.rb +83 -83
- data/test/integration/blob/delete_blob_test.rb +159 -159
- data/test/integration/blob/get_blob_test.rb +65 -65
- data/test/integration/blob/informative_errors_test.rb +38 -38
- data/test/integration/blob/lease/acquire_lease_test.rb +36 -36
- data/test/integration/blob/lease/break_lease_test.rb +40 -40
- data/test/integration/blob/lease/release_lease_test.rb +40 -40
- data/test/integration/blob/lease/renew_lease_test.rb +42 -42
- data/test/integration/blob/list_blobs_test.rb +113 -113
- data/test/integration/database/create_sql_server_firewall_test.rb +86 -86
- data/test/integration/database/create_sql_server_test.rb +53 -57
- data/test/integration/database/delete_sql_server_firewall_test.rb +70 -72
- data/test/integration/database/delete_sql_server_test.rb +58 -63
- data/test/integration/database/list_sql_server_firewall_test.rb +45 -46
- data/test/integration/database/list_sql_servers_test.rb +44 -45
- data/test/integration/database/reset_password_sql_server_test.rb +55 -56
- data/test/integration/location/Location_List_test.rb +39 -39
- data/test/integration/queue/clear_messages_test.rb +42 -42
- data/test/integration/queue/create_message_test.rb +75 -75
- data/test/integration/queue/create_queue_test.rb +50 -50
- data/test/integration/queue/delete_message_test.rb +67 -67
- data/test/integration/queue/delete_queue_test.rb +45 -45
- data/test/integration/queue/informative_errors_test.rb +41 -41
- data/test/integration/queue/list_messages_encoded_test.rb +79 -79
- data/test/integration/queue/list_messages_test.rb +79 -79
- data/test/integration/queue/list_queues_test.rb +44 -44
- data/test/integration/queue/peek_messages_test.rb +59 -59
- data/test/integration/queue/queue_gb18030_test.rb +131 -131
- data/test/integration/queue/queue_metadata_test.rb +40 -40
- data/test/integration/queue/update_message_test.rb +74 -74
- data/test/integration/service_bus/informative_errors_test.rb +36 -36
- data/test/integration/service_bus/queues_scenario_test.rb +200 -200
- data/test/integration/service_bus/queues_test.rb +265 -265
- data/test/integration/service_bus/rules_test.rb +144 -144
- data/test/integration/service_bus/sb_queue_gb18030_test.rb +182 -182
- data/test/integration/service_bus/scenario_test.rb +101 -101
- data/test/integration/service_bus/subscriptions_test.rb +211 -211
- data/test/integration/service_bus/topics_scenario_test.rb +406 -406
- data/test/integration/service_bus/topics_test.rb +129 -129
- data/test/integration/storage_management/storage_management_test.rb +160 -0
- data/test/integration/table/create_table_test.rb +35 -35
- data/test/integration/table/delete_entity_batch_test.rb +106 -106
- data/test/integration/table/delete_entity_test.rb +93 -93
- data/test/integration/table/delete_table_test.rb +39 -39
- data/test/integration/table/get_table_test.rb +36 -36
- data/test/integration/table/informative_errors_test.rb +38 -38
- data/test/integration/table/insert_entity_batch_test.rb +99 -99
- data/test/integration/table/insert_entity_test.rb +87 -87
- data/test/integration/table/insert_or_merge_entity_batch_test.rb +158 -158
- data/test/integration/table/insert_or_merge_entity_test.rb +142 -142
- data/test/integration/table/insert_or_replace_entity_batch_test.rb +151 -151
- data/test/integration/table/insert_or_replace_entity_test.rb +136 -136
- data/test/integration/table/merge_entity_batch_test.rb +127 -127
- data/test/integration/table/merge_entity_test.rb +112 -112
- data/test/integration/table/query_entities_test.rb +194 -194
- data/test/integration/table/query_tables_test.rb +42 -42
- data/test/integration/table/query_test.rb +250 -250
- data/test/integration/table/table_acl_test.rb +51 -51
- data/test/integration/table/table_gb18030_test.rb +355 -355
- data/test/integration/table/update_entity_batch_test.rb +148 -148
- data/test/integration/table/update_entity_test.rb +130 -130
- data/test/integration/test_helper.rb +42 -44
- data/test/integration/vm/VM_Create_test.rb +213 -235
- data/test/integration/vm/VM_Delete_test.rb +55 -55
- data/test/integration/vm/VM_List_test.rb +71 -71
- data/test/integration/vm/VM_ShutDown_test.rb +59 -59
- data/test/integration/vm_image/virtual_machine_disk_test.rb +37 -37
- data/test/integration/vm_image/virtual_machine_image_test.rb +36 -36
- data/test/integration/vnet/Virtual_Network_Create_test.rb +122 -122
- data/test/integration/vnet/Virtual_Network_list_test.rb +53 -53
- data/test/support/env.rb +19 -19
- data/test/support/fixtures.rb +36 -36
- data/test/support/name_generator.rb +160 -160
- data/test/support/stubs.rb +42 -42
- data/test/support/virtual_machine_name_generator.rb +117 -127
- data/test/support/virtual_network_helper.rb +73 -73
- data/test/test_helper.rb +52 -52
- data/test/unit/affinity_group/affinity_group_test.rb +192 -192
- data/test/unit/affinity_group/serialization_test.rb +88 -88
- data/test/unit/base_management/location_test.rb +57 -57
- data/test/unit/blob/blob_service_test.rb +1946 -1946
- data/test/unit/cloud_service_management/cloud_service_management_service_test.rb +94 -94
- data/test/unit/cloud_service_management/serialization_test.rb +169 -76
- data/test/unit/core/auth/shared_key_lite_test.rb +51 -51
- data/test/unit/core/auth/shared_key_test.rb +58 -58
- data/test/unit/core/auth/signer_test.rb +30 -30
- data/test/unit/core/http/http_error_test.rb +57 -57
- data/test/unit/core/http/http_request_test.rb +66 -66
- data/test/unit/core/http/http_response_test.rb +45 -45
- data/test/unit/core/http/retry_policy_test.rb +23 -23
- data/test/unit/database/serialization_test.rb +97 -95
- data/test/unit/database/sql_database_server_service_test.rb +288 -152
- data/test/unit/service/serialization_test.rb +501 -501
- data/test/unit/service/storage_service_test.rb +290 -290
- data/test/unit/storage_management/serialization_test.rb +232 -65
- data/test/unit/storage_management/storage_management_service_test.rb +233 -94
- data/test/unit/table/edmtype_test.rb +107 -107
- data/test/unit/virtual_machine_image_management/serialization_test.rb +34 -34
- data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb +60 -60
- data/test/unit/virtual_machine_management/serialization_test.rb +119 -116
- data/test/unit/virtual_machine_management/virtual_machine_management_service_test.rb +383 -386
- data/test/unit/vnet/serialization_test.rb +187 -187
- data/test/unit/vnet/virtual_network_management_service_test.rb +131 -131
- metadata +55 -23
@@ -1,160 +1,160 @@
|
|
1
|
-
#-------------------------------------------------------------------------
|
2
|
-
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
#--------------------------------------------------------------------------
|
15
|
-
require 'nokogiri'
|
16
|
-
|
17
|
-
require "azure/service_bus/queue"
|
18
|
-
require "azure/service_bus/topic"
|
19
|
-
require "azure/service_bus/subscription"
|
20
|
-
require "azure/service_bus/rule"
|
21
|
-
|
22
|
-
require "azure/service/enumeration_results"
|
23
|
-
|
24
|
-
module Azure
|
25
|
-
module ServiceBus
|
26
|
-
module Serialization
|
27
|
-
module ClassMethods
|
28
|
-
|
29
|
-
def rule_to_xml(xml, rule)
|
30
|
-
rule_aspect_to_xml xml, 'Filter', rule if rule.filter
|
31
|
-
rule_aspect_to_xml xml, 'Action', rule if rule.action
|
32
|
-
end
|
33
|
-
|
34
|
-
def rule_aspect_to_xml(xml, aspect_name, rule)
|
35
|
-
aspect = rule.description[aspect_name].dup
|
36
|
-
xml.send(aspect_name, "i:type" => aspect.delete(:type)) {
|
37
|
-
aspect.each { |k,v|
|
38
|
-
if k == :sql_expression
|
39
|
-
k = "SqlExpression"
|
40
|
-
elsif k == :compatibility_level
|
41
|
-
k = "CompatibilityLevel"
|
42
|
-
elsif k == :correlation_id
|
43
|
-
k = "CorrelationId"
|
44
|
-
end
|
45
|
-
|
46
|
-
xml.send(k, v)
|
47
|
-
}
|
48
|
-
}
|
49
|
-
end
|
50
|
-
|
51
|
-
def resource_to_xml(resource, entry)
|
52
|
-
doc = Nokogiri::XML::Builder.new(:encoding => "UTF-8") do |xml|
|
53
|
-
xml.entry(:xmlns => 'http://www.w3.org/2005/Atom') {
|
54
|
-
xml.content(:type => 'application/xml') {
|
55
|
-
xml.send("#{resource.to_s.capitalize}Description", 'xmlns' => 'http://schemas.microsoft.com/netservices/2010/10/servicebus/connect', 'xmlns:i' => 'http://www.w3.org/2001/XMLSchema-instance') {
|
56
|
-
if resource == :rule
|
57
|
-
rule_to_xml xml, entry
|
58
|
-
else
|
59
|
-
entry.get_props.each do |p|
|
60
|
-
xml.send(p[0], p[1].to_s)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
}
|
64
|
-
}
|
65
|
-
}
|
66
|
-
end
|
67
|
-
doc.to_xml
|
68
|
-
end
|
69
|
-
|
70
|
-
def resource_from_xml(resource, node)
|
71
|
-
resource = resource.to_s.capitalize
|
72
|
-
|
73
|
-
name = (node % "title").text
|
74
|
-
|
75
|
-
Azure::ServiceBus.const_get(resource).new(name) do |r|
|
76
|
-
r.id = URI((node % "id").text) if (node % "id")
|
77
|
-
r.published = Time.parse((node % "published").text) if (node % "published")
|
78
|
-
r.updated = Time.parse((node % "updated").text) if (node % "updated")
|
79
|
-
r.author_name = (node % "author/name").text if (node % "author/name")
|
80
|
-
|
81
|
-
r.description = (node / "content/#{resource}Description *").each_with_object({}) do |element, description|
|
82
|
-
if resource == "Rule"
|
83
|
-
handle_rule_description_element element, description
|
84
|
-
else
|
85
|
-
description[element.name] = element.text
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def handle_rule_description_element(element, description)
|
92
|
-
if element.name == "Filter" or element.name == "Action"
|
93
|
-
value = {}
|
94
|
-
value[:type] = element["type"]
|
95
|
-
element.children.each do |child|
|
96
|
-
if child.name == "SqlExpression"
|
97
|
-
value[:sql_expression] = child.content
|
98
|
-
elsif child.name == "CompatibilityLevel"
|
99
|
-
value[:compatibility_level] = child.content
|
100
|
-
elsif child.name == "CorrelationId"
|
101
|
-
value[:correlation_id] = child.content
|
102
|
-
end
|
103
|
-
end
|
104
|
-
description[element.name] = value
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def resources_from_xml(resource, xml)
|
109
|
-
feed = Nokogiri::XML(xml).remove_namespaces!
|
110
|
-
values = (feed / 'entry').map {|node| resource_from_xml(resource, node) }
|
111
|
-
values.class.module_eval { attr_accessor :next_link}
|
112
|
-
values.next_link = feed.xpath("//link[@rel='next']/@href")
|
113
|
-
values
|
114
|
-
end
|
115
|
-
|
116
|
-
def resources_from_xml_with_next_link(resource, xml)
|
117
|
-
feed = Nokogiri::XML(xml).remove_namespaces!
|
118
|
-
values = Azure::Service::EnumerationResults.new((feed / 'entry').map {|node| resource_from_xml(resource, node) })
|
119
|
-
|
120
|
-
next_token = nil
|
121
|
-
next_uri = feed.xpath("//link[@rel='next']/@href")
|
122
|
-
if next_uri != nil && next_uri.length > 0
|
123
|
-
u = URI.parse(next_uri.to_s)
|
124
|
-
p = CGI.parse(u.query)
|
125
|
-
|
126
|
-
if p['skip'] || p['top']
|
127
|
-
next_token = { }
|
128
|
-
next_token[:top] = p['top'] if p['top']
|
129
|
-
next_token[:skip] = p['skip'] if p['skip']
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
values.continuation_token = next_token
|
134
|
-
values
|
135
|
-
end
|
136
|
-
|
137
|
-
def to_bool(s)
|
138
|
-
(s || "").downcase == 'true'
|
139
|
-
end
|
140
|
-
|
141
|
-
def slopify(xml)
|
142
|
-
node = (xml.is_a? String) ? Nokogiri.Slop(xml).root : xml
|
143
|
-
node.slop! if node.is_a? Nokogiri::XML::Document unless node.respond_to? :method_missing
|
144
|
-
node = node.root if node.is_a? Nokogiri::XML::Document
|
145
|
-
node
|
146
|
-
end
|
147
|
-
|
148
|
-
def expect_node(node_name, xml)
|
149
|
-
raise "Xml is not a #{node_name} node." unless xml.name == node_name
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
extend ClassMethods
|
154
|
-
|
155
|
-
def self.included( other )
|
156
|
-
other.extend( ClassMethods )
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
1
|
+
#-------------------------------------------------------------------------
|
2
|
+
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
#--------------------------------------------------------------------------
|
15
|
+
require 'nokogiri'
|
16
|
+
|
17
|
+
require "azure/service_bus/queue"
|
18
|
+
require "azure/service_bus/topic"
|
19
|
+
require "azure/service_bus/subscription"
|
20
|
+
require "azure/service_bus/rule"
|
21
|
+
|
22
|
+
require "azure/service/enumeration_results"
|
23
|
+
|
24
|
+
module Azure
|
25
|
+
module ServiceBus
|
26
|
+
module Serialization
|
27
|
+
module ClassMethods
|
28
|
+
|
29
|
+
def rule_to_xml(xml, rule)
|
30
|
+
rule_aspect_to_xml xml, 'Filter', rule if rule.filter
|
31
|
+
rule_aspect_to_xml xml, 'Action', rule if rule.action
|
32
|
+
end
|
33
|
+
|
34
|
+
def rule_aspect_to_xml(xml, aspect_name, rule)
|
35
|
+
aspect = rule.description[aspect_name].dup
|
36
|
+
xml.send(aspect_name, "i:type" => aspect.delete(:type)) {
|
37
|
+
aspect.each { |k,v|
|
38
|
+
if k == :sql_expression
|
39
|
+
k = "SqlExpression"
|
40
|
+
elsif k == :compatibility_level
|
41
|
+
k = "CompatibilityLevel"
|
42
|
+
elsif k == :correlation_id
|
43
|
+
k = "CorrelationId"
|
44
|
+
end
|
45
|
+
|
46
|
+
xml.send(k, v)
|
47
|
+
}
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def resource_to_xml(resource, entry)
|
52
|
+
doc = Nokogiri::XML::Builder.new(:encoding => "UTF-8") do |xml|
|
53
|
+
xml.entry(:xmlns => 'http://www.w3.org/2005/Atom') {
|
54
|
+
xml.content(:type => 'application/xml') {
|
55
|
+
xml.send("#{resource.to_s.capitalize}Description", 'xmlns' => 'http://schemas.microsoft.com/netservices/2010/10/servicebus/connect', 'xmlns:i' => 'http://www.w3.org/2001/XMLSchema-instance') {
|
56
|
+
if resource == :rule
|
57
|
+
rule_to_xml xml, entry
|
58
|
+
else
|
59
|
+
entry.get_props.each do |p|
|
60
|
+
xml.send(p[0], p[1].to_s)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
end
|
67
|
+
doc.to_xml
|
68
|
+
end
|
69
|
+
|
70
|
+
def resource_from_xml(resource, node)
|
71
|
+
resource = resource.to_s.capitalize
|
72
|
+
|
73
|
+
name = (node % "title").text
|
74
|
+
|
75
|
+
Azure::ServiceBus.const_get(resource).new(name) do |r|
|
76
|
+
r.id = URI((node % "id").text) if (node % "id")
|
77
|
+
r.published = Time.parse((node % "published").text) if (node % "published")
|
78
|
+
r.updated = Time.parse((node % "updated").text) if (node % "updated")
|
79
|
+
r.author_name = (node % "author/name").text if (node % "author/name")
|
80
|
+
|
81
|
+
r.description = (node / "content/#{resource}Description *").each_with_object({}) do |element, description|
|
82
|
+
if resource == "Rule"
|
83
|
+
handle_rule_description_element element, description
|
84
|
+
else
|
85
|
+
description[element.name] = element.text
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def handle_rule_description_element(element, description)
|
92
|
+
if element.name == "Filter" or element.name == "Action"
|
93
|
+
value = {}
|
94
|
+
value[:type] = element["type"]
|
95
|
+
element.children.each do |child|
|
96
|
+
if child.name == "SqlExpression"
|
97
|
+
value[:sql_expression] = child.content
|
98
|
+
elsif child.name == "CompatibilityLevel"
|
99
|
+
value[:compatibility_level] = child.content
|
100
|
+
elsif child.name == "CorrelationId"
|
101
|
+
value[:correlation_id] = child.content
|
102
|
+
end
|
103
|
+
end
|
104
|
+
description[element.name] = value
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def resources_from_xml(resource, xml)
|
109
|
+
feed = Nokogiri::XML(xml).remove_namespaces!
|
110
|
+
values = (feed / 'entry').map {|node| resource_from_xml(resource, node) }
|
111
|
+
values.class.module_eval { attr_accessor :next_link}
|
112
|
+
values.next_link = feed.xpath("//link[@rel='next']/@href")
|
113
|
+
values
|
114
|
+
end
|
115
|
+
|
116
|
+
def resources_from_xml_with_next_link(resource, xml)
|
117
|
+
feed = Nokogiri::XML(xml).remove_namespaces!
|
118
|
+
values = Azure::Service::EnumerationResults.new((feed / 'entry').map {|node| resource_from_xml(resource, node) })
|
119
|
+
|
120
|
+
next_token = nil
|
121
|
+
next_uri = feed.xpath("//link[@rel='next']/@href")
|
122
|
+
if next_uri != nil && next_uri.length > 0
|
123
|
+
u = URI.parse(next_uri.to_s)
|
124
|
+
p = CGI.parse(u.query)
|
125
|
+
|
126
|
+
if p['skip'] || p['top']
|
127
|
+
next_token = { }
|
128
|
+
next_token[:top] = p['top'] if p['top']
|
129
|
+
next_token[:skip] = p['skip'] if p['skip']
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
values.continuation_token = next_token
|
134
|
+
values
|
135
|
+
end
|
136
|
+
|
137
|
+
def to_bool(s)
|
138
|
+
(s || "").downcase == 'true'
|
139
|
+
end
|
140
|
+
|
141
|
+
def slopify(xml)
|
142
|
+
node = (xml.is_a? String) ? Nokogiri.Slop(xml).root : xml
|
143
|
+
node.slop! if node.is_a? Nokogiri::XML::Document unless node.respond_to? :method_missing
|
144
|
+
node = node.root if node.is_a? Nokogiri::XML::Document
|
145
|
+
node
|
146
|
+
end
|
147
|
+
|
148
|
+
def expect_node(node_name, xml)
|
149
|
+
raise "Xml is not a #{node_name} node." unless xml.name == node_name
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
extend ClassMethods
|
154
|
+
|
155
|
+
def self.included( other )
|
156
|
+
other.extend( ClassMethods )
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -1,829 +1,829 @@
|
|
1
|
-
#-------------------------------------------------------------------------
|
2
|
-
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
#--------------------------------------------------------------------------
|
15
|
-
require 'azure/core/signed_service'
|
16
|
-
require 'azure/service_bus/auth/wrap_signer'
|
17
|
-
require 'azure/service_bus/serialization'
|
18
|
-
|
19
|
-
require 'azure/service_bus/brokered_message_serializer'
|
20
|
-
require 'azure/core/http/http_response'
|
21
|
-
|
22
|
-
module Azure
|
23
|
-
module ServiceBus
|
24
|
-
class ServiceBusService < Azure::Core::SignedService
|
25
|
-
|
26
|
-
DEFAULT_TIMEOUT = 60
|
27
|
-
|
28
|
-
def initialize(host=Azure.config.service_bus_host)
|
29
|
-
super(Azure::ServiceBus::Auth::WrapSigner.new)
|
30
|
-
@host = host
|
31
|
-
|
32
|
-
with_filter do |req, res|
|
33
|
-
req.headers.delete "x-ms-date"
|
34
|
-
req.headers.delete "x-ms-version"
|
35
|
-
req.headers.delete "DataServiceVersion"
|
36
|
-
req.headers.delete "MaxDataServiceVersion"
|
37
|
-
res.call
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# Creates a new queue. Once created, this queue's resource manifest is immutable.
|
42
|
-
#
|
43
|
-
# ==== Attributes
|
44
|
-
#
|
45
|
-
# * +queue+ - Azure::ServiceBus::Queue instance to create on server, or a string of the queue name
|
46
|
-
# * +options+ - Hash. The queue properties.
|
47
|
-
#
|
48
|
-
# ==== Options
|
49
|
-
#
|
50
|
-
# Accepted key/value pairs in options parameter are:
|
51
|
-
# * +:default_message_time_to_live+ - XML datetime. Determines how long a message lives in the associated subscriptions.
|
52
|
-
# * +:duplicate_detection_history_time_window+ - XML datetime. Specifies the time span during which the Service Bus will detect message duplication.
|
53
|
-
# * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
|
54
|
-
# * +:dead_lettering_on_message_expiration:+ - Boolean. This field controls how the Service Bus handles a message whose TTL has expired.
|
55
|
-
# * +:lock_duration+ - XML datetime. Determines the amount of time in seconds in which a message should be locked for processing by a receiver.
|
56
|
-
# * +:max_delivery_count+ - Number. A message is automatically deadlettered after this number of deliveries.
|
57
|
-
# * +:max_size_in_megabytes+ - Number. Specifies the maximum topic size in megabytes
|
58
|
-
# * +:message_count+ - Number. Displays the number of messages currently in the queue.
|
59
|
-
# * +:requires_duplicate_detection+ - Boolean. If enabled, the topic will detect duplicate messages within the time span specified by the DuplicateDetectionHistoryTimeWindow property
|
60
|
-
# * +:requires_session+ - Boolean. If set to true, the queue will be session-aware and only SessionReceiver will be supported.
|
61
|
-
# * +:size_in_bytes+ - Number. Reflects the actual bytes toward the topic quota that messages in the topic currently occupy.
|
62
|
-
#
|
63
|
-
def create_queue(queue, options={})
|
64
|
-
queue = _new_or_existing(Azure::ServiceBus::Queue, queue, options ? options : {})
|
65
|
-
create_resource_entry(:queue, queue, queue.name)
|
66
|
-
end
|
67
|
-
|
68
|
-
# Deletes an existing queue. This operation will also remove all associated state
|
69
|
-
# including messages in the queue.
|
70
|
-
#
|
71
|
-
# ==== Attributes
|
72
|
-
#
|
73
|
-
# * +queue+ - Azure::ServiceBus::Queue instance to delete or a string of the queue name
|
74
|
-
def delete_queue(queue)
|
75
|
-
delete_resource_entry(:queue, _name_for(queue))
|
76
|
-
end
|
77
|
-
|
78
|
-
# Retrieves an existing queue.
|
79
|
-
#
|
80
|
-
# ==== Attributes
|
81
|
-
#
|
82
|
-
# * +queue+ - Azure::ServiceBus::Queue instance to retrieve or a string of the queue name
|
83
|
-
def get_queue(queue)
|
84
|
-
resource_entry(:queue, _name_for(queue))
|
85
|
-
end
|
86
|
-
|
87
|
-
# Enumerates the queues in the service namespace.
|
88
|
-
#
|
89
|
-
# ==== Attributes
|
90
|
-
#
|
91
|
-
# * +options+ - Hash. Optional parameters.
|
92
|
-
#
|
93
|
-
# ==== Options
|
94
|
-
#
|
95
|
-
# Accepted key/value pairs in options parameter are:
|
96
|
-
# * +:skip+ - Integer. Number of queues to skip.
|
97
|
-
# * +:top+ - Integer. Number of queues to list.
|
98
|
-
def list_queues(options={})
|
99
|
-
query = {}
|
100
|
-
query["$skip"] = options[:skip].to_i.to_s if options[:skip]
|
101
|
-
query["$top"] = options[:top].to_i.to_s if options[:top]
|
102
|
-
|
103
|
-
resource_list(:queue, query)
|
104
|
-
end
|
105
|
-
|
106
|
-
# Creates a new topic. Once created, this topic resource manifest is immutable.
|
107
|
-
#
|
108
|
-
# ==== Attributes
|
109
|
-
#
|
110
|
-
# * +topic+ - Azure::ServiceBus::Topic instance to create on server, or a string of the topic name
|
111
|
-
# * +options+ - Hash. The topic properties.
|
112
|
-
#
|
113
|
-
# ==== Options
|
114
|
-
#
|
115
|
-
# Accepted key/value pairs in options parameter are:
|
116
|
-
# * +:default_message_time_to_tive+ - XML datetime. Determines how long a message lives in the associated subscriptions.
|
117
|
-
# * +:maximum_number_of_subscriptions+ - Number. Specifies the maximum number of subscriptions that can be associated with the topic.
|
118
|
-
# * +:max_size_in_megabytes+ - Number. Specifies the maximum topic size in megabytes
|
119
|
-
# * +:requires_duplicate_detection+ - Boolean. If enabled, the topic will detect duplicate messages within the time span specified by the DuplicateDetectionHistoryTimeWindow property
|
120
|
-
# * +:dead_lettering_on_filter_evaluation_exceptions+ - Boolean. Determines how the Service Bus handles a message that causes an exception during a subscription's filter evaluation.
|
121
|
-
# * +:duplicate_detection_history_time_window+ - XML datetime. Specifies the time span during which the Service Bus will detect message duplication.
|
122
|
-
# * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
|
123
|
-
#
|
124
|
-
def create_topic(topic, options={})
|
125
|
-
topic = _new_or_existing(Azure::ServiceBus::Topic, topic, options ? options : {})
|
126
|
-
create_resource_entry(:topic, topic, topic.name)
|
127
|
-
end
|
128
|
-
|
129
|
-
# Deletes an existing topic. This operation will also remove all associated state
|
130
|
-
# including associated subscriptions.
|
131
|
-
#
|
132
|
-
# ==== Attributes
|
133
|
-
#
|
134
|
-
# * +topic+ - Azure::ServiceBus::Topic instance to delete or a string of the topic name
|
135
|
-
def delete_topic(topic)
|
136
|
-
delete_resource_entry(:topic, _name_for(topic))
|
137
|
-
end
|
138
|
-
|
139
|
-
# Retrieves the description for the specified topic.
|
140
|
-
#
|
141
|
-
# ==== Attributes
|
142
|
-
#
|
143
|
-
# * +topic+ - Azure::ServiceBus::Topic instance to retrieve or a string of the topic name
|
144
|
-
def get_topic(topic)
|
145
|
-
resource_entry(:topic, _name_for(topic))
|
146
|
-
end
|
147
|
-
|
148
|
-
# Retrieves the topics in the service namespace.
|
149
|
-
#
|
150
|
-
# ==== Attributes
|
151
|
-
#
|
152
|
-
# * +options+ - Hash. Optional parameters.
|
153
|
-
#
|
154
|
-
# ==== Options
|
155
|
-
#
|
156
|
-
# Accepted key/value pairs in options parameter are:
|
157
|
-
# * +:skip+ - Integer. Number of topics to skip.
|
158
|
-
# * +:top+ - Integer. Number of topics to list.
|
159
|
-
def list_topics(options={})
|
160
|
-
query = {}
|
161
|
-
query["$skip"] = options[:skip].to_i.to_s if options[:skip]
|
162
|
-
query["$top"] = options[:top].to_i.to_s if options[:top]
|
163
|
-
|
164
|
-
resource_list(:topic, query)
|
165
|
-
end
|
166
|
-
|
167
|
-
# Creates a new rule. Once created, this rule's resource manifest is immutable.
|
168
|
-
#
|
169
|
-
# ==== Attributes
|
170
|
-
#
|
171
|
-
# Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a rule object.
|
172
|
-
# When using (topic_name, subscription_name, rule_name, options) overload, you may also pass the properties for the rule.
|
173
|
-
#
|
174
|
-
# ==== Options
|
175
|
-
#
|
176
|
-
# Accepted key/value pairs in options parameter are:
|
177
|
-
# * +:filter+ - String. The rule filter.
|
178
|
-
# * +:action+ - String. The rule action.
|
179
|
-
#
|
180
|
-
def create_rule(*p)
|
181
|
-
rule = _rule_from(*p)
|
182
|
-
result = create_resource_entry(:rule, rule, rule.topic, rule.subscription, rule.name)
|
183
|
-
result.topic = rule.topic
|
184
|
-
result.subscription = rule.subscription
|
185
|
-
result
|
186
|
-
end
|
187
|
-
|
188
|
-
# Deletes an existing rule.
|
189
|
-
#
|
190
|
-
# ==== Attributes
|
191
|
-
#
|
192
|
-
# Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a object with .name, .topic, and
|
193
|
-
# .subscription methods such as Azure::ServiceBus::Rule instance.
|
194
|
-
#
|
195
|
-
# Note: The default rule name is '$Default'. Use this name to delete the default rule for the subscription.
|
196
|
-
def delete_rule(*p)
|
197
|
-
topic_name, subscription_name, rule_name = _rule_args(*p)
|
198
|
-
|
199
|
-
delete_resource_entry(:rule, topic_name, subscription_name, rule_name)
|
200
|
-
end
|
201
|
-
|
202
|
-
# Retrieves the description for the specified rule.
|
203
|
-
#
|
204
|
-
# ==== Attributes
|
205
|
-
#
|
206
|
-
# Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a object with .name, .topic, and
|
207
|
-
# .subscription methods such as Azure::ServiceBus::Rule instance.
|
208
|
-
#
|
209
|
-
# Note: The default rule name is '$Default'. Use this name to retrieve the default rule for the subscription.
|
210
|
-
def get_rule(*p)
|
211
|
-
topic_name, subscription_name, rule_name = _rule_args(*p)
|
212
|
-
|
213
|
-
result = resource_entry(:rule, topic_name, subscription_name, rule_name)
|
214
|
-
result.topic = topic_name
|
215
|
-
result.subscription = subscription_name
|
216
|
-
result
|
217
|
-
end
|
218
|
-
|
219
|
-
# Retrieves the rules that exist under the specified subscription.
|
220
|
-
#
|
221
|
-
# ==== Attributes
|
222
|
-
#
|
223
|
-
# Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
|
224
|
-
# such as Azure::ServiceBus::Subscription instance.
|
225
|
-
#
|
226
|
-
# * +options+ - Hash. Optional parameters.
|
227
|
-
#
|
228
|
-
# ==== Options
|
229
|
-
#
|
230
|
-
# Accepted key/value pairs in options parameter are:
|
231
|
-
# * +:skip+ - Integer. Number of topics to skip.
|
232
|
-
# * +:top+ - Integer. Number of topics to list.
|
233
|
-
def list_rules(*p)
|
234
|
-
topic_name, subscription_name, options = _subscription_args(*p)
|
235
|
-
|
236
|
-
query = {}
|
237
|
-
query["$skip"] = options[:skip].to_i.to_s if options[:skip]
|
238
|
-
query["$top"] = options[:top].to_i.to_s if options[:top]
|
239
|
-
|
240
|
-
results = resource_list(:rule, topic_name, subscription_name, query)
|
241
|
-
results.each{|r| r.topic = topic_name; r.subscription=subscription_name}
|
242
|
-
|
243
|
-
return results
|
244
|
-
end
|
245
|
-
|
246
|
-
# Creates a new subscription. Once created, this subscription resource manifest is
|
247
|
-
# immutable.
|
248
|
-
#
|
249
|
-
# ==== Attributes
|
250
|
-
#
|
251
|
-
# Pass either (topic_name, subscription_name) as strings, or (subscription) a object.
|
252
|
-
# When using (topic_name, subscription_name) overload, you may also pass optional properties for the subscription.
|
253
|
-
#
|
254
|
-
# ==== Options
|
255
|
-
#
|
256
|
-
# Accepted key/value pairs in options parameter are:
|
257
|
-
# * +:lock_duration+ - XML datetime. Determines the amount of time in seconds in which a message should be locked for processing by a receiver.
|
258
|
-
# * +:requires_session+ - Boolean. If set to true, the queue will be session-aware and only SessionReceiver will be supported.
|
259
|
-
# * +:default_message_time_to_live+ - XML datetime. Determines how long a message lives in the associated subscriptions.
|
260
|
-
# * +:dead_lettering_on_message_expiration:+ - Boolean. This field controls how the Service Bus handles a message whose TTL has expired.
|
261
|
-
# * +:dead_lettering_on_filter_evaluation_exceptions+ - Boolean. Determines how the Service Bus handles a message that causes an exception during a subscription's filter evaluation.
|
262
|
-
# * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
|
263
|
-
# * +:max_delivery_count+ - Number. A message is automatically deadlettered after this number of deliveries.
|
264
|
-
# * +:message_count+ - Number. Displays the number of messages currently in the queue.
|
265
|
-
#
|
266
|
-
def create_subscription(*p)
|
267
|
-
subscription = _subscription_from(*p)
|
268
|
-
|
269
|
-
result = create_resource_entry(:subscription, subscription, subscription.topic, subscription.name)
|
270
|
-
result.topic = subscription.topic
|
271
|
-
result
|
272
|
-
end
|
273
|
-
|
274
|
-
#
|
275
|
-
# Deletes an existing subscription.
|
276
|
-
#
|
277
|
-
# ==== Attributes
|
278
|
-
#
|
279
|
-
# Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
|
280
|
-
# such as Azure::ServiceBus::Subscription instance.
|
281
|
-
def delete_subscription(*p)
|
282
|
-
topic_name, subscription_name = _subscription_args(*p)
|
283
|
-
|
284
|
-
delete_resource_entry(:subscription, topic_name, subscription_name)
|
285
|
-
end
|
286
|
-
|
287
|
-
# Gets an existing subscription.
|
288
|
-
#
|
289
|
-
# ==== Attributes
|
290
|
-
#
|
291
|
-
# Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
|
292
|
-
# such as Azure::ServiceBus::Subscription instance.
|
293
|
-
def get_subscription(*p)
|
294
|
-
topic_name, subscription_name = _subscription_args(*p)
|
295
|
-
|
296
|
-
result = resource_entry(:subscription, topic_name, subscription_name)
|
297
|
-
result.topic = topic_name
|
298
|
-
result
|
299
|
-
end
|
300
|
-
|
301
|
-
# Retrieves the subscriptions in the specified topic.
|
302
|
-
#
|
303
|
-
# ==== Attributes
|
304
|
-
#
|
305
|
-
# * +topic+ - Either a Azure::ServiceBus::Topic instance or a string of the topic name
|
306
|
-
# * +options+ - Hash. Optional parameters.
|
307
|
-
#
|
308
|
-
# ==== Options
|
309
|
-
#
|
310
|
-
# Accepted key/value pairs in options parameter are:
|
311
|
-
# * +:skip+ - Integer. Number of subscriptions to skip.
|
312
|
-
# * +:top+ - Integer. Number of subscriptions to list.
|
313
|
-
def list_subscriptions(topic, options={})
|
314
|
-
topic = _name_for(topic)
|
315
|
-
query = {}
|
316
|
-
query["$skip"] = options[:skip].to_i.to_s if options[:skip]
|
317
|
-
query["$top"] = options[:top].to_i.to_s if options[:top]
|
318
|
-
|
319
|
-
results = resource_list(:subscription, topic, query)
|
320
|
-
results.each { |s| s.topic = topic }
|
321
|
-
|
322
|
-
return results
|
323
|
-
end
|
324
|
-
|
325
|
-
# Enqueues a message into the specified topic. The limit to the number of messages
|
326
|
-
# which may be present in the topic is governed by the message size in MaxTopicSizeInBytes.
|
327
|
-
# If this message causes the topic to exceed its quota, a quota exceeded error is
|
328
|
-
# returned and the message will be rejected.
|
329
|
-
#
|
330
|
-
# ==== Attributes
|
331
|
-
#
|
332
|
-
# * +topic+ - Either a Azure::ServiceBus::Topic instance or a string of the topic name
|
333
|
-
# * +message+ - An Azure::ServiceBus::BrokeredMessage object containing message body and properties,
|
334
|
-
# or a string of the message body (a default BrokeredMessage will be created from the string).
|
335
|
-
def send_topic_message(topic, message)
|
336
|
-
_send_message(_name_for(topic), message)
|
337
|
-
end
|
338
|
-
|
339
|
-
# This operation is used to atomically retrieve and lock a message for processing.
|
340
|
-
# The message is guaranteed not to be delivered to other receivers during the lock
|
341
|
-
# duration period specified in buffer description. Once the lock expires, the
|
342
|
-
# message will be available to other receivers (on the same subscription only)
|
343
|
-
# during the lock duration period specified in the topic description. Once the lock
|
344
|
-
# expires, the message will be available to other receivers. In order to complete
|
345
|
-
# processing of the message, the receiver should issue a delete command with the
|
346
|
-
# lock ID received from this operation. To abandon processing of the message and
|
347
|
-
# unlock it for other receivers, an Unlock Message command should be issued, or
|
348
|
-
# the lock duration period can expire.
|
349
|
-
#
|
350
|
-
# ==== Attributes
|
351
|
-
#
|
352
|
-
# * +topic+ - String. The name of the topic or a Topic instance
|
353
|
-
# * +subscription+ - String. The name of the subscription or a Subscription instance
|
354
|
-
# * +options+ - Hash. Optional parameters.
|
355
|
-
#
|
356
|
-
# ==== Options
|
357
|
-
#
|
358
|
-
# Accepted key/value pairs in options parameter are:
|
359
|
-
# * +:timeout+ - Integer. Timeout for the REST call.
|
360
|
-
def peek_lock_subscription_message(topic, subscription, options={})
|
361
|
-
topic = _name_for(topic)
|
362
|
-
subscription = _name_for(subscription)
|
363
|
-
|
364
|
-
_peek_lock_message(subscriptions_path(topic, subscription), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
|
365
|
-
end
|
366
|
-
|
367
|
-
#
|
368
|
-
# Unlock a message for processing by other receivers on a given subscription.
|
369
|
-
# This operation deletes the lock object, causing the message to be unlocked.
|
370
|
-
# A message must have first been locked by a receiver before this operation
|
371
|
-
# is called.
|
372
|
-
#
|
373
|
-
# ==== Attributes
|
374
|
-
#
|
375
|
-
# * +message+ - String. Either the message location URL or a message object.
|
376
|
-
#
|
377
|
-
def unlock_subscription_message(message)
|
378
|
-
_unlock_message(message)
|
379
|
-
end
|
380
|
-
|
381
|
-
# Read and delete a message from a subscription as an atomic operation. This
|
382
|
-
# operation should be used when a best-effort guarantee is sufficient for an
|
383
|
-
# application; that is, using this operation it is possible for messages to
|
384
|
-
# be lost if processing fails.
|
385
|
-
#
|
386
|
-
# ==== Attributes
|
387
|
-
#
|
388
|
-
# * +topic+ - The name of the topic or a Topic instance
|
389
|
-
# * +subscription+ - The name of the subscription or a Subscription instance
|
390
|
-
# * +options+ - Hash. Optional parameters.
|
391
|
-
#
|
392
|
-
# ==== Options
|
393
|
-
#
|
394
|
-
# Accepted key/value pairs in options parameter are:
|
395
|
-
# * +:timeout+ - Integer. Timeout for the REST call.
|
396
|
-
#
|
397
|
-
def read_delete_subscription_message(topic, subscription, options={})
|
398
|
-
topic = _name_for(topic)
|
399
|
-
subscription = _name_for(subscription)
|
400
|
-
|
401
|
-
_read_delete_message(subscriptions_path(topic, subscription), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
|
402
|
-
end
|
403
|
-
|
404
|
-
# Completes processing on a locked message and delete it from the subscription.
|
405
|
-
# This operation should only be called after processing a previously locked
|
406
|
-
# message is successful to maintain At-Least-Once delivery assurances.
|
407
|
-
#
|
408
|
-
# ==== Attributes
|
409
|
-
#
|
410
|
-
# * +message+ - String. Either the message location URL or a message object.
|
411
|
-
#
|
412
|
-
def delete_subscription_message(message)
|
413
|
-
_delete_message(message)
|
414
|
-
end
|
415
|
-
|
416
|
-
# Sends a message into the specified queue. The limit to the number of messages
|
417
|
-
# which may be present in the topic is governed by the message size the
|
418
|
-
# MaxTopicSizeInMegaBytes. If this message will cause the queue to exceed its
|
419
|
-
# quota, a quota exceeded error is returned and the message will be rejected.
|
420
|
-
#
|
421
|
-
# ==== Attributes
|
422
|
-
#
|
423
|
-
# * +queue+ - Either a Azure::ServiceBus::Queue instance or a string of the queue name
|
424
|
-
# * +message+ - An Azure::ServiceBus::BrokeredMessage object containing message body and properties,
|
425
|
-
# or a string of the message body (a default BrokeredMessage will be created from the string).
|
426
|
-
def send_queue_message(queue, message)
|
427
|
-
_send_message(_name_for(queue), message)
|
428
|
-
end
|
429
|
-
|
430
|
-
#
|
431
|
-
# Automatically retrieves and locks a message from a queue for processing. The
|
432
|
-
# message is guaranteed not to be delivered to other receivers (on the same
|
433
|
-
# subscription only) during the lock duration period specified in the queue
|
434
|
-
# description. Once the lock expires, the message will be available to other
|
435
|
-
# receivers. In order to complete processing of the message, the receiver
|
436
|
-
# should issue a delete command with the lock ID received from this operation.
|
437
|
-
# To abandon processing of the message and unlock it for other receivers,
|
438
|
-
# an Unlock Message command should be issued, or the lock duration period
|
439
|
-
# can expire.
|
440
|
-
#
|
441
|
-
# ==== Attributes
|
442
|
-
#
|
443
|
-
# * +queue+ - String. Either a Azure::ServiceBus::Queue instance or a string of the queue name
|
444
|
-
# * +options+ - Hash. Optional parameters.
|
445
|
-
#
|
446
|
-
# ==== Options
|
447
|
-
#
|
448
|
-
# Accepted key/value pairs in options parameter are:
|
449
|
-
# * +:timeout+ - Integer. Timeout for the REST call.
|
450
|
-
#
|
451
|
-
def peek_lock_queue_message(queue, options={})
|
452
|
-
_peek_lock_message(_name_for(queue), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
|
453
|
-
end
|
454
|
-
|
455
|
-
# Unlocks a message for processing by other receivers on a given subscription.
|
456
|
-
# This operation deletes the lock object, causing the message to be unlocked.
|
457
|
-
# A message must have first been locked by a receiver before this operation is
|
458
|
-
# called.
|
459
|
-
#
|
460
|
-
# ==== Attributes
|
461
|
-
#
|
462
|
-
# * +message+ - String. Either the message location URL or a message object.
|
463
|
-
#
|
464
|
-
def unlock_queue_message(message)
|
465
|
-
_unlock_message(message)
|
466
|
-
end
|
467
|
-
|
468
|
-
# Reads and deletes a message from a queue as an atomic operation. This operation
|
469
|
-
# should be used when a best-effort guarantee is sufficient for an application;
|
470
|
-
# that is, using this operation it is possible for messages to be lost if
|
471
|
-
# processing fails.
|
472
|
-
#
|
473
|
-
# ==== Attributes
|
474
|
-
#
|
475
|
-
# * +queue+ - Either a Azure::ServiceBus::Queue instance or a string of the queue name
|
476
|
-
# * +options+ - Hash. Optional parameters.
|
477
|
-
#
|
478
|
-
# ==== Options
|
479
|
-
#
|
480
|
-
# Accepted key/value pairs in options parameter are:
|
481
|
-
# * +:timeout+ - Integer. Timeout for the REST call.
|
482
|
-
#
|
483
|
-
def read_delete_queue_message(queue, options={})
|
484
|
-
_read_delete_message(_name_for(queue), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
|
485
|
-
end
|
486
|
-
|
487
|
-
# Completes processing on a locked message and delete it from the queue. This
|
488
|
-
# operation should only be called after processing a previously locked message
|
489
|
-
# is successful to maintain At-Least-Once delivery assurances.
|
490
|
-
#
|
491
|
-
# ==== Attributes
|
492
|
-
#
|
493
|
-
# * +message+ - String. Either the message location URL or a message object.
|
494
|
-
#
|
495
|
-
def delete_queue_message(message)
|
496
|
-
_delete_message(message)
|
497
|
-
end
|
498
|
-
|
499
|
-
# Public: Receives a queue message.
|
500
|
-
#
|
501
|
-
# ==== Attributes
|
502
|
-
#
|
503
|
-
# * +queue+ - String. The queue name.
|
504
|
-
# * +options+ - Hash. Optional parameters.
|
505
|
-
#
|
506
|
-
# ==== Options
|
507
|
-
#
|
508
|
-
# Accepted key/value pairs in options parameter are:
|
509
|
-
# * +:peek_lock+ - Boolean. Lock when peeking.
|
510
|
-
# * +:timeout+ - Integer. Timeout for the REST call.
|
511
|
-
#
|
512
|
-
def receive_queue_message(queue, options={})
|
513
|
-
peek_lock = true
|
514
|
-
peek_lock = options[:peek_lock] if options[:peek_lock]
|
515
|
-
|
516
|
-
options[:timeout] = options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT
|
517
|
-
if peek_lock
|
518
|
-
peek_lock_queue_message(queue, options)
|
519
|
-
else
|
520
|
-
read_delete_queue_message(queue, options)
|
521
|
-
end
|
522
|
-
end
|
523
|
-
|
524
|
-
# Public: Receives a subscription message.
|
525
|
-
#
|
526
|
-
# ==== Attributes
|
527
|
-
#
|
528
|
-
# * +topic+ - String. The topic name.
|
529
|
-
# * +options+ - Hash. Optional parameters.
|
530
|
-
#
|
531
|
-
# ==== Options
|
532
|
-
#
|
533
|
-
# Accepted key/value pairs in options parameter are:
|
534
|
-
# * +:peek_lock+ - Boolean. Lock when peeking.
|
535
|
-
# * +:timeout+ - Integer. Timeout for the REST call.
|
536
|
-
#
|
537
|
-
def receive_subscription_message(topic, subscription, options={})
|
538
|
-
peek_lock = true
|
539
|
-
peek_lock = options[:peek_lock] if options[:peek_lock]
|
540
|
-
|
541
|
-
options[:timeout] = options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT
|
542
|
-
if peek_lock
|
543
|
-
peek_lock_subscription_message(topic, subscription, options)
|
544
|
-
else
|
545
|
-
read_delete_subscription_message(topic, subscription, options)
|
546
|
-
end
|
547
|
-
end
|
548
|
-
|
549
|
-
private
|
550
|
-
|
551
|
-
def _unlock_message(message)
|
552
|
-
_modify_message(:put, message)
|
553
|
-
end
|
554
|
-
|
555
|
-
def _delete_message(message)
|
556
|
-
_modify_message(:delete, message)
|
557
|
-
end
|
558
|
-
|
559
|
-
def _modify_message(method, message)
|
560
|
-
uri = nil
|
561
|
-
if (message.respond_to? :location)
|
562
|
-
uri = message.location
|
563
|
-
else
|
564
|
-
uri = message
|
565
|
-
end
|
566
|
-
|
567
|
-
call(method, uri)
|
568
|
-
nil
|
569
|
-
end
|
570
|
-
|
571
|
-
def _send_message(path, message)
|
572
|
-
message = Azure::ServiceBus::BrokeredMessage.new(message.to_s) unless message.kind_of?(Azure::ServiceBus::BrokeredMessage)
|
573
|
-
|
574
|
-
serializer = BrokeredMessageSerializer.new(message)
|
575
|
-
broker_properties = serializer.to_json
|
576
|
-
message_properties = serializer.get_property_headers
|
577
|
-
|
578
|
-
content_type = message.content_type || 'text/plain'
|
579
|
-
|
580
|
-
headers = {
|
581
|
-
'BrokerProperties'=> broker_properties
|
582
|
-
}
|
583
|
-
|
584
|
-
message_properties.each do |k,v|
|
585
|
-
headers[k.to_s.encode("UTF-8")] = v.encode("UTF-8")
|
586
|
-
end
|
587
|
-
|
588
|
-
headers["Content-Type"] = content_type
|
589
|
-
|
590
|
-
call(:post, messages_uri(path), message.body, headers)
|
591
|
-
nil
|
592
|
-
end
|
593
|
-
|
594
|
-
def _read_delete_message(path, timeout=DEFAULT_TIMEOUT)
|
595
|
-
_retrieve_message(:delete, path, timeout)
|
596
|
-
end
|
597
|
-
|
598
|
-
def _peek_lock_message(path, timeout=DEFAULT_TIMEOUT)
|
599
|
-
_retrieve_message(:post, path, timeout)
|
600
|
-
end
|
601
|
-
|
602
|
-
def _retrieve_message(method, path, timeout=DEFAULT_TIMEOUT)
|
603
|
-
uri = messages_head_uri(path, { "timeout"=> timeout.to_s })
|
604
|
-
|
605
|
-
response = call(method, uri)
|
606
|
-
(response.status_code == 204) ? nil : BrokeredMessageSerializer.get_from_http_response(response)
|
607
|
-
end
|
608
|
-
|
609
|
-
def _rule_from(*p)
|
610
|
-
rule = nil
|
611
|
-
|
612
|
-
if p.length == 3 or p.length == 4
|
613
|
-
rule = Azure::ServiceBus::Rule.new(p[2]) do |r|
|
614
|
-
r.topic = p[0]
|
615
|
-
r.subscription = p[1]
|
616
|
-
r.description = p[3] if p.length == 4
|
617
|
-
end
|
618
|
-
elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic and p[0].respond_to? :subscription and p[0].respond_to? :description
|
619
|
-
rule = p[0]
|
620
|
-
else
|
621
|
-
raise ArgumentError, "Must provide either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods such as Azure::ServiceBus::Subscription instance."
|
622
|
-
end
|
623
|
-
|
624
|
-
rule
|
625
|
-
end
|
626
|
-
|
627
|
-
def _rule_args(*p)
|
628
|
-
if p.length == 3
|
629
|
-
topic_name = p[0]
|
630
|
-
subscription_name = p[1]
|
631
|
-
rule_name = p[2]
|
632
|
-
elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic
|
633
|
-
topic_name = p[0].topic
|
634
|
-
subscription_name = p[0].subscription
|
635
|
-
rule_name = p[0].name
|
636
|
-
else
|
637
|
-
raise ArgumentError, "Must provide either (topic_name, subscription_name, rule_name) as strings, or (rule) a object with .name, .topic, and .subscription methods such as Azure::ServiceBus::Rule instance."
|
638
|
-
end
|
639
|
-
|
640
|
-
return topic_name, subscription_name, rule_name
|
641
|
-
end
|
642
|
-
|
643
|
-
def _subscription_from(*p)
|
644
|
-
subscription = nil
|
645
|
-
|
646
|
-
if p.length == 3
|
647
|
-
subscription = Azure::ServiceBus::Subscription.new(p[1], p[2]) do |sub|
|
648
|
-
sub.topic = p[0]
|
649
|
-
end
|
650
|
-
elsif p.length == 2
|
651
|
-
subscription = Azure::ServiceBus::Subscription.new(p[1]) do |sub|
|
652
|
-
sub.topic = p[0]
|
653
|
-
end
|
654
|
-
elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic and p[0].respond_to? :description
|
655
|
-
subscription = p[0]
|
656
|
-
else
|
657
|
-
raise ArgumentError, "Must provide either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods such as Azure::ServiceBus::Subscription instance."
|
658
|
-
end
|
659
|
-
|
660
|
-
subscription
|
661
|
-
end
|
662
|
-
|
663
|
-
def _subscription_args(*p)
|
664
|
-
|
665
|
-
raise ArgumentError, "Not enough args" if p.length < 1
|
666
|
-
topic_name = nil
|
667
|
-
subscription_name = nil
|
668
|
-
options = {}
|
669
|
-
|
670
|
-
if p.length == 3
|
671
|
-
# topic/sub/options
|
672
|
-
topic_name = _name_for(p[0])
|
673
|
-
subscription_name = _name_for(p[1])
|
674
|
-
options =p[2]
|
675
|
-
elsif p.length == 2
|
676
|
-
# either subscription/options or topic/sub
|
677
|
-
if p[0].respond_to? :name and p[0].respond_to? :topic
|
678
|
-
topic_name = p[0].topic
|
679
|
-
subscription_name = p[0].name
|
680
|
-
options =p[1]
|
681
|
-
else
|
682
|
-
topic_name = _name_for(p[0])
|
683
|
-
subscription_name = _name_for(p[1])
|
684
|
-
end
|
685
|
-
elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic
|
686
|
-
topic_name = p[0].topic
|
687
|
-
subscription_name = p[0].name
|
688
|
-
else
|
689
|
-
raise ArgumentError, "Must provide either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods such as Azure::ServiceBus::Subscription instance."
|
690
|
-
end
|
691
|
-
|
692
|
-
return topic_name, subscription_name, options
|
693
|
-
end
|
694
|
-
|
695
|
-
def _name_for(val)
|
696
|
-
val.respond_to?(:name) ? val.name : val
|
697
|
-
end
|
698
|
-
|
699
|
-
def _new_or_existing(type, *p)
|
700
|
-
p[0].kind_of?(type) ? p[0] : type.new(*p)
|
701
|
-
end
|
702
|
-
|
703
|
-
|
704
|
-
def create_resource_entry(resource, entry, *p)
|
705
|
-
body = Serialization.resource_to_xml resource, entry
|
706
|
-
response = call(:put, self.send("#{resource.to_s}_uri", *p), body)
|
707
|
-
results = Serialization.resources_from_xml(resource, response.body)
|
708
|
-
results ? results.first : results
|
709
|
-
end
|
710
|
-
|
711
|
-
def delete_resource_entry(resource, *p)
|
712
|
-
call(:delete, self.send("#{resource.to_s}_uri", *p))
|
713
|
-
nil
|
714
|
-
end
|
715
|
-
|
716
|
-
def resource_entry(resource, *p)
|
717
|
-
uri = self.send("#{resource.to_s}_uri", *p)
|
718
|
-
response = call(:get, uri)
|
719
|
-
results = Serialization.resources_from_xml(resource, response.body)
|
720
|
-
result = results ? results.first : results
|
721
|
-
raise Azure::Core::Http::HTTPError.new(Azure::Core::Http::HttpResponse.new(Azure::Core::Http::HttpResponse::MockResponse.new(404, '<?xml version="1.0"?><error><code>ResourceNotFound</code><message xml:lang="en-US">The specified resource does not exist.</message></error>', {}), uri)) unless result
|
722
|
-
result
|
723
|
-
end
|
724
|
-
|
725
|
-
def resource_list(resource, *p)
|
726
|
-
response = call(:get, self.send("#{resource.to_s}_list_uri", *p))
|
727
|
-
Serialization.resources_from_xml_with_next_link(resource, response.body)
|
728
|
-
end
|
729
|
-
|
730
|
-
# paths
|
731
|
-
|
732
|
-
protected
|
733
|
-
def message_path(path, sequence_number, lock_token)
|
734
|
-
"#{messages_path(path)}/#{sequence_number}/#{lock_token}"
|
735
|
-
end
|
736
|
-
|
737
|
-
protected
|
738
|
-
def messages_head_path(path)
|
739
|
-
"#{messages_path(path)}/head"
|
740
|
-
end
|
741
|
-
|
742
|
-
protected
|
743
|
-
def messages_path(path)
|
744
|
-
"#{path}/messages"
|
745
|
-
end
|
746
|
-
|
747
|
-
protected
|
748
|
-
def rule_path(topic, subscription, rule)
|
749
|
-
"#{subscriptions_path(topic, subscription)}/rules/#{rule}"
|
750
|
-
end
|
751
|
-
|
752
|
-
protected
|
753
|
-
def subscriptions_path(topic, subscription)
|
754
|
-
"#{topic}/subscriptions/#{subscription}"
|
755
|
-
end
|
756
|
-
|
757
|
-
# messages uris
|
758
|
-
|
759
|
-
protected
|
760
|
-
def message_uri(path, sequence_number, lock_token, query={})
|
761
|
-
generate_uri(message_path(path, sequence_number, lock_token), query)
|
762
|
-
end
|
763
|
-
|
764
|
-
protected
|
765
|
-
def messages_head_uri(path, query={})
|
766
|
-
generate_uri(messages_head_path(path), query)
|
767
|
-
end
|
768
|
-
|
769
|
-
protected
|
770
|
-
def messages_uri(path, query={})
|
771
|
-
generate_uri(messages_path(path), query)
|
772
|
-
end
|
773
|
-
|
774
|
-
# entry uris
|
775
|
-
protected
|
776
|
-
def rule_uri(topic, subscription, rule, query={})
|
777
|
-
generate_uri(rule_path(topic, subscription, rule), query)
|
778
|
-
end
|
779
|
-
|
780
|
-
protected
|
781
|
-
def subscription_uri(topic, subscription, query={})
|
782
|
-
generate_uri(subscriptions_path(topic, subscription), query)
|
783
|
-
end
|
784
|
-
|
785
|
-
protected
|
786
|
-
def queue_uri(topic, query={})
|
787
|
-
generate_uri(topic, query)
|
788
|
-
end
|
789
|
-
|
790
|
-
protected
|
791
|
-
def topic_uri(topic, query={})
|
792
|
-
generate_uri(topic, query)
|
793
|
-
end
|
794
|
-
|
795
|
-
# list uris
|
796
|
-
|
797
|
-
protected
|
798
|
-
def rule_list_uri(topic, subscription, query={})
|
799
|
-
resource_list_uri(:rule, query, subscriptions_path(topic, subscription))
|
800
|
-
end
|
801
|
-
|
802
|
-
protected
|
803
|
-
def subscription_list_uri(topic, query={})
|
804
|
-
resource_list_uri(:subscription, query, topic)
|
805
|
-
end
|
806
|
-
|
807
|
-
protected
|
808
|
-
def queue_list_uri(query={})
|
809
|
-
resource_list_uri(:queue, query)
|
810
|
-
end
|
811
|
-
|
812
|
-
protected
|
813
|
-
def topic_list_uri(query={})
|
814
|
-
resource_list_uri(:topic, query)
|
815
|
-
end
|
816
|
-
|
817
|
-
protected
|
818
|
-
def resource_list_uri(resource, query={}, subpath='$Resources')
|
819
|
-
skip = query.delete ["$skip"]
|
820
|
-
top = query.delete ["$top"]
|
821
|
-
|
822
|
-
uri = generate_uri("#{subpath}/#{resource.to_s.capitalize}s", query)
|
823
|
-
uri.query = [uri.query, "$skip=" + skip].join('&') if skip
|
824
|
-
uri.query = [uri.query, "$top=" + top].join('&') if top
|
825
|
-
uri
|
826
|
-
end
|
827
|
-
end
|
828
|
-
end
|
1
|
+
#-------------------------------------------------------------------------
|
2
|
+
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
#--------------------------------------------------------------------------
|
15
|
+
require 'azure/core/signed_service'
|
16
|
+
require 'azure/service_bus/auth/wrap_signer'
|
17
|
+
require 'azure/service_bus/serialization'
|
18
|
+
|
19
|
+
require 'azure/service_bus/brokered_message_serializer'
|
20
|
+
require 'azure/core/http/http_response'
|
21
|
+
|
22
|
+
module Azure
|
23
|
+
module ServiceBus
|
24
|
+
class ServiceBusService < Azure::Core::SignedService
|
25
|
+
|
26
|
+
DEFAULT_TIMEOUT = 60
|
27
|
+
|
28
|
+
def initialize(host=Azure.config.service_bus_host)
|
29
|
+
super(Azure::ServiceBus::Auth::WrapSigner.new)
|
30
|
+
@host = host
|
31
|
+
|
32
|
+
with_filter do |req, res|
|
33
|
+
req.headers.delete "x-ms-date"
|
34
|
+
req.headers.delete "x-ms-version"
|
35
|
+
req.headers.delete "DataServiceVersion"
|
36
|
+
req.headers.delete "MaxDataServiceVersion"
|
37
|
+
res.call
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Creates a new queue. Once created, this queue's resource manifest is immutable.
|
42
|
+
#
|
43
|
+
# ==== Attributes
|
44
|
+
#
|
45
|
+
# * +queue+ - Azure::ServiceBus::Queue instance to create on server, or a string of the queue name
|
46
|
+
# * +options+ - Hash. The queue properties.
|
47
|
+
#
|
48
|
+
# ==== Options
|
49
|
+
#
|
50
|
+
# Accepted key/value pairs in options parameter are:
|
51
|
+
# * +:default_message_time_to_live+ - XML datetime. Determines how long a message lives in the associated subscriptions.
|
52
|
+
# * +:duplicate_detection_history_time_window+ - XML datetime. Specifies the time span during which the Service Bus will detect message duplication.
|
53
|
+
# * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
|
54
|
+
# * +:dead_lettering_on_message_expiration:+ - Boolean. This field controls how the Service Bus handles a message whose TTL has expired.
|
55
|
+
# * +:lock_duration+ - XML datetime. Determines the amount of time in seconds in which a message should be locked for processing by a receiver.
|
56
|
+
# * +:max_delivery_count+ - Number. A message is automatically deadlettered after this number of deliveries.
|
57
|
+
# * +:max_size_in_megabytes+ - Number. Specifies the maximum topic size in megabytes
|
58
|
+
# * +:message_count+ - Number. Displays the number of messages currently in the queue.
|
59
|
+
# * +:requires_duplicate_detection+ - Boolean. If enabled, the topic will detect duplicate messages within the time span specified by the DuplicateDetectionHistoryTimeWindow property
|
60
|
+
# * +:requires_session+ - Boolean. If set to true, the queue will be session-aware and only SessionReceiver will be supported.
|
61
|
+
# * +:size_in_bytes+ - Number. Reflects the actual bytes toward the topic quota that messages in the topic currently occupy.
|
62
|
+
#
|
63
|
+
def create_queue(queue, options={})
|
64
|
+
queue = _new_or_existing(Azure::ServiceBus::Queue, queue, options ? options : {})
|
65
|
+
create_resource_entry(:queue, queue, queue.name)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Deletes an existing queue. This operation will also remove all associated state
|
69
|
+
# including messages in the queue.
|
70
|
+
#
|
71
|
+
# ==== Attributes
|
72
|
+
#
|
73
|
+
# * +queue+ - Azure::ServiceBus::Queue instance to delete or a string of the queue name
|
74
|
+
def delete_queue(queue)
|
75
|
+
delete_resource_entry(:queue, _name_for(queue))
|
76
|
+
end
|
77
|
+
|
78
|
+
# Retrieves an existing queue.
|
79
|
+
#
|
80
|
+
# ==== Attributes
|
81
|
+
#
|
82
|
+
# * +queue+ - Azure::ServiceBus::Queue instance to retrieve or a string of the queue name
|
83
|
+
def get_queue(queue)
|
84
|
+
resource_entry(:queue, _name_for(queue))
|
85
|
+
end
|
86
|
+
|
87
|
+
# Enumerates the queues in the service namespace.
|
88
|
+
#
|
89
|
+
# ==== Attributes
|
90
|
+
#
|
91
|
+
# * +options+ - Hash. Optional parameters.
|
92
|
+
#
|
93
|
+
# ==== Options
|
94
|
+
#
|
95
|
+
# Accepted key/value pairs in options parameter are:
|
96
|
+
# * +:skip+ - Integer. Number of queues to skip.
|
97
|
+
# * +:top+ - Integer. Number of queues to list.
|
98
|
+
def list_queues(options={})
|
99
|
+
query = {}
|
100
|
+
query["$skip"] = options[:skip].to_i.to_s if options[:skip]
|
101
|
+
query["$top"] = options[:top].to_i.to_s if options[:top]
|
102
|
+
|
103
|
+
resource_list(:queue, query)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Creates a new topic. Once created, this topic resource manifest is immutable.
|
107
|
+
#
|
108
|
+
# ==== Attributes
|
109
|
+
#
|
110
|
+
# * +topic+ - Azure::ServiceBus::Topic instance to create on server, or a string of the topic name
|
111
|
+
# * +options+ - Hash. The topic properties.
|
112
|
+
#
|
113
|
+
# ==== Options
|
114
|
+
#
|
115
|
+
# Accepted key/value pairs in options parameter are:
|
116
|
+
# * +:default_message_time_to_tive+ - XML datetime. Determines how long a message lives in the associated subscriptions.
|
117
|
+
# * +:maximum_number_of_subscriptions+ - Number. Specifies the maximum number of subscriptions that can be associated with the topic.
|
118
|
+
# * +:max_size_in_megabytes+ - Number. Specifies the maximum topic size in megabytes
|
119
|
+
# * +:requires_duplicate_detection+ - Boolean. If enabled, the topic will detect duplicate messages within the time span specified by the DuplicateDetectionHistoryTimeWindow property
|
120
|
+
# * +:dead_lettering_on_filter_evaluation_exceptions+ - Boolean. Determines how the Service Bus handles a message that causes an exception during a subscription's filter evaluation.
|
121
|
+
# * +:duplicate_detection_history_time_window+ - XML datetime. Specifies the time span during which the Service Bus will detect message duplication.
|
122
|
+
# * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
|
123
|
+
#
|
124
|
+
def create_topic(topic, options={})
|
125
|
+
topic = _new_or_existing(Azure::ServiceBus::Topic, topic, options ? options : {})
|
126
|
+
create_resource_entry(:topic, topic, topic.name)
|
127
|
+
end
|
128
|
+
|
129
|
+
# Deletes an existing topic. This operation will also remove all associated state
|
130
|
+
# including associated subscriptions.
|
131
|
+
#
|
132
|
+
# ==== Attributes
|
133
|
+
#
|
134
|
+
# * +topic+ - Azure::ServiceBus::Topic instance to delete or a string of the topic name
|
135
|
+
def delete_topic(topic)
|
136
|
+
delete_resource_entry(:topic, _name_for(topic))
|
137
|
+
end
|
138
|
+
|
139
|
+
# Retrieves the description for the specified topic.
|
140
|
+
#
|
141
|
+
# ==== Attributes
|
142
|
+
#
|
143
|
+
# * +topic+ - Azure::ServiceBus::Topic instance to retrieve or a string of the topic name
|
144
|
+
def get_topic(topic)
|
145
|
+
resource_entry(:topic, _name_for(topic))
|
146
|
+
end
|
147
|
+
|
148
|
+
# Retrieves the topics in the service namespace.
|
149
|
+
#
|
150
|
+
# ==== Attributes
|
151
|
+
#
|
152
|
+
# * +options+ - Hash. Optional parameters.
|
153
|
+
#
|
154
|
+
# ==== Options
|
155
|
+
#
|
156
|
+
# Accepted key/value pairs in options parameter are:
|
157
|
+
# * +:skip+ - Integer. Number of topics to skip.
|
158
|
+
# * +:top+ - Integer. Number of topics to list.
|
159
|
+
def list_topics(options={})
|
160
|
+
query = {}
|
161
|
+
query["$skip"] = options[:skip].to_i.to_s if options[:skip]
|
162
|
+
query["$top"] = options[:top].to_i.to_s if options[:top]
|
163
|
+
|
164
|
+
resource_list(:topic, query)
|
165
|
+
end
|
166
|
+
|
167
|
+
# Creates a new rule. Once created, this rule's resource manifest is immutable.
|
168
|
+
#
|
169
|
+
# ==== Attributes
|
170
|
+
#
|
171
|
+
# Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a rule object.
|
172
|
+
# When using (topic_name, subscription_name, rule_name, options) overload, you may also pass the properties for the rule.
|
173
|
+
#
|
174
|
+
# ==== Options
|
175
|
+
#
|
176
|
+
# Accepted key/value pairs in options parameter are:
|
177
|
+
# * +:filter+ - String. The rule filter.
|
178
|
+
# * +:action+ - String. The rule action.
|
179
|
+
#
|
180
|
+
def create_rule(*p)
|
181
|
+
rule = _rule_from(*p)
|
182
|
+
result = create_resource_entry(:rule, rule, rule.topic, rule.subscription, rule.name)
|
183
|
+
result.topic = rule.topic
|
184
|
+
result.subscription = rule.subscription
|
185
|
+
result
|
186
|
+
end
|
187
|
+
|
188
|
+
# Deletes an existing rule.
|
189
|
+
#
|
190
|
+
# ==== Attributes
|
191
|
+
#
|
192
|
+
# Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a object with .name, .topic, and
|
193
|
+
# .subscription methods such as Azure::ServiceBus::Rule instance.
|
194
|
+
#
|
195
|
+
# Note: The default rule name is '$Default'. Use this name to delete the default rule for the subscription.
|
196
|
+
def delete_rule(*p)
|
197
|
+
topic_name, subscription_name, rule_name = _rule_args(*p)
|
198
|
+
|
199
|
+
delete_resource_entry(:rule, topic_name, subscription_name, rule_name)
|
200
|
+
end
|
201
|
+
|
202
|
+
# Retrieves the description for the specified rule.
|
203
|
+
#
|
204
|
+
# ==== Attributes
|
205
|
+
#
|
206
|
+
# Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a object with .name, .topic, and
|
207
|
+
# .subscription methods such as Azure::ServiceBus::Rule instance.
|
208
|
+
#
|
209
|
+
# Note: The default rule name is '$Default'. Use this name to retrieve the default rule for the subscription.
|
210
|
+
def get_rule(*p)
|
211
|
+
topic_name, subscription_name, rule_name = _rule_args(*p)
|
212
|
+
|
213
|
+
result = resource_entry(:rule, topic_name, subscription_name, rule_name)
|
214
|
+
result.topic = topic_name
|
215
|
+
result.subscription = subscription_name
|
216
|
+
result
|
217
|
+
end
|
218
|
+
|
219
|
+
# Retrieves the rules that exist under the specified subscription.
|
220
|
+
#
|
221
|
+
# ==== Attributes
|
222
|
+
#
|
223
|
+
# Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
|
224
|
+
# such as Azure::ServiceBus::Subscription instance.
|
225
|
+
#
|
226
|
+
# * +options+ - Hash. Optional parameters.
|
227
|
+
#
|
228
|
+
# ==== Options
|
229
|
+
#
|
230
|
+
# Accepted key/value pairs in options parameter are:
|
231
|
+
# * +:skip+ - Integer. Number of topics to skip.
|
232
|
+
# * +:top+ - Integer. Number of topics to list.
|
233
|
+
def list_rules(*p)
|
234
|
+
topic_name, subscription_name, options = _subscription_args(*p)
|
235
|
+
|
236
|
+
query = {}
|
237
|
+
query["$skip"] = options[:skip].to_i.to_s if options[:skip]
|
238
|
+
query["$top"] = options[:top].to_i.to_s if options[:top]
|
239
|
+
|
240
|
+
results = resource_list(:rule, topic_name, subscription_name, query)
|
241
|
+
results.each{|r| r.topic = topic_name; r.subscription=subscription_name}
|
242
|
+
|
243
|
+
return results
|
244
|
+
end
|
245
|
+
|
246
|
+
# Creates a new subscription. Once created, this subscription resource manifest is
|
247
|
+
# immutable.
|
248
|
+
#
|
249
|
+
# ==== Attributes
|
250
|
+
#
|
251
|
+
# Pass either (topic_name, subscription_name) as strings, or (subscription) a object.
|
252
|
+
# When using (topic_name, subscription_name) overload, you may also pass optional properties for the subscription.
|
253
|
+
#
|
254
|
+
# ==== Options
|
255
|
+
#
|
256
|
+
# Accepted key/value pairs in options parameter are:
|
257
|
+
# * +:lock_duration+ - XML datetime. Determines the amount of time in seconds in which a message should be locked for processing by a receiver.
|
258
|
+
# * +:requires_session+ - Boolean. If set to true, the queue will be session-aware and only SessionReceiver will be supported.
|
259
|
+
# * +:default_message_time_to_live+ - XML datetime. Determines how long a message lives in the associated subscriptions.
|
260
|
+
# * +:dead_lettering_on_message_expiration:+ - Boolean. This field controls how the Service Bus handles a message whose TTL has expired.
|
261
|
+
# * +:dead_lettering_on_filter_evaluation_exceptions+ - Boolean. Determines how the Service Bus handles a message that causes an exception during a subscription's filter evaluation.
|
262
|
+
# * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
|
263
|
+
# * +:max_delivery_count+ - Number. A message is automatically deadlettered after this number of deliveries.
|
264
|
+
# * +:message_count+ - Number. Displays the number of messages currently in the queue.
|
265
|
+
#
|
266
|
+
def create_subscription(*p)
|
267
|
+
subscription = _subscription_from(*p)
|
268
|
+
|
269
|
+
result = create_resource_entry(:subscription, subscription, subscription.topic, subscription.name)
|
270
|
+
result.topic = subscription.topic
|
271
|
+
result
|
272
|
+
end
|
273
|
+
|
274
|
+
#
|
275
|
+
# Deletes an existing subscription.
|
276
|
+
#
|
277
|
+
# ==== Attributes
|
278
|
+
#
|
279
|
+
# Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
|
280
|
+
# such as Azure::ServiceBus::Subscription instance.
|
281
|
+
def delete_subscription(*p)
|
282
|
+
topic_name, subscription_name = _subscription_args(*p)
|
283
|
+
|
284
|
+
delete_resource_entry(:subscription, topic_name, subscription_name)
|
285
|
+
end
|
286
|
+
|
287
|
+
# Gets an existing subscription.
|
288
|
+
#
|
289
|
+
# ==== Attributes
|
290
|
+
#
|
291
|
+
# Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
|
292
|
+
# such as Azure::ServiceBus::Subscription instance.
|
293
|
+
def get_subscription(*p)
|
294
|
+
topic_name, subscription_name = _subscription_args(*p)
|
295
|
+
|
296
|
+
result = resource_entry(:subscription, topic_name, subscription_name)
|
297
|
+
result.topic = topic_name
|
298
|
+
result
|
299
|
+
end
|
300
|
+
|
301
|
+
# Retrieves the subscriptions in the specified topic.
|
302
|
+
#
|
303
|
+
# ==== Attributes
|
304
|
+
#
|
305
|
+
# * +topic+ - Either a Azure::ServiceBus::Topic instance or a string of the topic name
|
306
|
+
# * +options+ - Hash. Optional parameters.
|
307
|
+
#
|
308
|
+
# ==== Options
|
309
|
+
#
|
310
|
+
# Accepted key/value pairs in options parameter are:
|
311
|
+
# * +:skip+ - Integer. Number of subscriptions to skip.
|
312
|
+
# * +:top+ - Integer. Number of subscriptions to list.
|
313
|
+
def list_subscriptions(topic, options={})
|
314
|
+
topic = _name_for(topic)
|
315
|
+
query = {}
|
316
|
+
query["$skip"] = options[:skip].to_i.to_s if options[:skip]
|
317
|
+
query["$top"] = options[:top].to_i.to_s if options[:top]
|
318
|
+
|
319
|
+
results = resource_list(:subscription, topic, query)
|
320
|
+
results.each { |s| s.topic = topic }
|
321
|
+
|
322
|
+
return results
|
323
|
+
end
|
324
|
+
|
325
|
+
# Enqueues a message into the specified topic. The limit to the number of messages
|
326
|
+
# which may be present in the topic is governed by the message size in MaxTopicSizeInBytes.
|
327
|
+
# If this message causes the topic to exceed its quota, a quota exceeded error is
|
328
|
+
# returned and the message will be rejected.
|
329
|
+
#
|
330
|
+
# ==== Attributes
|
331
|
+
#
|
332
|
+
# * +topic+ - Either a Azure::ServiceBus::Topic instance or a string of the topic name
|
333
|
+
# * +message+ - An Azure::ServiceBus::BrokeredMessage object containing message body and properties,
|
334
|
+
# or a string of the message body (a default BrokeredMessage will be created from the string).
|
335
|
+
def send_topic_message(topic, message)
|
336
|
+
_send_message(_name_for(topic), message)
|
337
|
+
end
|
338
|
+
|
339
|
+
# This operation is used to atomically retrieve and lock a message for processing.
|
340
|
+
# The message is guaranteed not to be delivered to other receivers during the lock
|
341
|
+
# duration period specified in buffer description. Once the lock expires, the
|
342
|
+
# message will be available to other receivers (on the same subscription only)
|
343
|
+
# during the lock duration period specified in the topic description. Once the lock
|
344
|
+
# expires, the message will be available to other receivers. In order to complete
|
345
|
+
# processing of the message, the receiver should issue a delete command with the
|
346
|
+
# lock ID received from this operation. To abandon processing of the message and
|
347
|
+
# unlock it for other receivers, an Unlock Message command should be issued, or
|
348
|
+
# the lock duration period can expire.
|
349
|
+
#
|
350
|
+
# ==== Attributes
|
351
|
+
#
|
352
|
+
# * +topic+ - String. The name of the topic or a Topic instance
|
353
|
+
# * +subscription+ - String. The name of the subscription or a Subscription instance
|
354
|
+
# * +options+ - Hash. Optional parameters.
|
355
|
+
#
|
356
|
+
# ==== Options
|
357
|
+
#
|
358
|
+
# Accepted key/value pairs in options parameter are:
|
359
|
+
# * +:timeout+ - Integer. Timeout for the REST call.
|
360
|
+
def peek_lock_subscription_message(topic, subscription, options={})
|
361
|
+
topic = _name_for(topic)
|
362
|
+
subscription = _name_for(subscription)
|
363
|
+
|
364
|
+
_peek_lock_message(subscriptions_path(topic, subscription), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
|
365
|
+
end
|
366
|
+
|
367
|
+
#
|
368
|
+
# Unlock a message for processing by other receivers on a given subscription.
|
369
|
+
# This operation deletes the lock object, causing the message to be unlocked.
|
370
|
+
# A message must have first been locked by a receiver before this operation
|
371
|
+
# is called.
|
372
|
+
#
|
373
|
+
# ==== Attributes
|
374
|
+
#
|
375
|
+
# * +message+ - String. Either the message location URL or a message object.
|
376
|
+
#
|
377
|
+
def unlock_subscription_message(message)
|
378
|
+
_unlock_message(message)
|
379
|
+
end
|
380
|
+
|
381
|
+
# Read and delete a message from a subscription as an atomic operation. This
|
382
|
+
# operation should be used when a best-effort guarantee is sufficient for an
|
383
|
+
# application; that is, using this operation it is possible for messages to
|
384
|
+
# be lost if processing fails.
|
385
|
+
#
|
386
|
+
# ==== Attributes
|
387
|
+
#
|
388
|
+
# * +topic+ - The name of the topic or a Topic instance
|
389
|
+
# * +subscription+ - The name of the subscription or a Subscription instance
|
390
|
+
# * +options+ - Hash. Optional parameters.
|
391
|
+
#
|
392
|
+
# ==== Options
|
393
|
+
#
|
394
|
+
# Accepted key/value pairs in options parameter are:
|
395
|
+
# * +:timeout+ - Integer. Timeout for the REST call.
|
396
|
+
#
|
397
|
+
def read_delete_subscription_message(topic, subscription, options={})
|
398
|
+
topic = _name_for(topic)
|
399
|
+
subscription = _name_for(subscription)
|
400
|
+
|
401
|
+
_read_delete_message(subscriptions_path(topic, subscription), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
|
402
|
+
end
|
403
|
+
|
404
|
+
# Completes processing on a locked message and delete it from the subscription.
|
405
|
+
# This operation should only be called after processing a previously locked
|
406
|
+
# message is successful to maintain At-Least-Once delivery assurances.
|
407
|
+
#
|
408
|
+
# ==== Attributes
|
409
|
+
#
|
410
|
+
# * +message+ - String. Either the message location URL or a message object.
|
411
|
+
#
|
412
|
+
def delete_subscription_message(message)
|
413
|
+
_delete_message(message)
|
414
|
+
end
|
415
|
+
|
416
|
+
# Sends a message into the specified queue. The limit to the number of messages
|
417
|
+
# which may be present in the topic is governed by the message size the
|
418
|
+
# MaxTopicSizeInMegaBytes. If this message will cause the queue to exceed its
|
419
|
+
# quota, a quota exceeded error is returned and the message will be rejected.
|
420
|
+
#
|
421
|
+
# ==== Attributes
|
422
|
+
#
|
423
|
+
# * +queue+ - Either a Azure::ServiceBus::Queue instance or a string of the queue name
|
424
|
+
# * +message+ - An Azure::ServiceBus::BrokeredMessage object containing message body and properties,
|
425
|
+
# or a string of the message body (a default BrokeredMessage will be created from the string).
|
426
|
+
def send_queue_message(queue, message)
|
427
|
+
_send_message(_name_for(queue), message)
|
428
|
+
end
|
429
|
+
|
430
|
+
#
|
431
|
+
# Automatically retrieves and locks a message from a queue for processing. The
|
432
|
+
# message is guaranteed not to be delivered to other receivers (on the same
|
433
|
+
# subscription only) during the lock duration period specified in the queue
|
434
|
+
# description. Once the lock expires, the message will be available to other
|
435
|
+
# receivers. In order to complete processing of the message, the receiver
|
436
|
+
# should issue a delete command with the lock ID received from this operation.
|
437
|
+
# To abandon processing of the message and unlock it for other receivers,
|
438
|
+
# an Unlock Message command should be issued, or the lock duration period
|
439
|
+
# can expire.
|
440
|
+
#
|
441
|
+
# ==== Attributes
|
442
|
+
#
|
443
|
+
# * +queue+ - String. Either a Azure::ServiceBus::Queue instance or a string of the queue name
|
444
|
+
# * +options+ - Hash. Optional parameters.
|
445
|
+
#
|
446
|
+
# ==== Options
|
447
|
+
#
|
448
|
+
# Accepted key/value pairs in options parameter are:
|
449
|
+
# * +:timeout+ - Integer. Timeout for the REST call.
|
450
|
+
#
|
451
|
+
def peek_lock_queue_message(queue, options={})
|
452
|
+
_peek_lock_message(_name_for(queue), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
|
453
|
+
end
|
454
|
+
|
455
|
+
# Unlocks a message for processing by other receivers on a given subscription.
|
456
|
+
# This operation deletes the lock object, causing the message to be unlocked.
|
457
|
+
# A message must have first been locked by a receiver before this operation is
|
458
|
+
# called.
|
459
|
+
#
|
460
|
+
# ==== Attributes
|
461
|
+
#
|
462
|
+
# * +message+ - String. Either the message location URL or a message object.
|
463
|
+
#
|
464
|
+
def unlock_queue_message(message)
|
465
|
+
_unlock_message(message)
|
466
|
+
end
|
467
|
+
|
468
|
+
# Reads and deletes a message from a queue as an atomic operation. This operation
|
469
|
+
# should be used when a best-effort guarantee is sufficient for an application;
|
470
|
+
# that is, using this operation it is possible for messages to be lost if
|
471
|
+
# processing fails.
|
472
|
+
#
|
473
|
+
# ==== Attributes
|
474
|
+
#
|
475
|
+
# * +queue+ - Either a Azure::ServiceBus::Queue instance or a string of the queue name
|
476
|
+
# * +options+ - Hash. Optional parameters.
|
477
|
+
#
|
478
|
+
# ==== Options
|
479
|
+
#
|
480
|
+
# Accepted key/value pairs in options parameter are:
|
481
|
+
# * +:timeout+ - Integer. Timeout for the REST call.
|
482
|
+
#
|
483
|
+
def read_delete_queue_message(queue, options={})
|
484
|
+
_read_delete_message(_name_for(queue), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
|
485
|
+
end
|
486
|
+
|
487
|
+
# Completes processing on a locked message and delete it from the queue. This
|
488
|
+
# operation should only be called after processing a previously locked message
|
489
|
+
# is successful to maintain At-Least-Once delivery assurances.
|
490
|
+
#
|
491
|
+
# ==== Attributes
|
492
|
+
#
|
493
|
+
# * +message+ - String. Either the message location URL or a message object.
|
494
|
+
#
|
495
|
+
def delete_queue_message(message)
|
496
|
+
_delete_message(message)
|
497
|
+
end
|
498
|
+
|
499
|
+
# Public: Receives a queue message.
|
500
|
+
#
|
501
|
+
# ==== Attributes
|
502
|
+
#
|
503
|
+
# * +queue+ - String. The queue name.
|
504
|
+
# * +options+ - Hash. Optional parameters.
|
505
|
+
#
|
506
|
+
# ==== Options
|
507
|
+
#
|
508
|
+
# Accepted key/value pairs in options parameter are:
|
509
|
+
# * +:peek_lock+ - Boolean. Lock when peeking.
|
510
|
+
# * +:timeout+ - Integer. Timeout for the REST call.
|
511
|
+
#
|
512
|
+
def receive_queue_message(queue, options={})
|
513
|
+
peek_lock = true
|
514
|
+
peek_lock = options[:peek_lock] if options[:peek_lock]
|
515
|
+
|
516
|
+
options[:timeout] = options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT
|
517
|
+
if peek_lock
|
518
|
+
peek_lock_queue_message(queue, options)
|
519
|
+
else
|
520
|
+
read_delete_queue_message(queue, options)
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
# Public: Receives a subscription message.
|
525
|
+
#
|
526
|
+
# ==== Attributes
|
527
|
+
#
|
528
|
+
# * +topic+ - String. The topic name.
|
529
|
+
# * +options+ - Hash. Optional parameters.
|
530
|
+
#
|
531
|
+
# ==== Options
|
532
|
+
#
|
533
|
+
# Accepted key/value pairs in options parameter are:
|
534
|
+
# * +:peek_lock+ - Boolean. Lock when peeking.
|
535
|
+
# * +:timeout+ - Integer. Timeout for the REST call.
|
536
|
+
#
|
537
|
+
def receive_subscription_message(topic, subscription, options={})
|
538
|
+
peek_lock = true
|
539
|
+
peek_lock = options[:peek_lock] if options[:peek_lock]
|
540
|
+
|
541
|
+
options[:timeout] = options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT
|
542
|
+
if peek_lock
|
543
|
+
peek_lock_subscription_message(topic, subscription, options)
|
544
|
+
else
|
545
|
+
read_delete_subscription_message(topic, subscription, options)
|
546
|
+
end
|
547
|
+
end
|
548
|
+
|
549
|
+
private
|
550
|
+
|
551
|
+
def _unlock_message(message)
|
552
|
+
_modify_message(:put, message)
|
553
|
+
end
|
554
|
+
|
555
|
+
def _delete_message(message)
|
556
|
+
_modify_message(:delete, message)
|
557
|
+
end
|
558
|
+
|
559
|
+
def _modify_message(method, message)
|
560
|
+
uri = nil
|
561
|
+
if (message.respond_to? :location)
|
562
|
+
uri = message.location
|
563
|
+
else
|
564
|
+
uri = message
|
565
|
+
end
|
566
|
+
|
567
|
+
call(method, uri)
|
568
|
+
nil
|
569
|
+
end
|
570
|
+
|
571
|
+
def _send_message(path, message)
|
572
|
+
message = Azure::ServiceBus::BrokeredMessage.new(message.to_s) unless message.kind_of?(Azure::ServiceBus::BrokeredMessage)
|
573
|
+
|
574
|
+
serializer = BrokeredMessageSerializer.new(message)
|
575
|
+
broker_properties = serializer.to_json
|
576
|
+
message_properties = serializer.get_property_headers
|
577
|
+
|
578
|
+
content_type = message.content_type || 'text/plain'
|
579
|
+
|
580
|
+
headers = {
|
581
|
+
'BrokerProperties'=> broker_properties
|
582
|
+
}
|
583
|
+
|
584
|
+
message_properties.each do |k,v|
|
585
|
+
headers[k.to_s.encode("UTF-8")] = v.encode("UTF-8")
|
586
|
+
end
|
587
|
+
|
588
|
+
headers["Content-Type"] = content_type
|
589
|
+
|
590
|
+
call(:post, messages_uri(path), message.body, headers)
|
591
|
+
nil
|
592
|
+
end
|
593
|
+
|
594
|
+
def _read_delete_message(path, timeout=DEFAULT_TIMEOUT)
|
595
|
+
_retrieve_message(:delete, path, timeout)
|
596
|
+
end
|
597
|
+
|
598
|
+
def _peek_lock_message(path, timeout=DEFAULT_TIMEOUT)
|
599
|
+
_retrieve_message(:post, path, timeout)
|
600
|
+
end
|
601
|
+
|
602
|
+
def _retrieve_message(method, path, timeout=DEFAULT_TIMEOUT)
|
603
|
+
uri = messages_head_uri(path, { "timeout"=> timeout.to_s })
|
604
|
+
|
605
|
+
response = call(method, uri)
|
606
|
+
(response.status_code == 204) ? nil : BrokeredMessageSerializer.get_from_http_response(response)
|
607
|
+
end
|
608
|
+
|
609
|
+
def _rule_from(*p)
|
610
|
+
rule = nil
|
611
|
+
|
612
|
+
if p.length == 3 or p.length == 4
|
613
|
+
rule = Azure::ServiceBus::Rule.new(p[2]) do |r|
|
614
|
+
r.topic = p[0]
|
615
|
+
r.subscription = p[1]
|
616
|
+
r.description = p[3] if p.length == 4
|
617
|
+
end
|
618
|
+
elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic and p[0].respond_to? :subscription and p[0].respond_to? :description
|
619
|
+
rule = p[0]
|
620
|
+
else
|
621
|
+
raise ArgumentError, "Must provide either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods such as Azure::ServiceBus::Subscription instance."
|
622
|
+
end
|
623
|
+
|
624
|
+
rule
|
625
|
+
end
|
626
|
+
|
627
|
+
def _rule_args(*p)
|
628
|
+
if p.length == 3
|
629
|
+
topic_name = p[0]
|
630
|
+
subscription_name = p[1]
|
631
|
+
rule_name = p[2]
|
632
|
+
elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic
|
633
|
+
topic_name = p[0].topic
|
634
|
+
subscription_name = p[0].subscription
|
635
|
+
rule_name = p[0].name
|
636
|
+
else
|
637
|
+
raise ArgumentError, "Must provide either (topic_name, subscription_name, rule_name) as strings, or (rule) a object with .name, .topic, and .subscription methods such as Azure::ServiceBus::Rule instance."
|
638
|
+
end
|
639
|
+
|
640
|
+
return topic_name, subscription_name, rule_name
|
641
|
+
end
|
642
|
+
|
643
|
+
def _subscription_from(*p)
|
644
|
+
subscription = nil
|
645
|
+
|
646
|
+
if p.length == 3
|
647
|
+
subscription = Azure::ServiceBus::Subscription.new(p[1], p[2]) do |sub|
|
648
|
+
sub.topic = p[0]
|
649
|
+
end
|
650
|
+
elsif p.length == 2
|
651
|
+
subscription = Azure::ServiceBus::Subscription.new(p[1]) do |sub|
|
652
|
+
sub.topic = p[0]
|
653
|
+
end
|
654
|
+
elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic and p[0].respond_to? :description
|
655
|
+
subscription = p[0]
|
656
|
+
else
|
657
|
+
raise ArgumentError, "Must provide either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods such as Azure::ServiceBus::Subscription instance."
|
658
|
+
end
|
659
|
+
|
660
|
+
subscription
|
661
|
+
end
|
662
|
+
|
663
|
+
def _subscription_args(*p)
|
664
|
+
|
665
|
+
raise ArgumentError, "Not enough args" if p.length < 1
|
666
|
+
topic_name = nil
|
667
|
+
subscription_name = nil
|
668
|
+
options = {}
|
669
|
+
|
670
|
+
if p.length == 3
|
671
|
+
# topic/sub/options
|
672
|
+
topic_name = _name_for(p[0])
|
673
|
+
subscription_name = _name_for(p[1])
|
674
|
+
options =p[2]
|
675
|
+
elsif p.length == 2
|
676
|
+
# either subscription/options or topic/sub
|
677
|
+
if p[0].respond_to? :name and p[0].respond_to? :topic
|
678
|
+
topic_name = p[0].topic
|
679
|
+
subscription_name = p[0].name
|
680
|
+
options =p[1]
|
681
|
+
else
|
682
|
+
topic_name = _name_for(p[0])
|
683
|
+
subscription_name = _name_for(p[1])
|
684
|
+
end
|
685
|
+
elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic
|
686
|
+
topic_name = p[0].topic
|
687
|
+
subscription_name = p[0].name
|
688
|
+
else
|
689
|
+
raise ArgumentError, "Must provide either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods such as Azure::ServiceBus::Subscription instance."
|
690
|
+
end
|
691
|
+
|
692
|
+
return topic_name, subscription_name, options
|
693
|
+
end
|
694
|
+
|
695
|
+
def _name_for(val)
|
696
|
+
val.respond_to?(:name) ? val.name : val
|
697
|
+
end
|
698
|
+
|
699
|
+
def _new_or_existing(type, *p)
|
700
|
+
p[0].kind_of?(type) ? p[0] : type.new(*p)
|
701
|
+
end
|
702
|
+
|
703
|
+
|
704
|
+
def create_resource_entry(resource, entry, *p)
|
705
|
+
body = Serialization.resource_to_xml resource, entry
|
706
|
+
response = call(:put, self.send("#{resource.to_s}_uri", *p), body)
|
707
|
+
results = Serialization.resources_from_xml(resource, response.body)
|
708
|
+
results ? results.first : results
|
709
|
+
end
|
710
|
+
|
711
|
+
def delete_resource_entry(resource, *p)
|
712
|
+
call(:delete, self.send("#{resource.to_s}_uri", *p))
|
713
|
+
nil
|
714
|
+
end
|
715
|
+
|
716
|
+
def resource_entry(resource, *p)
|
717
|
+
uri = self.send("#{resource.to_s}_uri", *p)
|
718
|
+
response = call(:get, uri)
|
719
|
+
results = Serialization.resources_from_xml(resource, response.body)
|
720
|
+
result = results ? results.first : results
|
721
|
+
raise Azure::Core::Http::HTTPError.new(Azure::Core::Http::HttpResponse.new(Azure::Core::Http::HttpResponse::MockResponse.new(404, '<?xml version="1.0"?><error><code>ResourceNotFound</code><message xml:lang="en-US">The specified resource does not exist.</message></error>', {}), uri)) unless result
|
722
|
+
result
|
723
|
+
end
|
724
|
+
|
725
|
+
def resource_list(resource, *p)
|
726
|
+
response = call(:get, self.send("#{resource.to_s}_list_uri", *p))
|
727
|
+
Serialization.resources_from_xml_with_next_link(resource, response.body)
|
728
|
+
end
|
729
|
+
|
730
|
+
# paths
|
731
|
+
|
732
|
+
protected
|
733
|
+
def message_path(path, sequence_number, lock_token)
|
734
|
+
"#{messages_path(path)}/#{sequence_number}/#{lock_token}"
|
735
|
+
end
|
736
|
+
|
737
|
+
protected
|
738
|
+
def messages_head_path(path)
|
739
|
+
"#{messages_path(path)}/head"
|
740
|
+
end
|
741
|
+
|
742
|
+
protected
|
743
|
+
def messages_path(path)
|
744
|
+
"#{path}/messages"
|
745
|
+
end
|
746
|
+
|
747
|
+
protected
|
748
|
+
def rule_path(topic, subscription, rule)
|
749
|
+
"#{subscriptions_path(topic, subscription)}/rules/#{rule}"
|
750
|
+
end
|
751
|
+
|
752
|
+
protected
|
753
|
+
def subscriptions_path(topic, subscription)
|
754
|
+
"#{topic}/subscriptions/#{subscription}"
|
755
|
+
end
|
756
|
+
|
757
|
+
# messages uris
|
758
|
+
|
759
|
+
protected
|
760
|
+
def message_uri(path, sequence_number, lock_token, query={})
|
761
|
+
generate_uri(message_path(path, sequence_number, lock_token), query)
|
762
|
+
end
|
763
|
+
|
764
|
+
protected
|
765
|
+
def messages_head_uri(path, query={})
|
766
|
+
generate_uri(messages_head_path(path), query)
|
767
|
+
end
|
768
|
+
|
769
|
+
protected
|
770
|
+
def messages_uri(path, query={})
|
771
|
+
generate_uri(messages_path(path), query)
|
772
|
+
end
|
773
|
+
|
774
|
+
# entry uris
|
775
|
+
protected
|
776
|
+
def rule_uri(topic, subscription, rule, query={})
|
777
|
+
generate_uri(rule_path(topic, subscription, rule), query)
|
778
|
+
end
|
779
|
+
|
780
|
+
protected
|
781
|
+
def subscription_uri(topic, subscription, query={})
|
782
|
+
generate_uri(subscriptions_path(topic, subscription), query)
|
783
|
+
end
|
784
|
+
|
785
|
+
protected
|
786
|
+
def queue_uri(topic, query={})
|
787
|
+
generate_uri(topic, query)
|
788
|
+
end
|
789
|
+
|
790
|
+
protected
|
791
|
+
def topic_uri(topic, query={})
|
792
|
+
generate_uri(topic, query)
|
793
|
+
end
|
794
|
+
|
795
|
+
# list uris
|
796
|
+
|
797
|
+
protected
|
798
|
+
def rule_list_uri(topic, subscription, query={})
|
799
|
+
resource_list_uri(:rule, query, subscriptions_path(topic, subscription))
|
800
|
+
end
|
801
|
+
|
802
|
+
protected
|
803
|
+
def subscription_list_uri(topic, query={})
|
804
|
+
resource_list_uri(:subscription, query, topic)
|
805
|
+
end
|
806
|
+
|
807
|
+
protected
|
808
|
+
def queue_list_uri(query={})
|
809
|
+
resource_list_uri(:queue, query)
|
810
|
+
end
|
811
|
+
|
812
|
+
protected
|
813
|
+
def topic_list_uri(query={})
|
814
|
+
resource_list_uri(:topic, query)
|
815
|
+
end
|
816
|
+
|
817
|
+
protected
|
818
|
+
def resource_list_uri(resource, query={}, subpath='$Resources')
|
819
|
+
skip = query.delete ["$skip"]
|
820
|
+
top = query.delete ["$top"]
|
821
|
+
|
822
|
+
uri = generate_uri("#{subpath}/#{resource.to_s.capitalize}s", query)
|
823
|
+
uri.query = [uri.query, "$skip=" + skip].join('&') if skip
|
824
|
+
uri.query = [uri.query, "$top=" + top].join('&') if top
|
825
|
+
uri
|
826
|
+
end
|
827
|
+
end
|
828
|
+
end
|
829
829
|
end
|