1
#-------------------------------------------------------------------------
2
# Copyright (c) Microsoft. All rights reserved.
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
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
#--------------------------------------------------------------------------
19
>>> from azure.servicebus import *
20
>>> bus_service = ServiceBusService(ns, key, 'owner')
21
>>> bus_service.create_topic('mytopic')
24
>>> topic_options = Topic()
25
>>> topic_options.max_size_in_megabytes = '5120'
26
>>> topic_options.default_message_time_to_live = 'PT1M'
27
>>> bus_service.create_topic('mytopic2', topic_options)
30
How to Create Subscriptions
31
---------------------------
32
>>> bus_service.create_subscription('mytopic', 'AllMessages')
35
>>> bus_service.create_subscription('mytopic', 'HighMessages')
39
>>> rule.filter_type = 'SqlFilter'
40
>>> rule.filter_expression = 'messagenumber > 3'
41
>>> bus_service.create_rule('mytopic', 'HighMessages', 'HighMessageFilter', rule)
44
>>> bus_service.delete_rule('mytopic', 'HighMessages', DEFAULT_RULE_NAME)
47
>>> bus_service.create_subscription('mytopic', 'LowMessages')
51
>>> rule.filter_type = 'SqlFilter'
52
>>> rule.filter_expression = 'messagenumber <= 3'
53
>>> bus_service.create_rule('mytopic', 'LowMessages', 'LowMessageFilter', rule)
56
>>> bus_service.delete_rule('mytopic', 'LowMessages', DEFAULT_RULE_NAME)
59
How to Send Messages to a Topic
60
-------------------------------
61
>>> for i in range(5):
62
... msg = Message('Msg ' + str(i), custom_properties={'messagenumber':i})
63
... bus_service.send_topic_message('mytopic', msg)
65
How to Receive Messages from a Subscription
66
-------------------------------------------
67
>>> msg = bus_service.receive_subscription_message('mytopic', 'LowMessages')
71
>>> msg = bus_service.receive_subscription_message('mytopic', 'LowMessages', peek_lock=True)
76
How to Delete Topics and Subscriptions
77
--------------------------------------
78
>>> bus_service.delete_subscription('mytopic', 'HighMessages')
81
>>> bus_service.delete_queue('mytopic')
84
>>> bus_service.delete_queue('mytopic2')
88
from util import credentials
90
ns = credentials.getServiceBusNamespace()
91
key = credentials.getServiceBusKey()
93
if __name__ == "__main__":