From a15688750abbbf82e78acbca95f8770c8124fdc4 Mon Sep 17 00:00:00 2001 From: chradek Date: Tue, 26 May 2020 17:29:54 -0700 Subject: [PATCH] [testhub] update uuid imports --- sdk/eventhub/testhub/commands/sendReceive.ts | 47 +++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/sdk/eventhub/testhub/commands/sendReceive.ts b/sdk/eventhub/testhub/commands/sendReceive.ts index 9cd0ac33ae22..132ab2c0d323 100644 --- a/sdk/eventhub/testhub/commands/sendReceive.ts +++ b/sdk/eventhub/testhub/commands/sendReceive.ts @@ -3,11 +3,12 @@ import { CommandBuilder } from "yargs"; import { EventHubClient, EventPosition, EventData, delay } from "@azure/event-hubs"; import { log, setCurrentCommand, randomNumberFromInterval } from "../utils/util"; -import uuid from "uuid/v4"; +import { v4 as uuid } from "uuid"; export const command = "send-receive"; -export const describe = "Sends a message to an event hub partition and receives the message " + +export const describe = + "Sends a message to an event hub partition and receives the message " + "from that eventhub partition, thus verifying that the sent message was received successfully."; export const builder: CommandBuilder = { @@ -15,31 +16,33 @@ export const builder: CommandBuilder = { alias: "partitionId", describe: "The partition id to send the message and receive from.", default: "0", - string: true + string: true, }, g: { alias: "consumer", describe: "Consumer group name.", default: "$default", - string: true + string: true, }, w: { alias: "maxwait", - describe: "Max time in seconds to wait before sending the next message. " + + describe: + "Max time in seconds to wait before sending the next message. " + "A random number between 5 and the provided number", default: 2000, - number: true + number: true, }, }; - function validateArgs(argv: any) { if (!argv) { throw new Error(`argv cannot be null or undefined.`); } if (!argv.connStr && (!argv.key || !argv.keyName || !argv.address)) { - throw new Error(`Either provide --conn-str OR (--address "sb://{yournamespace}.servicebus.windows.net" --key-name "" --key "")`); + throw new Error( + `Either provide --conn-str OR (--address "sb://{yournamespace}.servicebus.windows.net" --key-name "" --key "")` + ); } } @@ -68,7 +71,9 @@ export async function handler(argv: any): Promise { } client1 = EventHubClient.createFromConnectionString(connectionString, argv.hub); client2 = EventHubClient.createFromConnectionString(connectionString, argv.hub); - log(`Created Receiver: for partition: "${partitionId}" in consumer group: "${consumerGroup}" in event hub "${argv.hub}".`); + log( + `Created Receiver: for partition: "${partitionId}" in consumer group: "${consumerGroup}" in event hub "${argv.hub}".` + ); log(`Created Sender: for partition: "${partitionId}" in event hub "${argv.hub}".`); const onMessage = (m: EventData) => { const mid = m.properties!.message_id as string; @@ -85,7 +90,10 @@ export async function handler(argv: any): Promise { log("^^^^^^^^^^ An error occured with the receiver: %o", err); }; const now = Date.now(); - client1.receive(partitionId, onMessage, onError, { consumerGroup: consumerGroup, eventPosition: EventPosition.fromEnqueuedTime(now) }); + client1.receive(partitionId, onMessage, onError, { + consumerGroup: consumerGroup, + eventPosition: EventPosition.fromEnqueuedTime(now), + }); log("Started receiving messages from enqueued time : '%s'.", new Date(now).toString()); await delay(3000); while (true) { @@ -95,8 +103,8 @@ export async function handler(argv: any): Promise { const m: EventData = { body: "Hello World Event Hub " + new Date().toString(), properties: { - message_id: messageId - } + message_id: messageId, + }, }; if (cache[messageId]) { log("Looks like message with id '%s' is already present in the cache %o", messageId, cache); @@ -104,13 +112,20 @@ export async function handler(argv: any): Promise { cache[messageId] = m; try { const delivery = await client2.send(m, partitionId); - log("Sent message with id '%s'. Delivery id '%d', tag '%s'.", - messageId, delivery.id, delivery.tag.toString()); + log( + "Sent message with id '%s'. Delivery id '%d', tag '%s'.", + messageId, + delivery.id, + delivery.tag.toString() + ); } catch (err) { log("An error occurred while sending the message with id '%s', %o", messageId, err); } - log("Sleeping for %d seconds. Next message will be sent around %s", - waitTime / 1000, new Date(nextIterationAt).toString()); + log( + "Sleeping for %d seconds. Next message will be sent around %s", + waitTime / 1000, + new Date(nextIterationAt).toString() + ); try { await delay(waitTime); } catch (err) {