stuartpreston-azure-sdk-for-ruby 0.7.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +11 -11
- data/.travis.yml +10 -10
- data/ChangeLog.txt +70 -68
- data/Gemfile +15 -15
- data/README.md +618 -618
- data/Rakefile +133 -133
- data/azure.gemspec +44 -44
- data/lib/azure.rb +52 -52
- data/lib/azure/base_management/affinity_group.rb +32 -32
- data/lib/azure/base_management/base_management_service.rb +304 -304
- data/lib/azure/base_management/location.rb +27 -27
- data/lib/azure/base_management/management_http_request.rb +171 -171
- data/lib/azure/base_management/serialization.rb +129 -129
- data/lib/azure/base_management/sql_management_http_request.rb +45 -45
- 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 -38
- data/lib/azure/cloud_service_management/cloud_service_management_service.rb +140 -140
- data/lib/azure/cloud_service_management/serialization.rb +117 -117
- data/lib/azure/core.rb +39 -39
- 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 -211
- 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/cors.rb +11 -11
- data/lib/azure/service/cors_rule.rb +15 -15
- 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 +297 -297
- data/lib/azure/service/signed_identifier.rb +29 -29
- data/lib/azure/service/storage_service.rb +82 -82
- data/lib/azure/service/storage_service_properties.rb +37 -37
- 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/relay.rb +87 -87
- 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 +161 -161
- data/lib/azure/service_bus/service_bus_service.rb +896 -896
- 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 -111
- data/lib/azure/sql_database_management/sql_database.rb +31 -31
- data/lib/azure/sql_database_management/sql_database_management_service.rb +200 -200
- data/lib/azure/storage_management/serialization.rb +184 -184
- data/lib/azure/storage_management/storage_account.rb +40 -40
- data/lib/azure/storage_management/storage_management_service.rb +166 -166
- 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 +31 -31
- data/lib/azure/virtual_machine_image_management/serialization.rb +66 -66
- data/lib/azure/virtual_machine_image_management/virtual_machine_disk.rb +25 -25
- data/lib/azure/virtual_machine_image_management/virtual_machine_image.rb +25 -25
- data/lib/azure/virtual_machine_image_management/virtual_machine_image_management_service.rb +94 -94
- data/lib/azure/virtual_machine_management/serialization.rb +462 -462
- data/lib/azure/virtual_machine_management/virtual_machine.rb +45 -45
- data/lib/azure/virtual_machine_management/virtual_machine_management_service.rb +588 -588
- data/lib/azure/virtual_network_management/serialization.rb +190 -190
- data/lib/azure/virtual_network_management/virtual_network.rb +37 -37
- 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 -5
- data/test/fixtures/create_storage_extendedprop_error.xml +8 -8
- data/test/fixtures/create_storage_extendedpropname_error.xml +6 -6
- data/test/fixtures/create_storage_full_error.xml +6 -6
- data/test/fixtures/create_storage_label_error.xml +5 -5
- data/test/fixtures/create_storage_location_error.xml +5 -5
- data/test/fixtures/create_storage_name_error.xml +6 -6
- data/test/fixtures/create_table_response_entry.xml +15 -15
- data/test/fixtures/delete_storage_container_error.xml +5 -5
- data/test/fixtures/delete_storage_error.xml +5 -5
- data/test/fixtures/deployment_error.xml +5 -5
- data/test/fixtures/get_storage_account_error.xml +5 -5
- data/test/fixtures/get_storage_account_properties.xml +31 -31
- data/test/fixtures/get_storage_account_properties_new.xml +31 -31
- 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 -38
- data/test/fixtures/list_containers.xml +37 -37
- data/test/fixtures/list_firewall_management_endpoint.xml +27 -27
- 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_account_single.xml +24 -24
- 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_relay_response.xml +15 -15
- 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 +54 -54
- data/test/fixtures/update_storage_account.xml +16 -16
- data/test/fixtures/update_storage_error.xml +4 -4
- data/test/fixtures/updated_storage_accounts.xml +52 -52
- data/test/fixtures/virtual_machine.xml +113 -113
- 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/cloud_service/Cloud_Create_test.rb +44 -44
- data/test/integration/cloud_service/Cloud_Delete_test.rb +44 -44
- data/test/integration/database/create_sql_server_firewall_test.rb +86 -86
- data/test/integration/database/create_sql_server_test.rb +53 -53
- data/test/integration/database/delete_sql_server_firewall_test.rb +70 -70
- data/test/integration/database/delete_sql_server_test.rb +58 -58
- data/test/integration/database/list_sql_server_firewall_test.rb +45 -45
- data/test/integration/database/list_sql_servers_test.rb +44 -44
- data/test/integration/database/reset_password_sql_server_test.rb +55 -55
- 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/relay_test.rb +131 -131
- 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 -160
- 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 -42
- data/test/integration/vm/VM_Create_test.rb +260 -260
- data/test/integration/vm/VM_Delete_test.rb +55 -55
- data/test/integration/vm/VM_Operations_test.rb +173 -173
- 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 +168 -168
- data/test/support/stubs.rb +42 -42
- data/test/support/virtual_machine_name_generator.rb +102 -102
- data/test/support/virtual_network_helper.rb +73 -73
- data/test/test_helper.rb +53 -53
- 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 -169
- 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 -97
- data/test/unit/database/sql_database_server_service_test.rb +288 -288
- data/test/unit/service/serialization_test.rb +532 -532
- data/test/unit/service/storage_service_test.rb +292 -292
- data/test/unit/storage_management/serialization_test.rb +232 -232
- data/test/unit/storage_management/storage_management_service_test.rb +261 -261
- data/test/unit/table/edmtype_test.rb +107 -107
- data/test/unit/virtual_machine_image_management/serialization_test.rb +35 -35
- data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb +65 -65
- data/test/unit/virtual_machine_management/serialization_test.rb +258 -258
- data/test/unit/virtual_machine_management/virtual_machine_management_service_test.rb +440 -440
- data/test/unit/vnet/serialization_test.rb +187 -187
- data/test/unit/vnet/virtual_network_management_service_test.rb +131 -131
- metadata +34 -27
@@ -1,34 +1,34 @@
|
|
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
|
-
module Azure
|
16
|
-
module ServiceBus
|
17
|
-
class RuleAspect
|
18
|
-
def initialize()
|
19
|
-
yield self if block_given?
|
20
|
-
end
|
21
|
-
|
22
|
-
def to_hash(hash={})
|
23
|
-
hash[:type]=self.class.name.split('::').last
|
24
|
-
hash
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.from_hash(hash)
|
28
|
-
hash = {} unless hash
|
29
|
-
type = hash[:type]
|
30
|
-
Azure::ServiceBus.const_get(type).new(hash) if type
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
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
|
+
module Azure
|
16
|
+
module ServiceBus
|
17
|
+
class RuleAspect
|
18
|
+
def initialize()
|
19
|
+
yield self if block_given?
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_hash(hash={})
|
23
|
+
hash[:type]=self.class.name.split('::').last
|
24
|
+
hash
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.from_hash(hash)
|
28
|
+
hash = {} unless hash
|
29
|
+
type = hash[:type]
|
30
|
+
Azure::ServiceBus.const_get(type).new(hash) if type
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,161 +1,161 @@
|
|
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
|
-
require "azure/service_bus/relay"
|
22
|
-
|
23
|
-
require "azure/service/enumeration_results"
|
24
|
-
|
25
|
-
module Azure
|
26
|
-
module ServiceBus
|
27
|
-
module Serialization
|
28
|
-
module ClassMethods
|
29
|
-
|
30
|
-
def rule_to_xml(xml, rule)
|
31
|
-
rule_aspect_to_xml xml, 'Filter', rule if rule.filter
|
32
|
-
rule_aspect_to_xml xml, 'Action', rule if rule.action
|
33
|
-
end
|
34
|
-
|
35
|
-
def rule_aspect_to_xml(xml, aspect_name, rule)
|
36
|
-
aspect = rule.description[aspect_name].dup
|
37
|
-
xml.send(aspect_name, "i:type" => aspect.delete(:type)) {
|
38
|
-
aspect.each { |k,v|
|
39
|
-
if k == :sql_expression
|
40
|
-
k = "SqlExpression"
|
41
|
-
elsif k == :compatibility_level
|
42
|
-
k = "CompatibilityLevel"
|
43
|
-
elsif k == :correlation_id
|
44
|
-
k = "CorrelationId"
|
45
|
-
end
|
46
|
-
|
47
|
-
xml.send(k, v)
|
48
|
-
}
|
49
|
-
}
|
50
|
-
end
|
51
|
-
|
52
|
-
def resource_to_xml(resource, entry)
|
53
|
-
doc = Nokogiri::XML::Builder.new(:encoding => "UTF-8") do |xml|
|
54
|
-
xml.entry(:xmlns => 'http://www.w3.org/2005/Atom') {
|
55
|
-
xml.content(:type => 'application/xml') {
|
56
|
-
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') {
|
57
|
-
if resource == :rule
|
58
|
-
rule_to_xml xml, entry
|
59
|
-
else
|
60
|
-
entry.get_props.each do |p|
|
61
|
-
xml.send(p[0], p[1].to_s)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
}
|
65
|
-
}
|
66
|
-
}
|
67
|
-
end
|
68
|
-
doc.to_xml
|
69
|
-
end
|
70
|
-
|
71
|
-
def resource_from_xml(resource, node)
|
72
|
-
resource = resource.to_s.capitalize
|
73
|
-
|
74
|
-
name = (node % "title").text
|
75
|
-
|
76
|
-
Azure::ServiceBus.const_get(resource).new(name) do |r|
|
77
|
-
r.id = URI((node % "id").text) if (node % "id")
|
78
|
-
r.published = Time.parse((node % "published").text) if (node % "published")
|
79
|
-
r.updated = Time.parse((node % "updated").text) if (node % "updated")
|
80
|
-
r.author_name = (node % "author/name").text if (node % "author/name")
|
81
|
-
|
82
|
-
r.description = (node / "content/#{resource}Description *").each_with_object({}) do |element, description|
|
83
|
-
if resource == "Rule"
|
84
|
-
handle_rule_description_element element, description
|
85
|
-
else
|
86
|
-
description[element.name] = element.text
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def handle_rule_description_element(element, description)
|
93
|
-
if element.name == "Filter" or element.name == "Action"
|
94
|
-
value = {}
|
95
|
-
value[:type] = element["type"]
|
96
|
-
element.children.each do |child|
|
97
|
-
if child.name == "SqlExpression"
|
98
|
-
value[:sql_expression] = child.content
|
99
|
-
elsif child.name == "CompatibilityLevel"
|
100
|
-
value[:compatibility_level] = child.content
|
101
|
-
elsif child.name == "CorrelationId"
|
102
|
-
value[:correlation_id] = child.content
|
103
|
-
end
|
104
|
-
end
|
105
|
-
description[element.name] = value
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def resources_from_xml(resource, xml)
|
110
|
-
feed = Nokogiri::XML(xml).remove_namespaces!
|
111
|
-
values = (feed / 'entry').map {|node| resource_from_xml(resource, node) }
|
112
|
-
values.class.module_eval { attr_accessor :next_link}
|
113
|
-
values.next_link = feed.xpath("//link[@rel='next']/@href")
|
114
|
-
values
|
115
|
-
end
|
116
|
-
|
117
|
-
def resources_from_xml_with_next_link(resource, xml)
|
118
|
-
feed = Nokogiri::XML(xml).remove_namespaces!
|
119
|
-
values = Azure::Service::EnumerationResults.new((feed / 'entry').map {|node| resource_from_xml(resource, node) })
|
120
|
-
|
121
|
-
next_token = nil
|
122
|
-
next_uri = feed.xpath("//link[@rel='next']/@href")
|
123
|
-
if next_uri != nil && next_uri.length > 0
|
124
|
-
u = URI.parse(next_uri.to_s)
|
125
|
-
p = CGI.parse(u.query)
|
126
|
-
|
127
|
-
if p['skip'] || p['top']
|
128
|
-
next_token = { }
|
129
|
-
next_token[:top] = p['top'] if p['top']
|
130
|
-
next_token[:skip] = p['skip'] if p['skip']
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
values.continuation_token = next_token
|
135
|
-
values
|
136
|
-
end
|
137
|
-
|
138
|
-
def to_bool(s)
|
139
|
-
(s || "").downcase == 'true'
|
140
|
-
end
|
141
|
-
|
142
|
-
def slopify(xml)
|
143
|
-
node = (xml.is_a? String) ? Nokogiri.Slop(xml).root : xml
|
144
|
-
node.slop! if node.is_a? Nokogiri::XML::Document unless node.respond_to? :method_missing
|
145
|
-
node = node.root if node.is_a? Nokogiri::XML::Document
|
146
|
-
node
|
147
|
-
end
|
148
|
-
|
149
|
-
def expect_node(node_name, xml)
|
150
|
-
raise "Xml is not a #{node_name} node." unless xml.name == node_name
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
extend ClassMethods
|
155
|
-
|
156
|
-
def self.included( other )
|
157
|
-
other.extend( ClassMethods )
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
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
|
+
require "azure/service_bus/relay"
|
22
|
+
|
23
|
+
require "azure/service/enumeration_results"
|
24
|
+
|
25
|
+
module Azure
|
26
|
+
module ServiceBus
|
27
|
+
module Serialization
|
28
|
+
module ClassMethods
|
29
|
+
|
30
|
+
def rule_to_xml(xml, rule)
|
31
|
+
rule_aspect_to_xml xml, 'Filter', rule if rule.filter
|
32
|
+
rule_aspect_to_xml xml, 'Action', rule if rule.action
|
33
|
+
end
|
34
|
+
|
35
|
+
def rule_aspect_to_xml(xml, aspect_name, rule)
|
36
|
+
aspect = rule.description[aspect_name].dup
|
37
|
+
xml.send(aspect_name, "i:type" => aspect.delete(:type)) {
|
38
|
+
aspect.each { |k,v|
|
39
|
+
if k == :sql_expression
|
40
|
+
k = "SqlExpression"
|
41
|
+
elsif k == :compatibility_level
|
42
|
+
k = "CompatibilityLevel"
|
43
|
+
elsif k == :correlation_id
|
44
|
+
k = "CorrelationId"
|
45
|
+
end
|
46
|
+
|
47
|
+
xml.send(k, v)
|
48
|
+
}
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def resource_to_xml(resource, entry)
|
53
|
+
doc = Nokogiri::XML::Builder.new(:encoding => "UTF-8") do |xml|
|
54
|
+
xml.entry(:xmlns => 'http://www.w3.org/2005/Atom') {
|
55
|
+
xml.content(:type => 'application/xml') {
|
56
|
+
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') {
|
57
|
+
if resource == :rule
|
58
|
+
rule_to_xml xml, entry
|
59
|
+
else
|
60
|
+
entry.get_props.each do |p|
|
61
|
+
xml.send(p[0], p[1].to_s)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
end
|
68
|
+
doc.to_xml
|
69
|
+
end
|
70
|
+
|
71
|
+
def resource_from_xml(resource, node)
|
72
|
+
resource = resource.to_s.capitalize
|
73
|
+
|
74
|
+
name = (node % "title").text
|
75
|
+
|
76
|
+
Azure::ServiceBus.const_get(resource).new(name) do |r|
|
77
|
+
r.id = URI((node % "id").text) if (node % "id")
|
78
|
+
r.published = Time.parse((node % "published").text) if (node % "published")
|
79
|
+
r.updated = Time.parse((node % "updated").text) if (node % "updated")
|
80
|
+
r.author_name = (node % "author/name").text if (node % "author/name")
|
81
|
+
|
82
|
+
r.description = (node / "content/#{resource}Description *").each_with_object({}) do |element, description|
|
83
|
+
if resource == "Rule"
|
84
|
+
handle_rule_description_element element, description
|
85
|
+
else
|
86
|
+
description[element.name] = element.text
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def handle_rule_description_element(element, description)
|
93
|
+
if element.name == "Filter" or element.name == "Action"
|
94
|
+
value = {}
|
95
|
+
value[:type] = element["type"]
|
96
|
+
element.children.each do |child|
|
97
|
+
if child.name == "SqlExpression"
|
98
|
+
value[:sql_expression] = child.content
|
99
|
+
elsif child.name == "CompatibilityLevel"
|
100
|
+
value[:compatibility_level] = child.content
|
101
|
+
elsif child.name == "CorrelationId"
|
102
|
+
value[:correlation_id] = child.content
|
103
|
+
end
|
104
|
+
end
|
105
|
+
description[element.name] = value
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def resources_from_xml(resource, xml)
|
110
|
+
feed = Nokogiri::XML(xml).remove_namespaces!
|
111
|
+
values = (feed / 'entry').map {|node| resource_from_xml(resource, node) }
|
112
|
+
values.class.module_eval { attr_accessor :next_link}
|
113
|
+
values.next_link = feed.xpath("//link[@rel='next']/@href")
|
114
|
+
values
|
115
|
+
end
|
116
|
+
|
117
|
+
def resources_from_xml_with_next_link(resource, xml)
|
118
|
+
feed = Nokogiri::XML(xml).remove_namespaces!
|
119
|
+
values = Azure::Service::EnumerationResults.new((feed / 'entry').map {|node| resource_from_xml(resource, node) })
|
120
|
+
|
121
|
+
next_token = nil
|
122
|
+
next_uri = feed.xpath("//link[@rel='next']/@href")
|
123
|
+
if next_uri != nil && next_uri.length > 0
|
124
|
+
u = URI.parse(next_uri.to_s)
|
125
|
+
p = CGI.parse(u.query)
|
126
|
+
|
127
|
+
if p['skip'] || p['top']
|
128
|
+
next_token = { }
|
129
|
+
next_token[:top] = p['top'] if p['top']
|
130
|
+
next_token[:skip] = p['skip'] if p['skip']
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
values.continuation_token = next_token
|
135
|
+
values
|
136
|
+
end
|
137
|
+
|
138
|
+
def to_bool(s)
|
139
|
+
(s || "").downcase == 'true'
|
140
|
+
end
|
141
|
+
|
142
|
+
def slopify(xml)
|
143
|
+
node = (xml.is_a? String) ? Nokogiri.Slop(xml).root : xml
|
144
|
+
node.slop! if node.is_a? Nokogiri::XML::Document unless node.respond_to? :method_missing
|
145
|
+
node = node.root if node.is_a? Nokogiri::XML::Document
|
146
|
+
node
|
147
|
+
end
|
148
|
+
|
149
|
+
def expect_node(node_name, xml)
|
150
|
+
raise "Xml is not a #{node_name} node." unless xml.name == node_name
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
extend ClassMethods
|
155
|
+
|
156
|
+
def self.included( other )
|
157
|
+
other.extend( ClassMethods )
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
@@ -1,897 +1,897 @@
|
|
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
|
-
req.headers["X-Process-At"] = "servicebus"
|
38
|
-
res.call
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# Creates a new relay endpoint. Once created, this relay endpoint resource manifest is immutable.
|
43
|
-
#
|
44
|
-
# ==== Attributes
|
45
|
-
#
|
46
|
-
# * +relay+ - Azure::ServiceBus::Relay instance to create on server, or a string of the relay endpoint name
|
47
|
-
# * +options+ - Hash. The relay endpoint properties.
|
48
|
-
#
|
49
|
-
# ==== Options
|
50
|
-
#
|
51
|
-
# Accepted key/value pairs in options parameter are:
|
52
|
-
# * +:relay_type+ - String. Determines the type of the relay endpoint.
|
53
|
-
# * +:requires_client_authorization+ - Boolean. Determines whether or not clients need to authenticate when making calls.
|
54
|
-
# * +:requires_transport_security+ - Boolean. Determines whether or not the endpoint uses transport security.
|
55
|
-
#
|
56
|
-
def create_relay(relay, options={})
|
57
|
-
relay = _new_or_existing(Azure::ServiceBus::Relay, relay, options ? options : {})
|
58
|
-
create_resource_entry(:relay, relay, relay.name)
|
59
|
-
end
|
60
|
-
|
61
|
-
# Deletes an existing relay endpoint.
|
62
|
-
#
|
63
|
-
# ==== Attributes
|
64
|
-
#
|
65
|
-
# * +relay+ - Azure::ServiceBus::Relay instance to delete or a string of the relay endpoint name
|
66
|
-
def delete_relay(relay)
|
67
|
-
delete_resource_entry(:relay, _name_for(relay))
|
68
|
-
end
|
69
|
-
|
70
|
-
# Retrieves the description for the specified relay endpoint.
|
71
|
-
#
|
72
|
-
# ==== Attributes
|
73
|
-
#
|
74
|
-
# * +relay+ - Azure::ServiceBus::Relay instance to retrieve or a string of the relay endpoint name
|
75
|
-
def get_relay(relay)
|
76
|
-
resource_entry(:relay, _name_for(relay))
|
77
|
-
end
|
78
|
-
|
79
|
-
# Enumerates the relay endpoints in the service namespace.
|
80
|
-
#
|
81
|
-
# ==== Attributes
|
82
|
-
#
|
83
|
-
# * +options+ - Hash. Optional parameters.
|
84
|
-
#
|
85
|
-
# ==== Options
|
86
|
-
#
|
87
|
-
# Accepted key/value pairs in options parameter are:
|
88
|
-
# * +:skip+ - Integer. Number of queues to skip.
|
89
|
-
# * +:top+ - Integer. Number of queues to list.
|
90
|
-
def list_relays(options={})
|
91
|
-
query = {}
|
92
|
-
query["$skip"] = options[:skip].to_i.to_s if options[:skip]
|
93
|
-
query["$top"] = options[:top].to_i.to_s if options[:top]
|
94
|
-
|
95
|
-
resource_list(:relay, query)
|
96
|
-
end
|
97
|
-
|
98
|
-
# Creates a new queue. Once created, this queue's resource manifest is immutable.
|
99
|
-
#
|
100
|
-
# ==== Attributes
|
101
|
-
#
|
102
|
-
# * +queue+ - Azure::ServiceBus::Queue instance to create on server, or a string of the queue name
|
103
|
-
# * +options+ - Hash. The queue properties.
|
104
|
-
#
|
105
|
-
# ==== Options
|
106
|
-
#
|
107
|
-
# Accepted key/value pairs in options parameter are:
|
108
|
-
# * +:default_message_time_to_live+ - XML datetime. Determines how long a message lives in the associated subscriptions.
|
109
|
-
# * +:duplicate_detection_history_time_window+ - XML datetime. Specifies the time span during which the Service Bus will detect message duplication.
|
110
|
-
# * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
|
111
|
-
# * +:dead_lettering_on_message_expiration:+ - Boolean. This field controls how the Service Bus handles a message whose TTL has expired.
|
112
|
-
# * +:lock_duration+ - XML datetime. Determines the amount of time in seconds in which a message should be locked for processing by a receiver.
|
113
|
-
# * +:max_delivery_count+ - Number. A message is automatically deadlettered after this number of deliveries.
|
114
|
-
# * +:max_size_in_megabytes+ - Number. Specifies the maximum topic size in megabytes
|
115
|
-
# * +:message_count+ - Number. Displays the number of messages currently in the queue.
|
116
|
-
# * +:requires_duplicate_detection+ - Boolean. If enabled, the topic will detect duplicate messages within the time span specified by the DuplicateDetectionHistoryTimeWindow property
|
117
|
-
# * +:requires_session+ - Boolean. If set to true, the queue will be session-aware and only SessionReceiver will be supported.
|
118
|
-
# * +:size_in_bytes+ - Number. Reflects the actual bytes toward the topic quota that messages in the topic currently occupy.
|
119
|
-
#
|
120
|
-
def create_queue(queue, options={})
|
121
|
-
queue = _new_or_existing(Azure::ServiceBus::Queue, queue, options ? options : {})
|
122
|
-
create_resource_entry(:queue, queue, queue.name)
|
123
|
-
end
|
124
|
-
|
125
|
-
# Deletes an existing queue. This operation will also remove all associated state
|
126
|
-
# including messages in the queue.
|
127
|
-
#
|
128
|
-
# ==== Attributes
|
129
|
-
#
|
130
|
-
# * +queue+ - Azure::ServiceBus::Queue instance to delete or a string of the queue name
|
131
|
-
def delete_queue(queue)
|
132
|
-
delete_resource_entry(:queue, _name_for(queue))
|
133
|
-
end
|
134
|
-
|
135
|
-
# Retrieves an existing queue.
|
136
|
-
#
|
137
|
-
# ==== Attributes
|
138
|
-
#
|
139
|
-
# * +queue+ - Azure::ServiceBus::Queue instance to retrieve or a string of the queue name
|
140
|
-
def get_queue(queue)
|
141
|
-
resource_entry(:queue, _name_for(queue))
|
142
|
-
end
|
143
|
-
|
144
|
-
# Enumerates the queues in the service namespace.
|
145
|
-
#
|
146
|
-
# ==== Attributes
|
147
|
-
#
|
148
|
-
# * +options+ - Hash. Optional parameters.
|
149
|
-
#
|
150
|
-
# ==== Options
|
151
|
-
#
|
152
|
-
# Accepted key/value pairs in options parameter are:
|
153
|
-
# * +:skip+ - Integer. Number of queues to skip.
|
154
|
-
# * +:top+ - Integer. Number of queues to list.
|
155
|
-
def list_queues(options={})
|
156
|
-
query = {}
|
157
|
-
query["$skip"] = options[:skip].to_i.to_s if options[:skip]
|
158
|
-
query["$top"] = options[:top].to_i.to_s if options[:top]
|
159
|
-
|
160
|
-
resource_list(:queue, query)
|
161
|
-
end
|
162
|
-
|
163
|
-
# Creates a new topic. Once created, this topic resource manifest is immutable.
|
164
|
-
#
|
165
|
-
# ==== Attributes
|
166
|
-
#
|
167
|
-
# * +topic+ - Azure::ServiceBus::Topic instance to create on server, or a string of the topic name
|
168
|
-
# * +options+ - Hash. The topic properties.
|
169
|
-
#
|
170
|
-
# ==== Options
|
171
|
-
#
|
172
|
-
# Accepted key/value pairs in options parameter are:
|
173
|
-
# * +:default_message_time_to_tive+ - XML datetime. Determines how long a message lives in the associated subscriptions.
|
174
|
-
# * +:maximum_number_of_subscriptions+ - Number. Specifies the maximum number of subscriptions that can be associated with the topic.
|
175
|
-
# * +:max_size_in_megabytes+ - Number. Specifies the maximum topic size in megabytes
|
176
|
-
# * +:requires_duplicate_detection+ - Boolean. If enabled, the topic will detect duplicate messages within the time span specified by the DuplicateDetectionHistoryTimeWindow property
|
177
|
-
# * +: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.
|
178
|
-
# * +:duplicate_detection_history_time_window+ - XML datetime. Specifies the time span during which the Service Bus will detect message duplication.
|
179
|
-
# * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
|
180
|
-
#
|
181
|
-
def create_topic(topic, options={})
|
182
|
-
topic = _new_or_existing(Azure::ServiceBus::Topic, topic, options ? options : {})
|
183
|
-
create_resource_entry(:topic, topic, topic.name)
|
184
|
-
end
|
185
|
-
|
186
|
-
# Deletes an existing topic. This operation will also remove all associated state
|
187
|
-
# including associated subscriptions.
|
188
|
-
#
|
189
|
-
# ==== Attributes
|
190
|
-
#
|
191
|
-
# * +topic+ - Azure::ServiceBus::Topic instance to delete or a string of the topic name
|
192
|
-
def delete_topic(topic)
|
193
|
-
delete_resource_entry(:topic, _name_for(topic))
|
194
|
-
end
|
195
|
-
|
196
|
-
# Retrieves the description for the specified topic.
|
197
|
-
#
|
198
|
-
# ==== Attributes
|
199
|
-
#
|
200
|
-
# * +topic+ - Azure::ServiceBus::Topic instance to retrieve or a string of the topic name
|
201
|
-
def get_topic(topic)
|
202
|
-
resource_entry(:topic, _name_for(topic))
|
203
|
-
end
|
204
|
-
|
205
|
-
# Retrieves the topics in the service namespace.
|
206
|
-
#
|
207
|
-
# ==== Attributes
|
208
|
-
#
|
209
|
-
# * +options+ - Hash. Optional parameters.
|
210
|
-
#
|
211
|
-
# ==== Options
|
212
|
-
#
|
213
|
-
# Accepted key/value pairs in options parameter are:
|
214
|
-
# * +:skip+ - Integer. Number of topics to skip.
|
215
|
-
# * +:top+ - Integer. Number of topics to list.
|
216
|
-
def list_topics(options={})
|
217
|
-
query = {}
|
218
|
-
query["$skip"] = options[:skip].to_i.to_s if options[:skip]
|
219
|
-
query["$top"] = options[:top].to_i.to_s if options[:top]
|
220
|
-
|
221
|
-
resource_list(:topic, query)
|
222
|
-
end
|
223
|
-
|
224
|
-
# Creates a new rule. Once created, this rule's resource manifest is immutable.
|
225
|
-
#
|
226
|
-
# ==== Attributes
|
227
|
-
#
|
228
|
-
# Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a rule object.
|
229
|
-
# When using (topic_name, subscription_name, rule_name, options) overload, you may also pass the properties for the rule.
|
230
|
-
#
|
231
|
-
# ==== Options
|
232
|
-
#
|
233
|
-
# Accepted key/value pairs in options parameter are:
|
234
|
-
# * +:filter+ - String. The rule filter.
|
235
|
-
# * +:action+ - String. The rule action.
|
236
|
-
#
|
237
|
-
def create_rule(*p)
|
238
|
-
rule = _rule_from(*p)
|
239
|
-
result = create_resource_entry(:rule, rule, rule.topic, rule.subscription, rule.name)
|
240
|
-
result.topic = rule.topic
|
241
|
-
result.subscription = rule.subscription
|
242
|
-
result
|
243
|
-
end
|
244
|
-
|
245
|
-
# Deletes an existing rule.
|
246
|
-
#
|
247
|
-
# ==== Attributes
|
248
|
-
#
|
249
|
-
# Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a object with .name, .topic, and
|
250
|
-
# .subscription methods such as Azure::ServiceBus::Rule instance.
|
251
|
-
#
|
252
|
-
# Note: The default rule name is '$Default'. Use this name to delete the default rule for the subscription.
|
253
|
-
def delete_rule(*p)
|
254
|
-
topic_name, subscription_name, rule_name = _rule_args(*p)
|
255
|
-
|
256
|
-
delete_resource_entry(:rule, topic_name, subscription_name, rule_name)
|
257
|
-
end
|
258
|
-
|
259
|
-
# Retrieves the description for the specified rule.
|
260
|
-
#
|
261
|
-
# ==== Attributes
|
262
|
-
#
|
263
|
-
# Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a object with .name, .topic, and
|
264
|
-
# .subscription methods such as Azure::ServiceBus::Rule instance.
|
265
|
-
#
|
266
|
-
# Note: The default rule name is '$Default'. Use this name to retrieve the default rule for the subscription.
|
267
|
-
def get_rule(*p)
|
268
|
-
topic_name, subscription_name, rule_name = _rule_args(*p)
|
269
|
-
|
270
|
-
result = resource_entry(:rule, topic_name, subscription_name, rule_name)
|
271
|
-
result.topic = topic_name
|
272
|
-
result.subscription = subscription_name
|
273
|
-
result
|
274
|
-
end
|
275
|
-
|
276
|
-
# Retrieves the rules that exist under the specified subscription.
|
277
|
-
#
|
278
|
-
# ==== Attributes
|
279
|
-
#
|
280
|
-
# Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
|
281
|
-
# such as Azure::ServiceBus::Subscription instance.
|
282
|
-
#
|
283
|
-
# * +options+ - Hash. Optional parameters.
|
284
|
-
#
|
285
|
-
# ==== Options
|
286
|
-
#
|
287
|
-
# Accepted key/value pairs in options parameter are:
|
288
|
-
# * +:skip+ - Integer. Number of topics to skip.
|
289
|
-
# * +:top+ - Integer. Number of topics to list.
|
290
|
-
def list_rules(*p)
|
291
|
-
topic_name, subscription_name, options = _subscription_args(*p)
|
292
|
-
|
293
|
-
query = {}
|
294
|
-
query["$skip"] = options[:skip].to_i.to_s if options[:skip]
|
295
|
-
query["$top"] = options[:top].to_i.to_s if options[:top]
|
296
|
-
|
297
|
-
results = resource_list(:rule, topic_name, subscription_name, query)
|
298
|
-
results.each{|r| r.topic = topic_name; r.subscription=subscription_name}
|
299
|
-
|
300
|
-
return results
|
301
|
-
end
|
302
|
-
|
303
|
-
# Creates a new subscription. Once created, this subscription resource manifest is
|
304
|
-
# immutable.
|
305
|
-
#
|
306
|
-
# ==== Attributes
|
307
|
-
#
|
308
|
-
# Pass either (topic_name, subscription_name) as strings, or (subscription) a object.
|
309
|
-
# When using (topic_name, subscription_name) overload, you may also pass optional properties for the subscription.
|
310
|
-
#
|
311
|
-
# ==== Options
|
312
|
-
#
|
313
|
-
# Accepted key/value pairs in options parameter are:
|
314
|
-
# * +:lock_duration+ - XML datetime. Determines the amount of time in seconds in which a message should be locked for processing by a receiver.
|
315
|
-
# * +:requires_session+ - Boolean. If set to true, the queue will be session-aware and only SessionReceiver will be supported.
|
316
|
-
# * +:default_message_time_to_live+ - XML datetime. Determines how long a message lives in the associated subscriptions.
|
317
|
-
# * +:dead_lettering_on_message_expiration:+ - Boolean. This field controls how the Service Bus handles a message whose TTL has expired.
|
318
|
-
# * +: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.
|
319
|
-
# * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
|
320
|
-
# * +:max_delivery_count+ - Number. A message is automatically deadlettered after this number of deliveries.
|
321
|
-
# * +:message_count+ - Number. Displays the number of messages currently in the queue.
|
322
|
-
#
|
323
|
-
def create_subscription(*p)
|
324
|
-
subscription = _subscription_from(*p)
|
325
|
-
|
326
|
-
result = create_resource_entry(:subscription, subscription, subscription.topic, subscription.name)
|
327
|
-
result.topic = subscription.topic
|
328
|
-
result
|
329
|
-
end
|
330
|
-
|
331
|
-
#
|
332
|
-
# Deletes an existing subscription.
|
333
|
-
#
|
334
|
-
# ==== Attributes
|
335
|
-
#
|
336
|
-
# Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
|
337
|
-
# such as Azure::ServiceBus::Subscription instance.
|
338
|
-
def delete_subscription(*p)
|
339
|
-
topic_name, subscription_name = _subscription_args(*p)
|
340
|
-
|
341
|
-
delete_resource_entry(:subscription, topic_name, subscription_name)
|
342
|
-
end
|
343
|
-
|
344
|
-
# Gets an existing subscription.
|
345
|
-
#
|
346
|
-
# ==== Attributes
|
347
|
-
#
|
348
|
-
# Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
|
349
|
-
# such as Azure::ServiceBus::Subscription instance.
|
350
|
-
def get_subscription(*p)
|
351
|
-
topic_name, subscription_name = _subscription_args(*p)
|
352
|
-
|
353
|
-
result = resource_entry(:subscription, topic_name, subscription_name)
|
354
|
-
result.topic = topic_name
|
355
|
-
result
|
356
|
-
end
|
357
|
-
|
358
|
-
# Retrieves the subscriptions in the specified topic.
|
359
|
-
#
|
360
|
-
# ==== Attributes
|
361
|
-
#
|
362
|
-
# * +topic+ - Either a Azure::ServiceBus::Topic instance or a string of the topic name
|
363
|
-
# * +options+ - Hash. Optional parameters.
|
364
|
-
#
|
365
|
-
# ==== Options
|
366
|
-
#
|
367
|
-
# Accepted key/value pairs in options parameter are:
|
368
|
-
# * +:skip+ - Integer. Number of subscriptions to skip.
|
369
|
-
# * +:top+ - Integer. Number of subscriptions to list.
|
370
|
-
def list_subscriptions(topic, options={})
|
371
|
-
topic = _name_for(topic)
|
372
|
-
query = {}
|
373
|
-
query["$skip"] = options[:skip].to_i.to_s if options[:skip]
|
374
|
-
query["$top"] = options[:top].to_i.to_s if options[:top]
|
375
|
-
|
376
|
-
results = resource_list(:subscription, topic, query)
|
377
|
-
results.each { |s| s.topic = topic }
|
378
|
-
|
379
|
-
return results
|
380
|
-
end
|
381
|
-
|
382
|
-
# Enqueues a message into the specified topic. The limit to the number of messages
|
383
|
-
# which may be present in the topic is governed by the message size in MaxTopicSizeInBytes.
|
384
|
-
# If this message causes the topic to exceed its quota, a quota exceeded error is
|
385
|
-
# returned and the message will be rejected.
|
386
|
-
#
|
387
|
-
# ==== Attributes
|
388
|
-
#
|
389
|
-
# * +topic+ - Either a Azure::ServiceBus::Topic instance or a string of the topic name
|
390
|
-
# * +message+ - An Azure::ServiceBus::BrokeredMessage object containing message body and properties,
|
391
|
-
# or a string of the message body (a default BrokeredMessage will be created from the string).
|
392
|
-
def send_topic_message(topic, message)
|
393
|
-
_send_message(_name_for(topic), message)
|
394
|
-
end
|
395
|
-
|
396
|
-
# This operation is used to atomically retrieve and lock a message for processing.
|
397
|
-
# The message is guaranteed not to be delivered to other receivers during the lock
|
398
|
-
# duration period specified in buffer description. Once the lock expires, the
|
399
|
-
# message will be available to other receivers (on the same subscription only)
|
400
|
-
# during the lock duration period specified in the topic description. Once the lock
|
401
|
-
# expires, the message will be available to other receivers. In order to complete
|
402
|
-
# processing of the message, the receiver should issue a delete command with the
|
403
|
-
# lock ID received from this operation. To abandon processing of the message and
|
404
|
-
# unlock it for other receivers, an Unlock Message command should be issued, or
|
405
|
-
# the lock duration period can expire.
|
406
|
-
#
|
407
|
-
# ==== Attributes
|
408
|
-
#
|
409
|
-
# * +topic+ - String. The name of the topic or a Topic instance
|
410
|
-
# * +subscription+ - String. The name of the subscription or a Subscription instance
|
411
|
-
# * +options+ - Hash. Optional parameters.
|
412
|
-
#
|
413
|
-
# ==== Options
|
414
|
-
#
|
415
|
-
# Accepted key/value pairs in options parameter are:
|
416
|
-
# * +:timeout+ - Integer. Timeout for the REST call.
|
417
|
-
def peek_lock_subscription_message(topic, subscription, options={})
|
418
|
-
topic = _name_for(topic)
|
419
|
-
subscription = _name_for(subscription)
|
420
|
-
|
421
|
-
_peek_lock_message(subscriptions_path(topic, subscription), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
|
422
|
-
end
|
423
|
-
|
424
|
-
#
|
425
|
-
# Unlock a message for processing by other receivers on a given subscription.
|
426
|
-
# This operation deletes the lock object, causing the message to be unlocked.
|
427
|
-
# A message must have first been locked by a receiver before this operation
|
428
|
-
# is called.
|
429
|
-
#
|
430
|
-
# ==== Attributes
|
431
|
-
#
|
432
|
-
# * +message+ - String. Either the message location URL or a message object.
|
433
|
-
#
|
434
|
-
def unlock_subscription_message(message)
|
435
|
-
_unlock_message(message)
|
436
|
-
end
|
437
|
-
|
438
|
-
# Read and delete a message from a subscription as an atomic operation. This
|
439
|
-
# operation should be used when a best-effort guarantee is sufficient for an
|
440
|
-
# application; that is, using this operation it is possible for messages to
|
441
|
-
# be lost if processing fails.
|
442
|
-
#
|
443
|
-
# ==== Attributes
|
444
|
-
#
|
445
|
-
# * +topic+ - The name of the topic or a Topic instance
|
446
|
-
# * +subscription+ - The name of the subscription or a Subscription instance
|
447
|
-
# * +options+ - Hash. Optional parameters.
|
448
|
-
#
|
449
|
-
# ==== Options
|
450
|
-
#
|
451
|
-
# Accepted key/value pairs in options parameter are:
|
452
|
-
# * +:timeout+ - Integer. Timeout for the REST call.
|
453
|
-
#
|
454
|
-
def read_delete_subscription_message(topic, subscription, options={})
|
455
|
-
topic = _name_for(topic)
|
456
|
-
subscription = _name_for(subscription)
|
457
|
-
|
458
|
-
_read_delete_message(subscriptions_path(topic, subscription), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
|
459
|
-
end
|
460
|
-
|
461
|
-
# Completes processing on a locked message and delete it from the subscription.
|
462
|
-
# This operation should only be called after processing a previously locked
|
463
|
-
# message is successful to maintain At-Least-Once delivery assurances.
|
464
|
-
#
|
465
|
-
# ==== Attributes
|
466
|
-
#
|
467
|
-
# * +message+ - String. Either the message location URL or a message object.
|
468
|
-
#
|
469
|
-
def delete_subscription_message(message)
|
470
|
-
_delete_message(message)
|
471
|
-
end
|
472
|
-
|
473
|
-
# Sends a message into the specified queue. The limit to the number of messages
|
474
|
-
# which may be present in the topic is governed by the message size the
|
475
|
-
# MaxTopicSizeInMegaBytes. If this message will cause the queue to exceed its
|
476
|
-
# quota, a quota exceeded error is returned and the message will be rejected.
|
477
|
-
#
|
478
|
-
# ==== Attributes
|
479
|
-
#
|
480
|
-
# * +queue+ - Either a Azure::ServiceBus::Queue instance or a string of the queue name
|
481
|
-
# * +message+ - An Azure::ServiceBus::BrokeredMessage object containing message body and properties,
|
482
|
-
# or a string of the message body (a default BrokeredMessage will be created from the string).
|
483
|
-
def send_queue_message(queue, message)
|
484
|
-
_send_message(_name_for(queue), message)
|
485
|
-
end
|
486
|
-
|
487
|
-
#
|
488
|
-
# Automatically retrieves and locks a message from a queue for processing. The
|
489
|
-
# message is guaranteed not to be delivered to other receivers (on the same
|
490
|
-
# subscription only) during the lock duration period specified in the queue
|
491
|
-
# description. Once the lock expires, the message will be available to other
|
492
|
-
# receivers. In order to complete processing of the message, the receiver
|
493
|
-
# should issue a delete command with the lock ID received from this operation.
|
494
|
-
# To abandon processing of the message and unlock it for other receivers,
|
495
|
-
# an Unlock Message command should be issued, or the lock duration period
|
496
|
-
# can expire.
|
497
|
-
#
|
498
|
-
# ==== Attributes
|
499
|
-
#
|
500
|
-
# * +queue+ - String. Either a Azure::ServiceBus::Queue instance or a string of the queue name
|
501
|
-
# * +options+ - Hash. Optional parameters.
|
502
|
-
#
|
503
|
-
# ==== Options
|
504
|
-
#
|
505
|
-
# Accepted key/value pairs in options parameter are:
|
506
|
-
# * +:timeout+ - Integer. Timeout for the REST call.
|
507
|
-
#
|
508
|
-
def peek_lock_queue_message(queue, options={})
|
509
|
-
_peek_lock_message(_name_for(queue), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
|
510
|
-
end
|
511
|
-
|
512
|
-
# Unlocks a message for processing by other receivers on a given subscription.
|
513
|
-
# This operation deletes the lock object, causing the message to be unlocked.
|
514
|
-
# A message must have first been locked by a receiver before this operation is
|
515
|
-
# called.
|
516
|
-
#
|
517
|
-
# ==== Attributes
|
518
|
-
#
|
519
|
-
# * +message+ - String. Either the message location URL or a message object.
|
520
|
-
#
|
521
|
-
def unlock_queue_message(message)
|
522
|
-
_unlock_message(message)
|
523
|
-
end
|
524
|
-
|
525
|
-
# Reads and deletes a message from a queue as an atomic operation. This operation
|
526
|
-
# should be used when a best-effort guarantee is sufficient for an application;
|
527
|
-
# that is, using this operation it is possible for messages to be lost if
|
528
|
-
# processing fails.
|
529
|
-
#
|
530
|
-
# ==== Attributes
|
531
|
-
#
|
532
|
-
# * +queue+ - Either a Azure::ServiceBus::Queue instance or a string of the queue name
|
533
|
-
# * +options+ - Hash. Optional parameters.
|
534
|
-
#
|
535
|
-
# ==== Options
|
536
|
-
#
|
537
|
-
# Accepted key/value pairs in options parameter are:
|
538
|
-
# * +:timeout+ - Integer. Timeout for the REST call.
|
539
|
-
#
|
540
|
-
def read_delete_queue_message(queue, options={})
|
541
|
-
_read_delete_message(_name_for(queue), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
|
542
|
-
end
|
543
|
-
|
544
|
-
# Completes processing on a locked message and delete it from the queue. This
|
545
|
-
# operation should only be called after processing a previously locked message
|
546
|
-
# is successful to maintain At-Least-Once delivery assurances.
|
547
|
-
#
|
548
|
-
# ==== Attributes
|
549
|
-
#
|
550
|
-
# * +message+ - String. Either the message location URL or a message object.
|
551
|
-
#
|
552
|
-
def delete_queue_message(message)
|
553
|
-
_delete_message(message)
|
554
|
-
end
|
555
|
-
|
556
|
-
# Public: Receives a queue message.
|
557
|
-
#
|
558
|
-
# ==== Attributes
|
559
|
-
#
|
560
|
-
# * +queue+ - String. The queue name.
|
561
|
-
# * +options+ - Hash. Optional parameters.
|
562
|
-
#
|
563
|
-
# ==== Options
|
564
|
-
#
|
565
|
-
# Accepted key/value pairs in options parameter are:
|
566
|
-
# * +:peek_lock+ - Boolean. Lock when peeking.
|
567
|
-
# * +:timeout+ - Integer. Timeout for the REST call.
|
568
|
-
#
|
569
|
-
def receive_queue_message(queue, options={})
|
570
|
-
peek_lock = true
|
571
|
-
peek_lock = options[:peek_lock] if options[:peek_lock]
|
572
|
-
|
573
|
-
options[:timeout] = options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT
|
574
|
-
if peek_lock
|
575
|
-
peek_lock_queue_message(queue, options)
|
576
|
-
else
|
577
|
-
read_delete_queue_message(queue, options)
|
578
|
-
end
|
579
|
-
end
|
580
|
-
|
581
|
-
# Public: Receives a subscription message.
|
582
|
-
#
|
583
|
-
# ==== Attributes
|
584
|
-
#
|
585
|
-
# * +topic+ - String. The topic name.
|
586
|
-
# * +options+ - Hash. Optional parameters.
|
587
|
-
#
|
588
|
-
# ==== Options
|
589
|
-
#
|
590
|
-
# Accepted key/value pairs in options parameter are:
|
591
|
-
# * +:peek_lock+ - Boolean. Lock when peeking.
|
592
|
-
# * +:timeout+ - Integer. Timeout for the REST call.
|
593
|
-
#
|
594
|
-
def receive_subscription_message(topic, subscription, options={})
|
595
|
-
peek_lock = true
|
596
|
-
peek_lock = options[:peek_lock] if options[:peek_lock]
|
597
|
-
|
598
|
-
options[:timeout] = options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT
|
599
|
-
if peek_lock
|
600
|
-
peek_lock_subscription_message(topic, subscription, options)
|
601
|
-
else
|
602
|
-
read_delete_subscription_message(topic, subscription, options)
|
603
|
-
end
|
604
|
-
end
|
605
|
-
|
606
|
-
private
|
607
|
-
|
608
|
-
def _unlock_message(message)
|
609
|
-
_modify_message(:put, message)
|
610
|
-
end
|
611
|
-
|
612
|
-
def _delete_message(message)
|
613
|
-
_modify_message(:delete, message)
|
614
|
-
end
|
615
|
-
|
616
|
-
def _modify_message(method, message)
|
617
|
-
uri = nil
|
618
|
-
if (message.respond_to? :location)
|
619
|
-
uri = message.location
|
620
|
-
else
|
621
|
-
uri = message
|
622
|
-
end
|
623
|
-
|
624
|
-
call(method, uri)
|
625
|
-
nil
|
626
|
-
end
|
627
|
-
|
628
|
-
def _send_message(path, message)
|
629
|
-
message = Azure::ServiceBus::BrokeredMessage.new(message.to_s) unless message.kind_of?(Azure::ServiceBus::BrokeredMessage)
|
630
|
-
|
631
|
-
serializer = BrokeredMessageSerializer.new(message)
|
632
|
-
broker_properties = serializer.to_json
|
633
|
-
message_properties = serializer.get_property_headers
|
634
|
-
|
635
|
-
content_type = message.content_type || 'text/plain'
|
636
|
-
|
637
|
-
headers = {
|
638
|
-
'BrokerProperties'=> broker_properties
|
639
|
-
}
|
640
|
-
|
641
|
-
message_properties.each do |k,v|
|
642
|
-
headers[k.to_s.encode("UTF-8")] = v.encode("UTF-8")
|
643
|
-
end
|
644
|
-
|
645
|
-
headers["Content-Type"] = content_type
|
646
|
-
|
647
|
-
call(:post, messages_uri(path), message.body, headers)
|
648
|
-
nil
|
649
|
-
end
|
650
|
-
|
651
|
-
def _read_delete_message(path, timeout=DEFAULT_TIMEOUT)
|
652
|
-
_retrieve_message(:delete, path, timeout)
|
653
|
-
end
|
654
|
-
|
655
|
-
def _peek_lock_message(path, timeout=DEFAULT_TIMEOUT)
|
656
|
-
_retrieve_message(:post, path, timeout)
|
657
|
-
end
|
658
|
-
|
659
|
-
def _retrieve_message(method, path, timeout=DEFAULT_TIMEOUT)
|
660
|
-
uri = messages_head_uri(path, { "timeout"=> timeout.to_s })
|
661
|
-
|
662
|
-
response = call(method, uri)
|
663
|
-
(response.status_code == 204) ? nil : BrokeredMessageSerializer.get_from_http_response(response)
|
664
|
-
end
|
665
|
-
|
666
|
-
def _rule_from(*p)
|
667
|
-
rule = nil
|
668
|
-
|
669
|
-
if p.length == 3 or p.length == 4
|
670
|
-
rule = Azure::ServiceBus::Rule.new(p[2]) do |r|
|
671
|
-
r.topic = p[0]
|
672
|
-
r.subscription = p[1]
|
673
|
-
r.description = p[3] if p.length == 4
|
674
|
-
end
|
675
|
-
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
|
676
|
-
rule = p[0]
|
677
|
-
else
|
678
|
-
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."
|
679
|
-
end
|
680
|
-
|
681
|
-
rule
|
682
|
-
end
|
683
|
-
|
684
|
-
def _rule_args(*p)
|
685
|
-
if p.length == 3
|
686
|
-
topic_name = p[0]
|
687
|
-
subscription_name = p[1]
|
688
|
-
rule_name = p[2]
|
689
|
-
elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic
|
690
|
-
topic_name = p[0].topic
|
691
|
-
subscription_name = p[0].subscription
|
692
|
-
rule_name = p[0].name
|
693
|
-
else
|
694
|
-
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."
|
695
|
-
end
|
696
|
-
|
697
|
-
return topic_name, subscription_name, rule_name
|
698
|
-
end
|
699
|
-
|
700
|
-
def _subscription_from(*p)
|
701
|
-
subscription = nil
|
702
|
-
|
703
|
-
if p.length == 3
|
704
|
-
subscription = Azure::ServiceBus::Subscription.new(p[1], p[2]) do |sub|
|
705
|
-
sub.topic = p[0]
|
706
|
-
end
|
707
|
-
elsif p.length == 2
|
708
|
-
subscription = Azure::ServiceBus::Subscription.new(p[1]) do |sub|
|
709
|
-
sub.topic = p[0]
|
710
|
-
end
|
711
|
-
elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic and p[0].respond_to? :description
|
712
|
-
subscription = p[0]
|
713
|
-
else
|
714
|
-
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."
|
715
|
-
end
|
716
|
-
|
717
|
-
subscription
|
718
|
-
end
|
719
|
-
|
720
|
-
def _subscription_args(*p)
|
721
|
-
|
722
|
-
raise ArgumentError, "Not enough args" if p.length < 1
|
723
|
-
topic_name = nil
|
724
|
-
subscription_name = nil
|
725
|
-
options = {}
|
726
|
-
|
727
|
-
if p.length == 3
|
728
|
-
# topic/sub/options
|
729
|
-
topic_name = _name_for(p[0])
|
730
|
-
subscription_name = _name_for(p[1])
|
731
|
-
options =p[2]
|
732
|
-
elsif p.length == 2
|
733
|
-
# either subscription/options or topic/sub
|
734
|
-
if p[0].respond_to? :name and p[0].respond_to? :topic
|
735
|
-
topic_name = p[0].topic
|
736
|
-
subscription_name = p[0].name
|
737
|
-
options =p[1]
|
738
|
-
else
|
739
|
-
topic_name = _name_for(p[0])
|
740
|
-
subscription_name = _name_for(p[1])
|
741
|
-
end
|
742
|
-
elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic
|
743
|
-
topic_name = p[0].topic
|
744
|
-
subscription_name = p[0].name
|
745
|
-
else
|
746
|
-
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."
|
747
|
-
end
|
748
|
-
|
749
|
-
return topic_name, subscription_name, options
|
750
|
-
end
|
751
|
-
|
752
|
-
def _name_for(val)
|
753
|
-
val.respond_to?(:name) ? val.name : val
|
754
|
-
end
|
755
|
-
|
756
|
-
def _new_or_existing(type, *p)
|
757
|
-
p[0].kind_of?(type) ? p[0] : type.new(*p)
|
758
|
-
end
|
759
|
-
|
760
|
-
|
761
|
-
def create_resource_entry(resource, entry, *p)
|
762
|
-
body = Serialization.resource_to_xml resource, entry
|
763
|
-
response = call(:put, self.send("#{resource.to_s}_uri", *p), body)
|
764
|
-
results = Serialization.resources_from_xml(resource, response.body)
|
765
|
-
results ? results.first : results
|
766
|
-
end
|
767
|
-
|
768
|
-
def delete_resource_entry(resource, *p)
|
769
|
-
call(:delete, self.send("#{resource.to_s}_uri", *p))
|
770
|
-
nil
|
771
|
-
end
|
772
|
-
|
773
|
-
def resource_entry(resource, *p)
|
774
|
-
uri = self.send("#{resource.to_s}_uri", *p)
|
775
|
-
response = call(:get, uri)
|
776
|
-
results = Serialization.resources_from_xml(resource, response.body)
|
777
|
-
result = results ? results.first : results
|
778
|
-
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
|
779
|
-
result
|
780
|
-
end
|
781
|
-
|
782
|
-
def resource_list(resource, *p)
|
783
|
-
response = call(:get, self.send("#{resource.to_s}_list_uri", *p))
|
784
|
-
Serialization.resources_from_xml_with_next_link(resource, response.body)
|
785
|
-
end
|
786
|
-
|
787
|
-
# paths
|
788
|
-
|
789
|
-
protected
|
790
|
-
def message_path(path, sequence_number, lock_token)
|
791
|
-
"#{messages_path(path)}/#{sequence_number}/#{lock_token}"
|
792
|
-
end
|
793
|
-
|
794
|
-
protected
|
795
|
-
def messages_head_path(path)
|
796
|
-
"#{messages_path(path)}/head"
|
797
|
-
end
|
798
|
-
|
799
|
-
protected
|
800
|
-
def messages_path(path)
|
801
|
-
"#{path}/messages"
|
802
|
-
end
|
803
|
-
|
804
|
-
protected
|
805
|
-
def rule_path(topic, subscription, rule)
|
806
|
-
"#{subscriptions_path(topic, subscription)}/rules/#{rule}"
|
807
|
-
end
|
808
|
-
|
809
|
-
protected
|
810
|
-
def subscriptions_path(topic, subscription)
|
811
|
-
"#{topic}/subscriptions/#{subscription}"
|
812
|
-
end
|
813
|
-
|
814
|
-
# messages uris
|
815
|
-
|
816
|
-
protected
|
817
|
-
def message_uri(path, sequence_number, lock_token, query={})
|
818
|
-
generate_uri(message_path(path, sequence_number, lock_token), query)
|
819
|
-
end
|
820
|
-
|
821
|
-
protected
|
822
|
-
def messages_head_uri(path, query={})
|
823
|
-
generate_uri(messages_head_path(path), query)
|
824
|
-
end
|
825
|
-
|
826
|
-
protected
|
827
|
-
def messages_uri(path, query={})
|
828
|
-
generate_uri(messages_path(path), query)
|
829
|
-
end
|
830
|
-
|
831
|
-
# entry uris
|
832
|
-
protected
|
833
|
-
def rule_uri(topic, subscription, rule, query={})
|
834
|
-
generate_uri(rule_path(topic, subscription, rule), query)
|
835
|
-
end
|
836
|
-
|
837
|
-
protected
|
838
|
-
def subscription_uri(topic, subscription, query={})
|
839
|
-
generate_uri(subscriptions_path(topic, subscription), query)
|
840
|
-
end
|
841
|
-
|
842
|
-
protected
|
843
|
-
def relay_uri(relay, query={})
|
844
|
-
query["api-version"] = "2013-10"
|
845
|
-
generate_uri(relay, query)
|
846
|
-
end
|
847
|
-
|
848
|
-
protected
|
849
|
-
def queue_uri(topic, query={})
|
850
|
-
generate_uri(topic, query)
|
851
|
-
end
|
852
|
-
|
853
|
-
protected
|
854
|
-
def topic_uri(topic, query={})
|
855
|
-
generate_uri(topic, query)
|
856
|
-
end
|
857
|
-
|
858
|
-
# list uris
|
859
|
-
|
860
|
-
protected
|
861
|
-
def rule_list_uri(topic, subscription, query={})
|
862
|
-
resource_list_uri(:rule, query, subscriptions_path(topic, subscription))
|
863
|
-
end
|
864
|
-
|
865
|
-
protected
|
866
|
-
def subscription_list_uri(topic, query={})
|
867
|
-
resource_list_uri(:subscription, query, topic)
|
868
|
-
end
|
869
|
-
|
870
|
-
protected
|
871
|
-
def relay_list_uri(query={})
|
872
|
-
resource_list_uri(:relay, query)
|
873
|
-
end
|
874
|
-
|
875
|
-
protected
|
876
|
-
def queue_list_uri(query={})
|
877
|
-
resource_list_uri(:queue, query)
|
878
|
-
end
|
879
|
-
|
880
|
-
protected
|
881
|
-
def topic_list_uri(query={})
|
882
|
-
resource_list_uri(:topic, query)
|
883
|
-
end
|
884
|
-
|
885
|
-
protected
|
886
|
-
def resource_list_uri(resource, query={}, subpath='$Resources')
|
887
|
-
skip = query.delete ["$skip"]
|
888
|
-
top = query.delete ["$top"]
|
889
|
-
|
890
|
-
uri = generate_uri("#{subpath}/#{resource.to_s.capitalize}s", query)
|
891
|
-
uri.query = [uri.query, "$skip=" + skip].join('&') if skip
|
892
|
-
uri.query = [uri.query, "$top=" + top].join('&') if top
|
893
|
-
uri
|
894
|
-
end
|
895
|
-
end
|
896
|
-
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
|
+
req.headers["X-Process-At"] = "servicebus"
|
38
|
+
res.call
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Creates a new relay endpoint. Once created, this relay endpoint resource manifest is immutable.
|
43
|
+
#
|
44
|
+
# ==== Attributes
|
45
|
+
#
|
46
|
+
# * +relay+ - Azure::ServiceBus::Relay instance to create on server, or a string of the relay endpoint name
|
47
|
+
# * +options+ - Hash. The relay endpoint properties.
|
48
|
+
#
|
49
|
+
# ==== Options
|
50
|
+
#
|
51
|
+
# Accepted key/value pairs in options parameter are:
|
52
|
+
# * +:relay_type+ - String. Determines the type of the relay endpoint.
|
53
|
+
# * +:requires_client_authorization+ - Boolean. Determines whether or not clients need to authenticate when making calls.
|
54
|
+
# * +:requires_transport_security+ - Boolean. Determines whether or not the endpoint uses transport security.
|
55
|
+
#
|
56
|
+
def create_relay(relay, options={})
|
57
|
+
relay = _new_or_existing(Azure::ServiceBus::Relay, relay, options ? options : {})
|
58
|
+
create_resource_entry(:relay, relay, relay.name)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Deletes an existing relay endpoint.
|
62
|
+
#
|
63
|
+
# ==== Attributes
|
64
|
+
#
|
65
|
+
# * +relay+ - Azure::ServiceBus::Relay instance to delete or a string of the relay endpoint name
|
66
|
+
def delete_relay(relay)
|
67
|
+
delete_resource_entry(:relay, _name_for(relay))
|
68
|
+
end
|
69
|
+
|
70
|
+
# Retrieves the description for the specified relay endpoint.
|
71
|
+
#
|
72
|
+
# ==== Attributes
|
73
|
+
#
|
74
|
+
# * +relay+ - Azure::ServiceBus::Relay instance to retrieve or a string of the relay endpoint name
|
75
|
+
def get_relay(relay)
|
76
|
+
resource_entry(:relay, _name_for(relay))
|
77
|
+
end
|
78
|
+
|
79
|
+
# Enumerates the relay endpoints in the service namespace.
|
80
|
+
#
|
81
|
+
# ==== Attributes
|
82
|
+
#
|
83
|
+
# * +options+ - Hash. Optional parameters.
|
84
|
+
#
|
85
|
+
# ==== Options
|
86
|
+
#
|
87
|
+
# Accepted key/value pairs in options parameter are:
|
88
|
+
# * +:skip+ - Integer. Number of queues to skip.
|
89
|
+
# * +:top+ - Integer. Number of queues to list.
|
90
|
+
def list_relays(options={})
|
91
|
+
query = {}
|
92
|
+
query["$skip"] = options[:skip].to_i.to_s if options[:skip]
|
93
|
+
query["$top"] = options[:top].to_i.to_s if options[:top]
|
94
|
+
|
95
|
+
resource_list(:relay, query)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Creates a new queue. Once created, this queue's resource manifest is immutable.
|
99
|
+
#
|
100
|
+
# ==== Attributes
|
101
|
+
#
|
102
|
+
# * +queue+ - Azure::ServiceBus::Queue instance to create on server, or a string of the queue name
|
103
|
+
# * +options+ - Hash. The queue properties.
|
104
|
+
#
|
105
|
+
# ==== Options
|
106
|
+
#
|
107
|
+
# Accepted key/value pairs in options parameter are:
|
108
|
+
# * +:default_message_time_to_live+ - XML datetime. Determines how long a message lives in the associated subscriptions.
|
109
|
+
# * +:duplicate_detection_history_time_window+ - XML datetime. Specifies the time span during which the Service Bus will detect message duplication.
|
110
|
+
# * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
|
111
|
+
# * +:dead_lettering_on_message_expiration:+ - Boolean. This field controls how the Service Bus handles a message whose TTL has expired.
|
112
|
+
# * +:lock_duration+ - XML datetime. Determines the amount of time in seconds in which a message should be locked for processing by a receiver.
|
113
|
+
# * +:max_delivery_count+ - Number. A message is automatically deadlettered after this number of deliveries.
|
114
|
+
# * +:max_size_in_megabytes+ - Number. Specifies the maximum topic size in megabytes
|
115
|
+
# * +:message_count+ - Number. Displays the number of messages currently in the queue.
|
116
|
+
# * +:requires_duplicate_detection+ - Boolean. If enabled, the topic will detect duplicate messages within the time span specified by the DuplicateDetectionHistoryTimeWindow property
|
117
|
+
# * +:requires_session+ - Boolean. If set to true, the queue will be session-aware and only SessionReceiver will be supported.
|
118
|
+
# * +:size_in_bytes+ - Number. Reflects the actual bytes toward the topic quota that messages in the topic currently occupy.
|
119
|
+
#
|
120
|
+
def create_queue(queue, options={})
|
121
|
+
queue = _new_or_existing(Azure::ServiceBus::Queue, queue, options ? options : {})
|
122
|
+
create_resource_entry(:queue, queue, queue.name)
|
123
|
+
end
|
124
|
+
|
125
|
+
# Deletes an existing queue. This operation will also remove all associated state
|
126
|
+
# including messages in the queue.
|
127
|
+
#
|
128
|
+
# ==== Attributes
|
129
|
+
#
|
130
|
+
# * +queue+ - Azure::ServiceBus::Queue instance to delete or a string of the queue name
|
131
|
+
def delete_queue(queue)
|
132
|
+
delete_resource_entry(:queue, _name_for(queue))
|
133
|
+
end
|
134
|
+
|
135
|
+
# Retrieves an existing queue.
|
136
|
+
#
|
137
|
+
# ==== Attributes
|
138
|
+
#
|
139
|
+
# * +queue+ - Azure::ServiceBus::Queue instance to retrieve or a string of the queue name
|
140
|
+
def get_queue(queue)
|
141
|
+
resource_entry(:queue, _name_for(queue))
|
142
|
+
end
|
143
|
+
|
144
|
+
# Enumerates the queues in the service namespace.
|
145
|
+
#
|
146
|
+
# ==== Attributes
|
147
|
+
#
|
148
|
+
# * +options+ - Hash. Optional parameters.
|
149
|
+
#
|
150
|
+
# ==== Options
|
151
|
+
#
|
152
|
+
# Accepted key/value pairs in options parameter are:
|
153
|
+
# * +:skip+ - Integer. Number of queues to skip.
|
154
|
+
# * +:top+ - Integer. Number of queues to list.
|
155
|
+
def list_queues(options={})
|
156
|
+
query = {}
|
157
|
+
query["$skip"] = options[:skip].to_i.to_s if options[:skip]
|
158
|
+
query["$top"] = options[:top].to_i.to_s if options[:top]
|
159
|
+
|
160
|
+
resource_list(:queue, query)
|
161
|
+
end
|
162
|
+
|
163
|
+
# Creates a new topic. Once created, this topic resource manifest is immutable.
|
164
|
+
#
|
165
|
+
# ==== Attributes
|
166
|
+
#
|
167
|
+
# * +topic+ - Azure::ServiceBus::Topic instance to create on server, or a string of the topic name
|
168
|
+
# * +options+ - Hash. The topic properties.
|
169
|
+
#
|
170
|
+
# ==== Options
|
171
|
+
#
|
172
|
+
# Accepted key/value pairs in options parameter are:
|
173
|
+
# * +:default_message_time_to_tive+ - XML datetime. Determines how long a message lives in the associated subscriptions.
|
174
|
+
# * +:maximum_number_of_subscriptions+ - Number. Specifies the maximum number of subscriptions that can be associated with the topic.
|
175
|
+
# * +:max_size_in_megabytes+ - Number. Specifies the maximum topic size in megabytes
|
176
|
+
# * +:requires_duplicate_detection+ - Boolean. If enabled, the topic will detect duplicate messages within the time span specified by the DuplicateDetectionHistoryTimeWindow property
|
177
|
+
# * +: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.
|
178
|
+
# * +:duplicate_detection_history_time_window+ - XML datetime. Specifies the time span during which the Service Bus will detect message duplication.
|
179
|
+
# * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
|
180
|
+
#
|
181
|
+
def create_topic(topic, options={})
|
182
|
+
topic = _new_or_existing(Azure::ServiceBus::Topic, topic, options ? options : {})
|
183
|
+
create_resource_entry(:topic, topic, topic.name)
|
184
|
+
end
|
185
|
+
|
186
|
+
# Deletes an existing topic. This operation will also remove all associated state
|
187
|
+
# including associated subscriptions.
|
188
|
+
#
|
189
|
+
# ==== Attributes
|
190
|
+
#
|
191
|
+
# * +topic+ - Azure::ServiceBus::Topic instance to delete or a string of the topic name
|
192
|
+
def delete_topic(topic)
|
193
|
+
delete_resource_entry(:topic, _name_for(topic))
|
194
|
+
end
|
195
|
+
|
196
|
+
# Retrieves the description for the specified topic.
|
197
|
+
#
|
198
|
+
# ==== Attributes
|
199
|
+
#
|
200
|
+
# * +topic+ - Azure::ServiceBus::Topic instance to retrieve or a string of the topic name
|
201
|
+
def get_topic(topic)
|
202
|
+
resource_entry(:topic, _name_for(topic))
|
203
|
+
end
|
204
|
+
|
205
|
+
# Retrieves the topics in the service namespace.
|
206
|
+
#
|
207
|
+
# ==== Attributes
|
208
|
+
#
|
209
|
+
# * +options+ - Hash. Optional parameters.
|
210
|
+
#
|
211
|
+
# ==== Options
|
212
|
+
#
|
213
|
+
# Accepted key/value pairs in options parameter are:
|
214
|
+
# * +:skip+ - Integer. Number of topics to skip.
|
215
|
+
# * +:top+ - Integer. Number of topics to list.
|
216
|
+
def list_topics(options={})
|
217
|
+
query = {}
|
218
|
+
query["$skip"] = options[:skip].to_i.to_s if options[:skip]
|
219
|
+
query["$top"] = options[:top].to_i.to_s if options[:top]
|
220
|
+
|
221
|
+
resource_list(:topic, query)
|
222
|
+
end
|
223
|
+
|
224
|
+
# Creates a new rule. Once created, this rule's resource manifest is immutable.
|
225
|
+
#
|
226
|
+
# ==== Attributes
|
227
|
+
#
|
228
|
+
# Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a rule object.
|
229
|
+
# When using (topic_name, subscription_name, rule_name, options) overload, you may also pass the properties for the rule.
|
230
|
+
#
|
231
|
+
# ==== Options
|
232
|
+
#
|
233
|
+
# Accepted key/value pairs in options parameter are:
|
234
|
+
# * +:filter+ - String. The rule filter.
|
235
|
+
# * +:action+ - String. The rule action.
|
236
|
+
#
|
237
|
+
def create_rule(*p)
|
238
|
+
rule = _rule_from(*p)
|
239
|
+
result = create_resource_entry(:rule, rule, rule.topic, rule.subscription, rule.name)
|
240
|
+
result.topic = rule.topic
|
241
|
+
result.subscription = rule.subscription
|
242
|
+
result
|
243
|
+
end
|
244
|
+
|
245
|
+
# Deletes an existing rule.
|
246
|
+
#
|
247
|
+
# ==== Attributes
|
248
|
+
#
|
249
|
+
# Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a object with .name, .topic, and
|
250
|
+
# .subscription methods such as Azure::ServiceBus::Rule instance.
|
251
|
+
#
|
252
|
+
# Note: The default rule name is '$Default'. Use this name to delete the default rule for the subscription.
|
253
|
+
def delete_rule(*p)
|
254
|
+
topic_name, subscription_name, rule_name = _rule_args(*p)
|
255
|
+
|
256
|
+
delete_resource_entry(:rule, topic_name, subscription_name, rule_name)
|
257
|
+
end
|
258
|
+
|
259
|
+
# Retrieves the description for the specified rule.
|
260
|
+
#
|
261
|
+
# ==== Attributes
|
262
|
+
#
|
263
|
+
# Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a object with .name, .topic, and
|
264
|
+
# .subscription methods such as Azure::ServiceBus::Rule instance.
|
265
|
+
#
|
266
|
+
# Note: The default rule name is '$Default'. Use this name to retrieve the default rule for the subscription.
|
267
|
+
def get_rule(*p)
|
268
|
+
topic_name, subscription_name, rule_name = _rule_args(*p)
|
269
|
+
|
270
|
+
result = resource_entry(:rule, topic_name, subscription_name, rule_name)
|
271
|
+
result.topic = topic_name
|
272
|
+
result.subscription = subscription_name
|
273
|
+
result
|
274
|
+
end
|
275
|
+
|
276
|
+
# Retrieves the rules that exist under the specified subscription.
|
277
|
+
#
|
278
|
+
# ==== Attributes
|
279
|
+
#
|
280
|
+
# Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
|
281
|
+
# such as Azure::ServiceBus::Subscription instance.
|
282
|
+
#
|
283
|
+
# * +options+ - Hash. Optional parameters.
|
284
|
+
#
|
285
|
+
# ==== Options
|
286
|
+
#
|
287
|
+
# Accepted key/value pairs in options parameter are:
|
288
|
+
# * +:skip+ - Integer. Number of topics to skip.
|
289
|
+
# * +:top+ - Integer. Number of topics to list.
|
290
|
+
def list_rules(*p)
|
291
|
+
topic_name, subscription_name, options = _subscription_args(*p)
|
292
|
+
|
293
|
+
query = {}
|
294
|
+
query["$skip"] = options[:skip].to_i.to_s if options[:skip]
|
295
|
+
query["$top"] = options[:top].to_i.to_s if options[:top]
|
296
|
+
|
297
|
+
results = resource_list(:rule, topic_name, subscription_name, query)
|
298
|
+
results.each{|r| r.topic = topic_name; r.subscription=subscription_name}
|
299
|
+
|
300
|
+
return results
|
301
|
+
end
|
302
|
+
|
303
|
+
# Creates a new subscription. Once created, this subscription resource manifest is
|
304
|
+
# immutable.
|
305
|
+
#
|
306
|
+
# ==== Attributes
|
307
|
+
#
|
308
|
+
# Pass either (topic_name, subscription_name) as strings, or (subscription) a object.
|
309
|
+
# When using (topic_name, subscription_name) overload, you may also pass optional properties for the subscription.
|
310
|
+
#
|
311
|
+
# ==== Options
|
312
|
+
#
|
313
|
+
# Accepted key/value pairs in options parameter are:
|
314
|
+
# * +:lock_duration+ - XML datetime. Determines the amount of time in seconds in which a message should be locked for processing by a receiver.
|
315
|
+
# * +:requires_session+ - Boolean. If set to true, the queue will be session-aware and only SessionReceiver will be supported.
|
316
|
+
# * +:default_message_time_to_live+ - XML datetime. Determines how long a message lives in the associated subscriptions.
|
317
|
+
# * +:dead_lettering_on_message_expiration:+ - Boolean. This field controls how the Service Bus handles a message whose TTL has expired.
|
318
|
+
# * +: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.
|
319
|
+
# * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
|
320
|
+
# * +:max_delivery_count+ - Number. A message is automatically deadlettered after this number of deliveries.
|
321
|
+
# * +:message_count+ - Number. Displays the number of messages currently in the queue.
|
322
|
+
#
|
323
|
+
def create_subscription(*p)
|
324
|
+
subscription = _subscription_from(*p)
|
325
|
+
|
326
|
+
result = create_resource_entry(:subscription, subscription, subscription.topic, subscription.name)
|
327
|
+
result.topic = subscription.topic
|
328
|
+
result
|
329
|
+
end
|
330
|
+
|
331
|
+
#
|
332
|
+
# Deletes an existing subscription.
|
333
|
+
#
|
334
|
+
# ==== Attributes
|
335
|
+
#
|
336
|
+
# Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
|
337
|
+
# such as Azure::ServiceBus::Subscription instance.
|
338
|
+
def delete_subscription(*p)
|
339
|
+
topic_name, subscription_name = _subscription_args(*p)
|
340
|
+
|
341
|
+
delete_resource_entry(:subscription, topic_name, subscription_name)
|
342
|
+
end
|
343
|
+
|
344
|
+
# Gets an existing subscription.
|
345
|
+
#
|
346
|
+
# ==== Attributes
|
347
|
+
#
|
348
|
+
# Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
|
349
|
+
# such as Azure::ServiceBus::Subscription instance.
|
350
|
+
def get_subscription(*p)
|
351
|
+
topic_name, subscription_name = _subscription_args(*p)
|
352
|
+
|
353
|
+
result = resource_entry(:subscription, topic_name, subscription_name)
|
354
|
+
result.topic = topic_name
|
355
|
+
result
|
356
|
+
end
|
357
|
+
|
358
|
+
# Retrieves the subscriptions in the specified topic.
|
359
|
+
#
|
360
|
+
# ==== Attributes
|
361
|
+
#
|
362
|
+
# * +topic+ - Either a Azure::ServiceBus::Topic instance or a string of the topic name
|
363
|
+
# * +options+ - Hash. Optional parameters.
|
364
|
+
#
|
365
|
+
# ==== Options
|
366
|
+
#
|
367
|
+
# Accepted key/value pairs in options parameter are:
|
368
|
+
# * +:skip+ - Integer. Number of subscriptions to skip.
|
369
|
+
# * +:top+ - Integer. Number of subscriptions to list.
|
370
|
+
def list_subscriptions(topic, options={})
|
371
|
+
topic = _name_for(topic)
|
372
|
+
query = {}
|
373
|
+
query["$skip"] = options[:skip].to_i.to_s if options[:skip]
|
374
|
+
query["$top"] = options[:top].to_i.to_s if options[:top]
|
375
|
+
|
376
|
+
results = resource_list(:subscription, topic, query)
|
377
|
+
results.each { |s| s.topic = topic }
|
378
|
+
|
379
|
+
return results
|
380
|
+
end
|
381
|
+
|
382
|
+
# Enqueues a message into the specified topic. The limit to the number of messages
|
383
|
+
# which may be present in the topic is governed by the message size in MaxTopicSizeInBytes.
|
384
|
+
# If this message causes the topic to exceed its quota, a quota exceeded error is
|
385
|
+
# returned and the message will be rejected.
|
386
|
+
#
|
387
|
+
# ==== Attributes
|
388
|
+
#
|
389
|
+
# * +topic+ - Either a Azure::ServiceBus::Topic instance or a string of the topic name
|
390
|
+
# * +message+ - An Azure::ServiceBus::BrokeredMessage object containing message body and properties,
|
391
|
+
# or a string of the message body (a default BrokeredMessage will be created from the string).
|
392
|
+
def send_topic_message(topic, message)
|
393
|
+
_send_message(_name_for(topic), message)
|
394
|
+
end
|
395
|
+
|
396
|
+
# This operation is used to atomically retrieve and lock a message for processing.
|
397
|
+
# The message is guaranteed not to be delivered to other receivers during the lock
|
398
|
+
# duration period specified in buffer description. Once the lock expires, the
|
399
|
+
# message will be available to other receivers (on the same subscription only)
|
400
|
+
# during the lock duration period specified in the topic description. Once the lock
|
401
|
+
# expires, the message will be available to other receivers. In order to complete
|
402
|
+
# processing of the message, the receiver should issue a delete command with the
|
403
|
+
# lock ID received from this operation. To abandon processing of the message and
|
404
|
+
# unlock it for other receivers, an Unlock Message command should be issued, or
|
405
|
+
# the lock duration period can expire.
|
406
|
+
#
|
407
|
+
# ==== Attributes
|
408
|
+
#
|
409
|
+
# * +topic+ - String. The name of the topic or a Topic instance
|
410
|
+
# * +subscription+ - String. The name of the subscription or a Subscription instance
|
411
|
+
# * +options+ - Hash. Optional parameters.
|
412
|
+
#
|
413
|
+
# ==== Options
|
414
|
+
#
|
415
|
+
# Accepted key/value pairs in options parameter are:
|
416
|
+
# * +:timeout+ - Integer. Timeout for the REST call.
|
417
|
+
def peek_lock_subscription_message(topic, subscription, options={})
|
418
|
+
topic = _name_for(topic)
|
419
|
+
subscription = _name_for(subscription)
|
420
|
+
|
421
|
+
_peek_lock_message(subscriptions_path(topic, subscription), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
|
422
|
+
end
|
423
|
+
|
424
|
+
#
|
425
|
+
# Unlock a message for processing by other receivers on a given subscription.
|
426
|
+
# This operation deletes the lock object, causing the message to be unlocked.
|
427
|
+
# A message must have first been locked by a receiver before this operation
|
428
|
+
# is called.
|
429
|
+
#
|
430
|
+
# ==== Attributes
|
431
|
+
#
|
432
|
+
# * +message+ - String. Either the message location URL or a message object.
|
433
|
+
#
|
434
|
+
def unlock_subscription_message(message)
|
435
|
+
_unlock_message(message)
|
436
|
+
end
|
437
|
+
|
438
|
+
# Read and delete a message from a subscription as an atomic operation. This
|
439
|
+
# operation should be used when a best-effort guarantee is sufficient for an
|
440
|
+
# application; that is, using this operation it is possible for messages to
|
441
|
+
# be lost if processing fails.
|
442
|
+
#
|
443
|
+
# ==== Attributes
|
444
|
+
#
|
445
|
+
# * +topic+ - The name of the topic or a Topic instance
|
446
|
+
# * +subscription+ - The name of the subscription or a Subscription instance
|
447
|
+
# * +options+ - Hash. Optional parameters.
|
448
|
+
#
|
449
|
+
# ==== Options
|
450
|
+
#
|
451
|
+
# Accepted key/value pairs in options parameter are:
|
452
|
+
# * +:timeout+ - Integer. Timeout for the REST call.
|
453
|
+
#
|
454
|
+
def read_delete_subscription_message(topic, subscription, options={})
|
455
|
+
topic = _name_for(topic)
|
456
|
+
subscription = _name_for(subscription)
|
457
|
+
|
458
|
+
_read_delete_message(subscriptions_path(topic, subscription), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
|
459
|
+
end
|
460
|
+
|
461
|
+
# Completes processing on a locked message and delete it from the subscription.
|
462
|
+
# This operation should only be called after processing a previously locked
|
463
|
+
# message is successful to maintain At-Least-Once delivery assurances.
|
464
|
+
#
|
465
|
+
# ==== Attributes
|
466
|
+
#
|
467
|
+
# * +message+ - String. Either the message location URL or a message object.
|
468
|
+
#
|
469
|
+
def delete_subscription_message(message)
|
470
|
+
_delete_message(message)
|
471
|
+
end
|
472
|
+
|
473
|
+
# Sends a message into the specified queue. The limit to the number of messages
|
474
|
+
# which may be present in the topic is governed by the message size the
|
475
|
+
# MaxTopicSizeInMegaBytes. If this message will cause the queue to exceed its
|
476
|
+
# quota, a quota exceeded error is returned and the message will be rejected.
|
477
|
+
#
|
478
|
+
# ==== Attributes
|
479
|
+
#
|
480
|
+
# * +queue+ - Either a Azure::ServiceBus::Queue instance or a string of the queue name
|
481
|
+
# * +message+ - An Azure::ServiceBus::BrokeredMessage object containing message body and properties,
|
482
|
+
# or a string of the message body (a default BrokeredMessage will be created from the string).
|
483
|
+
def send_queue_message(queue, message)
|
484
|
+
_send_message(_name_for(queue), message)
|
485
|
+
end
|
486
|
+
|
487
|
+
#
|
488
|
+
# Automatically retrieves and locks a message from a queue for processing. The
|
489
|
+
# message is guaranteed not to be delivered to other receivers (on the same
|
490
|
+
# subscription only) during the lock duration period specified in the queue
|
491
|
+
# description. Once the lock expires, the message will be available to other
|
492
|
+
# receivers. In order to complete processing of the message, the receiver
|
493
|
+
# should issue a delete command with the lock ID received from this operation.
|
494
|
+
# To abandon processing of the message and unlock it for other receivers,
|
495
|
+
# an Unlock Message command should be issued, or the lock duration period
|
496
|
+
# can expire.
|
497
|
+
#
|
498
|
+
# ==== Attributes
|
499
|
+
#
|
500
|
+
# * +queue+ - String. Either a Azure::ServiceBus::Queue instance or a string of the queue name
|
501
|
+
# * +options+ - Hash. Optional parameters.
|
502
|
+
#
|
503
|
+
# ==== Options
|
504
|
+
#
|
505
|
+
# Accepted key/value pairs in options parameter are:
|
506
|
+
# * +:timeout+ - Integer. Timeout for the REST call.
|
507
|
+
#
|
508
|
+
def peek_lock_queue_message(queue, options={})
|
509
|
+
_peek_lock_message(_name_for(queue), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
|
510
|
+
end
|
511
|
+
|
512
|
+
# Unlocks a message for processing by other receivers on a given subscription.
|
513
|
+
# This operation deletes the lock object, causing the message to be unlocked.
|
514
|
+
# A message must have first been locked by a receiver before this operation is
|
515
|
+
# called.
|
516
|
+
#
|
517
|
+
# ==== Attributes
|
518
|
+
#
|
519
|
+
# * +message+ - String. Either the message location URL or a message object.
|
520
|
+
#
|
521
|
+
def unlock_queue_message(message)
|
522
|
+
_unlock_message(message)
|
523
|
+
end
|
524
|
+
|
525
|
+
# Reads and deletes a message from a queue as an atomic operation. This operation
|
526
|
+
# should be used when a best-effort guarantee is sufficient for an application;
|
527
|
+
# that is, using this operation it is possible for messages to be lost if
|
528
|
+
# processing fails.
|
529
|
+
#
|
530
|
+
# ==== Attributes
|
531
|
+
#
|
532
|
+
# * +queue+ - Either a Azure::ServiceBus::Queue instance or a string of the queue name
|
533
|
+
# * +options+ - Hash. Optional parameters.
|
534
|
+
#
|
535
|
+
# ==== Options
|
536
|
+
#
|
537
|
+
# Accepted key/value pairs in options parameter are:
|
538
|
+
# * +:timeout+ - Integer. Timeout for the REST call.
|
539
|
+
#
|
540
|
+
def read_delete_queue_message(queue, options={})
|
541
|
+
_read_delete_message(_name_for(queue), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
|
542
|
+
end
|
543
|
+
|
544
|
+
# Completes processing on a locked message and delete it from the queue. This
|
545
|
+
# operation should only be called after processing a previously locked message
|
546
|
+
# is successful to maintain At-Least-Once delivery assurances.
|
547
|
+
#
|
548
|
+
# ==== Attributes
|
549
|
+
#
|
550
|
+
# * +message+ - String. Either the message location URL or a message object.
|
551
|
+
#
|
552
|
+
def delete_queue_message(message)
|
553
|
+
_delete_message(message)
|
554
|
+
end
|
555
|
+
|
556
|
+
# Public: Receives a queue message.
|
557
|
+
#
|
558
|
+
# ==== Attributes
|
559
|
+
#
|
560
|
+
# * +queue+ - String. The queue name.
|
561
|
+
# * +options+ - Hash. Optional parameters.
|
562
|
+
#
|
563
|
+
# ==== Options
|
564
|
+
#
|
565
|
+
# Accepted key/value pairs in options parameter are:
|
566
|
+
# * +:peek_lock+ - Boolean. Lock when peeking.
|
567
|
+
# * +:timeout+ - Integer. Timeout for the REST call.
|
568
|
+
#
|
569
|
+
def receive_queue_message(queue, options={})
|
570
|
+
peek_lock = true
|
571
|
+
peek_lock = options[:peek_lock] if options[:peek_lock]
|
572
|
+
|
573
|
+
options[:timeout] = options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT
|
574
|
+
if peek_lock
|
575
|
+
peek_lock_queue_message(queue, options)
|
576
|
+
else
|
577
|
+
read_delete_queue_message(queue, options)
|
578
|
+
end
|
579
|
+
end
|
580
|
+
|
581
|
+
# Public: Receives a subscription message.
|
582
|
+
#
|
583
|
+
# ==== Attributes
|
584
|
+
#
|
585
|
+
# * +topic+ - String. The topic name.
|
586
|
+
# * +options+ - Hash. Optional parameters.
|
587
|
+
#
|
588
|
+
# ==== Options
|
589
|
+
#
|
590
|
+
# Accepted key/value pairs in options parameter are:
|
591
|
+
# * +:peek_lock+ - Boolean. Lock when peeking.
|
592
|
+
# * +:timeout+ - Integer. Timeout for the REST call.
|
593
|
+
#
|
594
|
+
def receive_subscription_message(topic, subscription, options={})
|
595
|
+
peek_lock = true
|
596
|
+
peek_lock = options[:peek_lock] if options[:peek_lock]
|
597
|
+
|
598
|
+
options[:timeout] = options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT
|
599
|
+
if peek_lock
|
600
|
+
peek_lock_subscription_message(topic, subscription, options)
|
601
|
+
else
|
602
|
+
read_delete_subscription_message(topic, subscription, options)
|
603
|
+
end
|
604
|
+
end
|
605
|
+
|
606
|
+
private
|
607
|
+
|
608
|
+
def _unlock_message(message)
|
609
|
+
_modify_message(:put, message)
|
610
|
+
end
|
611
|
+
|
612
|
+
def _delete_message(message)
|
613
|
+
_modify_message(:delete, message)
|
614
|
+
end
|
615
|
+
|
616
|
+
def _modify_message(method, message)
|
617
|
+
uri = nil
|
618
|
+
if (message.respond_to? :location)
|
619
|
+
uri = message.location
|
620
|
+
else
|
621
|
+
uri = message
|
622
|
+
end
|
623
|
+
|
624
|
+
call(method, uri)
|
625
|
+
nil
|
626
|
+
end
|
627
|
+
|
628
|
+
def _send_message(path, message)
|
629
|
+
message = Azure::ServiceBus::BrokeredMessage.new(message.to_s) unless message.kind_of?(Azure::ServiceBus::BrokeredMessage)
|
630
|
+
|
631
|
+
serializer = BrokeredMessageSerializer.new(message)
|
632
|
+
broker_properties = serializer.to_json
|
633
|
+
message_properties = serializer.get_property_headers
|
634
|
+
|
635
|
+
content_type = message.content_type || 'text/plain'
|
636
|
+
|
637
|
+
headers = {
|
638
|
+
'BrokerProperties'=> broker_properties
|
639
|
+
}
|
640
|
+
|
641
|
+
message_properties.each do |k,v|
|
642
|
+
headers[k.to_s.encode("UTF-8")] = v.encode("UTF-8")
|
643
|
+
end
|
644
|
+
|
645
|
+
headers["Content-Type"] = content_type
|
646
|
+
|
647
|
+
call(:post, messages_uri(path), message.body, headers)
|
648
|
+
nil
|
649
|
+
end
|
650
|
+
|
651
|
+
def _read_delete_message(path, timeout=DEFAULT_TIMEOUT)
|
652
|
+
_retrieve_message(:delete, path, timeout)
|
653
|
+
end
|
654
|
+
|
655
|
+
def _peek_lock_message(path, timeout=DEFAULT_TIMEOUT)
|
656
|
+
_retrieve_message(:post, path, timeout)
|
657
|
+
end
|
658
|
+
|
659
|
+
def _retrieve_message(method, path, timeout=DEFAULT_TIMEOUT)
|
660
|
+
uri = messages_head_uri(path, { "timeout"=> timeout.to_s })
|
661
|
+
|
662
|
+
response = call(method, uri)
|
663
|
+
(response.status_code == 204) ? nil : BrokeredMessageSerializer.get_from_http_response(response)
|
664
|
+
end
|
665
|
+
|
666
|
+
def _rule_from(*p)
|
667
|
+
rule = nil
|
668
|
+
|
669
|
+
if p.length == 3 or p.length == 4
|
670
|
+
rule = Azure::ServiceBus::Rule.new(p[2]) do |r|
|
671
|
+
r.topic = p[0]
|
672
|
+
r.subscription = p[1]
|
673
|
+
r.description = p[3] if p.length == 4
|
674
|
+
end
|
675
|
+
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
|
676
|
+
rule = p[0]
|
677
|
+
else
|
678
|
+
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."
|
679
|
+
end
|
680
|
+
|
681
|
+
rule
|
682
|
+
end
|
683
|
+
|
684
|
+
def _rule_args(*p)
|
685
|
+
if p.length == 3
|
686
|
+
topic_name = p[0]
|
687
|
+
subscription_name = p[1]
|
688
|
+
rule_name = p[2]
|
689
|
+
elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic
|
690
|
+
topic_name = p[0].topic
|
691
|
+
subscription_name = p[0].subscription
|
692
|
+
rule_name = p[0].name
|
693
|
+
else
|
694
|
+
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."
|
695
|
+
end
|
696
|
+
|
697
|
+
return topic_name, subscription_name, rule_name
|
698
|
+
end
|
699
|
+
|
700
|
+
def _subscription_from(*p)
|
701
|
+
subscription = nil
|
702
|
+
|
703
|
+
if p.length == 3
|
704
|
+
subscription = Azure::ServiceBus::Subscription.new(p[1], p[2]) do |sub|
|
705
|
+
sub.topic = p[0]
|
706
|
+
end
|
707
|
+
elsif p.length == 2
|
708
|
+
subscription = Azure::ServiceBus::Subscription.new(p[1]) do |sub|
|
709
|
+
sub.topic = p[0]
|
710
|
+
end
|
711
|
+
elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic and p[0].respond_to? :description
|
712
|
+
subscription = p[0]
|
713
|
+
else
|
714
|
+
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."
|
715
|
+
end
|
716
|
+
|
717
|
+
subscription
|
718
|
+
end
|
719
|
+
|
720
|
+
def _subscription_args(*p)
|
721
|
+
|
722
|
+
raise ArgumentError, "Not enough args" if p.length < 1
|
723
|
+
topic_name = nil
|
724
|
+
subscription_name = nil
|
725
|
+
options = {}
|
726
|
+
|
727
|
+
if p.length == 3
|
728
|
+
# topic/sub/options
|
729
|
+
topic_name = _name_for(p[0])
|
730
|
+
subscription_name = _name_for(p[1])
|
731
|
+
options =p[2]
|
732
|
+
elsif p.length == 2
|
733
|
+
# either subscription/options or topic/sub
|
734
|
+
if p[0].respond_to? :name and p[0].respond_to? :topic
|
735
|
+
topic_name = p[0].topic
|
736
|
+
subscription_name = p[0].name
|
737
|
+
options =p[1]
|
738
|
+
else
|
739
|
+
topic_name = _name_for(p[0])
|
740
|
+
subscription_name = _name_for(p[1])
|
741
|
+
end
|
742
|
+
elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic
|
743
|
+
topic_name = p[0].topic
|
744
|
+
subscription_name = p[0].name
|
745
|
+
else
|
746
|
+
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."
|
747
|
+
end
|
748
|
+
|
749
|
+
return topic_name, subscription_name, options
|
750
|
+
end
|
751
|
+
|
752
|
+
def _name_for(val)
|
753
|
+
val.respond_to?(:name) ? val.name : val
|
754
|
+
end
|
755
|
+
|
756
|
+
def _new_or_existing(type, *p)
|
757
|
+
p[0].kind_of?(type) ? p[0] : type.new(*p)
|
758
|
+
end
|
759
|
+
|
760
|
+
|
761
|
+
def create_resource_entry(resource, entry, *p)
|
762
|
+
body = Serialization.resource_to_xml resource, entry
|
763
|
+
response = call(:put, self.send("#{resource.to_s}_uri", *p), body)
|
764
|
+
results = Serialization.resources_from_xml(resource, response.body)
|
765
|
+
results ? results.first : results
|
766
|
+
end
|
767
|
+
|
768
|
+
def delete_resource_entry(resource, *p)
|
769
|
+
call(:delete, self.send("#{resource.to_s}_uri", *p))
|
770
|
+
nil
|
771
|
+
end
|
772
|
+
|
773
|
+
def resource_entry(resource, *p)
|
774
|
+
uri = self.send("#{resource.to_s}_uri", *p)
|
775
|
+
response = call(:get, uri)
|
776
|
+
results = Serialization.resources_from_xml(resource, response.body)
|
777
|
+
result = results ? results.first : results
|
778
|
+
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
|
779
|
+
result
|
780
|
+
end
|
781
|
+
|
782
|
+
def resource_list(resource, *p)
|
783
|
+
response = call(:get, self.send("#{resource.to_s}_list_uri", *p))
|
784
|
+
Serialization.resources_from_xml_with_next_link(resource, response.body)
|
785
|
+
end
|
786
|
+
|
787
|
+
# paths
|
788
|
+
|
789
|
+
protected
|
790
|
+
def message_path(path, sequence_number, lock_token)
|
791
|
+
"#{messages_path(path)}/#{sequence_number}/#{lock_token}"
|
792
|
+
end
|
793
|
+
|
794
|
+
protected
|
795
|
+
def messages_head_path(path)
|
796
|
+
"#{messages_path(path)}/head"
|
797
|
+
end
|
798
|
+
|
799
|
+
protected
|
800
|
+
def messages_path(path)
|
801
|
+
"#{path}/messages"
|
802
|
+
end
|
803
|
+
|
804
|
+
protected
|
805
|
+
def rule_path(topic, subscription, rule)
|
806
|
+
"#{subscriptions_path(topic, subscription)}/rules/#{rule}"
|
807
|
+
end
|
808
|
+
|
809
|
+
protected
|
810
|
+
def subscriptions_path(topic, subscription)
|
811
|
+
"#{topic}/subscriptions/#{subscription}"
|
812
|
+
end
|
813
|
+
|
814
|
+
# messages uris
|
815
|
+
|
816
|
+
protected
|
817
|
+
def message_uri(path, sequence_number, lock_token, query={})
|
818
|
+
generate_uri(message_path(path, sequence_number, lock_token), query)
|
819
|
+
end
|
820
|
+
|
821
|
+
protected
|
822
|
+
def messages_head_uri(path, query={})
|
823
|
+
generate_uri(messages_head_path(path), query)
|
824
|
+
end
|
825
|
+
|
826
|
+
protected
|
827
|
+
def messages_uri(path, query={})
|
828
|
+
generate_uri(messages_path(path), query)
|
829
|
+
end
|
830
|
+
|
831
|
+
# entry uris
|
832
|
+
protected
|
833
|
+
def rule_uri(topic, subscription, rule, query={})
|
834
|
+
generate_uri(rule_path(topic, subscription, rule), query)
|
835
|
+
end
|
836
|
+
|
837
|
+
protected
|
838
|
+
def subscription_uri(topic, subscription, query={})
|
839
|
+
generate_uri(subscriptions_path(topic, subscription), query)
|
840
|
+
end
|
841
|
+
|
842
|
+
protected
|
843
|
+
def relay_uri(relay, query={})
|
844
|
+
query["api-version"] = "2013-10"
|
845
|
+
generate_uri(relay, query)
|
846
|
+
end
|
847
|
+
|
848
|
+
protected
|
849
|
+
def queue_uri(topic, query={})
|
850
|
+
generate_uri(topic, query)
|
851
|
+
end
|
852
|
+
|
853
|
+
protected
|
854
|
+
def topic_uri(topic, query={})
|
855
|
+
generate_uri(topic, query)
|
856
|
+
end
|
857
|
+
|
858
|
+
# list uris
|
859
|
+
|
860
|
+
protected
|
861
|
+
def rule_list_uri(topic, subscription, query={})
|
862
|
+
resource_list_uri(:rule, query, subscriptions_path(topic, subscription))
|
863
|
+
end
|
864
|
+
|
865
|
+
protected
|
866
|
+
def subscription_list_uri(topic, query={})
|
867
|
+
resource_list_uri(:subscription, query, topic)
|
868
|
+
end
|
869
|
+
|
870
|
+
protected
|
871
|
+
def relay_list_uri(query={})
|
872
|
+
resource_list_uri(:relay, query)
|
873
|
+
end
|
874
|
+
|
875
|
+
protected
|
876
|
+
def queue_list_uri(query={})
|
877
|
+
resource_list_uri(:queue, query)
|
878
|
+
end
|
879
|
+
|
880
|
+
protected
|
881
|
+
def topic_list_uri(query={})
|
882
|
+
resource_list_uri(:topic, query)
|
883
|
+
end
|
884
|
+
|
885
|
+
protected
|
886
|
+
def resource_list_uri(resource, query={}, subpath='$Resources')
|
887
|
+
skip = query.delete ["$skip"]
|
888
|
+
top = query.delete ["$top"]
|
889
|
+
|
890
|
+
uri = generate_uri("#{subpath}/#{resource.to_s.capitalize}s", query)
|
891
|
+
uri.query = [uri.query, "$skip=" + skip].join('&') if skip
|
892
|
+
uri.query = [uri.query, "$top=" + top].join('&') if top
|
893
|
+
uri
|
894
|
+
end
|
895
|
+
end
|
896
|
+
end
|
897
897
|
end
|