Skip to content

Commit d6c933b

Browse files
jsquirechristothes
andauthored
[Service Bus] Migration guide tweaks (Azure#37839)
* [Service Bus] Migration guide tweaks The focus of these changes is to revise some of the phrasing and streamline some of the explanations for migration scenarios. * Fixing broken link * Update sdk/servicebus/Azure.Messaging.ServiceBus/MigrationGuide.md Co-authored-by: Christopher Scott <chriscott@hotmail.com> * Fixing typo --------- Co-authored-by: Christopher Scott <chriscott@hotmail.com>
1 parent d9275d8 commit d6c933b

File tree

2 files changed

+26
-32
lines changed

2 files changed

+26
-32
lines changed

sdk/servicebus/Azure.Messaging.ServiceBus/MigrationGuide.md

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ We assume that you are familiar with the `Microsoft.Azure.ServiceBus` library. I
99
- [Guide for migrating to Azure.Messaging.ServiceBus from Microsoft.Azure.ServiceBus](#guide-for-migrating-to-azuremessagingservicebus-from-microsoftazureservicebus)
1010
- [Table of contents](#table-of-contents)
1111
- [Migration benefits](#migration-benefits)
12-
- [Cross Service SDK improvements](#cross-service-sdk-improvements)
12+
- [Cross-service SDK improvements](#cross-service-sdk-improvements)
1313
- [New features](#new-features)
1414
- [General changes](#general-changes)
1515
- [Package and namespaces](#package-and-namespaces)
@@ -24,7 +24,7 @@ We assume that you are familiar with the `Microsoft.Azure.ServiceBus` library. I
2424
- [Receiving messages](#receiving-messages)
2525
- [Dead letter messages](#dead-letter-messages)
2626
- [Working with sessions](#working-with-sessions)
27-
- [Cross-Entity transactions](#cross-entity-transactions)
27+
- [Cross-entity transactions](#cross-entity-transactions)
2828
- [Distributed tracing](#distributed-tracing)
2929
- [Plugins](#plugins)
3030
- [Additional samples](#additional-samples)
@@ -42,9 +42,9 @@ While we believe that there is significant benefit to adopting the new Service B
4242

4343
- `WindowsAzure.ServiceBus` has not been officially deprecated and will continue to be supported with security and bug fixes as well as receiving some minor refinements. However, in the near future it will not be under active development and new features are unlikely to be added.
4444

45-
- `Microsoft.Azure.ServiceBus` has been officially deprecated. While this package will continue to receive critical bug fixes, we strongly encourage you to upgrade.
45+
- `Microsoft.Azure.ServiceBus` has been officially deprecated. While this package will continue to receive critical bug fixes until it's retirement, we strongly encourage you to upgrade.
4646

47-
### Cross Service SDK improvements
47+
### Cross-service SDK improvements
4848

4949
The modern Service Bus client library also provides the ability to share in some of the cross-service improvements made to the Azure development experience, such as
5050

@@ -131,9 +131,7 @@ ServiceBusAdministrationClient client = new ServiceBusAdministrationClient(conne
131131

132132
### Sending messages
133133

134-
Previously, in `Microsoft.Azure.ServiceBus`, you could send messages either by using a `QueueClient` (or `TopicClient` if you are targetting a topic) or the `MessageSender`.
135-
136-
While the `QueueClient` supported the simple send operation, the `MessageSender` supported that and advanced scenarios like scheduling to send messages at a later time and cancelling such scheduled messages.
134+
In `Microsoft.Azure.ServiceBus`, you could send messages either by using a `QueueClient, TopicClient`, or `MessageSender`.
137135

138136
```C#
139137
// create a message to send
@@ -148,9 +146,9 @@ MessageSender sender = new MessageSender(connectionString, queueName);
148146
await sender.SendAsync(message);
149147
```
150148

151-
Now in `Azure.Messaging.ServiceBus`, we combine all the send related features under a common class `ServiceBusSender` that you can create from the top level client using the `CreateSender()` method. This method takes the queue or topic you want to target. This way, we give you a one stop shop for all your send related needs.
149+
In `Azure.Messaging.ServiceBus`, all of the send-related features are combined in a common class, `ServiceBusSender`, that is created by calling `CreateSender` on your `ServiceBusClient`. This method takes the queue or topic you want to send to and creates a sender for that specific entity.
152150

153-
We continue to support sending bytes in the message. Though, if you are working with strings, you can now create a message directly without having to convert it to bytes first.
151+
We continue to support sending bytes in the message. Though, if you are working with strings, you can now create a message directly without having to convert it to bytes explicitly.
154152

155153
```C# Snippet:ServiceBusSendSingleMessage
156154
string connectionString = "<connection_string>";
@@ -170,8 +168,7 @@ await sender.SendMessageAsync(message);
170168

171169
The feature to send a list of messages in a single call was implemented by batching all the messages into a single AMQP message and sending that to the service.
172170

173-
While we continue to support this feature, it had the potential to fail unexpectedly when the resulting batched AMQP message exceeded the size limit of the sender. To help with this, we now provide a safe way to batch multiple messages to be sent at once using the new `ServiceBusMessageBatch` class.
174-
While the below code sample uses a local queue as the source of messages to be safely batched and sent, your application may use a list or an array of messages that have accumulated from a different part of your code.
171+
While we continue to support this feature, it had the potential to fail unexpectedly when the resulting batched AMQP message exceeded the size limit of the sender. To help with this, we now provide a safe way to batch multiple messages to be sent at once using the new `ServiceBusMessageBatch` class. The batch allows you to measure your message with the `TryAdd` method, returning `false` when a message is too large to fit in the batch.
175172

176173
```C# Snippet:ServiceBusSendAndReceiveSafeBatch
177174
// add the messages that we plan to send to a local queue
@@ -218,9 +215,7 @@ while (messages.Count > 0)
218215

219216
### Receiving messages
220217

221-
Previously, in `Microsoft.Azure.ServiceBus`, you could receive messages either by using a `QueueClient` (or `SubscriptionClient` if you are targetting a subscription) or the `MessageReceiver`.
222-
223-
While the `QueueClient` supported the simple push model where you could register message and error handlers/callbacks, the `MessageReceiver` provided you with ways to receive messages (both normal and deferred) in batches, settle messages and renew locks.
218+
In `Microsoft.Azure.ServiceBus`, you could receive messages either by using a `QueueClient`, `SubscriptionClient`, or `MessageReceiver`.
224219

225220
```C#
226221
// create the QueueClient
@@ -253,11 +248,13 @@ Console.WriteLine($"Received message with Body:{Encoding.UTF8.GetString(received
253248
await receiver.CompleteAsync(receivedMessage);
254249
```
255250

256-
Now in `Azure.Messaging.ServiceBus`, we introduce a dedicated class `ServiceBusProcessor` which takes your message and error handlers to provide you with the same simple way to get started with processing your messages as message handlers in the previous packages, with auto-complete and auto-lock renewal features. This class also provides a graceful shutdown via the `StopProcessingAsync` method which will ensure that no more messages will be received, but at the same time you can continue the processing and settling the messages already in flight.
251+
In `Azure.Messaging.ServiceBus`, we introduced `ServiceBusProcessor` which uses a push-based approach to deliver messages to event handlers that you provide while managing locks, message completion, concurrency, and resiliency. The processor also provides a graceful shutdown via the `StopProcessingAsync` method which will ensure that no more messages will be received, but at the same time you can continue the processing and settling the messages already in flight.
257252

258-
The concept of a receiver remains for users who need to have a more fine grained control over the receiving and settling messages. The difference is that this is now created from the top-level `ServiceBusClient` via the `CreateReceiver()` method that would take the queue or subscription you want to target.
253+
The concept of a receiver remains for users who need to have a more fine-grained control over the reading and settling messages. The difference is that this is now created from the top-level `ServiceBusClient` via the `CreateReceiver` method taking the queue or subscription you want to read from and creating a receiver specific to that entity.
259254

260-
Another notable difference from the previous library when it comes to receiving messages, is that the new library uses a separate type for received messages, `ServiceBusReceivedMessage`. This helps reduce the surface area of the sendable messages by excluding properties that are set by the service itself and cannot be set by a user when sending messages. In order to construct a `ServiceBusReceivedMessage` for mocking purposes, use the `ServiceBusModelFactory.ServiceBusReceivedMessage` method. In general, output types that are meant to be constructed only by the library can be created for mocking using the `ServiceBusModelFactory` static class.
255+
Another notable difference from `Microsoft.Azure.ServiceBus` when it comes to receiving messages, is that `Azure.Messaging.ServiceBus` uses a separate type for received messages, `ServiceBusReceivedMessage`. This helps reduce the surface area of the sendable messages by excluding properties that are owned by the service and cannot be set when sending messages.
256+
257+
To support testing, the `ServiceBusModelFactory.ServiceBusReceivedMessage` method can be used to mock a message received from Service Bus. In general, all types that are meant to be created only by the library can be created for mocking using the `ServiceBusModelFactory` static class.
261258

262259
```C# Snippet:ServiceBusConfigureProcessor
263260
// create the options to use for configuring the processor
@@ -346,14 +343,12 @@ string description = dlqMessage.DeadLetterErrorDescription;
346343

347344
### Working with sessions
348345

349-
Previously, in `Microsoft.Azure.ServiceBus`, you had the below options to receive messages from a session enabled queue/subscription
350-
351-
- Register message and error handlers using the `QueueClient.RegisterSessionHandler()` method to receive messages from an available set of sessions
352-
- Use the `SessionClient.AcceptMessageSessionAsync()` method to get an instance of the `MessageSession` class that will be tied to a given sessionId or to the next available session if no sessionId is provided.
346+
In `Microsoft.Azure.ServiceBus`, you had the following options to receive messages from a session-enabled queue/subscription:
353347

354-
While the first option is similar to what you would do in a non-session scenario, the second that allows you finer-grained control is very different from any other pattern used in the library.
348+
- Register message and error handlers using the `QueueClient.RegisterSessionHandler` method to receive messages from an available set of sessions
349+
- Use the `SessionClient.AcceptMessageSessionAsync` method to get an instance of the `MessageSession` class that will be tied to a given sessionId or to the next available session if no sessionId is provided.
355350

356-
Now in `Azure.Messaging.ServiceBus`, we simplify this by giving session variants of the same methods and classes that are available when working with queues/subscriptions that do not have sessions enabled.
351+
In `Azure.Messaging.ServiceBus`, we simplify this by giving session-aware variants of the same methods and classes that are available when working with queues/subscriptions that do not have sessions enabled.
357352

358353
The below code snippet shows you the session variation of the `ServiceBusProcessor`.
359354

@@ -438,12 +433,11 @@ ServiceBusReceivedMessage receivedMessage = await receiver.ReceiveMessageAsync()
438433
Console.WriteLine(receivedMessage.SessionId);
439434
```
440435

441-
### Cross-Entity transactions
436+
### Cross-entity transactions
442437

443-
Previously, in `Microsoft.Azure.ServiceBus`, when performing a transaction that spanned multiple queues, topics, or subscriptions you would need to use the "Send-Via" option
444-
in the `MessageSender`.
438+
In `Microsoft.Azure.ServiceBus`, when performing a transaction that spanned multiple queues, topics, or subscriptions you would need to use the `Send-Via` option in the `MessageSender`.
445439

446-
Now in `Azure.Messaging.ServiceBus`, there is an `EnableCrossEntityTransactions` property on the `ServiceBusClientOptions`. When setting this property to `true`, the first operation that occurs using any senders or receivers created from the client implicitly becomes the send-via entity. Because of this, subsequent operations must either be by senders, or if they are by receivers, the receiver must be receiving from the send-via entity. For this reason, it probably makes more sense to have your first operation be a receive rather than a send when setting this property.
440+
In `Azure.Messaging.ServiceBus`, the `EnableCrossEntityTransactions` property on `ServiceBusClientOptions` serves this purpose. When setting this property to `true`, the first operation that occurs using any senders or receivers created from the client implicitly becomes the send-via entity. Because of this, subsequent operations must either be by senders, or if they are by receivers, the receiver must be receiving from the send-via entity. For this reason, it probably makes more sense to have your first operation be a receive rather than a send when setting this property.
447441

448442
The below code snippet shows you how to perform cross-entity transactions.
449443

@@ -471,13 +465,13 @@ using (var ts = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
471465

472466
In `Microsoft.Azure.ServiceBus`, the library would automatically flow [activity baggage](https://learn.microsoft.com/dotnet/api/system.diagnostics.activity.baggage) via the `Correlation-Context` entry of the `Message.UserProperties` dictionary. This would allow senders and receivers to correlate any information that was added to an Activity's baggage by an application.
473467

474-
In `Azure.Messaging.ServiceBus`, Activity baggage is not currently flowed through the message. Instead, when using the [experimental OpenTelemetry support](https://devblogs.microsoft.com/azure-sdk/introducing-experimental-opentelemetry-support-in-the-azure-sdk-for-net/), `tracestate` can be used to correlate the [Activity.TraceStateString](https://learn.microsoft.com/dotnet/api/system.diagnostics.activity.tracestatestring) between senders, receivers, and processors. The `tracestate` entry is populated in the `ServiceBusMessage.ApplicationProperties` if the enclosing Activity has a non-null `TraceStateString`. In the future, we plan to add additional support for propagating context between senders, receivers, and processors. More details about tracing support in the `Azure.Messaging.ServiceBus` library can be found in the [troubleshooting guide](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/servicebus/Azure.Messaging.ServiceBus/TROUBLESHOOTING.md#distributed-tracing).
468+
In `Azure.Messaging.ServiceBus`, activity baggage is not currently flowed through the message. Instead, when using the [experimental OpenTelemetry support](https://devblogs.microsoft.com/azure-sdk/introducing-experimental-opentelemetry-support-in-the-azure-sdk-for-net/), `tracestate` can be used to correlate the [Activity.TraceStateString](https://learn.microsoft.com/dotnet/api/system.diagnostics.activity.tracestatestring) between senders, receivers, and processors. The `tracestate` entry is populated in the `ServiceBusMessage.ApplicationProperties` if the enclosing Activity has a non-null `TraceStateString`. In the future, we plan to add additional support for propagating context between senders, receivers, and processors. More details about tracing support in the `Azure.Messaging.ServiceBus` library can be found in the [troubleshooting guide](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/servicebus/Azure.Messaging.ServiceBus/TROUBLESHOOTING.md#distributed-tracing).
475469

476470
## Plugins
477471

478472
In the previous library, `Microsoft.Azure.ServiceBus`, users could [register plugins](https://docs.microsoft.com/dotnet/api/microsoft.azure.servicebus.queueclient.registerplugin?view=azure-dotnet) that would alter an outgoing message before serialization, or alter an incoming message after being deserialized. These extension points allowed users of the Service Bus library to use common OSS extensions to enhance their applications without having to implement their own logic, and without having to wait for the SDK to explicitly support the needed feature. For instance, one use of the plugin functionality is to implement the [claim-check pattern](https://www.nuget.org/packages/ServiceBus.AttachmentPlugin/) to send and receive messages that exceed the Service Bus message size limits.
479473

480-
To achieve similar functionality with `Azure.Messaging.ServiceBus`, you can extend the various types as demonstrated in the [extensibility sample](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample09_Extensibility.md). We also have a [dedicated sample](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample10_ClaimCheck.md) that demonstrates using the claim check pattern in the new library. To discuss plugins further, feel free to comment [here](https://github.com/Azure/azure-sdk-for-net/issues/12943).
474+
To achieve similar functionality with `Azure.Messaging.ServiceBus`, you can extend the various types as demonstrated in the [extensibility sample](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample09_Extensibility.md). We also have a [dedicated sample](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample10_ClaimCheck.md) that demonstrates using the claim check pattern in the new library.
481475

482476
## Additional samples
483477

0 commit comments

Comments
 (0)