File: README.rst

package info (click to toggle)
python-azure 2.0.0~rc6%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 269,052 kB
  • ctags: 9,428
  • sloc: python: 81,857; makefile: 149
file content (222 lines) | stat: -rw-r--r-- 5,789 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
Microsoft Azure SDK for Python
==============================

This is the Microsoft Azure Service Bus Runtime Client Library.

This package has been tested with Python 2.7, 3.3, 3.4 and 3.5.

For a more complete set of Azure libraries, see the `azure <https://pypi.python.org/pypi/azure>`__ bundle package.


Compatibility
=============

**IMPORTANT**: If you have an earlier version of the azure package
(version < 1.0), you should uninstall it before installing this package.

You can check the version using pip:

.. code:: shell

    pip freeze

If you see azure==0.11.0 (or any version below 1.0), uninstall it first:

.. code:: shell

    pip uninstall azure


Features
========

-  Queues: create, list and delete queues; create, list, and delete subscriptions; send, receive, unlock and delete messages
-  Topics: create, list, and delete topics; create, list, and delete rules
-  Event Hubs: create and delete event hubs; send events


Installation
============

Download Package
----------------

To install via the Python Package Index (PyPI), type:

.. code:: shell

    pip install azure-servicebus


Download Source Code
--------------------

To get the source code of the SDK via **git** type:

.. code:: shell

    git clone https://github.com/Azure/azure-sdk-for-python.git
    cd azure-sdk-for-python
    cd azure-servicebus
    python setup.py install


Usage
=====

ServiceBus Queues
-----------------

ServiceBus Queues are an alternative to Storage Queues that might be
useful in scenarios where more advanced messaging features are needed
(larger message sizes, message ordering, single-operation destructive
reads, scheduled delivery) using push-style delivery (using long
polling).

The service can use Shared Access Signature authentication, or ACS
authentication.

Service bus namespaces created using the Azure portal after August 2014
no longer support ACS authentication. You can create ACS compatible
namespaces with the Azure SDK.

Shared Access Signature Authentication
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To use Shared Access Signature authentication, create the service bus
service with:

.. code:: python

    from azure.servicebus import ServiceBusService

    key_name = 'RootManageSharedAccessKey' # SharedAccessKeyName from Azure portal
    key_value = '' # SharedAccessKey from Azure portal
    sbs = ServiceBusService(service_namespace,
                            shared_access_key_name=key_name,
                            shared_access_key_value=key_value)

ACS Authentication
~~~~~~~~~~~~~~~~~~

To use ACS authentication, create the service bus service with:

.. code:: python

    from azure.servicebus import ServiceBusService

    account_key = '' # DEFAULT KEY from Azure portal
    issuer = 'owner' # DEFAULT ISSUER from Azure portal
    sbs = ServiceBusService(service_namespace,
                            account_key=account_key,
                            issuer=issuer)

Sending and Receiving Messages
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The **create\_queue** method can be used to ensure a queue exists:

.. code:: python

    sbs.create_queue('taskqueue')

The **send\_queue\_message** method can then be called to insert the
message into the queue:

.. code:: python

    from azure.servicebus import Message

    msg = Message('Hello World!')
    sbs.send_queue_message('taskqueue', msg)

It is then possible to call the **receive\_queue\_message** method to
dequeue the message.

.. code:: python

    msg = sbs.receive_queue_message('taskqueue')

ServiceBus Topics
-----------------

ServiceBus topics are an abstraction on top of ServiceBus Queues that
make pub/sub scenarios easy to implement.

The **create\_topic** method can be used to create a server-side topic:

.. code:: python

    sbs.create_topic('taskdiscussion')

The **send\_topic\_message** method can be used to send a message to a
topic:

.. code:: python

    from azure.servicebus import Message

    msg = Message('Hello World!')
    sbs.send_topic_message('taskdiscussion', msg)

A client can then create a subscription and start consuming messages by
calling the **create\_subscription** method followed by the
**receive\_subscription\_message** method. Please note that any messages
sent before the subscription is created will not be received.

.. code:: python

    from azure.servicebus import Message

    sbs.create_subscription('taskdiscussion', 'client1')
    msg = Message('Hello World!')
    sbs.send_topic_message('taskdiscussion', msg)
    msg = sbs.receive_subscription_message('taskdiscussion', 'client1')

Event Hub
---------

Event Hubs enable the collection of event streams at high throughput, from
a diverse set of devices and services.

The **create\_event\_hub** method can be used to create an event hub:

.. code:: python

    sbs.create_event_hub('myhub')

To send an event:

.. code:: python

    sbs.send_event('myhub', '{ "DeviceId":"dev-01", "Temperature":"37.0" }')

The event content is the event message or JSON-encoded string that contains multiple messages.


Need Help?
==========

Be sure to check out the Microsoft Azure `Developer Forums on Stack
Overflow <http://go.microsoft.com/fwlink/?LinkId=234489>`__ if you have
trouble with the provided code.


Contribute Code or Provide Feedback
===================================

If you would like to become an active contributor to this project please
follow the instructions provided in `Microsoft Azure Projects
Contribution
Guidelines <http://azure.github.io/guidelines.html>`__.

If you encounter any bugs with the library please file an issue in the
`Issues <https://github.com/Azure/azure-sdk-for-python/issues>`__
section of the project.


Learn More
==========

`Microsoft Azure Python Developer
Center <http://azure.microsoft.com/en-us/develop/python/>`__