From ba99925a6c80e996ad4e91c2ed0dd54334249a79 Mon Sep 17 00:00:00 2001 From: Amar Zavery Date: Fri, 5 Oct 2018 12:35:53 -0700 Subject: [PATCH] use EventHubConnectionConfig and remove dependency on amp-common and rhea-promise --- .travis.yml | 9 +++--- processor/changelog.md | 7 +++++ processor/lib/azureBlob.ts | 2 +- processor/lib/blobService.ts | 2 +- processor/lib/hostContext.ts | 16 +++++----- processor/lib/partitionScanner.ts | 2 +- processor/lib/util/constants.ts | 1 + processor/lib/util/utils.ts | 9 ++++++ processor/package-lock.json | 50 ++++++++++++++++--------------- processor/package.json | 26 ++++++++-------- processor/tests/eph.spec.ts | 3 +- processor/tests/iothub.spec.ts | 2 +- processor/tests/retry.spec.ts | 2 +- 13 files changed, 75 insertions(+), 56 deletions(-) diff --git a/.travis.yml b/.travis.yml index de15904..c519e9f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,12 @@ language: node_js node_js: + - "6" - "8" - "10" -before_install: - - cd client - +env: + - TEST_DIR=client + - TEST_DIR=processor script: - - npm test + - cd $TEST_DIR && npm install && npm test diff --git a/processor/changelog.md b/processor/changelog.md index ddf3c44..814ad2e 100644 --- a/processor/changelog.md +++ b/processor/changelog.md @@ -1,3 +1,10 @@ +## 2018-10-05 1.0.6 +- Remove `@azure/amqp-common` and `rhea-promise` as dependencies, since we use very little from +those libraries and there is a risk of having two instances of rhea in the dependency chain which +can cause problems while encoding types for filters. +- `HostContext.connectionConfig` is now of type `EventHubConnectionConfig`. +- Minimum dependency on `@azure/event-hubs: "^1.0.6"`. + ## 2018-10-01 1.0.5 - Bumping minimum version of @azure/event-hubs to "1.0.5". - Taking a dependency on "@azure/amqp-common" for reusing the common parts. diff --git a/processor/lib/azureBlob.ts b/processor/lib/azureBlob.ts index 26f84be..2360f19 100644 --- a/processor/lib/azureBlob.ts +++ b/processor/lib/azureBlob.ts @@ -3,7 +3,7 @@ import { BlobService, CreateContainerResult } from "./blobService"; import { BlobService as StorageBlobService } from "azure-storage"; -import { Dictionary } from "@azure/amqp-common"; +import { Dictionary } from "@azure/event-hubs"; /** * @ignore diff --git a/processor/lib/blobService.ts b/processor/lib/blobService.ts index ed6fcef..84defdd 100644 --- a/processor/lib/blobService.ts +++ b/processor/lib/blobService.ts @@ -1,11 +1,11 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +import { Dictionary } from "@azure/event-hubs"; import { createBlobService, BlobService as StorageBlobService, ServiceResponse } from "azure-storage"; import * as log from "./log"; import { validateType, getStorageError } from "./util/utils"; import { defaultMaximumExecutionTimeInMs } from "./util/constants"; -import { Dictionary } from "@azure/amqp-common"; const path = require("path-browserify"); /** * @ignore diff --git a/processor/lib/hostContext.ts b/processor/lib/hostContext.ts index 59f4496..a0362f4 100644 --- a/processor/lib/hostContext.ts +++ b/processor/lib/hostContext.ts @@ -3,10 +3,10 @@ import * as uuid from "uuid/v4"; import { - EventHubClient, EventPosition, TokenProvider, DefaultDataTransformer, - EventHubRuntimeInformation, EventHubPartitionRuntimeInformation, ConnectionConfig + EventHubClient, EventPosition, TokenProvider, DefaultDataTransformer, Dictionary, + EventHubRuntimeInformation, EventHubPartitionRuntimeInformation, EventHubConnectionConfig } from "@azure/event-hubs"; -import { Constants, Dictionary, getNewAsyncLock, AsyncLock } from "@azure/amqp-common"; +import * as AsyncLock from "async-lock"; import { LeaseManager } from "./leaseManager"; import { PumpManager } from "./pumpManager"; import { PartitionManager } from "./partitionManager"; @@ -25,7 +25,7 @@ import { import { maxLeaseDurationInSeconds, minLeaseDurationInSeconds, defaultLeaseRenewIntervalInSeconds, defaultLeaseDurationInSeconds, defaultStartupScanDelayInSeconds, packageInfo, userAgentPrefix, - defaultFastScanIntervalInSeconds, defaultSlowScanIntervalInSeconds + defaultFastScanIntervalInSeconds, defaultSlowScanIntervalInSeconds, defaultConsumerGroup } from "./util/constants"; /** @@ -39,7 +39,7 @@ export interface BaseHostContext { eventHubPath: string; storageContainerName?: string; eventHubConnectionString: string; - connectionConfig: ConnectionConfig; + connectionConfig: EventHubConnectionConfig; onEphError: OnEphError; leaseRenewInterval: number; leaseDuration: number; @@ -148,10 +148,10 @@ export namespace HostContext { const onEphErrorFunc: OnEphError = () => { // do nothing }; - const config = ConnectionConfig.create(options.eventHubConnectionString!, options.eventHubPath); + const config = EventHubConnectionConfig.create(options.eventHubConnectionString!, options.eventHubPath); // set defaults - if (!options.consumerGroup) options.consumerGroup = Constants.defaultConsumerGroup; + if (!options.consumerGroup) options.consumerGroup = defaultConsumerGroup; if (!options.eventHubPath) options.eventHubPath = config.entityPath; if (!options.leaseRenewInterval) options.leaseRenewInterval = defaultLeaseRenewIntervalInSeconds; if (!options.leaseDuration) options.leaseDuration = defaultLeaseDurationInSeconds; @@ -178,7 +178,7 @@ export namespace HostContext { const context: BaseHostContext = { hostName: hostName, - checkpointLock: getNewAsyncLock({ maxPending: 100000 }), + checkpointLock: new AsyncLock({ maxPending: 100000 }), checkpointLockId: `checkpoint-${uuid()}`, eventHubConnectionString: options.eventHubConnectionString!, connectionConfig: config, diff --git a/processor/lib/partitionScanner.ts b/processor/lib/partitionScanner.ts index bcdf481..f9ba30f 100644 --- a/processor/lib/partitionScanner.ts +++ b/processor/lib/partitionScanner.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -import { randomNumberFromInterval } from "@azure/amqp-common"; +import { randomNumberFromInterval } from "./util/utils"; import { HostContextWithPumpManager } from "./hostContext"; import { CompleteLease } from "./completeLease"; import { BaseLease } from "./baseLease"; diff --git a/processor/lib/util/constants.ts b/processor/lib/util/constants.ts index 969b7b4..51d48ad 100644 --- a/processor/lib/util/constants.ts +++ b/processor/lib/util/constants.ts @@ -16,6 +16,7 @@ export const leaseLost = "leaselost"; export const leaseIdMismatchWithLeaseOperation = "leaseidmismatchwithleaseoperation"; export const leaseIdMismatchWithBlobOperation = "leaseidmismatchwithbloboperation"; export const userAgentPrefix = "/js-event-processor-host"; +export const defaultConsumerGroup = "$default"; export const packageInfo = { name: "@azure/event-processor-host", version: "1.0.5" diff --git a/processor/lib/util/utils.ts b/processor/lib/util/utils.ts index 36edef6..f15f468 100644 --- a/processor/lib/util/utils.ts +++ b/processor/lib/util/utils.ts @@ -5,6 +5,15 @@ import * as log from "../log"; import { StorageError } from "azure-storage"; import { EPHDiagnosticInfo } from "../modelTypes"; +/** + * Generates a random number between the given interval + * @param {number} min Min number of the range (inclusive). + * @param {number} max Max number of the range (inclusive). + */ +export function randomNumberFromInterval(min: number, max: number): number { + return Math.floor(Math.random() * (max - min + 1) + min); +} + /** * Validates the type and requiredness of a given parameter. * @param paramName The name of the parameter. diff --git a/processor/package-lock.json b/processor/package-lock.json index 313ae43..d0d1ec8 100644 --- a/processor/package-lock.json +++ b/processor/package-lock.json @@ -1,13 +1,13 @@ { "name": "@azure/event-processor-host", - "version": "1.0.5", + "version": "1.0.6", "lockfileVersion": 1, "requires": true, "dependencies": { "@azure/amqp-common": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/@azure/amqp-common/-/amqp-common-0.1.3.tgz", - "integrity": "sha512-CxwWO35BlxwcROzShx7QylrY/PUc3LlyqQJd18hl9Vv957O4t5r3pyK5Xn15WfMDztXmR4UVZWSApB4jWCpvww==", + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/@azure/amqp-common/-/amqp-common-0.1.4.tgz", + "integrity": "sha512-EYNx4chSqy4Yjkd6h33Ju6hfwXnp16wAl/dWU01790WSqcu4BfYLNh6Z7WNdxR9QeDMzCPkc8u6V66cXlehTjA==", "requires": { "async-lock": "^1.1.3", "debug": "^3.1.0", @@ -19,9 +19,9 @@ } }, "@azure/event-hubs": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/@azure/event-hubs/-/event-hubs-1.0.5.tgz", - "integrity": "sha512-b3LHwtwB7ZDGhHpEe1i/MiatCRp0GEg9PBH9H4yayasDhaurQ3B7DJE36JMxZaW4zt63snopDcK38K61H/ZG3A==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@azure/event-hubs/-/event-hubs-1.0.6.tgz", + "integrity": "sha512-0Z6+jMqeo9kh9MRDsVBMOQw3Hr0BAs3kezGqKTDOnOLKEnLORcnHKni7NQOCnxhqcu6YsWuDmWO52OuAqSolzQ==", "requires": { "@azure/amqp-common": "^0.1.3", "async-lock": "^1.1.3", @@ -32,13 +32,6 @@ "rhea-promise": "^0.1.6", "tslib": "^1.9.3", "uuid": "^3.3.2" - }, - "dependencies": { - "is-buffer": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.2.tgz", - "integrity": "sha512-imvkm8cOGKeZ/NwkAd+FAURi0hsL9gr3kvdi0r3MnqChcOdPaQRIOQiOU+sD40XzUIe6nFmSHYtQjbkDvaQbEg==" - } } }, "@types/async-lock": { @@ -84,9 +77,9 @@ "dev": true }, "@types/node": { - "version": "8.10.31", - "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.31.tgz", - "integrity": "sha512-61Hi0+sBaxkJhcBuUaoDh91K8gJ3BjPHMorb8UdHmeluxUc9ZBGlYPd6ZxITuJhyv9D8JE32LthfWxyBITdUXQ==" + "version": "8.10.34", + "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.34.tgz", + "integrity": "sha512-alypNiaAEd0RBGXoWehJ2gchPYCITmw4CYBoB5nDlji8l8on7FsklfdfIs4DDmgpKLSX3OF3ha6SV+0W7cTzUA==" }, "@types/uuid": { "version": "3.4.4", @@ -657,9 +650,9 @@ "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, "is-buffer": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz", - "integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw==" + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.2.tgz", + "integrity": "sha512-imvkm8cOGKeZ/NwkAd+FAURi0hsL9gr3kvdi0r3MnqChcOdPaQRIOQiOU+sD40XzUIe6nFmSHYtQjbkDvaQbEg==" }, "is-stream": { "version": "1.1.0", @@ -779,7 +772,7 @@ }, "md5.js": { "version": "1.3.4", - "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.4.tgz", + "resolved": "http://registry.npmjs.org/md5.js/-/md5.js-1.3.4.tgz", "integrity": "sha1-6b296UogpawYsENA/Fdk1bCdkB0=", "requires": { "hash-base": "^3.0.0", @@ -1016,9 +1009,9 @@ } }, "rhea": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/rhea/-/rhea-0.3.2.tgz", - "integrity": "sha512-M/iuw38dVDcz8hmeZmzcgWcQ/40JLgaJW/hcNjHUXmUb02zUfsA9T0KE9qxQVW+Jxe5kHq/osLkbJ+fCcu4wzA==", + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/rhea/-/rhea-0.3.3.tgz", + "integrity": "sha512-kouSnd4EaODvbCvj3Af/UrVS+SH0xrQY3V9Q48ZZWg6k2rfWm74hUq5a8/9oXMKUMVLJTyUy1r5UzpcHc0g5cQ==", "requires": { "debug": "0.8.0 - 3.5.0" } @@ -1032,6 +1025,15 @@ "rhea": "^0.3.2" } }, + "rimraf": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", + "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", + "dev": true, + "requires": { + "glob": "^7.0.5" + } + }, "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", diff --git a/processor/package.json b/processor/package.json index dbbecc0..5b795fb 100644 --- a/processor/package.json +++ b/processor/package.json @@ -1,43 +1,43 @@ { "name": "@azure/event-processor-host", - "version": "1.0.5", + "version": "1.0.6", "description": "Azure Event Processor Host (Event Hubs) SDK for JS.", "author": "Microsoft Corporation", "license": "MIT", "main": "./dist/lib/index.js", "types": "./typings/lib/index.d.ts", "dependencies": { - "@azure/event-hubs": "^1.0.5", - "@azure/amqp-common": "^0.1.3", - "rhea-promise": "^0.1.6", + "@azure/event-hubs": "^1.0.6", "azure-storage": "^2.10.1", "async-lock": "^1.1.3", "debug": "^3.1.0", "ms-rest-azure": "^2.5.7", + "path-browserify": "^1.0.0", "tslib": "^1.9.3", - "uuid": "^3.3.2", - "path-browserify": "^1.0.0" + "uuid": "^3.3.2" }, "devDependencies": { "@types/async-lock": "^1.1.0", - "@types/uuid": "^3.4.3", - "@types/debug": "^0.0.30", - "@types/node": "^8.0.37", "@types/chai": "^4.1.4", "@types/chai-as-promised": "^7.1.0", + "@types/debug": "^0.0.30", + "@types/dotenv": "^4.0.3", "@types/mocha": "^5.2.5", + "@types/node": "^8.0.37", + "@types/uuid": "^3.4.3", "chai": "^4.1.2", "chai-as-promised": "^7.1.1", + "dotenv": "^5.0.1", "mocha": "^5.2.0", + "rimraf": "^2.6.2", "ts-node": "^7.0.0", "tslint": "^5.11.0", - "typescript": "^2.9.2", - "dotenv": "^5.0.1", - "@types/dotenv": "^4.0.3" + "typescript": "^2.9.2" }, "scripts": { "tslint": "tslint -p . -c tslint.json --exclude examples/**/*.ts --exclude tests/**/*.ts", "tsc": "tsc", + "prebuild": "rimraf dist && rimraf typings", "build": "npm run tslint && npm run tsc", "test": "npm run build", "unit": "mocha -r ts-node/register -t 50000 ./tests/**/*.spec.ts --exit", @@ -51,4 +51,4 @@ "bugs": { "url": "http://github.com/Azure/azure-event-hubs-node/issues" } -} \ No newline at end of file +} diff --git a/processor/tests/eph.spec.ts b/processor/tests/eph.spec.ts index 91a53bc..6ee1062 100644 --- a/processor/tests/eph.spec.ts +++ b/processor/tests/eph.spec.ts @@ -9,10 +9,9 @@ chai.use(chaiAsPromised); import * as debugModule from "debug"; const should = chai.should(); const debug = debugModule("azure:eph:eph-spec"); -import { EventHubClient, EventData, EventPosition, delay } from "@azure/event-hubs"; +import { EventHubClient, EventData, EventPosition, delay, Dictionary } from "@azure/event-hubs"; import * as dotenv from "dotenv"; import { PartitionContext, OnReceivedMessage, EventProcessorHost, OnReceivedError } from "../lib"; -import { Dictionary } from "@azure/amqp-common"; dotenv.config(); describe("EPH", function () { diff --git a/processor/tests/iothub.spec.ts b/processor/tests/iothub.spec.ts index 8abaabb..cf34285 100644 --- a/processor/tests/iothub.spec.ts +++ b/processor/tests/iothub.spec.ts @@ -12,7 +12,7 @@ const debug = debugModule("azure:eph:iothub-spec"); import { EventPosition, OnReceivedError, PartitionContext, EventData, OnReceivedMessage, EventProcessorHost } from "../lib"; -import { delay } from "@azure/amqp-common"; +import { delay } from "@azure/event-hubs"; dotenv.config(); describe("EPH with iothub connection string", function () { diff --git a/processor/tests/retry.spec.ts b/processor/tests/retry.spec.ts index c22f275..0630dd2 100644 --- a/processor/tests/retry.spec.ts +++ b/processor/tests/retry.spec.ts @@ -5,7 +5,7 @@ import "mocha"; import * as chai from "chai"; import { retry, RetryConfig } from "../lib/util/utils"; import * as chaiAsPromised from "chai-as-promised"; -import { delay } from "@azure/amqp-common"; +import { delay } from "@azure/event-hubs"; chai.use(chaiAsPromised); import * as debugModule from "debug"; const should = chai.should();