diff --git a/sdk/servicebus/service-bus/migrationguide.md b/sdk/servicebus/service-bus/migrationguide.md index 641d00c7b159..b0e6cfd5fbcb 100644 --- a/sdk/servicebus/service-bus/migrationguide.md +++ b/sdk/servicebus/service-bus/migrationguide.md @@ -16,6 +16,12 @@ The new version 7 of the Service Bus library provides the ability to share in so ## Changes in version 7 of the Service Bus library +### Message format changes + +Some key fields have been renamed in the ServiceBusMessage and ServiceBusReceivedMessage to better align with [AMQP](https://www.amqp.org/sites/amqp.org/files/amqp.pdf): +- `label` has been renamed to `subject` +- `userProperties` has been renamed to `applicationProperties` + ### Client hierarchy In the interest of simplifying the API surface we've made a single top level client called `ServiceBusClient`, rather than one for each of queue, topic, and subscription. This acts as the single entry point in contrast with multiple entry points from before. You can create senders and receivers from this client to the queue/topic/subscription/session of your choice and start sending/receiving messages. @@ -172,7 +178,25 @@ const serviceBusClient = new ServiceBusClient("my-namespace.servicebus.windows.n ### Settling messages Previously, the methods to settle messages (`complete()`, `abandon()`, `defer()` and `deadLetter()`) were on the messages themselves. + +```typescript +// legacy +const serviceBusReceivedMessage: ServiceBusReceivedMessage; +serviceBusReceivedMessage.complete(); +// or .abandon(), .defer(), deadLetter() +``` + These have been moved to the receiver in the new version, take the message as input and have the `Message` suffix in their name. + +```typescript +// current +const serviceBusReceivedMessage: ServiceBusReceivedMessage +const serviceBusReceiver: ServiceBusReceiver; + +serviceBusReceiver.completeMessage(serviceBusReceivedMessage); +// or .abandonMessage(), .deferMessage(), deadLetterMessage() +``` + The idea is to have the message represents just the data and not have the responsibility of any operation on the service side. Additionally, since a message cannot be settled if the receiver that was used to receive it is not alive, tying these operations to the receiver drives the message home better. diff --git a/sdk/servicebus/service-bus/samples/javascript/advanced/deferral.js b/sdk/servicebus/service-bus/samples/javascript/advanced/deferral.js index d8f6916f6ea4..185473561111 100644 --- a/sdk/servicebus/service-bus/samples/javascript/advanced/deferral.js +++ b/sdk/servicebus/service-bus/samples/javascript/advanced/deferral.js @@ -42,7 +42,7 @@ async function sendMessages() { for (let index = 0; index < data.length; index++) { const message = { body: data[index], - label: "RecipeStep", + subject: "RecipeStep", contentType: "application/json" }; // the way we shuffle the message order is to introduce a tiny random delay before each of the messages is sent diff --git a/sdk/servicebus/service-bus/samples/javascript/advanced/movingMessagesToDLQ.js b/sdk/servicebus/service-bus/samples/javascript/advanced/movingMessagesToDLQ.js index 2f1482f9e3f6..e5b982195e13 100644 --- a/sdk/servicebus/service-bus/samples/javascript/advanced/movingMessagesToDLQ.js +++ b/sdk/servicebus/service-bus/samples/javascript/advanced/movingMessagesToDLQ.js @@ -40,7 +40,7 @@ async function sendMessage() { type: "Dinner" }, contentType: "application/json", - label: "Recipe" + subject: "Recipe" }; await sender.sendMessages(message); await sender.close(); diff --git a/sdk/servicebus/service-bus/samples/javascript/advanced/sessionState.js b/sdk/servicebus/service-bus/samples/javascript/advanced/sessionState.js index 7d556fedd02d..2c3ab515e85f 100644 --- a/sdk/servicebus/service-bus/samples/javascript/advanced/sessionState.js +++ b/sdk/servicebus/service-bus/samples/javascript/advanced/sessionState.js @@ -98,7 +98,7 @@ async function sendMessagesForSession(shoppingEvents, sessionId) { const message = { sessionId: sessionId, body: shoppingEvents[index], - label: "Shopping Step" + subject: "Shopping Step" }; await sender.sendMessages(message); } diff --git a/sdk/servicebus/service-bus/samples/javascript/session.js b/sdk/servicebus/service-bus/samples/javascript/session.js index 318523e7e62d..da13a8976a94 100644 --- a/sdk/servicebus/service-bus/samples/javascript/session.js +++ b/sdk/servicebus/service-bus/samples/javascript/session.js @@ -63,7 +63,7 @@ async function sendMessage(sbClient, scientist, sessionId) { const message = { body: `${scientist.firstName} ${scientist.lastName}`, - label: "Scientist", + subject: "Scientist", sessionId: sessionId }; diff --git a/sdk/servicebus/service-bus/samples/typescript/src/advanced/deferral.ts b/sdk/servicebus/service-bus/samples/typescript/src/advanced/deferral.ts index 6cd3e2223057..3003ed134085 100644 --- a/sdk/servicebus/service-bus/samples/typescript/src/advanced/deferral.ts +++ b/sdk/servicebus/service-bus/samples/typescript/src/advanced/deferral.ts @@ -15,7 +15,8 @@ import { ServiceBusClient, delay, ProcessErrorArgs, - ServiceBusReceivedMessage + ServiceBusReceivedMessage, + ServiceBusMessage } from "@azure/service-bus"; // Load the .env file if it exists @@ -46,9 +47,9 @@ async function sendMessages() { ]; const promises = new Array(); for (let index = 0; index < data.length; index++) { - const message = { + const message: ServiceBusMessage = { body: data[index], - label: "RecipeStep", + subject: "RecipeStep", contentType: "application/json" }; // the way we shuffle the message order is to introduce a tiny random delay before each of the messages is sent diff --git a/sdk/servicebus/service-bus/samples/typescript/src/advanced/movingMessagesToDLQ.ts b/sdk/servicebus/service-bus/samples/typescript/src/advanced/movingMessagesToDLQ.ts index 1deb45795828..99d8acb23b15 100644 --- a/sdk/servicebus/service-bus/samples/typescript/src/advanced/movingMessagesToDLQ.ts +++ b/sdk/servicebus/service-bus/samples/typescript/src/advanced/movingMessagesToDLQ.ts @@ -9,7 +9,7 @@ Run processMessagesInDLQ example after this to see how the messages in DLQ can be reprocessed. */ -import { ServiceBusClient } from "@azure/service-bus"; +import { ServiceBusClient, ServiceBusMessage } from "@azure/service-bus"; // Load the .env file if it exists import * as dotenv from "dotenv"; @@ -35,13 +35,13 @@ async function sendMessage() { // createSender() can also be used to create a sender for a topic. const sender = sbClient.createSender(queueName); - const message = { + const message: ServiceBusMessage = { body: { name: "Creamy Chicken Pasta", type: "Dinner" }, contentType: "application/json", - label: "Recipe" + subject: "Recipe" }; await sender.sendMessages(message); await sender.close(); diff --git a/sdk/servicebus/service-bus/samples/typescript/src/advanced/sessionState.ts b/sdk/servicebus/service-bus/samples/typescript/src/advanced/sessionState.ts index 7835073cc575..68d240900cb5 100644 --- a/sdk/servicebus/service-bus/samples/typescript/src/advanced/sessionState.ts +++ b/sdk/servicebus/service-bus/samples/typescript/src/advanced/sessionState.ts @@ -19,7 +19,7 @@ to learn about session state. */ -import { ServiceBusClient } from "@azure/service-bus"; +import { ServiceBusClient, ServiceBusMessage } from "@azure/service-bus"; // Load the .env file if it exists import * as dotenv from "dotenv"; @@ -98,10 +98,10 @@ async function sendMessagesForSession(shoppingEvents: any[], sessionId: string) const sender = sbClient.createSender(userEventsQueueName); for (let index = 0; index < shoppingEvents.length; index++) { - const message = { + const message: ServiceBusMessage = { sessionId: sessionId, body: shoppingEvents[index], - label: "Shopping Step" + subject: "Shopping Step" }; await sender.sendMessages(message); } diff --git a/sdk/servicebus/service-bus/samples/typescript/src/session.ts b/sdk/servicebus/service-bus/samples/typescript/src/session.ts index 13b7a37305ce..ada6e2070095 100644 --- a/sdk/servicebus/service-bus/samples/typescript/src/session.ts +++ b/sdk/servicebus/service-bus/samples/typescript/src/session.ts @@ -62,9 +62,9 @@ async function sendMessage(sbClient: ServiceBusClient, scientist: any, sessionId // createSender() also works with topics const sender = sbClient.createSender(queueName); - const message = { + const message: ServiceBusMessage = { body: `${scientist.firstName} ${scientist.lastName}`, - label: "Scientist", + subject: "Scientist", sessionId: sessionId };