Skip to content

Commit

Permalink
[EventGrid] Fix Cloud Event samples (#11514)
Browse files Browse the repository at this point in the history
The samples were duplicates of the ones which sent events using the
event grid schema. Update them to call the correct API as well as the
shape of the event we send (so that the event actually matches the Cloud
Event schema)

Fixes: #11497
  • Loading branch information
ellismg authored Sep 25, 2020
1 parent d7af342 commit 90f1fa3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
15 changes: 7 additions & 8 deletions sdk/eventgrid/eventgrid/samples/javascript/src/sendCloudEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@ const dotenv = require("dotenv");
// Load the .env file if it exists
dotenv.config();

// The URL of the endpoint of the Event Grid topic.
// The URL of the endpoint of the Event Grid topic.
const endpoint = process.env["EVENT_GRID_ENDPOINT"] || "";

// You can find the access keys in the Azure portal.
// Navigate to Settings > Access keys in your Event Grid topic's menu blade to see both access keys (you may use either).
const accessKey = process.env["EVENT_GRID_ACCESS_KEY"] || "";

async function main() {
async function main() {
// Create the client used to publish events to the Event Grid Service
const client = new EventGridPublisherClient(endpoint, new AzureKeyCredential(accessKey));

// Send an event to the Event Grid Service, using the Event Grid schema.
// Send an event to the Event Grid Service, using the Cloud Event schema.
// A random ID will be generated for this event, since one is not provided.
await client.sendEvents([
await client.sendCloudEvents([
{
eventType: "Azure.SDK.Samples.CustomEvent",
subject: "azure/sdk/eventgrid/samples/sendEventSample",
dataVersion: "1.0",
type: "com.example.cloudevent",
source: "/azure/sdk/eventgrid/samples/sendEventSample",
data: {
message: "this is a sample event",
message: "this is a sample event"
}
}
]);
Expand Down
15 changes: 7 additions & 8 deletions sdk/eventgrid/eventgrid/samples/typescript/src/sendCloudEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@ import * as dotenv from "dotenv";
// Load the .env file if it exists
dotenv.config();

// The URL of the endpoint of the Event Grid topic.
// The URL of the endpoint of the Event Grid topic.
const endpoint = process.env["EVENT_GRID_ENDPOINT"] || "";

// You can find the access keys in the Azure portal.
// Navigate to Settings > Access keys in your Event Grid topic's menu blade to see both access keys (you may use either).
const accessKey = process.env["EVENT_GRID_ACCESS_KEY"] || "";

async function main(): Promise<void> {
async function main(): Promise<void> {
// Create the client used to publish events to the Event Grid Service
const client = new EventGridPublisherClient(endpoint, new AzureKeyCredential(accessKey));

// Send an event to the Event Grid Service, using the Event Grid schema.
// Send an event to the Event Grid Service, using the Cloud Event schema.
// A random ID will be generated for this event, since one is not provided.
await client.sendEvents([
await client.sendCloudEvents([
{
eventType: "Azure.SDK.Samples.CustomEvent",
subject: "azure/sdk/eventgrid/samples/sendEventSample",
dataVersion: "1.0",
type: "com.example.cloudevent",
source: "/azure/sdk/eventgrid/samples/sendEventSample",
data: {
message: "this is a sample event",
message: "this is a sample event"
}
}
]);
Expand Down

0 comments on commit 90f1fa3

Please sign in to comment.