Skip to content

Commit 86f9d2e

Browse files
authored
[EventGrid] Make `build:samples" work (Azure#13057)
- Update to the GA version of the Service Bus package in our samples and deal with the breaking changes. - Add `@azure/service-bus` as a dev-dependency since the samples use it and we need it around when we do `build:samples` - Have `build:samples` use `dev-tool` to prepare the samples and then build them, like our other packages do Fixes Azure#12730
1 parent 741ad61 commit 86f9d2e

File tree

6 files changed

+58
-42
lines changed

6 files changed

+58
-42
lines changed

sdk/eventgrid/eventgrid/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"build:autorest": "autorest ./swagger/README.md --typescript --v3",
5252
"build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1",
5353
"build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1",
54-
"build:samples": "echo Skipped.",
54+
"build:samples": "dev-tool samples prep && cd dist-samples && tsc -p .",
5555
"build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1",
5656
"build": "tsc -p . && rollup -c 2>&1 && api-extractor run --local",
5757
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
@@ -87,7 +87,9 @@
8787
"tslib": "^2.0.0"
8888
},
8989
"devDependencies": {
90+
"@azure/dev-tool": "^1.0.0",
9091
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
92+
"@azure/service-bus": "^7.0.0",
9193
"@azure/test-utils-recorder": "^1.0.0",
9294
"@microsoft/api-extractor": "7.7.11",
9395
"@rollup/plugin-commonjs": "11.0.2",

sdk/eventgrid/eventgrid/samples/javascript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"sideEffects": false,
2626
"dependencies": {
2727
"@azure/eventgrid": "next",
28-
"@azure/service-bus": "7.0.0-preview.5",
28+
"@azure/service-bus": "^7.0.0",
2929
"dotenv": "^8.2.0"
3030
},
3131
"devDependencies": {

sdk/eventgrid/eventgrid/samples/javascript/src/consumeEventsFromServiceBusQueue.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,43 @@ dotenv.config();
1010

1111
// The connection string for Service Bus namespace that Event Grid will deliver messages to.
1212
// You can find the connection string in the Azure portal.
13-
// Navigate to Settings > Shared access policies > RootManageSharedAccessKey in your Service Bus Namespace's menu blade to see
13+
// Navigate to Settings > Shared access policies > RootManageSharedAccessKey in your Service Bus Namespace's menu blade to see
1414
// the connection string.
1515
const serviceBusClientConnectionString = process.env["SERVICE_BUS_CONNECTION_STRING"] || "";
1616

1717
// The name of the queue within the Service Bus namespace that Event Grid will deliver messages to.
1818
const serviceBusQueueName = process.env["SERVICE_BUS_QUEUE_NAME"] || "";
1919

2020
// Create a receiver to read messages from the Service Bus Queue.
21-
const receiver = new ServiceBusClient(serviceBusClientConnectionString).createReceiver(serviceBusQueueName);
21+
const receiver = new ServiceBusClient(serviceBusClientConnectionString).createReceiver(
22+
serviceBusQueueName
23+
);
2224

2325
// Create a Event Grid Consumer which will decode the payload of service bus message into an array of EventGridEvent objects.
2426
const consumer = new EventGridConsumer();
2527

2628
// The handler function which will be run on each message we remove from the Service Bus Queue.
27-
async function processMessage(message) {
28-
// Convert the message into an array of Event Grid Events.
29-
const events = await consumer.deserializeEventGridEvents(message.body);
30-
31-
// Process each message, printing the type and ID. In addition, if the event is a system event generated by Azure when
32-
// a blob is created, print the URL from the event.
33-
for (const event of events) {
34-
console.log(`Processing event of type ${event.eventType} with id: ${event.id}`);
35-
if (isSystemEvent("Microsoft.Storage.BlobCreated", event)) {
36-
console.log(`A blob was created with URL: ${event.data.url}`);
37-
}
29+
async function processMessage(message) {
30+
// Convert the message into an array of Event Grid Events.
31+
const events = await consumer.deserializeEventGridEvents(message.body);
32+
33+
// Process each message, printing the type and ID. In addition, if the event is a system event generated by Azure when
34+
// a blob is created, print the URL from the event.
35+
for (const event of events) {
36+
console.log(`Processing event of type ${event.eventType} with id: ${event.id}`);
37+
if (isSystemEvent("Microsoft.Storage.BlobCreated", event)) {
38+
console.log(`A blob was created with URL: ${event.data.url}`);
3839
}
40+
}
3941

40-
// Complete the message so that it is removed from the queue and not processed again.
41-
await message.complete();
42+
// Complete the message so that it is removed from the queue and not processed again.
43+
await receiver.completeMessage(message);
4244
}
4345

4446
// Start processing events.
4547
receiver.subscribe({
46-
processMessage,
47-
processError: async (err) => {
48-
console.error("The sample encountered an error:", err);
49-
}
48+
processMessage,
49+
processError: async (err) => {
50+
console.error("The sample encountered an error:", err);
51+
}
5052
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"module": "commonjs",
5+
"outDir": "typescript/dist",
6+
"lib": ["dom", "dom.iterable", "esnext.asynciterable"]
7+
},
8+
"include": ["typescript/src/**.ts"],
9+
"exclude": ["typescript/*.json", "**/node_modules/", "../node_modules", "../typings"]
10+
}

sdk/eventgrid/eventgrid/samples/typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"sideEffects": false,
3131
"dependencies": {
3232
"@azure/eventgrid": "next",
33-
"@azure/service-bus": "7.0.0-preview.5",
33+
"@azure/service-bus": "^7.0.0",
3434
"dotenv": "^8.2.0"
3535
},
3636
"devDependencies": {

sdk/eventgrid/eventgrid/samples/typescript/src/consumeEventsFromServiceBusQueue.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,51 @@
22
// Licensed under the MIT license.
33

44
import { EventGridConsumer, isSystemEvent } from "@azure/eventgrid";
5-
import { ServiceBusClient, ReceivedMessageWithLock } from "@azure/service-bus";
5+
import { ServiceBusClient, ServiceBusReceivedMessage } from "@azure/service-bus";
66
import * as dotenv from "dotenv";
77

88
// Load the .env file if it exists
99
dotenv.config();
1010

1111
// The connection string for Service Bus namespace that Event Grid will deliver messages to.
1212
// You can find the connection string in the Azure portal.
13-
// Navigate to Settings > Shared access policies > RootManageSharedAccessKey in your Service Bus Namespace's menu blade to see
13+
// Navigate to Settings > Shared access policies > RootManageSharedAccessKey in your Service Bus Namespace's menu blade to see
1414
// the connection string.
1515
const serviceBusClientConnectionString = process.env["SERVICE_BUS_CONNECTION_STRING"] || "";
1616

1717
// The name of the queue within the Service Bus namespace that Event Grid will deliver messages to.
1818
const serviceBusQueueName = process.env["SERVICE_BUS_QUEUE_NAME"] || "";
1919

2020
// Create a receiver to read messages from the Service Bus Queue.
21-
const receiver = new ServiceBusClient(serviceBusClientConnectionString).createReceiver(serviceBusQueueName);
21+
const receiver = new ServiceBusClient(serviceBusClientConnectionString).createReceiver(
22+
serviceBusQueueName
23+
);
2224

2325
// Create a Event Grid Consumer which will decode the payload of service bus message into an array of EventGridEvent objects.
2426
const consumer = new EventGridConsumer();
2527

2628
// The handler function which will be run on each message we remove from the Service Bus Queue.
27-
async function processMessage(message: ReceivedMessageWithLock): Promise<void> {
28-
// Convert the message into an array of Event Grid Events.
29-
const events = await consumer.deserializeEventGridEvents(message.body);
30-
31-
// Process each message, printing the type and ID. In addition, if the event is a system event generated by Azure when
32-
// a blob is created, print the URL from the event.
33-
for (const event of events) {
34-
console.log(`Processing event of type ${event.eventType} with id: ${event.id}`);
35-
if (isSystemEvent("Microsoft.Storage.BlobCreated", event)) {
36-
console.log(`A blob was created with URL: ${event.data.url}`);
37-
}
29+
async function processMessage(message: ServiceBusReceivedMessage): Promise<void> {
30+
// Convert the message into an array of Event Grid Events.
31+
const events = await consumer.deserializeEventGridEvents(message.body);
32+
33+
// Process each message, printing the type and ID. In addition, if the event is a system event generated by Azure when
34+
// a blob is created, print the URL from the event.
35+
for (const event of events) {
36+
console.log(`Processing event of type ${event.eventType} with id: ${event.id}`);
37+
if (isSystemEvent("Microsoft.Storage.BlobCreated", event)) {
38+
console.log(`A blob was created with URL: ${event.data.url}`);
3839
}
40+
}
3941

40-
// Complete the message so that it is removed from the queue and not processed again.
41-
await message.complete();
42+
// Complete the message so that it is removed from the queue and not processed again.
43+
await receiver.completeMessage(message);
4244
}
4345

4446
// Start processing events.
4547
receiver.subscribe({
46-
processMessage,
47-
processError: async (err) => {
48-
console.error("The sample encountered an error:", err);
49-
}
48+
processMessage,
49+
processError: async (err) => {
50+
console.error("The sample encountered an error:", err);
51+
}
5052
});

0 commit comments

Comments
 (0)