Skip to content
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

[service-bus] Addressing some incorrect samples and missing migrationguide.md section #12879

Merged
5 commits merged into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions sdk/servicebus/service-bus/migrationguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function sendMessage() {
type: "Dinner"
},
contentType: "application/json",
label: "Recipe"
subject: "Recipe"
};
await sender.sendMessages(message);
await sender.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/servicebus/service-bus/samples/javascript/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function sendMessage(sbClient, scientist, sessionId) {

const message = {
body: `${scientist.firstName} ${scientist.lastName}`,
label: "Scientist",
subject: "Scientist",
sessionId: sessionId
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
ServiceBusClient,
delay,
ProcessErrorArgs,
ServiceBusReceivedMessage
ServiceBusReceivedMessage,
ServiceBusMessage
} from "@azure/service-bus";

// Load the .env file if it exists
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/servicebus/service-bus/samples/typescript/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down