az login
npm install @azure/eventgrid
Create an Event Grid custom topic and publish events from your app.
1 import { EventGridPublisherClient, AzureKeyCredential } from '@azure/eventgrid'; 2 3 const client = new EventGridPublisherClient( 4 process.env.TOPIC_ENDPOINT!, 5 'EventGrid', 6 new AzureKeyCredential(process.env.TOPIC_KEY!) 7 ); 8 9 async function publishOrderEvent(orderId: string, status: string) { 10 await client.send([{ 11 eventType: 'Order.StatusUpdated', 12 subject: `orders/${orderId}`, 13 dataVersion: '1.0', 14 data: { orderId, status, timestamp: new Date().toISOString() }, 15 }]); 16 console.log(`Published Order.StatusUpdated for ${orderId}`); 17 } 18 19 publishOrderEvent('ord-123', 'shipped');
Event published to topic, webhook receives POST with event array
Sign in to share your feedback and join the discussion.