Skip to content

Commit 76a0d91

Browse files
ServiceBus Track2 Small doc and readme cleanup prior to preview 2 (Azure#11195)
* Add additional samples to readme per doc review comments. * Make message settlement docstrings more precise
1 parent 04e0f48 commit 76a0d91

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

sdk/servicebus/azure-servicebus/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ The following sections provide several code snippets covering some of the most c
123123

124124
* [Send a message to a queue](#send-a-message-to-a-queue)
125125
* [Receive a message from a queue](#receive-a-message-from-a-queue)
126+
* [Sending and receiving a message from a session enabled subscription](#sending-and-receiving-a-message-from-a-session-enabled-subscription)
126127
* [Defer a message on receipt](#defer-a-message-on-receipt)
127128

128129
To perform management tasks such as creating and deleting queues/topics/subscriptions, please utilize the azure-mgmt-servicebus library, available [here][servicebus_management_repository].
@@ -165,6 +166,30 @@ with ServiceBusClient.from_connection_string(connstr) as client:
165166
msg.complete()
166167
```
167168

169+
### Sending and receiving a message from a session enabled subscription
170+
171+
Sessions provide first-in-first-out and single-receiver semantics on top of a queue or subscription. While the actual receive syntax is the same, initialization differs slightly.
172+
173+
```Python
174+
from azure.servicebus import ServiceBusClient, Message
175+
176+
import os
177+
connstr = os.environ['SERVICE_BUS_CONN_STR']
178+
topic_name = os.environ['SERVICE_BUS_TOPIC_NAME']
179+
subscription_name = os.environ['SERVICE_BUS_SUBSCRIPTION_NAME']
180+
session_id = os.environ.get('SERVICE_BUS_SESSION_ID')
181+
182+
with ServiceBusClient.from_connection_string(connstr) as client:
183+
with client.get_topic_sender(topic_name) as sender:
184+
sender.send(Message("Session Enabled Message", session_id=session_id))
185+
186+
# If session_id is null here, will receive from the first available session.
187+
with client.get_subscription_session_receiver(topic_name, subscription_name, session_id) as receiver:
188+
for msg in receiver:
189+
print(str(msg))
190+
msg.complete()
191+
```
192+
168193
### Defer a message on receipt
169194

170195
When receiving from a queue, you have multiple actions you can take on the messages you receive. Where the prior example completes a message,

sdk/servicebus/azure-servicebus/azure/servicebus/_common/message.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ def abandon(self):
644644
# type: () -> None
645645
"""Abandon the message.
646646
647-
This message will be returned to the queue to be reprocessed.
647+
This message will be returned to the queue and made available to be received again.
648648
649649
:rtype: None
650650
:raises: ~azure.servicebus.exceptions.MessageAlreadySettled if the message has been settled.
@@ -661,8 +661,8 @@ def defer(self):
661661
# type: () -> None
662662
"""Defer the message.
663663
664-
This message will remain in the queue but must be received
665-
specifically by its sequence number in order to be processed.
664+
This message will remain in the queue but must be requested
665+
specifically by its sequence number in order to be received.
666666
667667
:rtype: None
668668
:raises: ~azure.servicebus.exceptions.MessageAlreadySettled if the message has been settled.

sdk/servicebus/azure-servicebus/azure/servicebus/aio/_async_message.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ async def dead_letter(self, reason=None, description=None):
9494

9595
async def abandon(self):
9696
# type: () -> None
97-
"""Abandon the message. This message will be returned to the queue to be reprocessed.
97+
"""Abandon the message.
98+
99+
This message will be returned to the queue and made available to be received again.
98100
99101
:rtype: None
100102
:raises: ~azure.servicebus.exceptions.MessageAlreadySettled if the message has been settled.
@@ -108,7 +110,10 @@ async def abandon(self):
108110

109111
async def defer(self):
110112
# type: () -> None
111-
"""Abandon the message. This message will be returned to the queue to be reprocessed.
113+
"""Defers the message.
114+
115+
This message will remain in the queue but must be requested
116+
specifically by its sequence number in order to be received.
112117
113118
:rtype: None
114119
:raises: ~azure.servicebus.exceptions.MessageAlreadySettled if the message has been settled.

sdk/servicebus/azure-servicebus/samples/async_samples/session_pool_receive_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async def message_processing(servicebus_client, queue_name):
2929
print("Message: {}".format(message))
3030
print("Time to live: {}".format(message.header.time_to_live))
3131
print("Sequence number: {}".format(message.sequence_number))
32-
print("Enqueue Sequence numger: {}".format(message.enqueue_sequence_number))
32+
print("Enqueue Sequence number: {}".format(message.enqueue_sequence_number))
3333
print("Partition ID: {}".format(message.partition_id))
3434
print("Partition Key: {}".format(message.partition_key))
3535
print("Locked until: {}".format(message.locked_until_utc))

sdk/servicebus/azure-servicebus/samples/sync_samples/session_pool_receive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def message_processing(sb_client, queue_name, messages):
2828
print("Message: {}".format(message))
2929
print("Time to live: {}".format(message.header.time_to_live))
3030
print("Sequence number: {}".format(message.sequence_number))
31-
print("Enqueue Sequence numger: {}".format(message.enqueue_sequence_number))
31+
print("Enqueue Sequence number: {}".format(message.enqueue_sequence_number))
3232
print("Partition ID: {}".format(message.partition_id))
3333
print("Partition Key: {}".format(message.partition_key))
3434
print("Locked until: {}".format(message.locked_until_utc))

0 commit comments

Comments
 (0)