~andrewjbeach/juju-ci-tools/make-local-patcher

« back to all changes in this revision

Viewing changes to azure-sdk-for-python-master/tests/doctest_servicebusservicetopic.py

  • Committer: Curtis Hovey
  • Date: 2015-06-11 19:35:22 UTC
  • mto: This revision was merged to the branch mainline in revision 983.
  • Revision ID: curtis@canonical.com-20150611193522-o2nqkqb04o2i75wv
Remove euca_dump_logs because it has not been used this year.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#-------------------------------------------------------------------------
 
2
# Copyright (c) Microsoft.  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
 
 
16
"""
 
17
How to Create a Topic
 
18
---------------------
 
19
>>> from azure.servicebus import *
 
20
>>> bus_service = ServiceBusService(ns, key, 'owner')
 
21
>>> bus_service.create_topic('mytopic')
 
22
True
 
23
 
 
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)
 
28
True
 
29
 
 
30
How to Create Subscriptions
 
31
---------------------------
 
32
>>> bus_service.create_subscription('mytopic', 'AllMessages')
 
33
True
 
34
 
 
35
>>> bus_service.create_subscription('mytopic', 'HighMessages')
 
36
True
 
37
 
 
38
>>> rule = Rule()
 
39
>>> rule.filter_type = 'SqlFilter'
 
40
>>> rule.filter_expression = 'messagenumber > 3'
 
41
>>> bus_service.create_rule('mytopic', 'HighMessages', 'HighMessageFilter', rule)
 
42
True
 
43
 
 
44
>>> bus_service.delete_rule('mytopic', 'HighMessages', DEFAULT_RULE_NAME)
 
45
True
 
46
 
 
47
>>> bus_service.create_subscription('mytopic', 'LowMessages')
 
48
True
 
49
 
 
50
>>> rule = Rule()
 
51
>>> rule.filter_type = 'SqlFilter'
 
52
>>> rule.filter_expression = 'messagenumber <= 3'
 
53
>>> bus_service.create_rule('mytopic', 'LowMessages', 'LowMessageFilter', rule)
 
54
True
 
55
 
 
56
>>> bus_service.delete_rule('mytopic', 'LowMessages', DEFAULT_RULE_NAME)
 
57
True
 
58
 
 
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)
 
64
 
 
65
How to Receive Messages from a Subscription
 
66
-------------------------------------------
 
67
>>> msg = bus_service.receive_subscription_message('mytopic', 'LowMessages')
 
68
>>> print(msg.body)
 
69
Msg 0
 
70
 
 
71
>>> msg = bus_service.receive_subscription_message('mytopic', 'LowMessages', peek_lock=True)
 
72
>>> print(msg.body)
 
73
Msg 1
 
74
>>> msg.delete()
 
75
 
 
76
How to Delete Topics and Subscriptions
 
77
--------------------------------------
 
78
>>> bus_service.delete_subscription('mytopic', 'HighMessages')
 
79
True
 
80
 
 
81
>>> bus_service.delete_queue('mytopic')
 
82
True
 
83
 
 
84
>>> bus_service.delete_queue('mytopic2')
 
85
True
 
86
 
 
87
"""
 
88
from util import credentials
 
89
 
 
90
ns = credentials.getServiceBusNamespace()
 
91
key = credentials.getServiceBusKey()
 
92
 
 
93
if __name__ == "__main__":
 
94
    import doctest
 
95
    doctest.testmod()