-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[Service Bus] Clarify and sample session listing #50194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Eldert Grootenboer (EldertGrootenboer)
merged 7 commits into
main
from
sample/servicebus-list-sessions
Aug 20, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a902b86
docs(servicebus): clarify and sample session listing
EldertGrootenboer f4a05b8
docs: address list sessions review feedback
EldertGrootenboer 98982f7
docs: finalize Service Bus beta changelog
EldertGrootenboer eea5e66
docs: update Service Bus beta release date
EldertGrootenboer c205b4d
docs: update Service Bus README release version
EldertGrootenboer ee14a0a
Merge branch 'main' into sample/servicebus-list-sessions
EldertGrootenboer 61a80bb
docs: keep release prep separate from session samples
EldertGrootenboer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...g-servicebus/src/samples/java/com/azure/messaging/servicebus/ListSessionsAsyncSample.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.messaging.servicebus; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.time.OffsetDateTime; | ||
| import java.time.ZoneOffset; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| /** | ||
| * Demonstrates how to asynchronously list sessions using both supported modes. Default listing returns sessions with | ||
| * active messages or stored session state and excludes sessions with neither. A cutoff returns only sessions whose | ||
| * stored state was set or updated after that time. | ||
| */ | ||
| public class ListSessionsAsyncSample { | ||
| String connectionString = System.getenv("AZURE_SERVICEBUS_NAMESPACE_CONNECTION_STRING"); | ||
| String topicName = System.getenv("AZURE_SERVICEBUS_SAMPLE_TOPIC_NAME"); | ||
| String subscriptionName = System.getenv("AZURE_SERVICEBUS_SAMPLE_SESSION_SUBSCRIPTION_NAME"); | ||
|
|
||
| /** | ||
| * Main method to invoke this demo on how to list session IDs in a Service Bus topic subscription. | ||
| * | ||
| * @param args Unused arguments to the program. | ||
| * @throws InterruptedException If the program is interrupted while waiting for the operation to complete. | ||
| */ | ||
| public static void main(String[] args) throws InterruptedException { | ||
| ListSessionsAsyncSample sample = new ListSessionsAsyncSample(); | ||
| sample.run(); | ||
| } | ||
|
|
||
| /** | ||
| * Lists sessions using both supported modes. | ||
| * | ||
| * @throws InterruptedException If the program is interrupted while waiting for the operation to complete. | ||
| */ | ||
| @Test | ||
| public void run() throws InterruptedException { | ||
| CountDownLatch countdownLatch = new CountDownLatch(1); | ||
| ServiceBusSessionReceiverAsyncClient sessionReceiver = new ServiceBusClientBuilder() | ||
| .connectionString(connectionString) | ||
| .sessionReceiver() | ||
| .topicName(topicName) | ||
| .subscriptionName(subscriptionName) | ||
| .buildAsyncClient(); | ||
|
|
||
| try { | ||
| OffsetDateTime sessionStateUpdatedAfter = OffsetDateTime.now(ZoneOffset.UTC).minusDays(7); | ||
|
|
||
| sessionReceiver.listSessions() | ||
| .doOnNext(sessionId -> System.out.println("Session ID: " + sessionId)) | ||
| .thenMany(sessionReceiver.listSessions(sessionStateUpdatedAfter)) | ||
| .subscribe( | ||
| sessionId -> System.out.println("Recently updated session ID: " + sessionId), | ||
| error -> { | ||
| System.err.println("Error occurred: " + error); | ||
| countdownLatch.countDown(); | ||
| }, | ||
| countdownLatch::countDown); | ||
|
|
||
| countdownLatch.await(30, TimeUnit.SECONDS); | ||
| } finally { | ||
| sessionReceiver.close(); | ||
| } | ||
| } | ||
| } |
61 changes: 61 additions & 0 deletions
61
...saging-servicebus/src/samples/java/com/azure/messaging/servicebus/ListSessionsSample.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.messaging.servicebus; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.time.OffsetDateTime; | ||
| import java.time.ZoneOffset; | ||
|
|
||
| /** | ||
| * Demonstrates how to list sessions using both supported modes. Default listing returns sessions with active messages | ||
| * or stored session state and excludes sessions with neither. A cutoff returns only sessions whose stored state was set | ||
| * or updated after that time. | ||
| */ | ||
| public class ListSessionsSample { | ||
| String connectionString = System.getenv("AZURE_SERVICEBUS_NAMESPACE_CONNECTION_STRING"); | ||
| String queueName = System.getenv("AZURE_SERVICEBUS_SAMPLE_SESSION_QUEUE_NAME"); | ||
|
|
||
| /** | ||
| * Main method to invoke this demo on how to list session IDs in a Service Bus queue. | ||
| * | ||
| * @param args Unused arguments to the program. | ||
| */ | ||
| public static void main(String[] args) { | ||
| ListSessionsSample sample = new ListSessionsSample(); | ||
| sample.run(); | ||
| } | ||
|
|
||
| /** | ||
| * Lists sessions using both supported modes. | ||
| */ | ||
| @Test | ||
| public void run() { | ||
| ServiceBusSessionReceiverClient sessionReceiver = new ServiceBusClientBuilder() | ||
| .connectionString(connectionString) | ||
| .sessionReceiver() | ||
| .queueName(queueName) | ||
| .buildClient(); | ||
|
|
||
| try { | ||
| listSessionsWithMessagesOrState(sessionReceiver); | ||
| listSessionsWithRecentlyUpdatedState(sessionReceiver); | ||
| } finally { | ||
| sessionReceiver.close(); | ||
| } | ||
| } | ||
|
|
||
| private static void listSessionsWithMessagesOrState(ServiceBusSessionReceiverClient sessionReceiver) { | ||
| // Omitting the cutoff returns sessions with active messages or stored session state. | ||
| sessionReceiver.listSessions() | ||
| .forEach(sessionId -> System.out.println("Session ID: " + sessionId)); | ||
| } | ||
|
|
||
| private static void listSessionsWithRecentlyUpdatedState(ServiceBusSessionReceiverClient sessionReceiver) { | ||
| // Supplying a cutoff returns only sessions whose stored state was set or updated after that time. | ||
| OffsetDateTime sessionStateUpdatedAfter = OffsetDateTime.now(ZoneOffset.UTC).minusDays(7); | ||
| sessionReceiver.listSessions(sessionStateUpdatedAfter) | ||
| .forEach(sessionId -> System.out.println("Recently updated session ID: " + sessionId)); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.