diff --git a/sdk/eventhub/event-hubs/samples/interactiveLogin.ts b/sdk/eventhub/event-hubs/samples/interactiveLogin.ts index 626f6e99fadf..1815a8331e23 100644 --- a/sdk/eventhub/event-hubs/samples/interactiveLogin.ts +++ b/sdk/eventhub/event-hubs/samples/interactiveLogin.ts @@ -22,7 +22,7 @@ async function main(): Promise { const client = EventHubClient.createFromAadTokenCredentials(evenHubsEndpoint, eventHubsName, credentials); /* Refer to other samples, and place your code here - to send/receive messages + to send/receive events */ await client.close(); } diff --git a/sdk/eventhub/event-hubs/samples/loginWithAzureAccount.ts b/sdk/eventhub/event-hubs/samples/loginWithAzureAccount.ts index 1d6a7bf74d72..b16623af68f5 100644 --- a/sdk/eventhub/event-hubs/samples/loginWithAzureAccount.ts +++ b/sdk/eventhub/event-hubs/samples/loginWithAzureAccount.ts @@ -30,7 +30,7 @@ async function main(): Promise { const client = EventHubClient.createFromAadTokenCredentials(evenHubsEndpoint, eventHubsName, credentials); /* Refer to other samples, and place your code here - to send/receive messages + to send/receive events */ await client.close(); } diff --git a/sdk/eventhub/event-hubs/samples/receiveMessagesLoop.ts b/sdk/eventhub/event-hubs/samples/receiveEventsLoop.ts similarity index 61% rename from sdk/eventhub/event-hubs/samples/receiveMessagesLoop.ts rename to sdk/eventhub/event-hubs/samples/receiveEventsLoop.ts index 73a0963c5673..a8779410115e 100644 --- a/sdk/eventhub/event-hubs/samples/receiveMessagesLoop.ts +++ b/sdk/eventhub/event-hubs/samples/receiveEventsLoop.ts @@ -2,10 +2,9 @@ Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT Licence. - This sample demonstrates how the receiveBatch() function can be used to receive Event Hubs - messages in a loop. + This sample demonstrates how the receiveBatch() function can be used to receive events in a loop. - If your Event Hubs instance doesn't have any messages, then please run "sendMesages.ts" sample + If your Event Hubs instance doesn't have any events, then please run "sendEvents.ts" sample to populate Event Hubs before running this sample. */ @@ -22,15 +21,16 @@ async function main(): Promise { const batchSize = 1; for (let i = 0; i < 10; i++) { - const messages = await client.receiveBatch(partitionIds[0], batchSize, 5, { - eventPosition: eventPosition + const events = await client.receiveBatch(partitionIds[0], batchSize, 5, { + eventPosition: eventPosition, + consumerGroup: "$Default" }); - if (!messages.length) { - console.log("No more messages to receive"); + if (!events.length) { + console.log("No more events to receive"); break; } - eventPosition = EventPosition.fromSequenceNumber(messages[messages.length - 1].sequenceNumber!); - console.log(`Received messages #${i}: ${messages.map(msg => msg.body)}`); + eventPosition = EventPosition.fromSequenceNumber(events[events.length - 1].sequenceNumber!); + console.log(`Received events #${i}: ${events.map(event => event.body)}`); } await client.close(); } diff --git a/sdk/eventhub/event-hubs/samples/receiveMessagesStreaming.ts b/sdk/eventhub/event-hubs/samples/receiveEventsStreaming.ts similarity index 81% rename from sdk/eventhub/event-hubs/samples/receiveMessagesStreaming.ts rename to sdk/eventhub/event-hubs/samples/receiveEventsStreaming.ts index 3ef6f34bb5cb..a232b19018f5 100644 --- a/sdk/eventhub/event-hubs/samples/receiveMessagesStreaming.ts +++ b/sdk/eventhub/event-hubs/samples/receiveEventsStreaming.ts @@ -2,10 +2,9 @@ Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT Licence. - This sample demonstrates how the receive() function can be used to receive Event Hubs messages - in a stream. + This sample demonstrates how the receive() function can be used to receive events in a stream. - If your Event Hubs instance doesn't have any messages, then please run "sendMesages.ts" sample + If your Event Hubs instance doesn't have any events, then please run "sendEvents.ts" sample to populate Event Hubs before running this sample. */ @@ -20,17 +19,18 @@ async function main(): Promise { const partitionIds = await client.getPartitionIds(); const onMessageHandler: OnMessage = async (brokeredMessage: EventData) => { - console.log(`Received message: ${brokeredMessage.body}`); + console.log(`Received event: ${brokeredMessage.body}`); }; const onErrorHandler: OnError = (err: MessagingError | Error) => { console.log("Error occurred: ", err); }; const rcvHandler = client.receive(partitionIds[0], onMessageHandler, onErrorHandler, { - eventPosition: EventPosition.fromStart() + eventPosition: EventPosition.fromStart(), + consumerGroup: "$Default" }); - // Waiting long enough before closing the receiver to receive messages + // Waiting long enough before closing the receiver to receive event await delay(5000); await rcvHandler.stop(); await client.close(); diff --git a/sdk/eventhub/event-hubs/samples/sendMessages.ts b/sdk/eventhub/event-hubs/samples/sendEvents.ts similarity index 85% rename from sdk/eventhub/event-hubs/samples/sendMessages.ts rename to sdk/eventhub/event-hubs/samples/sendEvents.ts index bfb40258ccfb..49a2d62b5afb 100644 --- a/sdk/eventhub/event-hubs/samples/sendMessages.ts +++ b/sdk/eventhub/event-hubs/samples/sendEvents.ts @@ -2,7 +2,7 @@ Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT Licence. - This sample demonstrates how the send() function can be used to send messages to Event Hubs. + This sample demonstrates how the send() function can be used to send events to Event Hubs. See https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-about to learn about Event Hubs. @@ -33,14 +33,14 @@ async function main(): Promise { for (let index = 0; index < listOfScientists.length; index++) { const scientist = listOfScientists[index]; - const data: EventData = { + const eventData: EventData = { body: `${scientist.firstName} ${scientist.name}` }; // NOTE: For receiving events from Azure Stream Analytics, please send Events to an EventHub // where the body is a JSON object/array. - // const data = { body: { "message": `${scientist.firstName} ${scientist.name}` } }; - console.log(`Sending message: ${data.body}`); - await client.send(data, partitionIds[0]); + // const eventData = { body: { "message": `${scientist.firstName} ${scientist.name}` } }; + console.log(`Sending event: ${eventData.body}`); + await client.send(eventData, partitionIds[0]); } await client.close(); diff --git a/sdk/eventhub/event-hubs/samples/servicePrincipalLogin.ts b/sdk/eventhub/event-hubs/samples/servicePrincipalLogin.ts index c658a47e71f8..652aaa3e43c3 100644 --- a/sdk/eventhub/event-hubs/samples/servicePrincipalLogin.ts +++ b/sdk/eventhub/event-hubs/samples/servicePrincipalLogin.ts @@ -36,7 +36,7 @@ async function main(): Promise { const client = EventHubClient.createFromAadTokenCredentials(evenHubsEndpoint, eventHubsName, credentials); /* Refer to other samples, and place your code here - to send/receive messages + to send/receive events */ await client.close(); } diff --git a/sdk/eventhub/event-hubs/samples/useProxy.ts b/sdk/eventhub/event-hubs/samples/useProxy.ts index 2192a95c6382..0ec492bb8090 100644 --- a/sdk/eventhub/event-hubs/samples/useProxy.ts +++ b/sdk/eventhub/event-hubs/samples/useProxy.ts @@ -29,7 +29,7 @@ async function main(): Promise { }); /* Refer to other samples, and place your code here - to send/receive messages + to send/receive events */ await client.close(); }